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

Side by Side Diff: chrome/browser/media_gallery/linux/mtp_get_file_info_worker.h

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 #ifndef CHROME_BROWSER_MEDIA_GALLERY_LINUX_MTP_GET_FILE_INFO_WORKER_H_
6 #define CHROME_BROWSER_MEDIA_GALLERY_LINUX_MTP_GET_FILE_INFO_WORKER_H_
7
8 #include "base/memory/ref_counted.h"
9 #include "base/platform_file.h"
10 #include "base/sequenced_task_runner_helpers.h"
11 #include "base/synchronization/cancellation_flag.h"
12 #include "chrome/browser/media_gallery/linux/mtp_device_operations_utils.h"
13 #include "chrome/browser/media_transfer_protocol/mtp_file_entry.pb.h"
14
15 namespace base {
16 class SequencedTaskRunner;
17 class WaitableEvent;
18 }
19
20 namespace chrome {
21
22 class MTPGetFileInfoWorker;
23 typedef struct WorkerDeleter<class MTPGetFileInfoWorker>
24 MTPGetFileInfoWorkerDeleter;
25
26 // Worker class to get media device file information given a |path|.
27 class MTPGetFileInfoWorker
28 : public base::RefCountedThreadSafe<MTPGetFileInfoWorker,
29 MTPGetFileInfoWorkerDeleter> {
30 public:
31 // Constructed on |media_task_runner_| thread.
32 MTPGetFileInfoWorker(const std::string& handle,
33 const std::string& path,
34 base::SequencedTaskRunner* task_runner,
35 base::WaitableEvent* task_completed_event,
36 base::WaitableEvent* shutdown_event);
37
38 // This function is invoked on |media_task_runner_| to post the task on UI
39 // thread. This blocks the |media_task_runner_| until the task is complete.
40 void Run();
41
42 // Returns GetFileInfo() result and fills in |file_info| with requested file
43 // entry details.
44 base::PlatformFileError get_file_info(
45 base::PlatformFileInfo* file_info) const;
46
47 // Returns the |media_task_runner_| associated with this worker object.
48 // This function is exposed for WorkerDeleter struct to access the
49 // |media_task_runner_|.
50 base::SequencedTaskRunner* media_task_runner() const {
51 return media_task_runner_.get();
52 }
53
54 private:
55 friend struct WorkerDeleter<MTPGetFileInfoWorker>;
56 friend class base::DeleteHelper<MTPGetFileInfoWorker>;
57 friend class base::RefCountedThreadSafe<MTPGetFileInfoWorker,
58 MTPGetFileInfoWorkerDeleter>;
59
60 // Destructed via MTPGetFileInfoWorkerDeleter.
61 virtual ~MTPGetFileInfoWorker();
62
63 // Dispatches a request to MediaTransferProtocolManager to get file
64 // information.
65 void DoWorkOnUIThread();
66
67 // Query callback for DoWorkOnUIThread(). On success, |file_entry| has media
68 // file information. On failure, |error| is set to true. This function signals
69 // to unblock |media_task_runner_|.
70 void OnDidWorkOnUIThread(const MtpFileEntry& file_entry, bool error);
71
72 // Stores the device handle to query the device.
73 const std::string device_handle_;
74
75 // Stores the requested media device file path.
76 const std::string path_;
77
78 // Stores a reference to |media_task_runner_| to destruct this object on the
79 // correct thread.
80 scoped_refptr<base::SequencedTaskRunner> media_task_runner_;
81
82 // Stores the result of GetFileInfo().
83 base::PlatformFileError error_;
84
85 // Stores the media file entry information.
86 base::PlatformFileInfo file_entry_info_;
87
88 // |media_task_runner_| can wait on this event until the required operation
89 // is complete.
90 // TODO(kmadhusu): Remove this WaitableEvent after modifying the
91 // DeviceMediaFileUtil functions as asynchronous functions.
92 base::WaitableEvent* on_task_completed_event_;
93
94 // Stores a reference to waitable event associated with the shut down message.
95 base::WaitableEvent* on_shutdown_event_;
96
97 // Set to ignore the request results. This will be set when
98 // MTPDeviceDelegateImplLinux object is about to be deleted.
99 // |on_task_completed_event_| and |on_shutdown_event_| should not be
100 // dereferenced when this is set.
101 base::CancellationFlag cancel_tasks_flag_;
102
103 DISALLOW_COPY_AND_ASSIGN(MTPGetFileInfoWorker);
104 };
105
106 } // namespace chrome
107
108 #endif // CHROME_BROWSER_MEDIA_GALLERY_LINUX_MTP_GET_FILE_INFO_WORKER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698