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

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

Issue 947943002: Implement CopyFileFromLocal of MTPDeviceAsyncDelegate. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments. 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 (c) 2012 The Chromium Authors. All rights reserved. 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 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_DELEGATE_IMPL_LINUX_H_ 5 #ifndef CHROME_BROWSER_MEDIA_GALLERIES_LINUX_MTP_DEVICE_DELEGATE_IMPL_LINUX_H_
6 #define CHROME_BROWSER_MEDIA_GALLERIES_LINUX_MTP_DEVICE_DELEGATE_IMPL_LINUX_H_ 6 #define CHROME_BROWSER_MEDIA_GALLERIES_LINUX_MTP_DEVICE_DELEGATE_IMPL_LINUX_H_
7 7
8 #include <deque> 8 #include <deque>
9 #include <map> 9 #include <map>
10 #include <set> 10 #include <set>
(...skipping 14 matching lines...) Expand all
25 // MTPDeviceDelegateImplLinux communicates with the media transfer protocol 25 // MTPDeviceDelegateImplLinux communicates with the media transfer protocol
26 // (MTP) device to complete file system operations. These operations are 26 // (MTP) device to complete file system operations. These operations are
27 // performed asynchronously. Instantiate this class per MTP device storage. 27 // performed asynchronously. Instantiate this class per MTP device storage.
28 // MTPDeviceDelegateImplLinux lives on the IO thread. 28 // MTPDeviceDelegateImplLinux lives on the IO thread.
29 // MTPDeviceDelegateImplLinux does a call-and-reply to the UI thread 29 // MTPDeviceDelegateImplLinux does a call-and-reply to the UI thread
30 // to dispatch the requests to MediaTransferProtocolManager. 30 // to dispatch the requests to MediaTransferProtocolManager.
31 class MTPDeviceDelegateImplLinux : public MTPDeviceAsyncDelegate { 31 class MTPDeviceDelegateImplLinux : public MTPDeviceAsyncDelegate {
32 private: 32 private:
33 friend void CreateMTPDeviceAsyncDelegate( 33 friend void CreateMTPDeviceAsyncDelegate(
34 const std::string&, 34 const std::string&,
35 const bool read_only,
35 const CreateMTPDeviceAsyncDelegateCallback&); 36 const CreateMTPDeviceAsyncDelegateCallback&);
36 37
37 enum InitializationState { 38 enum InitializationState {
38 UNINITIALIZED = 0, 39 UNINITIALIZED = 0,
39 PENDING_INIT, 40 PENDING_INIT,
40 INITIALIZED 41 INITIALIZED
41 }; 42 };
42 43
43 // Used to represent pending task details. 44 // Used to represent pending task details.
44 struct PendingTaskInfo { 45 struct PendingTaskInfo {
(...skipping 14 matching lines...) Expand all
59 60
60 // Maps file ids to file nodes. 61 // Maps file ids to file nodes.
61 typedef std::map<uint32, MTPFileNode*> FileIdToMTPFileNodeMap; 62 typedef std::map<uint32, MTPFileNode*> FileIdToMTPFileNodeMap;
62 63
63 // Maps file paths to file info. 64 // Maps file paths to file info.
64 typedef std::map<base::FilePath, storage::DirectoryEntry> FileInfoCache; 65 typedef std::map<base::FilePath, storage::DirectoryEntry> FileInfoCache;
65 66
66 // Should only be called by CreateMTPDeviceAsyncDelegate() factory call. 67 // Should only be called by CreateMTPDeviceAsyncDelegate() factory call.
67 // Defer the device initializations until the first file operation request. 68 // Defer the device initializations until the first file operation request.
68 // Do all the initializations in EnsureInitAndRunTask() function. 69 // Do all the initializations in EnsureInitAndRunTask() function.
69 explicit MTPDeviceDelegateImplLinux(const std::string& device_location); 70 MTPDeviceDelegateImplLinux(const std::string& device_location,
71 const bool read_only);
70 72
71 // Destructed via CancelPendingTasksAndDeleteDelegate(). 73 // Destructed via CancelPendingTasksAndDeleteDelegate().
72 ~MTPDeviceDelegateImplLinux() override; 74 ~MTPDeviceDelegateImplLinux() override;
73 75
74 // MTPDeviceAsyncDelegate: 76 // MTPDeviceAsyncDelegate:
75 void GetFileInfo(const base::FilePath& file_path, 77 void GetFileInfo(const base::FilePath& file_path,
76 const GetFileInfoSuccessCallback& success_callback, 78 const GetFileInfoSuccessCallback& success_callback,
77 const ErrorCallback& error_callback) override; 79 const ErrorCallback& error_callback) override;
78 void ReadDirectory(const base::FilePath& root, 80 void ReadDirectory(const base::FilePath& root,
79 const ReadDirectorySuccessCallback& success_callback, 81 const ReadDirectorySuccessCallback& success_callback,
80 const ErrorCallback& error_callback) override; 82 const ErrorCallback& error_callback) override;
81 void CreateSnapshotFile( 83 void CreateSnapshotFile(
82 const base::FilePath& device_file_path, 84 const base::FilePath& device_file_path,
83 const base::FilePath& local_path, 85 const base::FilePath& local_path,
84 const CreateSnapshotFileSuccessCallback& success_callback, 86 const CreateSnapshotFileSuccessCallback& success_callback,
85 const ErrorCallback& error_callback) override; 87 const ErrorCallback& error_callback) override;
86 bool IsStreaming() override; 88 bool IsStreaming() override;
87 void ReadBytes(const base::FilePath& device_file_path, 89 void ReadBytes(const base::FilePath& device_file_path,
88 const scoped_refptr<net::IOBuffer>& buf, 90 const scoped_refptr<net::IOBuffer>& buf,
89 int64 offset, 91 int64 offset,
90 int buf_len, 92 int buf_len,
91 const ReadBytesSuccessCallback& success_callback, 93 const ReadBytesSuccessCallback& success_callback,
92 const ErrorCallback& error_callback) override; 94 const ErrorCallback& error_callback) override;
95 bool IsReadOnly() override;
96 void CopyFileFromLocal(
97 const base::FilePath& source_file_path,
98 const base::FilePath& device_file_path,
99 const CopyFileFromLocalSuccessCallback& success_callback,
100 const ErrorCallback& error_callback) override;
93 void CancelPendingTasksAndDeleteDelegate() override; 101 void CancelPendingTasksAndDeleteDelegate() override;
94 102
95 // The internal methods correspond to the similarly named methods above. 103 // The internal methods correspond to the similarly named methods above.
96 // The |root_node_| cache should be filled at this point. 104 // The |root_node_| cache should be filled at this point.
97 virtual void GetFileInfoInternal( 105 virtual void GetFileInfoInternal(
98 const base::FilePath& file_path, 106 const base::FilePath& file_path,
99 const GetFileInfoSuccessCallback& success_callback, 107 const GetFileInfoSuccessCallback& success_callback,
100 const ErrorCallback& error_callback); 108 const ErrorCallback& error_callback);
101 virtual void ReadDirectoryInternal( 109 virtual void ReadDirectoryInternal(
102 const base::FilePath& root, 110 const base::FilePath& root,
103 const ReadDirectorySuccessCallback& success_callback, 111 const ReadDirectorySuccessCallback& success_callback,
104 const ErrorCallback& error_callback); 112 const ErrorCallback& error_callback);
105 virtual void CreateSnapshotFileInternal( 113 virtual void CreateSnapshotFileInternal(
106 const base::FilePath& device_file_path, 114 const base::FilePath& device_file_path,
107 const base::FilePath& local_path, 115 const base::FilePath& local_path,
108 const CreateSnapshotFileSuccessCallback& success_callback, 116 const CreateSnapshotFileSuccessCallback& success_callback,
109 const ErrorCallback& error_callback); 117 const ErrorCallback& error_callback);
110 virtual void ReadBytesInternal( 118 virtual void ReadBytesInternal(
111 const base::FilePath& device_file_path, 119 const base::FilePath& device_file_path,
112 net::IOBuffer* buf, int64 offset, int buf_len, 120 net::IOBuffer* buf, int64 offset, int buf_len,
113 const ReadBytesSuccessCallback& success_callback, 121 const ReadBytesSuccessCallback& success_callback,
114 const ErrorCallback& error_callback); 122 const ErrorCallback& error_callback);
123 virtual void CopyFileFromLocalInternal(
124 const base::FilePath& source_file_path,
125 const base::FilePath& device_file_path,
126 const CopyFileFromLocalSuccessCallback& success_callback,
127 const ErrorCallback& error_callback);
128 virtual void OnDidOpenFileDescriptorToCopyFileFromLocal(
129 const int source_file_descriptor,
130 const base::FilePath& device_file_path,
131 const CopyFileFromLocalSuccessCallback& success_callback,
132 const ErrorCallback& error_callback);
115 133
116 // Ensures the device is initialized for communication. 134 // Ensures the device is initialized for communication.
117 // If the device is already initialized, call RunTask(). 135 // If the device is already initialized, call RunTask().
118 // 136 //
119 // If the device is uninitialized, store the |task_info| in a pending task 137 // If the device is uninitialized, store the |task_info| in a pending task
120 // queue and runs the pending tasks in the queue once the device is 138 // queue and runs the pending tasks in the queue once the device is
121 // successfully initialized. 139 // successfully initialized.
122 void EnsureInitAndRunTask(const PendingTaskInfo& task_info); 140 void EnsureInitAndRunTask(const PendingTaskInfo& task_info);
123 141
124 // Runs a task. If |task_info.path| is empty, or if the path is cached, runs 142 // Runs a task. If |task_info.path| is empty, or if the path is cached, runs
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 const base::File::Info& file_info, int bytes_read); 233 const base::File::Info& file_info, int bytes_read);
216 234
217 // Called when FillFileCache() succeeds. 235 // Called when FillFileCache() succeeds.
218 void OnDidFillFileCache(const base::FilePath& path, 236 void OnDidFillFileCache(const base::FilePath& path,
219 const storage::AsyncFileUtil::EntryList& file_list, 237 const storage::AsyncFileUtil::EntryList& file_list,
220 bool has_more); 238 bool has_more);
221 239
222 // Called when FillFileCache() fails. 240 // Called when FillFileCache() fails.
223 void OnFillFileCacheFailed(base::File::Error error); 241 void OnFillFileCacheFailed(base::File::Error error);
224 242
243 // Called when CopyFileFromLocal() succeeds.
244 void OnDidCopyFileFromLocal(
245 const CopyFileFromLocalSuccessCallback& success_callback,
246 const int source_file_descriptor);
247
248 // Called when CopyFileFromLocal() fails.
249 void HandleCopyFileFromLocalError(const ErrorCallback& error_callback,
250 const int source_file_descriptor,
251 base::File::Error error);
252
225 // Handles the device file |error| while operating on |file_id|. 253 // Handles the device file |error| while operating on |file_id|.
226 // |error_callback| is invoked to notify the caller about the file error. 254 // |error_callback| is invoked to notify the caller about the file error.
227 void HandleDeviceFileError(const ErrorCallback& error_callback, 255 void HandleDeviceFileError(const ErrorCallback& error_callback,
228 uint32 file_id, 256 uint32 file_id,
229 base::File::Error error); 257 base::File::Error error);
230 258
231 // Given a full path, returns a non-empty sub-path that needs to be read into 259 // Given a full path, returns a non-empty sub-path that needs to be read into
232 // the cache if such a uncached path exists. 260 // the cache if such a uncached path exists.
233 // |cached_path| is the portion of |path| that has had cache lookup attempts. 261 // |cached_path| is the portion of |path| that has had cache lookup attempts.
234 base::FilePath NextUncachedPathComponent( 262 base::FilePath NextUncachedPathComponent(
(...skipping 15 matching lines...) Expand all
250 // overload the device. 278 // overload the device.
251 bool task_in_progress_; 279 bool task_in_progress_;
252 280
253 // Registered file system device path. This path does not 281 // Registered file system device path. This path does not
254 // correspond to a real device path (e.g. "/usb:2,2:81282"). 282 // correspond to a real device path (e.g. "/usb:2,2:81282").
255 const base::FilePath device_path_; 283 const base::FilePath device_path_;
256 284
257 // MTP device storage name (e.g. "usb:2,2:81282"). 285 // MTP device storage name (e.g. "usb:2,2:81282").
258 std::string storage_name_; 286 std::string storage_name_;
259 287
288 // Mode for opening storage.
289 const bool read_only_;
290
260 // A list of pending tasks that needs to be run when the device is 291 // A list of pending tasks that needs to be run when the device is
261 // initialized or when the current task in progress is complete. 292 // initialized or when the current task in progress is complete.
262 std::deque<PendingTaskInfo> pending_tasks_; 293 std::deque<PendingTaskInfo> pending_tasks_;
263 294
264 // Used to track the current snapshot file request. A snapshot file is created 295 // Used to track the current snapshot file request. A snapshot file is created
265 // incrementally. CreateSnapshotFile request reads the device file and writes 296 // incrementally. CreateSnapshotFile request reads the device file and writes
266 // to the snapshot file in chunks. In order to retain the order of the 297 // to the snapshot file in chunks. In order to retain the order of the
267 // snapshot file requests, make sure there is only one active snapshot file 298 // snapshot file requests, make sure there is only one active snapshot file
268 // request at any time. 299 // request at any time.
269 scoped_ptr<SnapshotRequestInfo> current_snapshot_request_info_; 300 scoped_ptr<SnapshotRequestInfo> current_snapshot_request_info_;
(...skipping 16 matching lines...) Expand all
286 // the ReadDirectory operation. 317 // the ReadDirectory operation.
287 FileInfoCache file_info_cache_; 318 FileInfoCache file_info_cache_;
288 319
289 // For callbacks that may run after destruction. 320 // For callbacks that may run after destruction.
290 base::WeakPtrFactory<MTPDeviceDelegateImplLinux> weak_ptr_factory_; 321 base::WeakPtrFactory<MTPDeviceDelegateImplLinux> weak_ptr_factory_;
291 322
292 DISALLOW_COPY_AND_ASSIGN(MTPDeviceDelegateImplLinux); 323 DISALLOW_COPY_AND_ASSIGN(MTPDeviceDelegateImplLinux);
293 }; 324 };
294 325
295 #endif // CHROME_BROWSER_MEDIA_GALLERIES_LINUX_MTP_DEVICE_DELEGATE_IMPL_LINUX_H _ 326 #endif // CHROME_BROWSER_MEDIA_GALLERIES_LINUX_MTP_DEVICE_DELEGATE_IMPL_LINUX_H _
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698