| 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_CHROMEOS_DRIVE_FILE_SYSTEM_MOVE_OPERATION_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_MOVE_OPERATION_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_MOVE_OPERATION_H_ | 6 #define CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_MOVE_OPERATION_H_ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 | 22 |
| 23 namespace file_system { | 23 namespace file_system { |
| 24 | 24 |
| 25 class OperationObserver; | 25 class OperationObserver; |
| 26 | 26 |
| 27 // This class encapsulates the drive Move function. It is responsible for | 27 // This class encapsulates the drive Move function. It is responsible for |
| 28 // sending the request to the drive API, then updating the local state and | 28 // sending the request to the drive API, then updating the local state and |
| 29 // metadata to reflect the new state. | 29 // metadata to reflect the new state. |
| 30 class MoveOperation { | 30 class MoveOperation { |
| 31 public: | 31 public: |
| 32 MoveOperation(OperationObserver* observer, | 32 MoveOperation(base::SequencedTaskRunner* blocking_task_runner, |
| 33 OperationObserver* observer, |
| 33 JobScheduler* scheduler, | 34 JobScheduler* scheduler, |
| 34 internal::ResourceMetadata* metadata); | 35 internal::ResourceMetadata* metadata); |
| 35 ~MoveOperation(); | 36 ~MoveOperation(); |
| 36 | 37 |
| 37 // Performs the move operation on the file at drive path |src_file_path| | 38 // Performs the move operation on the file at drive path |src_file_path| |
| 38 // with a target of |dest_file_path|. Invokes |callback| when finished with | 39 // with a target of |dest_file_path|. Invokes |callback| when finished with |
| 39 // the result of the operation. |callback| must not be null. | 40 // the result of the operation. |callback| must not be null. |
| 40 void Move(const base::FilePath& src_file_path, | 41 void Move(const base::FilePath& src_file_path, |
| 41 const base::FilePath& dest_file_path, | 42 const base::FilePath& dest_file_path, |
| 42 const FileOperationCallback& callback); | 43 const FileOperationCallback& callback); |
| 44 |
| 43 private: | 45 private: |
| 44 // Step 1 of Move(), called after the resource entry of the source and the | 46 // Part of Move(). Called after local metadata look up. |
| 45 // destination directory is obtained. It renames the resource in the source | 47 void MoveAfterPrepare(const base::FilePath& src_file_path, |
| 46 // directory, before moving between directories. | 48 const base::FilePath& dest_file_path, |
| 47 void MoveAfterGetResourceEntryPair( | 49 const FileOperationCallback& callback, |
| 48 const base::FilePath& dest_file_path, | 50 scoped_ptr<ResourceEntry> src_entry, |
| 51 scoped_ptr<ResourceEntry> dest_parent_entry, |
| 52 FileError error); |
| 53 |
| 54 // Part of Move(). Called after renaming (without moving the directory) |
| 55 // is completed. |
| 56 void MoveAfterRename(const base::FilePath& src_file_path, |
| 57 const base::FilePath& dest_file_path, |
| 58 const FileOperationCallback& callback, |
| 59 scoped_ptr<ResourceEntry> src_entry, |
| 60 scoped_ptr<ResourceEntry> dest_parent_entry, |
| 61 FileError error); |
| 62 |
| 63 // Part of Move(). Called after adding the entry to the parent is done. |
| 64 void MoveAfterAddToDirectory(const base::FilePath& src_file_path, |
| 65 const base::FilePath& dest_file_path, |
| 66 const FileOperationCallback& callback, |
| 67 const std::string& resource_id, |
| 68 const std::string& parent_resource_id, |
| 69 FileError error); |
| 70 |
| 71 |
| 72 // Renames the |entry| to |new_title|. Upon completion, |callback| will be |
| 73 // called. Note that if |entry|'s title is same as |new_title|, does nothing |
| 74 // and calls |callback|. |
| 75 // |callback| must not be null. |
| 76 void Rename(const ResourceEntry& entry, |
| 77 const std::string& new_title, |
| 78 const FileOperationCallback& callback); |
| 79 |
| 80 // Part of Rename(). Called after server side renaming is done. |
| 81 void RenameAfterRenameResource(const std::string& resource_id, |
| 82 const std::string& new_title, |
| 83 const FileOperationCallback& callback, |
| 84 google_apis::GDataErrorCode status); |
| 85 |
| 86 |
| 87 // Adds the entry with |resource_id| to the directory |parent_resource_id|. |
| 88 // Upon completion, |callback| will be called. |
| 89 void AddToDirectory(const std::string& resource_id, |
| 90 const std::string& parent_resource_id, |
| 91 const FileOperationCallback& callback); |
| 92 |
| 93 // Part of AddToDirectory(). Called after server side updating is done. |
| 94 void AddToDirectoryAfterAddResourceToDirectory( |
| 95 const std::string& resource_id, |
| 96 const std::string& parent_resource_id, |
| 49 const FileOperationCallback& callback, | 97 const FileOperationCallback& callback, |
| 50 scoped_ptr<EntryInfoPairResult> src_dest_info); | |
| 51 | |
| 52 // Step 2 of Move(), called after renaming is completed. It adds the resource | |
| 53 // to the destination directory. | |
| 54 void MoveAfterRename(const FileOperationCallback& callback, | |
| 55 scoped_ptr<EntryInfoPairResult> src_dest_info, | |
| 56 FileError error, | |
| 57 const base::FilePath& src_path); | |
| 58 | |
| 59 // Step 3 of Move(), called after the resource is added to the new directory. | |
| 60 // It removes the resource from the old directory in the remote server. While | |
| 61 // our local metadata assumes tree structure, on the server side a resource | |
| 62 // can belong to multiple collections (directories). At this point the | |
| 63 // resource is contained in both the new and the old directories. | |
| 64 void MoveAfterAddToDirectory(const FileOperationCallback& callback, | |
| 65 scoped_ptr<EntryInfoPairResult> src_dest_info, | |
| 66 FileError error, | |
| 67 const base::FilePath& src_path); | |
| 68 | |
| 69 // Step 4 of Move(), called after the resource is removed from the old | |
| 70 // directory. It calls back to the caller of Move(). | |
| 71 void MoveAfterRemoveFromDirectory( | |
| 72 const FileOperationCallback& callback, | |
| 73 scoped_ptr<EntryInfoPairResult> src_dest_info, | |
| 74 google_apis::GDataErrorCode status); | 98 google_apis::GDataErrorCode status); |
| 75 | 99 |
| 76 // Renames a resource |src_id| at |src_path| to |new_name| in the same | |
| 77 // directory. |callback| will receive the new file path if the operation is | |
| 78 // successful. If the new name already exists in the same directory, the file | |
| 79 // name is uniquified by adding a parenthesized serial number like | |
| 80 // "foo (2).txt". | |
| 81 void Rename(const std::string& src_id, | |
| 82 const base::FilePath& src_path, | |
| 83 const base::FilePath& new_name, | |
| 84 bool new_name_has_hosted_extension, | |
| 85 const FileMoveCallback& callback); | |
| 86 | 100 |
| 87 // Called in Rename() to reflect the rename on the local metadata. | 101 // Removes the resource with |resource_id| from the directory with |
| 88 void RenameLocally(const base::FilePath& src_path, | 102 // |directory_resource_id|. |
| 89 const std::string& new_title, | 103 // Upon completion, |callback| will be called. |
| 90 const FileMoveCallback& callback, | |
| 91 google_apis::GDataErrorCode status); | |
| 92 | |
| 93 | |
| 94 // Moves a resource |src_id| at |src_path| to another directory |dest_dir_id| | |
| 95 // at |dest_dir_path|. |callback| will receive the new file path if the | |
| 96 // operation is successful. | |
| 97 void AddToDirectory(const std::string& src_id, | |
| 98 const std::string& dest_dir_id, | |
| 99 const base::FilePath& src_path, | |
| 100 const base::FilePath& dest_dir_path, | |
| 101 const FileMoveCallback& callback); | |
| 102 | |
| 103 // Called in AddToDirectory() to reflect the move on the local metadata. | |
| 104 void AddToDirectoryLocally(const base::FilePath& src_path, | |
| 105 const base::FilePath& dest_dir_path, | |
| 106 const FileMoveCallback& callback, | |
| 107 google_apis::GDataErrorCode status); | |
| 108 | |
| 109 // Removes a resource |resource_id| from |directory_resource_id|. | |
| 110 void RemoveFromDirectory(const std::string& resource_id, | 104 void RemoveFromDirectory(const std::string& resource_id, |
| 111 const std::string& directory_resource_id, | 105 const std::string& directory_resource_id, |
| 112 const FileOperationCallback& callback); | 106 const FileOperationCallback& callback); |
| 113 | 107 |
| 114 // Called in RemoveFromDirectory(). | 108 // Part of RemoveFromDirectory(). Called after server side updating is done. |
| 115 void RemoveFromDirectoryCompleted(const FileOperationCallback& callback, | 109 void RemoveFromDirectoryAfterRemoveResourceFromDirectory( |
| 116 google_apis::GDataErrorCode status); | 110 const FileOperationCallback& callback, |
| 111 google_apis::GDataErrorCode status); |
| 117 | 112 |
| 113 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; |
| 118 OperationObserver* observer_; | 114 OperationObserver* observer_; |
| 119 JobScheduler* scheduler_; | 115 JobScheduler* scheduler_; |
| 120 internal::ResourceMetadata* metadata_; | 116 internal::ResourceMetadata* metadata_; |
| 121 | 117 |
| 122 // Note: This should remain the last member so it'll be destroyed and | 118 // Note: This should remain the last member so it'll be destroyed and |
| 123 // invalidate the weak pointers before any other members are destroyed. | 119 // invalidate the weak pointers before any other members are destroyed. |
| 124 base::WeakPtrFactory<MoveOperation> weak_ptr_factory_; | 120 base::WeakPtrFactory<MoveOperation> weak_ptr_factory_; |
| 125 DISALLOW_COPY_AND_ASSIGN(MoveOperation); | 121 DISALLOW_COPY_AND_ASSIGN(MoveOperation); |
| 126 }; | 122 }; |
| 127 | 123 |
| 128 } // namespace file_system | 124 } // namespace file_system |
| 129 } // namespace drive | 125 } // namespace drive |
| 130 | 126 |
| 131 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_MOVE_OPERATION_H_ | 127 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_MOVE_OPERATION_H_ |
| OLD | NEW |