| 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_COPY_OPERATION_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_COPY_OPERATION_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_COPY_OPERATION_H_ | 6 #define CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_COPY_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" |
| 11 #include "chrome/browser/chromeos/drive/drive_resource_metadata.h" | 11 #include "chrome/browser/chromeos/drive/drive_resource_metadata.h" |
| 12 #include "chrome/browser/google_apis/gdata_errorcode.h" | 12 #include "chrome/browser/google_apis/gdata_errorcode.h" |
| 13 | 13 |
| 14 class FilePath; | |
| 15 class GURL; | 14 class GURL; |
| 16 | 15 |
| 17 namespace base { | 16 namespace base { |
| 17 class FilePath; |
| 18 class Value; | 18 class Value; |
| 19 } | 19 } |
| 20 | 20 |
| 21 namespace google_apis { | 21 namespace google_apis { |
| 22 class DriveUploaderInterface; | 22 class DriveUploaderInterface; |
| 23 } | 23 } |
| 24 | 24 |
| 25 namespace drive { | 25 namespace drive { |
| 26 | 26 |
| 27 class DriveEntryProto; | 27 class DriveEntryProto; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 42 DriveFileSystemInterface* drive_file_system, | 42 DriveFileSystemInterface* drive_file_system, |
| 43 DriveResourceMetadata* metadata, | 43 DriveResourceMetadata* metadata, |
| 44 google_apis::DriveUploaderInterface* uploader, | 44 google_apis::DriveUploaderInterface* uploader, |
| 45 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner, | 45 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner, |
| 46 OperationObserver* observer); | 46 OperationObserver* observer); |
| 47 virtual ~CopyOperation(); | 47 virtual ~CopyOperation(); |
| 48 | 48 |
| 49 // Performs the copy operation on the file at drive path |src_file_path| | 49 // Performs the copy operation on the file at drive path |src_file_path| |
| 50 // with a target of |dest_file_path|. Invokes |callback| when finished with | 50 // with a target of |dest_file_path|. Invokes |callback| when finished with |
| 51 // the result of the operation. |callback| must not be null. | 51 // the result of the operation. |callback| must not be null. |
| 52 virtual void Copy(const FilePath& src_file_path, | 52 virtual void Copy(const base::FilePath& src_file_path, |
| 53 const FilePath& dest_file_path, | 53 const base::FilePath& dest_file_path, |
| 54 const FileOperationCallback& callback); | 54 const FileOperationCallback& callback); |
| 55 | 55 |
| 56 // Initiates transfer of |remote_src_file_path| to |local_dest_file_path|. | 56 // Initiates transfer of |remote_src_file_path| to |local_dest_file_path|. |
| 57 // |remote_src_file_path| is the virtual source path on the Drive file system. | 57 // |remote_src_file_path| is the virtual source path on the Drive file system. |
| 58 // |local_dest_file_path| is the destination path on the local file system. | 58 // |local_dest_file_path| is the destination path on the local file system. |
| 59 // | 59 // |
| 60 // Must be called from *UI* thread. |callback| is run on the calling thread. | 60 // Must be called from *UI* thread. |callback| is run on the calling thread. |
| 61 // |callback| must not be null. | 61 // |callback| must not be null. |
| 62 virtual void TransferFileFromRemoteToLocal( | 62 virtual void TransferFileFromRemoteToLocal( |
| 63 const FilePath& remote_src_file_path, | 63 const base::FilePath& remote_src_file_path, |
| 64 const FilePath& local_dest_file_path, | 64 const base::FilePath& local_dest_file_path, |
| 65 const FileOperationCallback& callback); | 65 const FileOperationCallback& callback); |
| 66 | 66 |
| 67 // Initiates transfer of |local_src_file_path| to |remote_dest_file_path|. | 67 // Initiates transfer of |local_src_file_path| to |remote_dest_file_path|. |
| 68 // |local_src_file_path| must be a file from the local file system. | 68 // |local_src_file_path| must be a file from the local file system. |
| 69 // |remote_dest_file_path| is the virtual destination path within Drive file | 69 // |remote_dest_file_path| is the virtual destination path within Drive file |
| 70 // system. | 70 // system. |
| 71 // | 71 // |
| 72 // Must be called from *UI* thread. |callback| is run on the calling thread. | 72 // Must be called from *UI* thread. |callback| is run on the calling thread. |
| 73 // |callback| must not be null. | 73 // |callback| must not be null. |
| 74 virtual void TransferFileFromLocalToRemote( | 74 virtual void TransferFileFromLocalToRemote( |
| 75 const FilePath& local_src_file_path, | 75 const base::FilePath& local_src_file_path, |
| 76 const FilePath& remote_dest_file_path, | 76 const base::FilePath& remote_dest_file_path, |
| 77 const FileOperationCallback& callback); | 77 const FileOperationCallback& callback); |
| 78 | 78 |
| 79 // Initiates transfer of |local_file_path| to |remote_dest_file_path|. | 79 // Initiates transfer of |local_file_path| to |remote_dest_file_path|. |
| 80 // |local_file_path| must be a regular file (i.e. not a hosted document) from | 80 // |local_file_path| must be a regular file (i.e. not a hosted document) from |
| 81 // the local file system, |remote_dest_file_path| is the virtual destination | 81 // the local file system, |remote_dest_file_path| is the virtual destination |
| 82 // path within Drive file system. | 82 // path within Drive file system. |
| 83 // | 83 // |
| 84 // Must be called from *UI* thread. |callback| is run on the calling thread. | 84 // Must be called from *UI* thread. |callback| is run on the calling thread. |
| 85 // |callback| must not be null. | 85 // |callback| must not be null. |
| 86 virtual void TransferRegularFile(const FilePath& local_file_path, | 86 virtual void TransferRegularFile(const base::FilePath& local_file_path, |
| 87 const FilePath& remote_dest_file_path, | 87 const base::FilePath& remote_dest_file_path, |
| 88 const FileOperationCallback& callback); | 88 const FileOperationCallback& callback); |
| 89 | 89 |
| 90 private: | 90 private: |
| 91 // Struct used for StartFileUpload(). | 91 // Struct used for StartFileUpload(). |
| 92 struct StartFileUploadParams; | 92 struct StartFileUploadParams; |
| 93 | 93 |
| 94 // Invoked upon completion of GetFileByPath initiated by | 94 // Invoked upon completion of GetFileByPath initiated by |
| 95 // TransferFileFromRemoteToLocal. If GetFileByPath reports no error, calls | 95 // TransferFileFromRemoteToLocal. If GetFileByPath reports no error, calls |
| 96 // CopyLocalFileOnBlockingPool to copy |local_file_path| to | 96 // CopyLocalFileOnBlockingPool to copy |local_file_path| to |
| 97 // |local_dest_file_path|. | 97 // |local_dest_file_path|. |
| 98 // | 98 // |
| 99 // Can be called from UI thread. |callback| is run on the calling thread. | 99 // Can be called from UI thread. |callback| is run on the calling thread. |
| 100 // |callback| must not be null. | 100 // |callback| must not be null. |
| 101 void OnGetFileCompleteForTransferFile(const FilePath& local_dest_file_path, | 101 void OnGetFileCompleteForTransferFile( |
| 102 const FileOperationCallback& callback, | 102 const base::FilePath& local_dest_file_path, |
| 103 DriveFileError error, | 103 const FileOperationCallback& callback, |
| 104 const FilePath& local_file_path, | 104 DriveFileError error, |
| 105 const std::string& unused_mime_type, | 105 const base::FilePath& local_file_path, |
| 106 DriveFileType file_type); | 106 const std::string& unused_mime_type, |
| 107 DriveFileType file_type); |
| 107 | 108 |
| 108 // Copies a hosted document with |resource_id| to the directory at |dir_path| | 109 // Copies a hosted document with |resource_id| to the directory at |dir_path| |
| 109 // and names the copied document as |new_name|. | 110 // and names the copied document as |new_name|. |
| 110 // | 111 // |
| 111 // Can be called from UI thread. |callback| is run on the calling thread. | 112 // Can be called from UI thread. |callback| is run on the calling thread. |
| 112 // |callback| must not be null. | 113 // |callback| must not be null. |
| 113 void CopyHostedDocumentToDirectory(const FilePath& dir_path, | 114 void CopyHostedDocumentToDirectory(const base::FilePath& dir_path, |
| 114 const std::string& resource_id, | 115 const std::string& resource_id, |
| 115 const FilePath::StringType& new_name, | 116 const base::FilePath::StringType& new_name, |
| 116 const FileOperationCallback& callback); | 117 const FileOperationCallback& callback); |
| 117 | 118 |
| 118 // Callback for handling document copy attempt. | 119 // Callback for handling document copy attempt. |
| 119 // |callback| must not be null. | 120 // |callback| must not be null. |
| 120 void OnCopyHostedDocumentCompleted( | 121 void OnCopyHostedDocumentCompleted( |
| 121 const FilePath& dir_path, | 122 const base::FilePath& dir_path, |
| 122 const FileOperationCallback& callback, | 123 const FileOperationCallback& callback, |
| 123 google_apis::GDataErrorCode status, | 124 google_apis::GDataErrorCode status, |
| 124 scoped_ptr<google_apis::ResourceEntry> resource_entry); | 125 scoped_ptr<google_apis::ResourceEntry> resource_entry); |
| 125 | 126 |
| 126 // Moves a file or directory at |file_path| in the root directory to | 127 // Moves a file or directory at |file_path| in the root directory to |
| 127 // another directory at |dir_path|. This function does nothing if | 128 // another directory at |dir_path|. This function does nothing if |
| 128 // |dir_path| points to the root directory. | 129 // |dir_path| points to the root directory. |
| 129 // | 130 // |
| 130 // Can be called from UI thread. |callback| is run on the calling thread. | 131 // Can be called from UI thread. |callback| is run on the calling thread. |
| 131 // |callback| must not be null. | 132 // |callback| must not be null. |
| 132 void MoveEntryFromRootDirectory(const FilePath& directory_path, | 133 void MoveEntryFromRootDirectory(const base::FilePath& directory_path, |
| 133 const FileOperationCallback& callback, | 134 const FileOperationCallback& callback, |
| 134 DriveFileError error, | 135 DriveFileError error, |
| 135 const FilePath& file_path); | 136 const base::FilePath& file_path); |
| 136 | 137 |
| 137 // Part of Copy(). Called after GetEntryInfoPairByPaths() is | 138 // Part of Copy(). Called after GetEntryInfoPairByPaths() is |
| 138 // complete. |callback| must not be null. | 139 // complete. |callback| must not be null. |
| 139 void CopyAfterGetEntryInfoPair(const FilePath& dest_file_path, | 140 void CopyAfterGetEntryInfoPair(const base::FilePath& dest_file_path, |
| 140 const FileOperationCallback& callback, | 141 const FileOperationCallback& callback, |
| 141 scoped_ptr<EntryInfoPairResult> result); | 142 scoped_ptr<EntryInfoPairResult> result); |
| 142 | 143 |
| 143 // Invoked upon completion of GetFileByPath initiated by Copy. If | 144 // Invoked upon completion of GetFileByPath initiated by Copy. If |
| 144 // GetFileByPath reports no error, calls TransferRegularFile to transfer | 145 // GetFileByPath reports no error, calls TransferRegularFile to transfer |
| 145 // |local_file_path| to |remote_dest_file_path|. | 146 // |local_file_path| to |remote_dest_file_path|. |
| 146 // | 147 // |
| 147 // Can be called from UI thread. |callback| is run on the calling thread. | 148 // Can be called from UI thread. |callback| is run on the calling thread. |
| 148 void OnGetFileCompleteForCopy(const FilePath& remote_dest_file_path, | 149 void OnGetFileCompleteForCopy(const base::FilePath& remote_dest_file_path, |
| 149 const FileOperationCallback& callback, | 150 const FileOperationCallback& callback, |
| 150 DriveFileError error, | 151 DriveFileError error, |
| 151 const FilePath& local_file_path, | 152 const base::FilePath& local_file_path, |
| 152 const std::string& unused_mime_type, | 153 const std::string& unused_mime_type, |
| 153 DriveFileType file_type); | 154 DriveFileType file_type); |
| 154 | 155 |
| 155 // Kicks off file upload once it receives |content_type|. | 156 // Kicks off file upload once it receives |content_type|. |
| 156 void StartFileUpload(const StartFileUploadParams& params, | 157 void StartFileUpload(const StartFileUploadParams& params, |
| 157 const std::string* content_type, | 158 const std::string* content_type, |
| 158 bool got_content_type); | 159 bool got_content_type); |
| 159 | 160 |
| 160 // Part of StartFileUpload(). Called after GetEntryInfoByPath() | 161 // Part of StartFileUpload(). Called after GetEntryInfoByPath() |
| 161 // is complete. | 162 // is complete. |
| 162 void StartFileUploadAfterGetEntryInfo( | 163 void StartFileUploadAfterGetEntryInfo( |
| 163 const StartFileUploadParams& params, | 164 const StartFileUploadParams& params, |
| 164 const std::string& content_type, | 165 const std::string& content_type, |
| 165 DriveFileError error, | 166 DriveFileError error, |
| 166 scoped_ptr<DriveEntryProto> entry_proto); | 167 scoped_ptr<DriveEntryProto> entry_proto); |
| 167 | 168 |
| 168 // Helper function that completes bookkeeping tasks related to | 169 // Helper function that completes bookkeeping tasks related to |
| 169 // completed file transfer. | 170 // completed file transfer. |
| 170 void OnTransferCompleted( | 171 void OnTransferCompleted( |
| 171 const FileOperationCallback& callback, | 172 const FileOperationCallback& callback, |
| 172 google_apis::DriveUploadError error, | 173 google_apis::DriveUploadError error, |
| 173 const FilePath& drive_path, | 174 const base::FilePath& drive_path, |
| 174 const FilePath& file_path, | 175 const base::FilePath& file_path, |
| 175 scoped_ptr<google_apis::ResourceEntry> resource_entry); | 176 scoped_ptr<google_apis::ResourceEntry> resource_entry); |
| 176 | 177 |
| 177 // Part of TransferFileFromLocalToRemote(). Called after | 178 // Part of TransferFileFromLocalToRemote(). Called after |
| 178 // GetEntryInfoByPath() is complete. | 179 // GetEntryInfoByPath() is complete. |
| 179 void TransferFileFromLocalToRemoteAfterGetEntryInfo( | 180 void TransferFileFromLocalToRemoteAfterGetEntryInfo( |
| 180 const FilePath& local_src_file_path, | 181 const base::FilePath& local_src_file_path, |
| 181 const FilePath& remote_dest_file_path, | 182 const base::FilePath& remote_dest_file_path, |
| 182 const FileOperationCallback& callback, | 183 const FileOperationCallback& callback, |
| 183 DriveFileError error, | 184 DriveFileError error, |
| 184 scoped_ptr<DriveEntryProto> entry_proto); | 185 scoped_ptr<DriveEntryProto> entry_proto); |
| 185 | 186 |
| 186 // Initiates transfer of |local_file_path| with |resource_id| to | 187 // Initiates transfer of |local_file_path| with |resource_id| to |
| 187 // |remote_dest_file_path|. |local_file_path| must be a file from the local | 188 // |remote_dest_file_path|. |local_file_path| must be a file from the local |
| 188 // file system, |remote_dest_file_path| is the virtual destination path within | 189 // file system, |remote_dest_file_path| is the virtual destination path within |
| 189 // Drive file system. If |resource_id| is a non-empty string, the transfer is | 190 // Drive file system. If |resource_id| is a non-empty string, the transfer is |
| 190 // handled by CopyDocumentToDirectory. Otherwise, the transfer is handled by | 191 // handled by CopyDocumentToDirectory. Otherwise, the transfer is handled by |
| 191 // TransferRegularFile. | 192 // TransferRegularFile. |
| 192 // | 193 // |
| 193 // Must be called from *UI* thread. |callback| is run on the calling thread. | 194 // Must be called from *UI* thread. |callback| is run on the calling thread. |
| 194 // |callback| must not be null. | 195 // |callback| must not be null. |
| 195 void TransferFileForResourceId(const FilePath& local_file_path, | 196 void TransferFileForResourceId(const base::FilePath& local_file_path, |
| 196 const FilePath& remote_dest_file_path, | 197 const base::FilePath& remote_dest_file_path, |
| 197 const FileOperationCallback& callback, | 198 const FileOperationCallback& callback, |
| 198 const std::string& resource_id); | 199 const std::string& resource_id); |
| 199 | 200 |
| 200 DriveScheduler* drive_scheduler_; | 201 DriveScheduler* drive_scheduler_; |
| 201 DriveFileSystemInterface* drive_file_system_; | 202 DriveFileSystemInterface* drive_file_system_; |
| 202 DriveResourceMetadata* metadata_; | 203 DriveResourceMetadata* metadata_; |
| 203 google_apis::DriveUploaderInterface* uploader_; | 204 google_apis::DriveUploaderInterface* uploader_; |
| 204 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; | 205 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; |
| 205 OperationObserver* observer_; | 206 OperationObserver* observer_; |
| 206 | 207 |
| 207 // Copying a hosted document is internally implemented by using a move. | 208 // Copying a hosted document is internally implemented by using a move. |
| 208 scoped_ptr<MoveOperation> move_operation_; | 209 scoped_ptr<MoveOperation> move_operation_; |
| 209 | 210 |
| 210 // WeakPtrFactory bound to the UI thread. | 211 // WeakPtrFactory bound to the UI thread. |
| 211 // Note: This should remain the last member so it'll be destroyed and | 212 // Note: This should remain the last member so it'll be destroyed and |
| 212 // invalidate the weak pointers before any other members are destroyed. | 213 // invalidate the weak pointers before any other members are destroyed. |
| 213 base::WeakPtrFactory<CopyOperation> weak_ptr_factory_; | 214 base::WeakPtrFactory<CopyOperation> weak_ptr_factory_; |
| 214 | 215 |
| 215 DISALLOW_COPY_AND_ASSIGN(CopyOperation); | 216 DISALLOW_COPY_AND_ASSIGN(CopyOperation); |
| 216 }; | 217 }; |
| 217 | 218 |
| 218 } // namespace file_system | 219 } // namespace file_system |
| 219 } // namespace drive | 220 } // namespace drive |
| 220 | 221 |
| 221 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_COPY_OPERATION_H_ | 222 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_FILE_SYSTEM_COPY_OPERATION_H_ |
| OLD | NEW |