Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 // | |
| 5 // RecursiveMTPDeviceObjectEnumerator implementation. | |
| 6 | |
| 7 #include "chrome/browser/media_gallery/win/recursive_mtp_device_object_enumerato r.h" | |
| 8 | |
| 9 #include "base/file_path.h" | |
| 10 #include "base/threading/thread_restrictions.h" | |
| 11 #include "chrome/browser/media_gallery/win/mtp_device_object_entry.h" | |
| 12 #include "chrome/browser/media_gallery/win/mtp_device_object_enumerator.h" | |
| 13 #include "chrome/browser/media_gallery/win/mtp_device_operations_util.h" | |
| 14 #include "content/public/browser/browser_thread.h" | |
| 15 | |
| 16 namespace chrome { | |
| 17 | |
| 18 RecursiveMTPDeviceObjectEnumerator::RecursiveMTPDeviceObjectEnumerator( | |
| 19 IPortableDevice* device, | |
| 20 const MTPDeviceObjectEntries& entries) | |
| 21 : device_(device), | |
| 22 curr_object_entries_(entries), | |
| 23 object_entry_iter_(curr_object_entries_.begin()) { | |
| 24 base::ThreadRestrictions::AssertIOAllowed(); | |
| 25 current_enumerator_.reset(new MTPDeviceObjectEnumerator(entries)); | |
| 26 } | |
| 27 | |
| 28 RecursiveMTPDeviceObjectEnumerator::~RecursiveMTPDeviceObjectEnumerator() { | |
| 29 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 30 } | |
| 31 | |
| 32 FilePath RecursiveMTPDeviceObjectEnumerator::Next() { | |
| 33 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 34 MaybeUpdateCurrentObjectList(); | |
| 35 if (curr_object_entries_.empty()) | |
| 36 return FilePath(); | |
| 37 | |
| 38 DCHECK(object_entry_iter_ != curr_object_entries_.end()); | |
| 39 MTPDeviceObjectEntry current_object_entry = *(object_entry_iter_++); | |
|
Lei Zhang
2013/01/14 23:25:30
const ref
kmadhusu
2013/01/15 19:08:17
Done.
| |
| 40 if (current_object_entry.is_directory) { | |
| 41 // If |current_object_entry| is a directory, add it to | |
| 42 // |unparsed_directory_object_ids_| to scan after scanning this directory. | |
| 43 unparsed_directory_object_ids_.push(current_object_entry.object_id); | |
| 44 } | |
| 45 return current_enumerator_->Next(); | |
| 46 } | |
| 47 | |
| 48 int64 RecursiveMTPDeviceObjectEnumerator::Size() { | |
| 49 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 50 return current_enumerator_->Size(); | |
| 51 } | |
| 52 | |
| 53 bool RecursiveMTPDeviceObjectEnumerator::IsDirectory() { | |
| 54 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 55 return current_enumerator_->IsDirectory(); | |
| 56 } | |
| 57 | |
| 58 base::Time RecursiveMTPDeviceObjectEnumerator::LastModifiedTime() { | |
| 59 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 60 return current_enumerator_->LastModifiedTime(); | |
| 61 } | |
| 62 | |
| 63 void RecursiveMTPDeviceObjectEnumerator::MaybeUpdateCurrentObjectList() { | |
| 64 if (object_entry_iter_ != curr_object_entries_.end()) | |
| 65 return; | |
| 66 | |
| 67 curr_object_entries_.clear(); | |
| 68 while (curr_object_entries_.empty() && | |
| 69 !unparsed_directory_object_ids_.empty()) { | |
| 70 DirectoryObjectId object_id = unparsed_directory_object_ids_.front(); | |
| 71 unparsed_directory_object_ids_.pop(); | |
| 72 if (media_transfer_protocol::GetDirectoryEntries(device_.get(), object_id, | |
| 73 &curr_object_entries_) && | |
| 74 !curr_object_entries_.empty()) { | |
| 75 current_enumerator_.reset( | |
| 76 new MTPDeviceObjectEnumerator(curr_object_entries_)); | |
| 77 break; | |
| 78 } | |
| 79 } | |
| 80 | |
| 81 if (curr_object_entries_.empty()) { | |
| 82 // Parsed all the objects. | |
| 83 current_enumerator_.reset( | |
| 84 new fileapi::FileSystemFileUtil::EmptyFileEnumerator()); | |
| 85 } | |
| 86 object_entry_iter_ = curr_object_entries_.begin(); | |
| 87 } | |
| 88 | |
| 89 } // namespace chrome | |
| OLD | NEW |