Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(599)

Unified Diff: chrome/browser/media_gallery/linux/get_mtp_file_info_worker.cc

Issue 11348337: Move MTPDeviceDelegateImplLinux worker classes to its own files. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: '' Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/media_gallery/linux/get_mtp_file_info_worker.cc
diff --git a/chrome/browser/media_gallery/linux/get_mtp_file_info_worker.cc b/chrome/browser/media_gallery/linux/get_mtp_file_info_worker.cc
new file mode 100644
index 0000000000000000000000000000000000000000..235efd8cdf4214d139e00ccca554f5b385b9a474
--- /dev/null
+++ b/chrome/browser/media_gallery/linux/get_mtp_file_info_worker.cc
@@ -0,0 +1,96 @@
+// 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/get_mtp_file_info_worker.h"
+
+#include "base/bind.h"
+#include "base/sequenced_task_runner.h"
+#include "base/synchronization/waitable_event.h"
+#include "chrome/browser/media_transfer_protocol/media_transfer_protocol_manager.h"
+#include "content/public/browser/browser_thread.h"
+
+namespace chrome {
+
+using content::BrowserThread;
+
+GetMTPFileInfoWorker::GetMTPFileInfoWorker(
+ const std::string& handle,
+ const std::string& path,
+ base::SequencedTaskRunner* task_runner,
+ base::WaitableEvent* task_completed_event,
+ base::WaitableEvent* shutdown_event)
+ : device_handle_(handle),
+ path_(path),
+ media_task_runner_(task_runner),
+ error_(base::PLATFORM_FILE_OK),
+ on_task_completed_event_(task_completed_event),
+ on_shutdown_event_(shutdown_event) {
+ DCHECK(on_task_completed_event_);
+ DCHECK(on_shutdown_event_);
+}
+
+void GetMTPFileInfoWorker::Run() {
+ if (on_shutdown_event_->IsSignaled()) {
+ // Process is in shutdown mode.
+ // Do not post any task on |media_task_runner_|.
+ return;
+ }
+
+ BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
+ base::Bind(&GetMTPFileInfoWorker::DoWorkOnUIThread,
+ this));
+ on_task_completed_event_->Wait();
+
+ if (on_shutdown_event_->IsSignaled())
+ cancel_tasks_flag_.Set();
+}
+
+base::PlatformFileError GetMTPFileInfoWorker::get_file_info(
+ base::PlatformFileInfo* file_info) const {
+ if (file_info)
+ *file_info = file_entry_info_;
+ return error_;
+}
+
+GetMTPFileInfoWorker::~GetMTPFileInfoWorker() {
+ // This object must be destructed on |media_task_runner_|.
+}
+
+void GetMTPFileInfoWorker::DoWorkOnUIThread() {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ if (cancel_tasks_flag_.IsSet()) {
+ error_ = base::PLATFORM_FILE_ERROR_FAILED;
+ return;
+ }
+
+ GetMediaTransferProtocolManager()->GetFileInfoByPath(
+ device_handle_, path_,
+ base::Bind(&GetMTPFileInfoWorker::OnDidWorkOnUIThread, this));
+}
+
+void GetMTPFileInfoWorker::OnDidWorkOnUIThread(const MtpFileEntry& file_entry,
+ bool error) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ if (cancel_tasks_flag_.IsSet()) {
+ error_ = base::PLATFORM_FILE_ERROR_FAILED;
+ return;
+ }
+
+ if (error) {
+ error_ = base::PLATFORM_FILE_ERROR_NOT_FOUND;
+ } else {
+ file_entry_info_.size = file_entry.file_size();
+ file_entry_info_.is_directory =
+ file_entry.file_type() == MtpFileEntry::FILE_TYPE_FOLDER;
+ file_entry_info_.is_symbolic_link = false;
+ file_entry_info_.last_modified =
+ base::Time::FromTimeT(file_entry.modification_time());
+ file_entry_info_.last_accessed =
+ base::Time::FromTimeT(file_entry.modification_time());
+ file_entry_info_.creation_time = base::Time();
+ }
+ on_task_completed_event_->Signal();
+}
+
+} // namespace chrome

Powered by Google App Engine
This is Rietveld 408576698