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

Side by Side 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: 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/media_gallery/linux/mtp_recursive_device_object_enumera tor.h" 5 #include "chrome/browser/media_gallery/linux/mtp_recursive_device_object_enumera tor.h"
6 6
7 #include "base/sequenced_task_runner.h" 7 #include "base/sequenced_task_runner.h"
8 #include "base/synchronization/waitable_event.h" 8 #include "base/synchronization/waitable_event.h"
9 #include "chrome/browser/media_gallery/linux/mtp_device_object_enumerator.h" 9 #include "chrome/browser/media_gallery/linux/mtp_device_object_enumerator.h"
10 #include "chrome/browser/media_gallery/linux/mtp_read_directory_worker.h" 10 #include "chrome/browser/media_gallery/linux/mtp_read_directory_worker.h"
(...skipping 19 matching lines...) Expand all
30 30
31 MTPRecursiveDeviceObjectEnumerator::~MTPRecursiveDeviceObjectEnumerator() { 31 MTPRecursiveDeviceObjectEnumerator::~MTPRecursiveDeviceObjectEnumerator() {
32 } 32 }
33 33
34 FilePath MTPRecursiveDeviceObjectEnumerator::Next() { 34 FilePath MTPRecursiveDeviceObjectEnumerator::Next() {
35 if (on_shutdown_event_->IsSignaled()) { 35 if (on_shutdown_event_->IsSignaled()) {
36 // Process is in shut down mode. 36 // Process is in shut down mode.
37 return FilePath(); 37 return FilePath();
38 } 38 }
39 39
40 FilePath path = current_enumerator_->Next(); 40 MaybeUpdateCurrentFileEntryList();
Lei Zhang 2013/01/11 06:35:44 side note: functions named "MaybeSomething" sounds
kmadhusu 2013/01/11 22:34:22 Renamed the function and updated the function defi
41 if (!path.empty()) 41 if (file_entries_.empty())
42 return path;
43
44 // We reached the end.
45 if (file_entry_iter_ == file_entries_.end())
46 return FilePath(); 42 return FilePath();
47 43
48 // Enumerate subdirectories of the next media file entry. 44 DCHECK(file_entry_iter_ != file_entries_.end());
49 MtpFileEntry next_file_entry = *file_entry_iter_; 45 MtpFileEntry curr_file_entry = *(file_entry_iter_++);
50 ++file_entry_iter_; 46 if (curr_file_entry.file_type() == MtpFileEntry::FILE_TYPE_FOLDER) {
51 47 // If |curr_file_entry| is a directory, add it to
52 // Create a MTPReadDirectoryWorker object to enumerate sub directories. 48 // |unparsed_directory_entry_ids_| to scan after scanning this directory.
53 scoped_refptr<MTPReadDirectoryWorker> worker(new MTPReadDirectoryWorker( 49 unparsed_directory_entry_ids_.push(curr_file_entry.item_id());
54 device_handle_, next_file_entry.item_id(), media_task_runner_,
55 on_task_completed_event_, on_shutdown_event_));
56 worker->Run();
57 if (!worker->get_file_entries().empty()) {
58 current_enumerator_.reset(
59 new MTPDeviceObjectEnumerator(worker->get_file_entries()));
kmadhusu 2013/01/11 04:51:39 This code was listing only the top 2 levels of the
60 } else {
61 current_enumerator_.reset(
62 new fileapi::FileSystemFileUtil::EmptyFileEnumerator());
63 } 50 }
64 return current_enumerator_->Next(); 51 return current_enumerator_->Next();
65 } 52 }
66 53
67 int64 MTPRecursiveDeviceObjectEnumerator::Size() { 54 int64 MTPRecursiveDeviceObjectEnumerator::Size() {
68 return current_enumerator_->Size(); 55 return current_enumerator_->Size();
69 } 56 }
70 57
71 bool MTPRecursiveDeviceObjectEnumerator::IsDirectory() { 58 bool MTPRecursiveDeviceObjectEnumerator::IsDirectory() {
72 return current_enumerator_->IsDirectory(); 59 return current_enumerator_->IsDirectory();
73 } 60 }
74 61
75 base::Time MTPRecursiveDeviceObjectEnumerator::LastModifiedTime() { 62 base::Time MTPRecursiveDeviceObjectEnumerator::LastModifiedTime() {
76 return current_enumerator_->LastModifiedTime(); 63 return current_enumerator_->LastModifiedTime();
77 } 64 }
78 65
66 void MTPRecursiveDeviceObjectEnumerator::MaybeUpdateCurrentFileEntryList() {
67 if (file_entry_iter_ != file_entries_.end())
68 return;
69
70 file_entries_.clear();
71 while (file_entries_.empty() &&
72 !unparsed_directory_entry_ids_.empty()) {
73 // Create a MTPReadDirectoryWorker object to enumerate sub directories.
74 DirectoryEntryId dir_entry_id = unparsed_directory_entry_ids_.front();
75 unparsed_directory_entry_ids_.pop();
76 scoped_refptr<MTPReadDirectoryWorker> worker(new MTPReadDirectoryWorker(
77 device_handle_, dir_entry_id, media_task_runner_,
78 on_task_completed_event_, on_shutdown_event_));
79 worker->Run();
80 file_entries_ = worker->get_file_entries();
81 if (!file_entries_.empty()) {
82 current_enumerator_.reset(new MTPDeviceObjectEnumerator(file_entries_));
83 break;
84 }
85 }
86
87 if (file_entries_.empty()) {
88 // Reached the end. Parsed all the sub directories.
89 current_enumerator_.reset(
90 new fileapi::FileSystemFileUtil::EmptyFileEnumerator());
91 }
92 file_entry_iter_ = file_entries_.begin();
93 }
94
79 } // namespace chrome 95 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698