Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5393)

Unified Diff: chrome/browser/media_gallery/linux/mtp_recursive_device_object_enumerator.cc

Issue 11855005: [Linux, Media Gallery] Fix MTPRecursiveDeviceObjectEnumerator to recursively enumerate all the medi… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed review comments Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/media_gallery/linux/mtp_recursive_device_object_enumerator.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/media_gallery/linux/mtp_recursive_device_object_enumerator.cc
diff --git a/chrome/browser/media_gallery/linux/mtp_recursive_device_object_enumerator.cc b/chrome/browser/media_gallery/linux/mtp_recursive_device_object_enumerator.cc
index 2b5ceebea0759b0b0c5e0735df5953bbf83c3388..0e524d3073580a76f49e17eefeb6ac2edc6eac51 100644
--- a/chrome/browser/media_gallery/linux/mtp_recursive_device_object_enumerator.cc
+++ b/chrome/browser/media_gallery/linux/mtp_recursive_device_object_enumerator.cc
@@ -19,12 +19,11 @@ MTPRecursiveDeviceObjectEnumerator::MTPRecursiveDeviceObjectEnumerator(
base::WaitableEvent* shutdown_event)
: device_handle_(handle),
media_task_runner_(task_runner),
- file_entries_(entries),
- file_entry_iter_(file_entries_.begin()),
on_task_completed_event_(task_completed_event),
on_shutdown_event_(shutdown_event) {
DCHECK(on_task_completed_event_);
DCHECK(on_shutdown_event_);
+ DCHECK(!entries.empty());
current_enumerator_.reset(new MTPDeviceObjectEnumerator(entries));
}
@@ -37,29 +36,28 @@ FilePath MTPRecursiveDeviceObjectEnumerator::Next() {
return FilePath();
}
- FilePath path = current_enumerator_->Next();
- if (!path.empty())
- return path;
-
- // We reached the end.
- if (file_entry_iter_ == file_entries_.end())
+ MTPDeviceObjectEnumerator* enumerator =
+ static_cast<MTPDeviceObjectEnumerator*>(current_enumerator_.get());
+ if (!enumerator) {
Lei Zhang 2013/01/12 00:08:36 I fail to see how this helps. How does |enumerator
kmadhusu 2013/01/12 01:03:53 Removed this check and modified code to handle the
+ // This should not ever be null. If it happens this function is not used
+ // correctly.
+ // Correct usage:
+ // while (!enumerator->Next().empty()) {
+ // // doSomething();
+ // }
return FilePath();
+ }
- // Enumerate subdirectories of the next media file entry.
- MtpFileEntry next_file_entry = *file_entry_iter_;
- ++file_entry_iter_;
+ if (!enumerator->HasMoreEntries())
+ UpdateEnumeratorToTraverseSubdirectory();
- // Create a MTPReadDirectoryWorker object to enumerate sub directories.
- scoped_refptr<MTPReadDirectoryWorker> worker(new MTPReadDirectoryWorker(
- device_handle_, next_file_entry.item_id(), media_task_runner_,
- on_task_completed_event_, on_shutdown_event_));
- worker->Run();
- if (!worker->get_file_entries().empty()) {
- current_enumerator_.reset(
- new MTPDeviceObjectEnumerator(worker->get_file_entries()));
- } else {
- current_enumerator_.reset(
- new fileapi::FileSystemFileUtil::EmptyFileEnumerator());
+ if (IsDirectory()) {
+ // If the current entry is a directory, add it to
+ // |untraversed_directory_entry_ids_| to scan after scanning this directory.
+ DirectoryEntryId dir_entry_id;
+ if (static_cast<MTPDeviceObjectEnumerator*>(
+ current_enumerator_.get())->GetEntryId(&dir_entry_id))
+ untraversed_directory_entry_ids_.push(dir_entry_id);
}
return current_enumerator_->Next();
}
@@ -76,4 +74,26 @@ base::Time MTPRecursiveDeviceObjectEnumerator::LastModifiedTime() {
return current_enumerator_->LastModifiedTime();
}
+void MTPRecursiveDeviceObjectEnumerator::
+UpdateEnumeratorToTraverseSubdirectory() {
+ while (!untraversed_directory_entry_ids_.empty()) {
+ // Create a MTPReadDirectoryWorker object to enumerate sub directories.
+ DirectoryEntryId dir_entry_id = untraversed_directory_entry_ids_.front();
+ untraversed_directory_entry_ids_.pop();
+ scoped_refptr<MTPReadDirectoryWorker> worker(new MTPReadDirectoryWorker(
+ device_handle_, dir_entry_id, media_task_runner_,
+ on_task_completed_event_, on_shutdown_event_));
+ worker->Run();
+ if (!worker->get_file_entries().empty()) {
+ current_enumerator_.reset(
+ new MTPDeviceObjectEnumerator(worker->get_file_entries()));
+ return;
+ }
+ }
+
+ // Reached the end. Traversed all the sub directories.
+ current_enumerator_.reset(
+ new fileapi::FileSystemFileUtil::EmptyFileEnumerator());
+}
+
} // namespace chrome
« no previous file with comments | « chrome/browser/media_gallery/linux/mtp_recursive_device_object_enumerator.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698