| 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 object_entries_(entries), |
| 23 object_entry_iter_(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 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 if (!GetDirectoryEntries(device_.get(), next_object_entry.object_id, |
| 48 &object_entries) || |
| 49 object_entries.empty()) { |
| 50 current_enumerator_.reset( |
| 51 new fileapi::FileSystemFileUtil::EmptyFileEnumerator()); |
| 52 } else { |
| 53 current_enumerator_.reset( |
| 54 new MTPDeviceObjectEnumerator(object_entries)); |
| 55 } |
| 56 return current_enumerator_->Next(); |
| 57 } |
| 58 |
| 59 int64 RecursiveMTPDeviceObjectEnumerator::Size() { |
| 60 DCHECK(thread_checker_.CalledOnValidThread()); |
| 61 return current_enumerator_->Size(); |
| 62 } |
| 63 |
| 64 bool RecursiveMTPDeviceObjectEnumerator::IsDirectory() { |
| 65 DCHECK(thread_checker_.CalledOnValidThread()); |
| 66 return current_enumerator_->IsDirectory(); |
| 67 } |
| 68 |
| 69 base::Time RecursiveMTPDeviceObjectEnumerator::LastModifiedTime() { |
| 70 DCHECK(thread_checker_.CalledOnValidThread()); |
| 71 return current_enumerator_->LastModifiedTime(); |
| 72 } |
| 73 |
| 74 } // namespace chrome |
| OLD | NEW |