OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_MEDIA_GALLERIES_LINUX_MTP_DEVICE_TASK_HELPER_H_ | 5 #ifndef CHROME_BROWSER_MEDIA_GALLERIES_LINUX_MTP_DEVICE_TASK_HELPER_H_ |
6 #define CHROME_BROWSER_MEDIA_GALLERIES_LINUX_MTP_DEVICE_TASK_HELPER_H_ | 6 #define CHROME_BROWSER_MEDIA_GALLERIES_LINUX_MTP_DEVICE_TASK_HELPER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 13 matching lines...) Expand all Loading... |
24 // MTPDeviceTaskHelper lives on the UI thread. MTPDeviceTaskHelperMapService | 24 // MTPDeviceTaskHelper lives on the UI thread. MTPDeviceTaskHelperMapService |
25 // owns the MTPDeviceTaskHelper objects. MTPDeviceTaskHelper is instantiated per | 25 // owns the MTPDeviceTaskHelper objects. MTPDeviceTaskHelper is instantiated per |
26 // MTP device storage. | 26 // MTP device storage. |
27 class MTPDeviceTaskHelper { | 27 class MTPDeviceTaskHelper { |
28 public: | 28 public: |
29 typedef base::Callback<void(bool succeeded)> OpenStorageCallback; | 29 typedef base::Callback<void(bool succeeded)> OpenStorageCallback; |
30 | 30 |
31 typedef MTPDeviceAsyncDelegate::GetFileInfoSuccessCallback | 31 typedef MTPDeviceAsyncDelegate::GetFileInfoSuccessCallback |
32 GetFileInfoSuccessCallback; | 32 GetFileInfoSuccessCallback; |
33 | 33 |
| 34 // NOTE: The file names in the entry list have their file id appended at the |
| 35 // end. e.g. foo.jpg with file id 45 becomes foo.jpg,45. |
34 typedef base::Callback<void(const fileapi::AsyncFileUtil::EntryList&)> | 36 typedef base::Callback<void(const fileapi::AsyncFileUtil::EntryList&)> |
35 ReadDirectorySuccessCallback; | 37 ReadDirectorySuccessCallback; |
36 | 38 |
37 typedef MTPDeviceAsyncDelegate::ErrorCallback ErrorCallback; | 39 typedef MTPDeviceAsyncDelegate::ErrorCallback ErrorCallback; |
38 | 40 |
39 MTPDeviceTaskHelper(); | 41 MTPDeviceTaskHelper(); |
40 ~MTPDeviceTaskHelper(); | 42 ~MTPDeviceTaskHelper(); |
41 | 43 |
42 // Dispatches the request to the MediaTransferProtocolManager to open the MTP | 44 // Dispatches the request to the MediaTransferProtocolManager to open the MTP |
43 // storage for communication. | 45 // storage for communication. |
44 // | 46 // |
45 // |storage_name| specifies the name of the storage device. | 47 // |storage_name| specifies the name of the storage device. |
46 // |callback| is called when the OpenStorage request completes. |callback| | 48 // |callback| is called when the OpenStorage request completes. |callback| |
47 // runs on the IO thread. | 49 // runs on the IO thread. |
48 void OpenStorage(const std::string& storage_name, | 50 void OpenStorage(const std::string& storage_name, |
49 const OpenStorageCallback& callback); | 51 const OpenStorageCallback& callback); |
50 | 52 |
51 // Dispatches the GetFileInfoByPath request to the | 53 // Dispatches the GetFileInfoById request to the |
52 // MediaTransferProtocolManager. | 54 // MediaTransferProtocolManager. |
53 // | 55 // |
54 // |file_path| specifies the relative of the file whose details are requested. | 56 // |file_id| specifies the id of the file whose details are requested. |
55 // | 57 // |
56 // If the file details are fetched successfully, |success_callback| is invoked | 58 // If the file details are fetched successfully, |success_callback| is invoked |
57 // on the IO thread to notify the caller about the file details. | 59 // on the IO thread to notify the caller about the file details. |
58 // | 60 // |
59 // If there is an error, |error_callback| is invoked on the IO thread to | 61 // If there is an error, |error_callback| is invoked on the IO thread to |
60 // notify the caller about the file error. | 62 // notify the caller about the file error. |
61 void GetFileInfoByPath( | 63 void GetFileInfoById( |
62 const std::string& file_path, | 64 uint32 file_id, |
63 const GetFileInfoSuccessCallback& success_callback, | 65 const GetFileInfoSuccessCallback& success_callback, |
64 const ErrorCallback& error_callback); | 66 const ErrorCallback& error_callback); |
65 | 67 |
66 // Dispatches the read directory request to the MediaTransferProtocolManager. | 68 // Dispatches the read directory request to the MediaTransferProtocolManager. |
67 // | 69 // |
68 // |dir_path| specifies the directory file path. | 70 // |dir_id| specifies the directory id. |
69 // | 71 // |
70 // If the directory file entries are enumerated successfully, | 72 // If the directory file entries are enumerated successfully, |
71 // |success_callback| is invoked on the IO thread to notify the caller about | 73 // |success_callback| is invoked on the IO thread to notify the caller about |
72 // the directory file entries. | 74 // the directory file entries. Please see the note in the |
| 75 // ReadDirectorySuccessCallback typedef regarding the special treatment of |
| 76 // file names. |
73 // | 77 // |
74 // If there is an error, |error_callback| is invoked on the IO thread to | 78 // If there is an error, |error_callback| is invoked on the IO thread to |
75 // notify the caller about the file error. | 79 // notify the caller about the file error. |
76 void ReadDirectoryByPath(const std::string& dir_path, | 80 void ReadDirectoryById(uint32 dir_id, |
77 const ReadDirectorySuccessCallback& success_callback, | 81 const ReadDirectorySuccessCallback& success_callback, |
78 const ErrorCallback& error_callback); | 82 const ErrorCallback& error_callback); |
79 | 83 |
80 // Forwards the WriteDataIntoSnapshotFile request to the MTPReadFileWorker | 84 // Forwards the WriteDataIntoSnapshotFile request to the MTPReadFileWorker |
81 // object. | 85 // object. |
82 // | 86 // |
83 // |request_info| specifies the snapshot file request params. | 87 // |request_info| specifies the snapshot file request params. |
84 // |snapshot_file_info| specifies the metadata of the snapshot file. | 88 // |snapshot_file_info| specifies the metadata of the snapshot file. |
85 void WriteDataIntoSnapshotFile( | 89 void WriteDataIntoSnapshotFile( |
86 const SnapshotRequestInfo& request_info, | 90 const SnapshotRequestInfo& request_info, |
87 const base::File::Info& snapshot_file_info); | 91 const base::File::Info& snapshot_file_info); |
88 | 92 |
(...skipping 26 matching lines...) Expand all Loading... |
115 // |success_callback| is invoked on the IO thread to notify the caller. | 119 // |success_callback| is invoked on the IO thread to notify the caller. |
116 // | 120 // |
117 // If there is an error, |file_entry| is invalid and |error| is | 121 // If there is an error, |file_entry| is invalid and |error| is |
118 // set to true. |error_callback| is invoked on the IO thread to notify the | 122 // set to true. |error_callback| is invoked on the IO thread to notify the |
119 // caller. | 123 // caller. |
120 void OnGetFileInfo(const GetFileInfoSuccessCallback& success_callback, | 124 void OnGetFileInfo(const GetFileInfoSuccessCallback& success_callback, |
121 const ErrorCallback& error_callback, | 125 const ErrorCallback& error_callback, |
122 const MtpFileEntry& file_entry, | 126 const MtpFileEntry& file_entry, |
123 bool error) const; | 127 bool error) const; |
124 | 128 |
125 // Query callback for ReadDirectoryByPath(). | 129 // Query callback for ReadDirectoryById(). |
126 // | 130 // |
127 // If there is no error, |error| is set to false, |file_entries| has the | 131 // If there is no error, |error| is set to false, |file_entries| has the |
128 // directory file entries and |success_callback| is invoked on the IO thread | 132 // directory file entries and |success_callback| is invoked on the IO thread |
129 // to notify the caller. | 133 // to notify the caller. |
130 // | 134 // |
131 // If there is an error, |error| is set to true, |file_entries| is empty | 135 // If there is an error, |error| is set to true, |file_entries| is empty |
132 // and |error_callback| is invoked on the IO thread to notify the caller. | 136 // and |error_callback| is invoked on the IO thread to notify the caller. |
133 void OnDidReadDirectoryByPath( | 137 void OnDidReadDirectoryById( |
134 const ReadDirectorySuccessCallback& success_callback, | 138 const ReadDirectorySuccessCallback& success_callback, |
135 const ErrorCallback& error_callback, | 139 const ErrorCallback& error_callback, |
136 const std::vector<MtpFileEntry>& file_entries, | 140 const std::vector<MtpFileEntry>& file_entries, |
137 bool error) const; | 141 bool error) const; |
138 | 142 |
139 // Intermediate step to finish a ReadBytes request. | 143 // Intermediate step to finish a ReadBytes request. |
140 void OnGetFileInfoToReadBytes( | 144 void OnGetFileInfoToReadBytes( |
141 const MTPDeviceAsyncDelegate::ReadBytesRequest& request, | 145 const MTPDeviceAsyncDelegate::ReadBytesRequest& request, |
142 const MtpFileEntry& file_entry, | 146 const MtpFileEntry& file_entry, |
143 bool error); | 147 bool error); |
(...skipping 26 matching lines...) Expand all Loading... |
170 // Used to handle WriteDataInfoSnapshotFile request. | 174 // Used to handle WriteDataInfoSnapshotFile request. |
171 scoped_ptr<MTPReadFileWorker> read_file_worker_; | 175 scoped_ptr<MTPReadFileWorker> read_file_worker_; |
172 | 176 |
173 // For callbacks that may run after destruction. | 177 // For callbacks that may run after destruction. |
174 base::WeakPtrFactory<MTPDeviceTaskHelper> weak_ptr_factory_; | 178 base::WeakPtrFactory<MTPDeviceTaskHelper> weak_ptr_factory_; |
175 | 179 |
176 DISALLOW_COPY_AND_ASSIGN(MTPDeviceTaskHelper); | 180 DISALLOW_COPY_AND_ASSIGN(MTPDeviceTaskHelper); |
177 }; | 181 }; |
178 | 182 |
179 #endif // CHROME_BROWSER_MEDIA_GALLERIES_LINUX_MTP_DEVICE_TASK_HELPER_H_ | 183 #endif // CHROME_BROWSER_MEDIA_GALLERIES_LINUX_MTP_DEVICE_TASK_HELPER_H_ |
OLD | NEW |