| OLD | NEW |
| 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 }; | 57 }; |
| 58 | 58 |
| 59 class MTPFileNode; | 59 class MTPFileNode; |
| 60 | 60 |
| 61 // Maps file ids to file nodes. | 61 // Maps file ids to file nodes. |
| 62 typedef std::map<uint32, MTPFileNode*> FileIdToMTPFileNodeMap; | 62 typedef std::map<uint32, MTPFileNode*> FileIdToMTPFileNodeMap; |
| 63 | 63 |
| 64 // Maps file paths to file info. | 64 // Maps file paths to file info. |
| 65 typedef std::map<base::FilePath, storage::DirectoryEntry> FileInfoCache; | 65 typedef std::map<base::FilePath, storage::DirectoryEntry> FileInfoCache; |
| 66 | 66 |
| 67 typedef base::Closure DeleteObjectSuccessCallback; |
| 68 |
| 67 // Should only be called by CreateMTPDeviceAsyncDelegate() factory call. | 69 // Should only be called by CreateMTPDeviceAsyncDelegate() factory call. |
| 68 // Defer the device initializations until the first file operation request. | 70 // Defer the device initializations until the first file operation request. |
| 69 // Do all the initializations in EnsureInitAndRunTask() function. | 71 // Do all the initializations in EnsureInitAndRunTask() function. |
| 70 MTPDeviceDelegateImplLinux(const std::string& device_location, | 72 MTPDeviceDelegateImplLinux(const std::string& device_location, |
| 71 const bool read_only); | 73 const bool read_only); |
| 72 | 74 |
| 73 // Destructed via CancelPendingTasksAndDeleteDelegate(). | 75 // Destructed via CancelPendingTasksAndDeleteDelegate(). |
| 74 ~MTPDeviceDelegateImplLinux() override; | 76 ~MTPDeviceDelegateImplLinux() override; |
| 75 | 77 |
| 76 // MTPDeviceAsyncDelegate: | 78 // MTPDeviceAsyncDelegate: |
| 77 void GetFileInfo(const base::FilePath& file_path, | 79 void GetFileInfo(const base::FilePath& file_path, |
| 78 const GetFileInfoSuccessCallback& success_callback, | 80 const GetFileInfoSuccessCallback& success_callback, |
| 79 const ErrorCallback& error_callback) override; | 81 const ErrorCallback& error_callback) override; |
| 80 void ReadDirectory(const base::FilePath& root, | 82 void ReadDirectory(const base::FilePath& root, |
| 81 const ReadDirectorySuccessCallback& success_callback, | 83 const ReadDirectorySuccessCallback& success_callback, |
| 82 const ErrorCallback& error_callback) override; | 84 const ErrorCallback& error_callback) override; |
| 83 void CreateSnapshotFile( | 85 void CreateSnapshotFile( |
| 84 const base::FilePath& device_file_path, | 86 const base::FilePath& device_file_path, |
| 85 const base::FilePath& local_path, | 87 const base::FilePath& local_path, |
| 86 const CreateSnapshotFileSuccessCallback& success_callback, | 88 const CreateSnapshotFileSuccessCallback& success_callback, |
| 87 const ErrorCallback& error_callback) override; | 89 const ErrorCallback& error_callback) override; |
| 88 bool IsStreaming() override; | 90 bool IsStreaming() override; |
| 89 void ReadBytes(const base::FilePath& device_file_path, | 91 void ReadBytes(const base::FilePath& device_file_path, |
| 90 const scoped_refptr<net::IOBuffer>& buf, | 92 const scoped_refptr<net::IOBuffer>& buf, |
| 91 int64 offset, | 93 int64 offset, |
| 92 int buf_len, | 94 int buf_len, |
| 93 const ReadBytesSuccessCallback& success_callback, | 95 const ReadBytesSuccessCallback& success_callback, |
| 94 const ErrorCallback& error_callback) override; | 96 const ErrorCallback& error_callback) override; |
| 95 bool IsReadOnly() override; | 97 bool IsReadOnly() const override; |
| 96 void CopyFileFromLocal( | 98 void CopyFileFromLocal( |
| 97 const base::FilePath& source_file_path, | 99 const base::FilePath& source_file_path, |
| 98 const base::FilePath& device_file_path, | 100 const base::FilePath& device_file_path, |
| 99 const CopyFileFromLocalSuccessCallback& success_callback, | 101 const CopyFileFromLocalSuccessCallback& success_callback, |
| 100 const ErrorCallback& error_callback) override; | 102 const ErrorCallback& error_callback) override; |
| 103 void DeleteFile(const base::FilePath& file_path, |
| 104 const DeleteFileSuccessCallback& success_callback, |
| 105 const ErrorCallback& error_callback) override; |
| 106 void DeleteDirectory(const base::FilePath& file_path, |
| 107 const DeleteDirectorySuccessCallback& success_callback, |
| 108 const ErrorCallback& error_callback) override; |
| 101 void CancelPendingTasksAndDeleteDelegate() override; | 109 void CancelPendingTasksAndDeleteDelegate() override; |
| 102 | 110 |
| 103 // The internal methods correspond to the similarly named methods above. | 111 // The internal methods correspond to the similarly named methods above. |
| 104 // The |root_node_| cache should be filled at this point. | 112 // The |root_node_| cache should be filled at this point. |
| 105 virtual void GetFileInfoInternal( | 113 virtual void GetFileInfoInternal( |
| 106 const base::FilePath& file_path, | 114 const base::FilePath& file_path, |
| 107 const GetFileInfoSuccessCallback& success_callback, | 115 const GetFileInfoSuccessCallback& success_callback, |
| 108 const ErrorCallback& error_callback); | 116 const ErrorCallback& error_callback); |
| 109 virtual void ReadDirectoryInternal( | 117 virtual void ReadDirectoryInternal( |
| 110 const base::FilePath& root, | 118 const base::FilePath& root, |
| 111 const ReadDirectorySuccessCallback& success_callback, | 119 const ReadDirectorySuccessCallback& success_callback, |
| 112 const ErrorCallback& error_callback); | 120 const ErrorCallback& error_callback); |
| 113 virtual void CreateSnapshotFileInternal( | 121 virtual void CreateSnapshotFileInternal( |
| 114 const base::FilePath& device_file_path, | 122 const base::FilePath& device_file_path, |
| 115 const base::FilePath& local_path, | 123 const base::FilePath& local_path, |
| 116 const CreateSnapshotFileSuccessCallback& success_callback, | 124 const CreateSnapshotFileSuccessCallback& success_callback, |
| 117 const ErrorCallback& error_callback); | 125 const ErrorCallback& error_callback); |
| 118 virtual void ReadBytesInternal( | 126 virtual void ReadBytesInternal( |
| 119 const base::FilePath& device_file_path, | 127 const base::FilePath& device_file_path, |
| 120 net::IOBuffer* buf, int64 offset, int buf_len, | 128 net::IOBuffer* buf, int64 offset, int buf_len, |
| 121 const ReadBytesSuccessCallback& success_callback, | 129 const ReadBytesSuccessCallback& success_callback, |
| 122 const ErrorCallback& error_callback); | 130 const ErrorCallback& error_callback); |
| 123 virtual void CopyFileFromLocalInternal( | 131 virtual void CopyFileFromLocalInternal( |
| 124 const base::FilePath& device_file_path, | 132 const base::FilePath& device_file_path, |
| 125 const CopyFileFromLocalSuccessCallback& success_callback, | 133 const CopyFileFromLocalSuccessCallback& success_callback, |
| 126 const ErrorCallback& error_callback, | 134 const ErrorCallback& error_callback, |
| 127 const int source_file_descriptor); | 135 const int source_file_descriptor); |
| 136 virtual void DeleteFileInternal( |
| 137 const base::FilePath& file_path, |
| 138 const DeleteFileSuccessCallback& success_callback, |
| 139 const ErrorCallback& error_callback, |
| 140 const base::File::Info& file_info); |
| 141 virtual void DeleteDirectoryInternal( |
| 142 const base::FilePath& file_path, |
| 143 const DeleteDirectorySuccessCallback& success_callback, |
| 144 const ErrorCallback& error_callback, |
| 145 const base::File::Info& file_info); |
| 146 |
| 147 // Called when ReadDirectory succeeds. |
| 148 virtual void OnDidReadDirectoryToDeleteDirectory( |
| 149 const uint32 directory_id, |
| 150 const DeleteDirectorySuccessCallback& success_callback, |
| 151 const ErrorCallback& error_callback, |
| 152 const storage::AsyncFileUtil::EntryList& entries, |
| 153 const bool has_more); |
| 154 |
| 155 // Calls DeleteObjectOnUIThread on UI thread. |
| 156 virtual void RunDeleteObjectOnUIThread( |
| 157 const uint32 object_id, |
| 158 const DeleteObjectSuccessCallback& success_callback, |
| 159 const ErrorCallback& error_callback); |
| 128 | 160 |
| 129 // Ensures the device is initialized for communication. | 161 // Ensures the device is initialized for communication. |
| 130 // If the device is already initialized, call RunTask(). | 162 // If the device is already initialized, call RunTask(). |
| 131 // | 163 // |
| 132 // If the device is uninitialized, store the |task_info| in a pending task | 164 // If the device is uninitialized, store the |task_info| in a pending task |
| 133 // queue and runs the pending tasks in the queue once the device is | 165 // queue and runs the pending tasks in the queue once the device is |
| 134 // successfully initialized. | 166 // successfully initialized. |
| 135 void EnsureInitAndRunTask(const PendingTaskInfo& task_info); | 167 void EnsureInitAndRunTask(const PendingTaskInfo& task_info); |
| 136 | 168 |
| 137 // Runs a task. If |task_info.path| is empty, or if the path is cached, runs | 169 // Runs a task. If |task_info.path| is empty, or if the path is cached, runs |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 // Called when CopyFileFromLocal() succeeds. | 270 // Called when CopyFileFromLocal() succeeds. |
| 239 void OnDidCopyFileFromLocal( | 271 void OnDidCopyFileFromLocal( |
| 240 const CopyFileFromLocalSuccessCallback& success_callback, | 272 const CopyFileFromLocalSuccessCallback& success_callback, |
| 241 const int source_file_descriptor); | 273 const int source_file_descriptor); |
| 242 | 274 |
| 243 // Called when CopyFileFromLocal() fails. | 275 // Called when CopyFileFromLocal() fails. |
| 244 void HandleCopyFileFromLocalError(const ErrorCallback& error_callback, | 276 void HandleCopyFileFromLocalError(const ErrorCallback& error_callback, |
| 245 const int source_file_descriptor, | 277 const int source_file_descriptor, |
| 246 base::File::Error error); | 278 base::File::Error error); |
| 247 | 279 |
| 280 // Called when DeleteObject() succeeds. |
| 281 void OnDidDeleteObject(const uint32 object_id, |
| 282 const DeleteObjectSuccessCallback success_callback); |
| 283 |
| 284 // Called when DeleteFileOrDirectory() fails. |
| 285 void HandleDeleteFileOrDirectoryError(const ErrorCallback& error_callback, |
| 286 base::File::Error error); |
| 287 |
| 248 // Handles the device file |error| while operating on |file_id|. | 288 // Handles the device file |error| while operating on |file_id|. |
| 249 // |error_callback| is invoked to notify the caller about the file error. | 289 // |error_callback| is invoked to notify the caller about the file error. |
| 250 void HandleDeviceFileError(const ErrorCallback& error_callback, | 290 void HandleDeviceFileError(const ErrorCallback& error_callback, |
| 251 uint32 file_id, | 291 uint32 file_id, |
| 252 base::File::Error error); | 292 base::File::Error error); |
| 253 | 293 |
| 254 // Given a full path, returns a non-empty sub-path that needs to be read into | 294 // Given a full path, returns a non-empty sub-path that needs to be read into |
| 255 // the cache if such a uncached path exists. | 295 // the cache if such a uncached path exists. |
| 256 // |cached_path| is the portion of |path| that has had cache lookup attempts. | 296 // |cached_path| is the portion of |path| that has had cache lookup attempts. |
| 257 base::FilePath NextUncachedPathComponent( | 297 base::FilePath NextUncachedPathComponent( |
| 258 const base::FilePath& path, | 298 const base::FilePath& path, |
| 259 const base::FilePath& cached_path) const; | 299 const base::FilePath& cached_path) const; |
| 260 | 300 |
| 261 // Fills the file cache using the results from NextUncachedPathComponent(). | 301 // Fills the file cache using the results from NextUncachedPathComponent(). |
| 262 void FillFileCache(const base::FilePath& uncached_path); | 302 void FillFileCache(const base::FilePath& uncached_path); |
| 263 | 303 |
| 264 // Given a full path, if it exists in the cache, writes the file's id to |id| | 304 // Given a full path, if it exists in the cache, writes the file's id to |id| |
| 265 // and return true. | 305 // and return true. |
| 266 bool CachedPathToId(const base::FilePath& path, uint32* id) const; | 306 bool CachedPathToId(const base::FilePath& path, uint32* id) const; |
| 267 | 307 |
| 308 // Evict the cache of |id|. |
| 309 void EvictCachedPathToId(const uint32 id); |
| 310 |
| 268 // MTP device initialization state. | 311 // MTP device initialization state. |
| 269 InitializationState init_state_; | 312 InitializationState init_state_; |
| 270 | 313 |
| 271 // Used to make sure only one task is in progress at any time. | 314 // Used to make sure only one task is in progress at any time. |
| 272 // Otherwise the browser will try to send too many requests at once and | 315 // Otherwise the browser will try to send too many requests at once and |
| 273 // overload the device. | 316 // overload the device. |
| 274 bool task_in_progress_; | 317 bool task_in_progress_; |
| 275 | 318 |
| 276 // Registered file system device path. This path does not | 319 // Registered file system device path. This path does not |
| 277 // correspond to a real device path (e.g. "/usb:2,2:81282"). | 320 // correspond to a real device path (e.g. "/usb:2,2:81282"). |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 // the ReadDirectory operation. | 355 // the ReadDirectory operation. |
| 313 FileInfoCache file_info_cache_; | 356 FileInfoCache file_info_cache_; |
| 314 | 357 |
| 315 // For callbacks that may run after destruction. | 358 // For callbacks that may run after destruction. |
| 316 base::WeakPtrFactory<MTPDeviceDelegateImplLinux> weak_ptr_factory_; | 359 base::WeakPtrFactory<MTPDeviceDelegateImplLinux> weak_ptr_factory_; |
| 317 | 360 |
| 318 DISALLOW_COPY_AND_ASSIGN(MTPDeviceDelegateImplLinux); | 361 DISALLOW_COPY_AND_ASSIGN(MTPDeviceDelegateImplLinux); |
| 319 }; | 362 }; |
| 320 | 363 |
| 321 #endif // CHROME_BROWSER_MEDIA_GALLERIES_LINUX_MTP_DEVICE_DELEGATE_IMPL_LINUX_H
_ | 364 #endif // CHROME_BROWSER_MEDIA_GALLERIES_LINUX_MTP_DEVICE_DELEGATE_IMPL_LINUX_H
_ |
| OLD | NEW |