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..80857180968d792c8eb65ab83f9f477f26f3555c |
| --- /dev/null |
| +++ b/chrome/browser/media_gallery/win/recursive_mtp_device_object_enumerator.cc |
| @@ -0,0 +1,75 @@ |
| +// 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/sequenced_worker_pool.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()) { |
| + DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); |
| + 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(); |
|
Peter Kasting
2012/11/01 21:38:37
Same question as before about whether we're suppos
kmadhusu
2012/11/02 03:27:16
This function is mainly called from FileUtilHelper
|
| + |
| + // Enumerate subdirectories of the next media object entry. |
| + MTPDeviceObjectEntry next_object_entry = *object_entry_iter_; |
| + ++object_entry_iter_; |
| + |
| + MTPDeviceObjectEntries object_entries; |
| + bool success = MTPDeviceOperationsUtil::GetDirectoryEntries( |
| + device_.get(), next_object_entry.object_id(), &object_entries); |
| + |
| + if (!success || object_entries.empty()) { |
|
Peter Kasting
2012/11/01 21:38:37
Nit: Or just:
if (!MTPDeviceOperationsUtil::Get
kmadhusu
2012/11/02 03:27:16
I would like to use the "bool ret = GetFunc()" for
Peter Kasting
2012/11/02 04:08:11
Again, why? I may agree with you if you tell me y
kmadhusu
2012/11/29 23:58:14
There is no strong reason. It was easier for me to
|
| + current_enumerator_.reset( |
| + new fileapi::FileSystemFileUtil::EmptyFileEnumerator()); |
| + } else { |
| + current_enumerator_.reset( |
| + new MTPDeviceObjectEnumerator(object_entries)); |
| + } |
| + 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 |