| 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 <stdint.h> |
| 9 |
| 8 #include <deque> | 10 #include <deque> |
| 9 #include <map> | 11 #include <map> |
| 10 #include <set> | 12 #include <set> |
| 11 #include <string> | 13 #include <string> |
| 12 | 14 |
| 13 #include "base/callback.h" | 15 #include "base/callback.h" |
| 14 #include "base/containers/scoped_ptr_hash_map.h" | 16 #include "base/containers/scoped_ptr_hash_map.h" |
| 15 #include "base/files/file_path.h" | 17 #include "base/files/file_path.h" |
| 16 #include "base/location.h" | 18 #include "base/location.h" |
| 17 #include "base/memory/scoped_ptr.h" | 19 #include "base/memory/scoped_ptr.h" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 base::FilePath path; | 55 base::FilePath path; |
| 54 base::FilePath cached_path; | 56 base::FilePath cached_path; |
| 55 const content::BrowserThread::ID thread_id; | 57 const content::BrowserThread::ID thread_id; |
| 56 const tracked_objects::Location location; | 58 const tracked_objects::Location location; |
| 57 const base::Closure task; | 59 const base::Closure task; |
| 58 }; | 60 }; |
| 59 | 61 |
| 60 class MTPFileNode; | 62 class MTPFileNode; |
| 61 | 63 |
| 62 // Maps file ids to file nodes. | 64 // Maps file ids to file nodes. |
| 63 typedef std::map<uint32, MTPFileNode*> FileIdToMTPFileNodeMap; | 65 typedef std::map<uint32_t, MTPFileNode*> FileIdToMTPFileNodeMap; |
| 64 | 66 |
| 65 // Maps file paths to file info. | 67 // Maps file paths to file info. |
| 66 typedef std::map<base::FilePath, MTPDeviceTaskHelper::MTPEntry> FileInfoCache; | 68 typedef std::map<base::FilePath, MTPDeviceTaskHelper::MTPEntry> FileInfoCache; |
| 67 | 69 |
| 68 typedef base::Closure DeleteObjectSuccessCallback; | 70 typedef base::Closure DeleteObjectSuccessCallback; |
| 69 | 71 |
| 70 // Should only be called by CreateMTPDeviceAsyncDelegate() factory call. | 72 // Should only be called by CreateMTPDeviceAsyncDelegate() factory call. |
| 71 // Defer the device initializations until the first file operation request. | 73 // Defer the device initializations until the first file operation request. |
| 72 // Do all the initializations in EnsureInitAndRunTask() function. | 74 // Do all the initializations in EnsureInitAndRunTask() function. |
| 73 MTPDeviceDelegateImplLinux(const std::string& device_location, | 75 MTPDeviceDelegateImplLinux(const std::string& device_location, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 89 const ReadDirectorySuccessCallback& success_callback, | 91 const ReadDirectorySuccessCallback& success_callback, |
| 90 const ErrorCallback& error_callback) override; | 92 const ErrorCallback& error_callback) override; |
| 91 void CreateSnapshotFile( | 93 void CreateSnapshotFile( |
| 92 const base::FilePath& device_file_path, | 94 const base::FilePath& device_file_path, |
| 93 const base::FilePath& local_path, | 95 const base::FilePath& local_path, |
| 94 const CreateSnapshotFileSuccessCallback& success_callback, | 96 const CreateSnapshotFileSuccessCallback& success_callback, |
| 95 const ErrorCallback& error_callback) override; | 97 const ErrorCallback& error_callback) override; |
| 96 bool IsStreaming() override; | 98 bool IsStreaming() override; |
| 97 void ReadBytes(const base::FilePath& device_file_path, | 99 void ReadBytes(const base::FilePath& device_file_path, |
| 98 const scoped_refptr<net::IOBuffer>& buf, | 100 const scoped_refptr<net::IOBuffer>& buf, |
| 99 int64 offset, | 101 int64_t offset, |
| 100 int buf_len, | 102 int buf_len, |
| 101 const ReadBytesSuccessCallback& success_callback, | 103 const ReadBytesSuccessCallback& success_callback, |
| 102 const ErrorCallback& error_callback) override; | 104 const ErrorCallback& error_callback) override; |
| 103 bool IsReadOnly() const override; | 105 bool IsReadOnly() const override; |
| 104 void CopyFileLocal( | 106 void CopyFileLocal( |
| 105 const base::FilePath& source_file_path, | 107 const base::FilePath& source_file_path, |
| 106 const base::FilePath& device_file_path, | 108 const base::FilePath& device_file_path, |
| 107 const CreateTemporaryFileCallback& create_temporary_file_callback, | 109 const CreateTemporaryFileCallback& create_temporary_file_callback, |
| 108 const CopyFileProgressCallback& progress_callback, | 110 const CopyFileProgressCallback& progress_callback, |
| 109 const CopyFileLocalSuccessCallback& success_callback, | 111 const CopyFileLocalSuccessCallback& success_callback, |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 const base::FilePath& root, | 155 const base::FilePath& root, |
| 154 const ReadDirectorySuccessCallback& success_callback, | 156 const ReadDirectorySuccessCallback& success_callback, |
| 155 const ErrorCallback& error_callback); | 157 const ErrorCallback& error_callback); |
| 156 virtual void CreateSnapshotFileInternal( | 158 virtual void CreateSnapshotFileInternal( |
| 157 const base::FilePath& device_file_path, | 159 const base::FilePath& device_file_path, |
| 158 const base::FilePath& local_path, | 160 const base::FilePath& local_path, |
| 159 const CreateSnapshotFileSuccessCallback& success_callback, | 161 const CreateSnapshotFileSuccessCallback& success_callback, |
| 160 const ErrorCallback& error_callback); | 162 const ErrorCallback& error_callback); |
| 161 virtual void ReadBytesInternal( | 163 virtual void ReadBytesInternal( |
| 162 const base::FilePath& device_file_path, | 164 const base::FilePath& device_file_path, |
| 163 net::IOBuffer* buf, int64 offset, int buf_len, | 165 net::IOBuffer* buf, |
| 166 int64_t offset, |
| 167 int buf_len, |
| 164 const ReadBytesSuccessCallback& success_callback, | 168 const ReadBytesSuccessCallback& success_callback, |
| 165 const ErrorCallback& error_callback); | 169 const ErrorCallback& error_callback); |
| 166 virtual void MoveFileLocalInternal( | 170 virtual void MoveFileLocalInternal( |
| 167 const base::FilePath& source_file_path, | 171 const base::FilePath& source_file_path, |
| 168 const base::FilePath& device_file_path, | 172 const base::FilePath& device_file_path, |
| 169 const CreateTemporaryFileCallback& create_temporary_file_callback, | 173 const CreateTemporaryFileCallback& create_temporary_file_callback, |
| 170 const MoveFileLocalSuccessCallback& success_callback, | 174 const MoveFileLocalSuccessCallback& success_callback, |
| 171 const ErrorCallback& error_callback, | 175 const ErrorCallback& error_callback, |
| 172 const base::File::Info& source_file_info); | 176 const base::File::Info& source_file_info); |
| 173 virtual void OnDidOpenFDToCopyFileFromLocal( | 177 virtual void OnDidOpenFDToCopyFileFromLocal( |
| (...skipping 26 matching lines...) Expand all Loading... |
| 200 const std::vector<base::FilePath>& components, | 204 const std::vector<base::FilePath>& components, |
| 201 const bool exclusive, | 205 const bool exclusive, |
| 202 const CreateDirectorySuccessCallback& success_callback, | 206 const CreateDirectorySuccessCallback& success_callback, |
| 203 const ErrorCallback& error_callback, | 207 const ErrorCallback& error_callback, |
| 204 const storage::AsyncFileUtil::EntryList& entries, | 208 const storage::AsyncFileUtil::EntryList& entries, |
| 205 const bool has_more); | 209 const bool has_more); |
| 206 | 210 |
| 207 // Called when ReadDirectory succeeds. | 211 // Called when ReadDirectory succeeds. |
| 208 virtual void OnDidReadDirectoryToDeleteDirectory( | 212 virtual void OnDidReadDirectoryToDeleteDirectory( |
| 209 const base::FilePath& directory_path, | 213 const base::FilePath& directory_path, |
| 210 const uint32 directory_id, | 214 const uint32_t directory_id, |
| 211 const DeleteDirectorySuccessCallback& success_callback, | 215 const DeleteDirectorySuccessCallback& success_callback, |
| 212 const ErrorCallback& error_callback, | 216 const ErrorCallback& error_callback, |
| 213 const MTPDeviceTaskHelper::MTPEntries& entries, | 217 const MTPDeviceTaskHelper::MTPEntries& entries, |
| 214 const bool has_more); | 218 const bool has_more); |
| 215 | 219 |
| 216 // Calls DeleteObjectOnUIThread on UI thread. | 220 // Calls DeleteObjectOnUIThread on UI thread. |
| 217 virtual void RunDeleteObjectOnUIThread( | 221 virtual void RunDeleteObjectOnUIThread( |
| 218 const base::FilePath& object_path, | 222 const base::FilePath& object_path, |
| 219 const uint32 object_id, | 223 const uint32_t object_id, |
| 220 const DeleteObjectSuccessCallback& success_callback, | 224 const DeleteObjectSuccessCallback& success_callback, |
| 221 const ErrorCallback& error_callback); | 225 const ErrorCallback& error_callback); |
| 222 | 226 |
| 223 // Notifies |chage_type| of |file_path| to watchers. | 227 // Notifies |chage_type| of |file_path| to watchers. |
| 224 void NotifyFileChange(const base::FilePath& file_path, | 228 void NotifyFileChange(const base::FilePath& file_path, |
| 225 const storage::WatcherManager::ChangeType change_type); | 229 const storage::WatcherManager::ChangeType change_type); |
| 226 | 230 |
| 227 // Ensures the device is initialized for communication. | 231 // Ensures the device is initialized for communication. |
| 228 // If the device is already initialized, call RunTask(). | 232 // If the device is already initialized, call RunTask(). |
| 229 // | 233 // |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 // Called when GetFileInfo() succeeds. GetFileInfo() is invoked to | 286 // Called when GetFileInfo() succeeds. GetFileInfo() is invoked to |
| 283 // get the |dir_id| directory metadata details. |file_info| specifies the | 287 // get the |dir_id| directory metadata details. |file_info| specifies the |
| 284 // |dir_id| directory details. | 288 // |dir_id| directory details. |
| 285 // | 289 // |
| 286 // If |dir_id| is a directory, post a task on the UI thread to read the | 290 // If |dir_id| is a directory, post a task on the UI thread to read the |
| 287 // |dir_id| directory file entries. | 291 // |dir_id| directory file entries. |
| 288 // | 292 // |
| 289 // If |dir_id| is not a directory, |error_callback| is invoked to notify the | 293 // If |dir_id| is not a directory, |error_callback| is invoked to notify the |
| 290 // caller about the file error and process the next pending request. | 294 // caller about the file error and process the next pending request. |
| 291 void OnDidGetFileInfoToReadDirectory( | 295 void OnDidGetFileInfoToReadDirectory( |
| 292 uint32 dir_id, | 296 uint32_t dir_id, |
| 293 const ReadDirectorySuccessCallback& success_callback, | 297 const ReadDirectorySuccessCallback& success_callback, |
| 294 const ErrorCallback& error_callback, | 298 const ErrorCallback& error_callback, |
| 295 const base::File::Info& file_info); | 299 const base::File::Info& file_info); |
| 296 | 300 |
| 297 // Called when GetFileInfo() succeeds. GetFileInfo() is invoked to | 301 // Called when GetFileInfo() succeeds. GetFileInfo() is invoked to |
| 298 // create the snapshot file of |snapshot_request_info.device_file_path|. | 302 // create the snapshot file of |snapshot_request_info.device_file_path|. |
| 299 // |file_info| specifies the device file metadata details. | 303 // |file_info| specifies the device file metadata details. |
| 300 // | 304 // |
| 301 // Posts a task on the UI thread to copy the data contents of the device file | 305 // Posts a task on the UI thread to copy the data contents of the device file |
| 302 // to the snapshot file. | 306 // to the snapshot file. |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 const ErrorCallback& callback, | 344 const ErrorCallback& callback, |
| 341 const base::File::Error error); | 345 const base::File::Error error); |
| 342 | 346 |
| 343 // Called when ReadDirectory() succeeds. | 347 // Called when ReadDirectory() succeeds. |
| 344 // | 348 // |
| 345 // |dir_id| is the directory read. | 349 // |dir_id| is the directory read. |
| 346 // |success_callback| is invoked to notify the caller about the directory | 350 // |success_callback| is invoked to notify the caller about the directory |
| 347 // file entries. | 351 // file entries. |
| 348 // |file_list| contains the directory file entries with their file ids. | 352 // |file_list| contains the directory file entries with their file ids. |
| 349 // |has_more| is true if there are more file entries to read. | 353 // |has_more| is true if there are more file entries to read. |
| 350 void OnDidReadDirectory(uint32 dir_id, | 354 void OnDidReadDirectory(uint32_t dir_id, |
| 351 const ReadDirectorySuccessCallback& success_callback, | 355 const ReadDirectorySuccessCallback& success_callback, |
| 352 const MTPDeviceTaskHelper::MTPEntries& mtp_entries, | 356 const MTPDeviceTaskHelper::MTPEntries& mtp_entries, |
| 353 bool has_more); | 357 bool has_more); |
| 354 | 358 |
| 355 // Called when WriteDataIntoSnapshotFile() succeeds. | 359 // Called when WriteDataIntoSnapshotFile() succeeds. |
| 356 // | 360 // |
| 357 // |snapshot_file_info| specifies the snapshot file metadata details. | 361 // |snapshot_file_info| specifies the snapshot file metadata details. |
| 358 // | 362 // |
| 359 // |current_snapshot_request_info_.success_callback| is invoked to notify the | 363 // |current_snapshot_request_info_.success_callback| is invoked to notify the |
| 360 // caller about |snapshot_file_info|. | 364 // caller about |snapshot_file_info|. |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 406 | 410 |
| 407 // Called when CopyFileFromLocal() succeeds for CopyFileLocal. | 411 // Called when CopyFileFromLocal() succeeds for CopyFileLocal. |
| 408 void OnDidCopyFileFromLocalOfCopyFileLocal( | 412 void OnDidCopyFileFromLocalOfCopyFileLocal( |
| 409 const CopyFileFromLocalSuccessCallback success_callback, | 413 const CopyFileFromLocalSuccessCallback success_callback, |
| 410 const base::FilePath& temporary_file_path); | 414 const base::FilePath& temporary_file_path); |
| 411 | 415 |
| 412 // Called when MoveFileLocal() succeeds with rename operation. | 416 // Called when MoveFileLocal() succeeds with rename operation. |
| 413 void OnDidMoveFileLocalWithRename( | 417 void OnDidMoveFileLocalWithRename( |
| 414 const MoveFileLocalSuccessCallback& success_callback, | 418 const MoveFileLocalSuccessCallback& success_callback, |
| 415 const base::FilePath& source_file_path, | 419 const base::FilePath& source_file_path, |
| 416 const uint32 file_id); | 420 const uint32_t file_id); |
| 417 | 421 |
| 418 // Called when CopyFileFromLocal() succeeds. | 422 // Called when CopyFileFromLocal() succeeds. |
| 419 void OnDidCopyFileFromLocal( | 423 void OnDidCopyFileFromLocal( |
| 420 const CopyFileFromLocalSuccessCallback& success_callback, | 424 const CopyFileFromLocalSuccessCallback& success_callback, |
| 421 const base::FilePath& file_path, | 425 const base::FilePath& file_path, |
| 422 const int source_file_descriptor); | 426 const int source_file_descriptor); |
| 423 | 427 |
| 424 // Called when CopyFileLocal() fails. | 428 // Called when CopyFileLocal() fails. |
| 425 void HandleCopyFileLocalError(const ErrorCallback& error_callback, | 429 void HandleCopyFileLocalError(const ErrorCallback& error_callback, |
| 426 const base::FilePath& temporary_file_path, | 430 const base::FilePath& temporary_file_path, |
| 427 const base::File::Error error); | 431 const base::File::Error error); |
| 428 | 432 |
| 429 // Called when CopyFileFromLocal() fails. | 433 // Called when CopyFileFromLocal() fails. |
| 430 void HandleCopyFileFromLocalError(const ErrorCallback& error_callback, | 434 void HandleCopyFileFromLocalError(const ErrorCallback& error_callback, |
| 431 const int source_file_descriptor, | 435 const int source_file_descriptor, |
| 432 base::File::Error error); | 436 base::File::Error error); |
| 433 | 437 |
| 434 // Called when DeleteObject() succeeds. | 438 // Called when DeleteObject() succeeds. |
| 435 void OnDidDeleteObject(const base::FilePath& object_path, | 439 void OnDidDeleteObject(const base::FilePath& object_path, |
| 436 const uint32 object_id, | 440 const uint32_t object_id, |
| 437 const DeleteObjectSuccessCallback success_callback); | 441 const DeleteObjectSuccessCallback success_callback); |
| 438 | 442 |
| 439 // Called when DeleteFileOrDirectory() fails. | 443 // Called when DeleteFileOrDirectory() fails. |
| 440 void HandleDeleteFileOrDirectoryError(const ErrorCallback& error_callback, | 444 void HandleDeleteFileOrDirectoryError(const ErrorCallback& error_callback, |
| 441 base::File::Error error); | 445 base::File::Error error); |
| 442 | 446 |
| 443 // Handles the device file |error| while operating on |file_id|. | 447 // Handles the device file |error| while operating on |file_id|. |
| 444 // |error_callback| is invoked to notify the caller about the file error. | 448 // |error_callback| is invoked to notify the caller about the file error. |
| 445 void HandleDeviceFileError(const ErrorCallback& error_callback, | 449 void HandleDeviceFileError(const ErrorCallback& error_callback, |
| 446 uint32 file_id, | 450 uint32_t file_id, |
| 447 base::File::Error error); | 451 base::File::Error error); |
| 448 | 452 |
| 449 // Given a full path, returns a non-empty sub-path that needs to be read into | 453 // Given a full path, returns a non-empty sub-path that needs to be read into |
| 450 // the cache if such a uncached path exists. | 454 // the cache if such a uncached path exists. |
| 451 // |cached_path| is the portion of |path| that has had cache lookup attempts. | 455 // |cached_path| is the portion of |path| that has had cache lookup attempts. |
| 452 base::FilePath NextUncachedPathComponent( | 456 base::FilePath NextUncachedPathComponent( |
| 453 const base::FilePath& path, | 457 const base::FilePath& path, |
| 454 const base::FilePath& cached_path) const; | 458 const base::FilePath& cached_path) const; |
| 455 | 459 |
| 456 // Fills the file cache using the results from NextUncachedPathComponent(). | 460 // Fills the file cache using the results from NextUncachedPathComponent(). |
| 457 void FillFileCache(const base::FilePath& uncached_path); | 461 void FillFileCache(const base::FilePath& uncached_path); |
| 458 | 462 |
| 459 // Given a full path, if it exists in the cache, writes the file's id to |id| | 463 // Given a full path, if it exists in the cache, writes the file's id to |id| |
| 460 // and return true. | 464 // and return true. |
| 461 bool CachedPathToId(const base::FilePath& path, uint32* id) const; | 465 bool CachedPathToId(const base::FilePath& path, uint32_t* id) const; |
| 462 | 466 |
| 463 // Evict the cache of |id|. | 467 // Evict the cache of |id|. |
| 464 void EvictCachedPathToId(const uint32 id); | 468 void EvictCachedPathToId(const uint32_t id); |
| 465 | 469 |
| 466 // MTP device initialization state. | 470 // MTP device initialization state. |
| 467 InitializationState init_state_; | 471 InitializationState init_state_; |
| 468 | 472 |
| 469 // Used to make sure only one task is in progress at any time. | 473 // Used to make sure only one task is in progress at any time. |
| 470 // Otherwise the browser will try to send too many requests at once and | 474 // Otherwise the browser will try to send too many requests at once and |
| 471 // overload the device. | 475 // overload the device. |
| 472 bool task_in_progress_; | 476 bool task_in_progress_; |
| 473 | 477 |
| 474 // Registered file system device path. This path does not | 478 // Registered file system device path. This path does not |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 516 // the ReadDirectory operation. | 520 // the ReadDirectory operation. |
| 517 FileInfoCache file_info_cache_; | 521 FileInfoCache file_info_cache_; |
| 518 | 522 |
| 519 // For callbacks that may run after destruction. | 523 // For callbacks that may run after destruction. |
| 520 base::WeakPtrFactory<MTPDeviceDelegateImplLinux> weak_ptr_factory_; | 524 base::WeakPtrFactory<MTPDeviceDelegateImplLinux> weak_ptr_factory_; |
| 521 | 525 |
| 522 DISALLOW_COPY_AND_ASSIGN(MTPDeviceDelegateImplLinux); | 526 DISALLOW_COPY_AND_ASSIGN(MTPDeviceDelegateImplLinux); |
| 523 }; | 527 }; |
| 524 | 528 |
| 525 #endif // CHROME_BROWSER_MEDIA_GALLERIES_LINUX_MTP_DEVICE_DELEGATE_IMPL_LINUX_H
_ | 529 #endif // CHROME_BROWSER_MEDIA_GALLERIES_LINUX_MTP_DEVICE_DELEGATE_IMPL_LINUX_H
_ |
| OLD | NEW |