| 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/sequenced_worker_pool.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 object_entries_(entries), |
| 23 object_entry_iter_(object_entries_.begin()) { |
| 24 DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); |
| 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 FilePath path = current_enumerator_->Next(); |
| 35 if (!path.empty()) |
| 36 return path; |
| 37 |
| 38 // We reached the end. |
| 39 if (object_entry_iter_ == object_entries_.end()) |
| 40 return FilePath(); |
| 41 |
| 42 // Enumerate subdirectories of the next media object entry. |
| 43 MTPDeviceObjectEntry next_object_entry = *object_entry_iter_; |
| 44 ++object_entry_iter_; |
| 45 |
| 46 MTPDeviceObjectEntries object_entries; |
| 47 bool success = MTPDeviceOperationsUtil::GetDirectoryEntries( |
| 48 device_.get(), next_object_entry.object_id, &object_entries); |
| 49 |
| 50 if (!success || object_entries.empty()) { |
| 51 current_enumerator_.reset( |
| 52 new fileapi::FileSystemFileUtil::EmptyFileEnumerator()); |
| 53 } else { |
| 54 current_enumerator_.reset( |
| 55 new MTPDeviceObjectEnumerator(object_entries)); |
| 56 } |
| 57 return current_enumerator_->Next(); |
| 58 } |
| 59 |
| 60 int64 RecursiveMTPDeviceObjectEnumerator::Size() { |
| 61 DCHECK(thread_checker_.CalledOnValidThread()); |
| 62 return current_enumerator_->Size(); |
| 63 } |
| 64 |
| 65 bool RecursiveMTPDeviceObjectEnumerator::IsDirectory() { |
| 66 DCHECK(thread_checker_.CalledOnValidThread()); |
| 67 return current_enumerator_->IsDirectory(); |
| 68 } |
| 69 |
| 70 base::Time RecursiveMTPDeviceObjectEnumerator::LastModifiedTime() { |
| 71 DCHECK(thread_checker_.CalledOnValidThread()); |
| 72 return current_enumerator_->LastModifiedTime(); |
| 73 } |
| 74 |
| 75 } // namespace chrome |
| OLD | NEW |