Chromium Code Reviews| Index: chrome/browser/media_gallery/win/recursive_mtp_device_object_enumerator.cc |
| diff --git a/chrome/browser/media_gallery/win/recursive_mtp_device_object_enumerator.cc b/chrome/browser/media_gallery/win/recursive_mtp_device_object_enumerator.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..35652c37f7f84fcfd400a4f0ca838d23deabf94b |
| --- /dev/null |
| +++ b/chrome/browser/media_gallery/win/recursive_mtp_device_object_enumerator.cc |
| @@ -0,0 +1,74 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| +// |
| +// RecursiveMTPDeviceObjectEnumerator implementation. |
| + |
| +#include "chrome/browser/media_gallery/win/recursive_mtp_device_object_enumerator.h" |
| + |
| +#include "base/file_path.h" |
| +#include "base/threading/thread_restrictions.h" |
| +#include "chrome/browser/media_gallery/win/mtp_device_object_entry.h" |
| +#include "chrome/browser/media_gallery/win/mtp_device_object_enumerator.h" |
| +#include "chrome/browser/media_gallery/win/mtp_device_operations_util.h" |
| +#include "content/public/browser/browser_thread.h" |
| + |
| +namespace chrome { |
| + |
| +RecursiveMTPDeviceObjectEnumerator::RecursiveMTPDeviceObjectEnumerator( |
| + IPortableDevice* device, |
| + const MTPDeviceObjectEntries& entries) |
| + : device_(device), |
| + object_entries_(entries), |
| + object_entry_iter_(object_entries_.begin()) { |
| + base::ThreadRestrictions::AssertIOAllowed(); |
| + current_enumerator_.reset(new MTPDeviceObjectEnumerator(entries)); |
| +} |
| + |
| +RecursiveMTPDeviceObjectEnumerator::~RecursiveMTPDeviceObjectEnumerator() { |
| + DCHECK(thread_checker_.CalledOnValidThread()); |
| +} |
| + |
| +FilePath RecursiveMTPDeviceObjectEnumerator::Next() { |
| + DCHECK(thread_checker_.CalledOnValidThread()); |
| + FilePath path = current_enumerator_->Next(); |
| + if (!path.empty()) |
| + return path; |
| + |
| + // We reached the end. |
| + if (object_entry_iter_ == object_entries_.end()) |
| + return FilePath(); |
| + |
| + // Enumerate subdirectories of the next media object entry. |
| + MTPDeviceObjectEntry next_object_entry = *object_entry_iter_; |
|
Ryan Sleevi
2013/01/09 20:22:25
nit: *(object_entry_iter_++)
kmadhusu
2013/01/10 04:59:19
Done.
|
| + ++object_entry_iter_; |
| + |
| + MTPDeviceObjectEntries object_entries; |
| + if (!GetDirectoryEntries(device_.get(), next_object_entry.object_id, |
| + &object_entries) || |
| + object_entries.empty()) { |
| + current_enumerator_.reset( |
| + new fileapi::FileSystemFileUtil::EmptyFileEnumerator()); |
| + } else { |
| + current_enumerator_.reset( |
| + new MTPDeviceObjectEnumerator(object_entries)); |
|
Ryan Sleevi
2013/01/09 20:22:25
Why do you not go further recursively?
kmadhusu
2013/01/10 04:59:19
Good catch. I had a recursive enumerator in my tes
kmadhusu
2013/01/10 23:37:56
Fixed.
|
| + } |
| + return current_enumerator_->Next(); |
| +} |
| + |
| +int64 RecursiveMTPDeviceObjectEnumerator::Size() { |
| + DCHECK(thread_checker_.CalledOnValidThread()); |
| + return current_enumerator_->Size(); |
| +} |
| + |
| +bool RecursiveMTPDeviceObjectEnumerator::IsDirectory() { |
| + DCHECK(thread_checker_.CalledOnValidThread()); |
| + return current_enumerator_->IsDirectory(); |
| +} |
| + |
| +base::Time RecursiveMTPDeviceObjectEnumerator::LastModifiedTime() { |
| + DCHECK(thread_checker_.CalledOnValidThread()); |
| + return current_enumerator_->LastModifiedTime(); |
| +} |
| + |
| +} // namespace chrome |