| Index: chrome/browser/media_gallery/linux/recursive_mtp_device_object_enumerator.cc
|
| diff --git a/chrome/browser/media_gallery/linux/recursive_mtp_device_object_enumerator.cc b/chrome/browser/media_gallery/linux/recursive_mtp_device_object_enumerator.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..9a133fe9745ccb3076b65c741d81a214f39202ea
|
| --- /dev/null
|
| +++ b/chrome/browser/media_gallery/linux/recursive_mtp_device_object_enumerator.cc
|
| @@ -0,0 +1,79 @@
|
| +// 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.
|
| +
|
| +#include "chrome/browser/media_gallery/linux/recursive_mtp_device_object_enumerator.h"
|
| +
|
| +#include "base/sequenced_task_runner.h"
|
| +#include "base/synchronization/waitable_event.h"
|
| +#include "chrome/browser/media_gallery/linux/mtp_device_object_enumerator.h"
|
| +#include "chrome/browser/media_gallery/linux/read_mtp_directory_worker.h"
|
| +
|
| +namespace chrome {
|
| +
|
| +RecursiveMTPDeviceObjectEnumerator::RecursiveMTPDeviceObjectEnumerator(
|
| + const std::string& handle,
|
| + base::SequencedTaskRunner* task_runner,
|
| + const std::vector<MtpFileEntry>& entries,
|
| + base::WaitableEvent* task_completed_event,
|
| + base::WaitableEvent* shutdown_event)
|
| + : device_handle_(handle),
|
| + media_task_runner_(task_runner),
|
| + file_entries_(entries),
|
| + file_entry_iter_(file_entries_.begin()),
|
| + on_task_completed_event_(task_completed_event),
|
| + on_shutdown_event_(shutdown_event) {
|
| + DCHECK(on_task_completed_event_);
|
| + DCHECK(on_shutdown_event_);
|
| + current_enumerator_.reset(new MTPDeviceObjectEnumerator(entries));
|
| +}
|
| +
|
| +RecursiveMTPDeviceObjectEnumerator::~RecursiveMTPDeviceObjectEnumerator() {
|
| +}
|
| +
|
| +FilePath RecursiveMTPDeviceObjectEnumerator::Next() {
|
| + if (on_shutdown_event_->IsSignaled()) {
|
| + // Process is in shut down mode.
|
| + return FilePath();
|
| + }
|
| +
|
| + FilePath path = current_enumerator_->Next();
|
| + if (!path.empty())
|
| + return path;
|
| +
|
| + // We reached the end.
|
| + if (file_entry_iter_ == file_entries_.end())
|
| + return FilePath();
|
| +
|
| + // Enumerate subdirectories of the next media file entry.
|
| + MtpFileEntry next_file_entry = *file_entry_iter_;
|
| + ++file_entry_iter_;
|
| +
|
| + // Create a ReadMTPDirectoryWorker object to enumerate sub directories.
|
| + scoped_refptr<ReadMTPDirectoryWorker> worker(new ReadMTPDirectoryWorker(
|
| + device_handle_, next_file_entry.item_id(), media_task_runner_,
|
| + on_task_completed_event_, on_shutdown_event_));
|
| + worker->Run();
|
| + if (!worker->get_file_entries().empty()) {
|
| + current_enumerator_.reset(
|
| + new MTPDeviceObjectEnumerator(worker->get_file_entries()));
|
| + } else {
|
| + current_enumerator_.reset(
|
| + new fileapi::FileSystemFileUtil::EmptyFileEnumerator());
|
| + }
|
| + return current_enumerator_->Next();
|
| +}
|
| +
|
| +int64 RecursiveMTPDeviceObjectEnumerator::Size() {
|
| + return current_enumerator_->Size();
|
| +}
|
| +
|
| +bool RecursiveMTPDeviceObjectEnumerator::IsDirectory() {
|
| + return current_enumerator_->IsDirectory();
|
| +}
|
| +
|
| +base::Time RecursiveMTPDeviceObjectEnumerator::LastModifiedTime() {
|
| + return current_enumerator_->LastModifiedTime();
|
| +}
|
| +
|
| +} // namespace chrome
|
|
|