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

Side by Side Diff: chrome/browser/media_gallery/linux/mtp_get_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: Addressed review comments 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/media_gallery/linux/mtp_get_file_info_worker.h"
6
7 #include "base/bind.h"
8 #include "base/sequenced_task_runner.h"
9 #include "base/synchronization/waitable_event.h"
10 #include "chrome/browser/media_transfer_protocol/media_transfer_protocol_manager .h"
11 #include "content/public/browser/browser_thread.h"
12
13 namespace chrome {
14
15 using content::BrowserThread;
16
17 MTPGetFileInfoWorker::MTPGetFileInfoWorker(
18 const std::string& handle,
19 const std::string& path,
20 base::SequencedTaskRunner* task_runner,
21 base::WaitableEvent* task_completed_event,
22 base::WaitableEvent* shutdown_event)
23 : device_handle_(handle),
24 path_(path),
25 media_task_runner_(task_runner),
26 error_(base::PLATFORM_FILE_OK),
27 on_task_completed_event_(task_completed_event),
28 on_shutdown_event_(shutdown_event) {
29 DCHECK(on_task_completed_event_);
30 DCHECK(on_shutdown_event_);
31 }
32
33 void MTPGetFileInfoWorker::Run() {
34 if (on_shutdown_event_->IsSignaled()) {
35 // Process is in shutdown mode.
36 // Do not post any task on |media_task_runner_|.
37 return;
38 }
39
40 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
41 base::Bind(&MTPGetFileInfoWorker::DoWorkOnUIThread,
42 this));
43 on_task_completed_event_->Wait();
44
45 if (on_shutdown_event_->IsSignaled())
46 cancel_tasks_flag_.Set();
47 }
48
49 base::PlatformFileError MTPGetFileInfoWorker::get_file_info(
50 base::PlatformFileInfo* file_info) const {
51 if (file_info)
52 *file_info = file_entry_info_;
53 return error_;
54 }
55
56 MTPGetFileInfoWorker::~MTPGetFileInfoWorker() {
57 // This object must be destructed on |media_task_runner_|.
58 }
59
60 void MTPGetFileInfoWorker::DoWorkOnUIThread() {
61 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
62 if (cancel_tasks_flag_.IsSet()) {
63 error_ = base::PLATFORM_FILE_ERROR_FAILED;
64 return;
65 }
66
67 GetMediaTransferProtocolManager()->GetFileInfoByPath(
68 device_handle_, path_,
69 base::Bind(&MTPGetFileInfoWorker::OnDidWorkOnUIThread, this));
70 }
71
72 void MTPGetFileInfoWorker::OnDidWorkOnUIThread(const MtpFileEntry& file_entry,
73 bool error) {
74 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
75 if (cancel_tasks_flag_.IsSet()) {
76 error_ = base::PLATFORM_FILE_ERROR_FAILED;
77 return;
78 }
79
80 if (error) {
81 error_ = base::PLATFORM_FILE_ERROR_NOT_FOUND;
82 } else {
83 file_entry_info_.size = file_entry.file_size();
84 file_entry_info_.is_directory =
85 file_entry.file_type() == MtpFileEntry::FILE_TYPE_FOLDER;
86 file_entry_info_.is_symbolic_link = false;
87 file_entry_info_.last_modified =
88 base::Time::FromTimeT(file_entry.modification_time());
89 file_entry_info_.last_accessed =
90 base::Time::FromTimeT(file_entry.modification_time());
91 file_entry_info_.creation_time = base::Time();
92 }
93 on_task_completed_event_->Signal();
94 }
95
96 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698