| 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();
|
| +
|
| + // 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()) {
|
| + 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
|
|
|