Chromium Code Reviews| OLD | NEW |
|---|---|
| (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_READ_MTP_DIRECTORY_WORKER_H_ | |
| 6 #define CHROME_BROWSER_MEDIA_GALLERY_LINUX_READ_MTP_DIRECTORY_WORKER_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 #include <vector> | |
| 10 | |
| 11 #include "base/memory/ref_counted.h" | |
| 12 #include "base/sequenced_task_runner_helpers.h" | |
| 13 #include "base/synchronization/cancellation_flag.h" | |
| 14 #include "chrome/browser/media_gallery/linux/mtp_device_operations_utils.h" | |
| 15 #include "chrome/browser/media_transfer_protocol/mtp_file_entry.pb.h" | |
| 16 | |
| 17 namespace base { | |
| 18 class SequencedTaskRunner; | |
| 19 class WaitableEvent; | |
| 20 } | |
| 21 | |
| 22 namespace chrome { | |
| 23 | |
| 24 class ReadMTPDirectoryWorker; | |
| 25 typedef struct WorkerDeleter<class ReadMTPDirectoryWorker> | |
| 26 ReadMTPDirectoryWorkerDeleter; | |
| 27 | |
| 28 // Worker class to read directory contents. Device is already opened for | |
| 29 // communication. | |
| 30 class ReadMTPDirectoryWorker | |
| 31 : public base::RefCountedThreadSafe<ReadMTPDirectoryWorker, | |
| 32 ReadMTPDirectoryWorkerDeleter> { | |
| 33 public: | |
| 34 // Construct a worker object given the directory |path|. This object is | |
| 35 // constructed on |media_task_runner_| thread. | |
| 36 ReadMTPDirectoryWorker(const std::string& handle, | |
| 37 const std::string& path, | |
| 38 base::SequencedTaskRunner* task_runner, | |
| 39 base::WaitableEvent* task_completed_event, | |
| 40 base::WaitableEvent* shutdown_event); | |
| 41 | |
| 42 // Construct a worker object given the directory |entry_id|. This object is | |
| 43 // constructed on |media_task_runner_| thread. | |
| 44 ReadMTPDirectoryWorker(const std::string& storage_name, | |
|
Lei Zhang
2012/12/03 22:23:54
Are you using this ctor anywhere? If not, let's ge
kmadhusu
2012/12/03 23:30:00
Yes in RecursiveMTPDeviceObjectEnumerator::Next().
| |
| 45 const uint32_t entry_id, | |
| 46 base::SequencedTaskRunner* task_runner, | |
| 47 base::WaitableEvent* task_completed_event, | |
| 48 base::WaitableEvent* shutdown_event); | |
| 49 | |
| 50 // This function is invoked on |media_task_runner_| to post the task on UI | |
| 51 // thread. This blocks the |media_task_runner_| until the task is complete. | |
| 52 void Run(); | |
| 53 | |
| 54 // Returns the directory entries for the given directory path. | |
| 55 const std::vector<MtpFileEntry>& get_file_entries() const { | |
| 56 return file_entries_; | |
| 57 } | |
| 58 | |
| 59 // Returns the |media_task_runner_| associated with this worker object. | |
| 60 // This function is exposed for WorkerDeleter struct to access the | |
| 61 // |media_task_runner_|. | |
| 62 base::SequencedTaskRunner* media_task_runner() const { | |
| 63 return media_task_runner_.get(); | |
| 64 } | |
| 65 | |
| 66 private: | |
| 67 friend struct WorkerDeleter<ReadMTPDirectoryWorker>; | |
| 68 friend class base::DeleteHelper<ReadMTPDirectoryWorker>; | |
| 69 friend class base::RefCountedThreadSafe<ReadMTPDirectoryWorker, | |
| 70 ReadMTPDirectoryWorkerDeleter>; | |
| 71 | |
| 72 // Destructed via ReadMTPDirectoryWorkerDeleter. | |
| 73 virtual ~ReadMTPDirectoryWorker(); | |
| 74 | |
| 75 // Dispatches a request to MediaTransferProtocolManager to read the directory | |
| 76 // entries. This is called on UI thread. | |
| 77 void DoWorkOnUIThread(); | |
| 78 | |
| 79 // Query callback for DoWorkOnUIThread(). On success, |file_entries| has the | |
| 80 // directory file entries. |error| is true if there was an error. This | |
| 81 // function signals to unblock |media_task_runner_|. | |
| 82 void OnDidWorkOnUIThread(const std::vector<MtpFileEntry>& file_entries, | |
| 83 bool error); | |
| 84 | |
| 85 // Stores the device handle to communicate with storage device. | |
| 86 const std::string device_handle_; | |
| 87 | |
| 88 // Stores the directory path whose contents needs to be listed. | |
| 89 const std::string dir_path_; | |
| 90 | |
| 91 // Stores the directory entry id whose contents needs to be listed. | |
| 92 const uint32_t dir_entry_id_; | |
| 93 | |
| 94 // Stores a reference to |media_task_runner_| to destruct this object on the | |
| 95 // correct thread. | |
| 96 scoped_refptr<base::SequencedTaskRunner> media_task_runner_; | |
| 97 | |
| 98 // |media_task_runner_| can wait on this event until the required operation | |
| 99 // is complete. | |
| 100 // TODO(kmadhusu): Remove this WaitableEvent after modifying the | |
| 101 // DeviceMediaFileUtil functions as asynchronous functions. | |
| 102 base::WaitableEvent* on_task_completed_event_; | |
| 103 | |
| 104 // Stores a reference to waitable event associated with the shut down message. | |
| 105 base::WaitableEvent* on_shutdown_event_; | |
| 106 | |
| 107 // Stores the result of read directory request. | |
| 108 std::vector<MtpFileEntry> file_entries_; | |
| 109 | |
| 110 // Set to ignore the request results. This will be set when | |
| 111 // MTPDeviceDelegateImplLinux object is about to be deleted. | |
| 112 // |on_task_completed_event_| and |on_shutdown_event_| should not be | |
| 113 // dereferenced when this is set. | |
| 114 base::CancellationFlag cancel_tasks_flag_; | |
| 115 | |
| 116 DISALLOW_COPY_AND_ASSIGN(ReadMTPDirectoryWorker); | |
| 117 }; | |
| 118 | |
| 119 } // namespace chrome | |
| 120 | |
| 121 #endif // CHROME_BROWSER_MEDIA_GALLERY_LINUX_READ_MTP_DIRECTORY_WORKER_H_ | |
| OLD | NEW |