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

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: 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 unified diff | Download patch | Annotate | Revision Log
« 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
11 11
12 namespace chrome { 12 namespace chrome {
13 13
14 MTPRecursiveDeviceObjectEnumerator::MTPRecursiveDeviceObjectEnumerator( 14 MTPRecursiveDeviceObjectEnumerator::MTPRecursiveDeviceObjectEnumerator(
15 const std::string& handle, 15 const std::string& handle,
16 base::SequencedTaskRunner* task_runner, 16 base::SequencedTaskRunner* task_runner,
17 const std::vector<MtpFileEntry>& entries, 17 const std::vector<MtpFileEntry>& entries,
18 base::WaitableEvent* task_completed_event, 18 base::WaitableEvent* task_completed_event,
19 base::WaitableEvent* shutdown_event) 19 base::WaitableEvent* shutdown_event)
20 : device_handle_(handle), 20 : device_handle_(handle),
21 media_task_runner_(task_runner), 21 media_task_runner_(task_runner),
22 file_entries_(entries),
23 file_entry_iter_(file_entries_.begin()),
24 on_task_completed_event_(task_completed_event), 22 on_task_completed_event_(task_completed_event),
25 on_shutdown_event_(shutdown_event) { 23 on_shutdown_event_(shutdown_event) {
26 DCHECK(on_task_completed_event_); 24 DCHECK(on_task_completed_event_);
27 DCHECK(on_shutdown_event_); 25 DCHECK(on_shutdown_event_);
Lei Zhang 2013/01/11 23:25:24 Can you also add a DCHECK to make sure |entries| i
kmadhusu 2013/01/11 23:52:45 Done.
28 current_enumerator_.reset(new MTPDeviceObjectEnumerator(entries)); 26 current_enumerator_.reset(new MTPDeviceObjectEnumerator(entries));
29 } 27 }
30 28
31 MTPRecursiveDeviceObjectEnumerator::~MTPRecursiveDeviceObjectEnumerator() { 29 MTPRecursiveDeviceObjectEnumerator::~MTPRecursiveDeviceObjectEnumerator() {
32 } 30 }
33 31
34 FilePath MTPRecursiveDeviceObjectEnumerator::Next() { 32 FilePath MTPRecursiveDeviceObjectEnumerator::Next() {
35 if (on_shutdown_event_->IsSignaled()) { 33 if (on_shutdown_event_->IsSignaled()) {
36 // Process is in shut down mode. 34 // Process is in shut down mode.
37 return FilePath(); 35 return FilePath();
38 } 36 }
39 37
40 FilePath path = current_enumerator_->Next(); 38 if (!static_cast<MTPDeviceObjectEnumerator*>(
41 if (!path.empty()) 39 current_enumerator_.get())->HasMoreEntries())
Lei Zhang 2013/01/11 23:25:24 If you call Next() after you reach the end, you ar
kmadhusu 2013/01/11 23:52:45 If current_enumerator is set to EmptyFileEnumerato
Lei Zhang 2013/01/12 00:08:35 It should never happen, but it can happen. If it d
42 return path; 40 UpdateEnumeratorToTraverseSubdirectory();
43 41
44 // We reached the end. 42 if (IsDirectory()) {
45 if (file_entry_iter_ == file_entries_.end()) 43 // If the current entry is a directory, add it to
46 return FilePath(); 44 // |untraversed_directory_entry_ids_| to scan after scanning this directory.
47 45 DirectoryEntryId dir_entry_id;
48 // Enumerate subdirectories of the next media file entry. 46 if (static_cast<MTPDeviceObjectEnumerator*>(
49 MtpFileEntry next_file_entry = *file_entry_iter_; 47 current_enumerator_.get())->GetEntryId(&dir_entry_id))
50 ++file_entry_iter_; 48 untraversed_directory_entry_ids_.push(dir_entry_id);
51
52 // Create a MTPReadDirectoryWorker object to enumerate sub directories.
53 scoped_refptr<MTPReadDirectoryWorker> worker(new MTPReadDirectoryWorker(
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()));
60 } else {
61 current_enumerator_.reset(
62 new fileapi::FileSystemFileUtil::EmptyFileEnumerator());
63 } 49 }
64 return current_enumerator_->Next(); 50 return current_enumerator_->Next();
65 } 51 }
66 52
67 int64 MTPRecursiveDeviceObjectEnumerator::Size() { 53 int64 MTPRecursiveDeviceObjectEnumerator::Size() {
68 return current_enumerator_->Size(); 54 return current_enumerator_->Size();
69 } 55 }
70 56
71 bool MTPRecursiveDeviceObjectEnumerator::IsDirectory() { 57 bool MTPRecursiveDeviceObjectEnumerator::IsDirectory() {
72 return current_enumerator_->IsDirectory(); 58 return current_enumerator_->IsDirectory();
73 } 59 }
74 60
75 base::Time MTPRecursiveDeviceObjectEnumerator::LastModifiedTime() { 61 base::Time MTPRecursiveDeviceObjectEnumerator::LastModifiedTime() {
76 return current_enumerator_->LastModifiedTime(); 62 return current_enumerator_->LastModifiedTime();
77 } 63 }
78 64
65 void MTPRecursiveDeviceObjectEnumerator::
66 UpdateEnumeratorToTraverseSubdirectory() {
67 bool has_more_entries = false;
68 while (!untraversed_directory_entry_ids_.empty()) {
69 // Create a MTPReadDirectoryWorker object to enumerate sub directories.
70 DirectoryEntryId dir_entry_id = untraversed_directory_entry_ids_.front();
71 untraversed_directory_entry_ids_.pop();
72 scoped_refptr<MTPReadDirectoryWorker> worker(new MTPReadDirectoryWorker(
73 device_handle_, dir_entry_id, media_task_runner_,
74 on_task_completed_event_, on_shutdown_event_));
75 worker->Run();
76 if (!worker->get_file_entries().empty()) {
77 current_enumerator_.reset(
78 new MTPDeviceObjectEnumerator(worker->get_file_entries()));
79 has_more_entries = true;
80 break;
Lei Zhang 2013/01/11 23:25:24 you can just return here and get rid of |has_more
kmadhusu 2013/01/11 23:52:45 Done.
81 }
82 }
83
84 if (!has_more_entries) {
85 // Reached the end. Traversed all the sub directories.
86 current_enumerator_.reset(
87 new fileapi::FileSystemFileUtil::EmptyFileEnumerator());
88 }
89 }
90
79 } // namespace chrome 91 } // namespace chrome
OLDNEW
« 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