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

Side by Side Diff: chrome/browser/media_galleries/linux/mtp_device_task_helper.h

Issue 982283002: Implement DeleteFile and DeleteDirectory. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add DCHECK. Created 5 years, 9 months 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
OLDNEW
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 18 matching lines...) Expand all
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 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. 35 // end. e.g. foo.jpg with file id 45 becomes foo.jpg,45.
36 typedef base::Callback<void(const storage::AsyncFileUtil::EntryList& entries, 36 typedef base::Callback<void(const storage::AsyncFileUtil::EntryList& entries,
37 bool has_more)> ReadDirectorySuccessCallback; 37 bool has_more)> ReadDirectorySuccessCallback;
38 38
39 typedef base::Callback<void(const std::vector<uint32>& file_ids)>
40 ReadDirectoryEntryIdsSuccessCallback;
41
39 typedef base::Closure CopyFileFromLocalSuccessCallback; 42 typedef base::Closure CopyFileFromLocalSuccessCallback;
40 43
44 typedef base::Closure DeleteObjectSuccessCallback;
45
41 typedef MTPDeviceAsyncDelegate::ErrorCallback ErrorCallback; 46 typedef MTPDeviceAsyncDelegate::ErrorCallback ErrorCallback;
42 47
43 MTPDeviceTaskHelper(); 48 MTPDeviceTaskHelper();
44 ~MTPDeviceTaskHelper(); 49 ~MTPDeviceTaskHelper();
45 50
46 // Dispatches the request to the MediaTransferProtocolManager to open the MTP 51 // Dispatches the request to the MediaTransferProtocolManager to open the MTP
47 // storage for communication. 52 // storage for communication.
48 // 53 //
49 // |storage_name| specifies the name of the storage device. 54 // |storage_name| specifies the name of the storage device.
50 // |callback| is called when the OpenStorage request completes. |callback| 55 // |callback| is called when the OpenStorage request completes. |callback|
(...skipping 24 matching lines...) Expand all
75 // the directory file entries. Please see the note in the 80 // the directory file entries. Please see the note in the
76 // ReadDirectorySuccessCallback typedef regarding the special treatment of 81 // ReadDirectorySuccessCallback typedef regarding the special treatment of
77 // file names. 82 // file names.
78 // 83 //
79 // If there is an error, |error_callback| is invoked on the IO thread to 84 // If there is an error, |error_callback| is invoked on the IO thread to
80 // notify the caller about the file error. 85 // notify the caller about the file error.
81 void ReadDirectory(uint32 dir_id, 86 void ReadDirectory(uint32 dir_id,
82 const ReadDirectorySuccessCallback& success_callback, 87 const ReadDirectorySuccessCallback& success_callback,
83 const ErrorCallback& error_callback); 88 const ErrorCallback& error_callback);
84 89
90 void ReadDirectoryEntryIds(
91 const uint32 directory_id,
92 const ReadDirectoryEntryIdsSuccessCallback& success_callback,
93 const ErrorCallback& error_callback);
94
85 // Forwards the WriteDataIntoSnapshotFile request to the MTPReadFileWorker 95 // Forwards the WriteDataIntoSnapshotFile request to the MTPReadFileWorker
86 // object. 96 // object.
87 // 97 //
88 // |request_info| specifies the snapshot file request params. 98 // |request_info| specifies the snapshot file request params.
89 // |snapshot_file_info| specifies the metadata of the snapshot file. 99 // |snapshot_file_info| specifies the metadata of the snapshot file.
90 void WriteDataIntoSnapshotFile( 100 void WriteDataIntoSnapshotFile(
91 const SnapshotRequestInfo& request_info, 101 const SnapshotRequestInfo& request_info,
92 const base::File::Info& snapshot_file_info); 102 const base::File::Info& snapshot_file_info);
93 103
94 // Dispatches the read bytes request to the MediaTransferProtocolManager. 104 // Dispatches the read bytes request to the MediaTransferProtocolManager.
95 // 105 //
96 // |request| contains details about the byte request including the file path, 106 // |request| contains details about the byte request including the file path,
97 // byte range, and the callbacks. The callbacks specified within |request| are 107 // byte range, and the callbacks. The callbacks specified within |request| are
98 // called on the IO thread to notify the caller about success or failure. 108 // called on the IO thread to notify the caller about success or failure.
99 void ReadBytes(const MTPDeviceAsyncDelegate::ReadBytesRequest& request); 109 void ReadBytes(const MTPDeviceAsyncDelegate::ReadBytesRequest& request);
100 110
101 // Forwards CopyFileFromLocal request to the MediaTransferProtocolManager. 111 // Forwards CopyFileFromLocal request to the MediaTransferProtocolManager.
102 void CopyFileFromLocal( 112 void CopyFileFromLocal(
103 const std::string& storage_name, 113 const std::string& storage_name,
104 const int source_file_descriptor, 114 const int source_file_descriptor,
105 const uint32 parent_id, 115 const uint32 parent_id,
106 const std::string& file_name, 116 const std::string& file_name,
107 const CopyFileFromLocalSuccessCallback& success_callback, 117 const CopyFileFromLocalSuccessCallback& success_callback,
108 const ErrorCallback& error_callback); 118 const ErrorCallback& error_callback);
109 119
120 // Forwards DeleteObject request to the MediaTransferProtocolManager.
121 void DeleteObject(const uint32 object_id,
122 const DeleteObjectSuccessCallback& success_callback,
123 const ErrorCallback& error_callback);
124
110 // Dispatches the CloseStorage request to the MediaTransferProtocolManager. 125 // Dispatches the CloseStorage request to the MediaTransferProtocolManager.
111 void CloseStorage() const; 126 void CloseStorage() const;
112 127
113 private: 128 private:
114 // Query callback for OpenStorage() to run |callback| on the IO thread. 129 // Query callback for OpenStorage() to run |callback| on the IO thread.
115 // 130 //
116 // If OpenStorage request succeeds, |error| is set to false and 131 // If OpenStorage request succeeds, |error| is set to false and
117 // |device_handle| contains the handle to communicate with the MTP device. 132 // |device_handle| contains the handle to communicate with the MTP device.
118 // 133 //
119 // If OpenStorage request fails, |error| is set to true and |device_handle| is 134 // If OpenStorage request fails, |error| is set to true and |device_handle| is
(...skipping 23 matching lines...) Expand all
143 // to notify the caller. 158 // to notify the caller.
144 // 159 //
145 // If there is an error, |error| is set to true, |file_entries| is empty 160 // If there is an error, |error| is set to true, |file_entries| is empty
146 // and |error_callback| is invoked on the IO thread to notify the caller. 161 // and |error_callback| is invoked on the IO thread to notify the caller.
147 void OnDidReadDirectory(const ReadDirectorySuccessCallback& success_callback, 162 void OnDidReadDirectory(const ReadDirectorySuccessCallback& success_callback,
148 const ErrorCallback& error_callback, 163 const ErrorCallback& error_callback,
149 const std::vector<MtpFileEntry>& file_entries, 164 const std::vector<MtpFileEntry>& file_entries,
150 bool has_more, 165 bool has_more,
151 bool error) const; 166 bool error) const;
152 167
168 void OnDidReadDirectoryEntryIds(
169 const ReadDirectoryEntryIdsSuccessCallback& success_callback,
170 const ErrorCallback& error_callback,
171 const std::vector<uint32>& file_ids,
172 const bool error) const;
173
153 // Intermediate step to finish a ReadBytes request. 174 // Intermediate step to finish a ReadBytes request.
154 void OnGetFileInfoToReadBytes( 175 void OnGetFileInfoToReadBytes(
155 const MTPDeviceAsyncDelegate::ReadBytesRequest& request, 176 const MTPDeviceAsyncDelegate::ReadBytesRequest& request,
156 const MtpFileEntry& file_entry, 177 const MtpFileEntry& file_entry,
157 bool error); 178 bool error);
158 179
159 // Query callback for ReadBytes(); 180 // Query callback for ReadBytes();
160 // 181 //
161 // If there is no error, |error| is set to false, the buffer within |request| 182 // If there is no error, |error| is set to false, the buffer within |request|
162 // is written to, and the success callback within |request| is invoked on the 183 // is written to, and the success callback within |request| is invoked on the
163 // IO thread to notify the caller. 184 // IO thread to notify the caller.
164 // 185 //
165 // If there is an error, |error| is set to true, the buffer within |request| 186 // If there is an error, |error| is set to true, the buffer within |request|
166 // is untouched, and the error callback within |request| is invoked on the 187 // is untouched, and the error callback within |request| is invoked on the
167 // IO thread to notify the caller. 188 // IO thread to notify the caller.
168 void OnDidReadBytes( 189 void OnDidReadBytes(
169 const MTPDeviceAsyncDelegate::ReadBytesRequest& request, 190 const MTPDeviceAsyncDelegate::ReadBytesRequest& request,
170 const base::File::Info& file_info, 191 const base::File::Info& file_info,
171 const std::string& data, 192 const std::string& data,
172 bool error) const; 193 bool error) const;
173 194
174 // Called when CopyFileFromLocal completed no matter if it succeeded or 195 // Called when CopyFileFromLocal completes.
175 // failed.
176 void OnCopyFileFromLocal( 196 void OnCopyFileFromLocal(
177 const CopyFileFromLocalSuccessCallback& success_callback, 197 const CopyFileFromLocalSuccessCallback& success_callback,
178 const ErrorCallback& error_callback, 198 const ErrorCallback& error_callback,
179 const bool error) const; 199 const bool error) const;
180 200
201 // Called when DeleteObject completes.
202 void OnDeleteObject(const DeleteObjectSuccessCallback& success_callback,
203 const ErrorCallback& error_callback,
204 const bool error) const;
205
181 // Called when the device is uninitialized. 206 // Called when the device is uninitialized.
182 // 207 //
183 // Runs |error_callback| on the IO thread to notify the caller about the 208 // Runs |error_callback| on the IO thread to notify the caller about the
184 // device |error|. 209 // device |error|.
185 void HandleDeviceError(const ErrorCallback& error_callback, 210 void HandleDeviceError(const ErrorCallback& error_callback,
186 base::File::Error error) const; 211 base::File::Error error) const;
187 212
188 // Handle to communicate with the MTP device. 213 // Handle to communicate with the MTP device.
189 std::string device_handle_; 214 std::string device_handle_;
190 215
191 // Used to handle WriteDataInfoSnapshotFile request. 216 // Used to handle WriteDataInfoSnapshotFile request.
192 scoped_ptr<MTPReadFileWorker> read_file_worker_; 217 scoped_ptr<MTPReadFileWorker> read_file_worker_;
193 218
194 // For callbacks that may run after destruction. 219 // For callbacks that may run after destruction.
195 base::WeakPtrFactory<MTPDeviceTaskHelper> weak_ptr_factory_; 220 base::WeakPtrFactory<MTPDeviceTaskHelper> weak_ptr_factory_;
196 221
197 DISALLOW_COPY_AND_ASSIGN(MTPDeviceTaskHelper); 222 DISALLOW_COPY_AND_ASSIGN(MTPDeviceTaskHelper);
198 }; 223 };
199 224
200 #endif // CHROME_BROWSER_MEDIA_GALLERIES_LINUX_MTP_DEVICE_TASK_HELPER_H_ 225 #endif // CHROME_BROWSER_MEDIA_GALLERIES_LINUX_MTP_DEVICE_TASK_HELPER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698