| 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_GOOGLE_APIS_DRIVE_UPLOADER_H_ | 5 #ifndef CHROME_BROWSER_GOOGLE_APIS_DRIVE_UPLOADER_H_ |
| 6 #define CHROME_BROWSER_GOOGLE_APIS_DRIVE_UPLOADER_H_ | 6 #define CHROME_BROWSER_GOOGLE_APIS_DRIVE_UPLOADER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 typedef base::Callback<void(GDataErrorCode error, | 31 typedef base::Callback<void(GDataErrorCode error, |
| 32 const GURL& upload_location, | 32 const GURL& upload_location, |
| 33 scoped_ptr<ResourceEntry> resource_entry)> | 33 scoped_ptr<ResourceEntry> resource_entry)> |
| 34 UploadCompletionCallback; | 34 UploadCompletionCallback; |
| 35 | 35 |
| 36 class DriveUploaderInterface { | 36 class DriveUploaderInterface { |
| 37 public: | 37 public: |
| 38 virtual ~DriveUploaderInterface() {} | 38 virtual ~DriveUploaderInterface() {} |
| 39 | 39 |
| 40 // Uploads a new file to a directory specified by |upload_location|. | 40 // Uploads a new file to a directory specified by |upload_location|. |
| 41 // Returns the upload_id. | 41 // Returns a callback for cancelling the uploading job. |
| 42 // | 42 // |
| 43 // parent_resource_id: | 43 // parent_resource_id: |
| 44 // resource id of the destination directory. | 44 // resource id of the destination directory. |
| 45 // | 45 // |
| 46 // drive_file_path: | 46 // drive_file_path: |
| 47 // The destination path like "drive/foo/bar.txt". | 47 // The destination path like "drive/foo/bar.txt". |
| 48 // | 48 // |
| 49 // local_file_path: | 49 // local_file_path: |
| 50 // The path to the local file to be uploaded. | 50 // The path to the local file to be uploaded. |
| 51 // | 51 // |
| 52 // title: | 52 // title: |
| 53 // The title (file name) of the file to be uploaded. | 53 // The title (file name) of the file to be uploaded. |
| 54 // | 54 // |
| 55 // content_type: | 55 // content_type: |
| 56 // The content type of the file to be uploaded. | 56 // The content type of the file to be uploaded. |
| 57 // | 57 // |
| 58 // callback: | 58 // callback: |
| 59 // Called when an upload is done regardless of it was successful or not. | 59 // Called when an upload is done regardless of it was successful or not. |
| 60 // Must not be null. | 60 // Must not be null. |
| 61 // | 61 // |
| 62 // progress_callback: | 62 // progress_callback: |
| 63 // Periodically called back with the total number of bytes sent so far. | 63 // Periodically called back with the total number of bytes sent so far. |
| 64 // May be null if the information is not needed. | 64 // May be null if the information is not needed. |
| 65 virtual void UploadNewFile(const std::string& parent_resource_id, | 65 virtual CancelCallback UploadNewFile( |
| 66 const base::FilePath& drive_file_path, | 66 const std::string& parent_resource_id, |
| 67 const base::FilePath& local_file_path, | 67 const base::FilePath& drive_file_path, |
| 68 const std::string& title, | 68 const base::FilePath& local_file_path, |
| 69 const std::string& content_type, | 69 const std::string& title, |
| 70 const UploadCompletionCallback& callback, | 70 const std::string& content_type, |
| 71 const ProgressCallback& progress_callback) = 0; | 71 const UploadCompletionCallback& callback, |
| 72 const ProgressCallback& progress_callback) = 0; |
| 72 | 73 |
| 73 // Uploads an existing file (a file that already exists on Drive). | 74 // Uploads an existing file (a file that already exists on Drive). |
| 74 // | 75 // |
| 75 // See comments at UploadNewFile() about common parameters. | 76 // See comments at UploadNewFile about common parameters and the return value. |
| 76 // | 77 // |
| 77 // resource_id: | 78 // resource_id: |
| 78 // resource id of the existing file to be overwritten. | 79 // resource id of the existing file to be overwritten. |
| 79 // | 80 // |
| 80 // etag: | 81 // etag: |
| 81 // Expected ETag for the destination file. If it does not match, the upload | 82 // Expected ETag for the destination file. If it does not match, the upload |
| 82 // fails with UPLOAD_ERROR_CONFLICT. | 83 // fails with UPLOAD_ERROR_CONFLICT. |
| 83 // If |etag| is empty, the test is skipped. | 84 // If |etag| is empty, the test is skipped. |
| 84 virtual void UploadExistingFile( | 85 virtual CancelCallback UploadExistingFile( |
| 85 const std::string& resource_id, | 86 const std::string& resource_id, |
| 86 const base::FilePath& drive_file_path, | 87 const base::FilePath& drive_file_path, |
| 87 const base::FilePath& local_file_path, | 88 const base::FilePath& local_file_path, |
| 88 const std::string& content_type, | 89 const std::string& content_type, |
| 89 const std::string& etag, | 90 const std::string& etag, |
| 90 const UploadCompletionCallback& callback, | 91 const UploadCompletionCallback& callback, |
| 91 const ProgressCallback& progress_callback) = 0; | 92 const ProgressCallback& progress_callback) = 0; |
| 92 | 93 |
| 93 // Resumes the uploading process termineted before the completion. | 94 // Resumes the uploading process terminated before the completion. |
| 94 // |upload_location| should be the one returned via UploadCompletionCallback | 95 // |upload_location| should be the one returned via UploadCompletionCallback |
| 95 // for previous invocation. |drive_file_path|, |local_file_path| and | 96 // for previous invocation. |drive_file_path|, |local_file_path| and |
| 96 // |content_type| must be set to the same ones for previous invocation. | 97 // |content_type| must be set to the same ones for previous invocation. |
| 97 // | 98 // |
| 98 // See comments for UploadNewFile() about common parameters. | 99 // See comments at UploadNewFile about common parameters and the return value. |
| 99 virtual void ResumeUploadFile( | 100 virtual CancelCallback ResumeUploadFile( |
| 100 const GURL& upload_location, | 101 const GURL& upload_location, |
| 101 const base::FilePath& drive_file_path, | 102 const base::FilePath& drive_file_path, |
| 102 const base::FilePath& local_file_path, | 103 const base::FilePath& local_file_path, |
| 103 const std::string& content_type, | 104 const std::string& content_type, |
| 104 const UploadCompletionCallback& callback, | 105 const UploadCompletionCallback& callback, |
| 105 const ProgressCallback& progress_callback) = 0; | 106 const ProgressCallback& progress_callback) = 0; |
| 106 }; | 107 }; |
| 107 | 108 |
| 108 class DriveUploader : public DriveUploaderInterface { | 109 class DriveUploader : public DriveUploaderInterface { |
| 109 public: | 110 public: |
| 110 explicit DriveUploader(DriveServiceInterface* drive_service); | 111 explicit DriveUploader(DriveServiceInterface* drive_service); |
| 111 virtual ~DriveUploader(); | 112 virtual ~DriveUploader(); |
| 112 | 113 |
| 113 // DriveUploaderInterface overrides. | 114 // DriveUploaderInterface overrides. |
| 114 virtual void UploadNewFile( | 115 virtual CancelCallback UploadNewFile( |
| 115 const std::string& parent_resource_id, | 116 const std::string& parent_resource_id, |
| 116 const base::FilePath& drive_file_path, | 117 const base::FilePath& drive_file_path, |
| 117 const base::FilePath& local_file_path, | 118 const base::FilePath& local_file_path, |
| 118 const std::string& title, | 119 const std::string& title, |
| 119 const std::string& content_type, | 120 const std::string& content_type, |
| 120 const UploadCompletionCallback& callback, | 121 const UploadCompletionCallback& callback, |
| 121 const ProgressCallback& progress_callback) OVERRIDE; | 122 const ProgressCallback& progress_callback) OVERRIDE; |
| 122 virtual void UploadExistingFile( | 123 virtual CancelCallback UploadExistingFile( |
| 123 const std::string& resource_id, | 124 const std::string& resource_id, |
| 124 const base::FilePath& drive_file_path, | 125 const base::FilePath& drive_file_path, |
| 125 const base::FilePath& local_file_path, | 126 const base::FilePath& local_file_path, |
| 126 const std::string& content_type, | 127 const std::string& content_type, |
| 127 const std::string& etag, | 128 const std::string& etag, |
| 128 const UploadCompletionCallback& callback, | 129 const UploadCompletionCallback& callback, |
| 129 const ProgressCallback& progress_callback) OVERRIDE; | 130 const ProgressCallback& progress_callback) OVERRIDE; |
| 130 virtual void ResumeUploadFile( | 131 virtual CancelCallback ResumeUploadFile( |
| 131 const GURL& upload_location, | 132 const GURL& upload_location, |
| 132 const base::FilePath& drive_file_path, | 133 const base::FilePath& drive_file_path, |
| 133 const base::FilePath& local_file_path, | 134 const base::FilePath& local_file_path, |
| 134 const std::string& content_type, | 135 const std::string& content_type, |
| 135 const UploadCompletionCallback& callback, | 136 const UploadCompletionCallback& callback, |
| 136 const ProgressCallback& progress_callback) OVERRIDE; | 137 const ProgressCallback& progress_callback) OVERRIDE; |
| 137 | 138 |
| 138 private: | 139 private: |
| 139 struct UploadFileInfo; | 140 struct UploadFileInfo; |
| 140 typedef base::Callback<void(scoped_ptr<UploadFileInfo> upload_file_info)> | 141 typedef base::Callback<void(scoped_ptr<UploadFileInfo> upload_file_info)> |
| 141 StartInitiateUploadCallback; | 142 StartInitiateUploadCallback; |
| 142 | 143 |
| 143 // Starts uploading a file with |upload_file_info|. | 144 // Starts uploading a file with |upload_file_info|. |
| 144 void StartUploadFile( | 145 void StartUploadFile( |
| 145 scoped_ptr<UploadFileInfo> upload_file_info, | 146 scoped_ptr<UploadFileInfo> upload_file_info, |
| 146 const StartInitiateUploadCallback& start_initiate_upload_callback); | 147 const StartInitiateUploadCallback& start_initiate_upload_callback); |
| 147 void StartUploadFileAfterGetFileSize( | 148 void StartUploadFileAfterGetFileSize( |
| 148 scoped_ptr<UploadFileInfo> upload_file_info, | 149 scoped_ptr<UploadFileInfo> upload_file_info, |
| 149 const StartInitiateUploadCallback& start_initiate_upload_callback, | 150 const StartInitiateUploadCallback& start_initiate_upload_callback, |
| 150 bool get_file_size_result); | 151 bool get_file_size_result); |
| 151 | 152 |
| 152 // Starts to initate the new file uploading. | 153 // Starts to initiate the new file uploading. |
| 153 // Upon completion, OnUploadLocationReceived should be called. | 154 // Upon completion, OnUploadLocationReceived should be called. |
| 154 void StartInitiateUploadNewFile( | 155 void StartInitiateUploadNewFile( |
| 155 const std::string& parent_resource_id, | 156 const std::string& parent_resource_id, |
| 156 const std::string& title, | 157 const std::string& title, |
| 157 scoped_ptr<UploadFileInfo> upload_file_info); | 158 scoped_ptr<UploadFileInfo> upload_file_info); |
| 158 | 159 |
| 159 // Starts to initate the existing file uploading. | 160 // Starts to initiate the existing file uploading. |
| 160 // Upon completion, OnUploadLocationReceived should be called. | 161 // Upon completion, OnUploadLocationReceived should be called. |
| 161 void StartInitiateUploadExistingFile( | 162 void StartInitiateUploadExistingFile( |
| 162 const std::string& resource_id, | 163 const std::string& resource_id, |
| 163 const std::string& etag, | 164 const std::string& etag, |
| 164 scoped_ptr<UploadFileInfo> upload_file_info); | 165 scoped_ptr<UploadFileInfo> upload_file_info); |
| 165 | 166 |
| 166 // DriveService callback for InitiateUpload. | 167 // DriveService callback for InitiateUpload. |
| 167 void OnUploadLocationReceived(scoped_ptr<UploadFileInfo> upload_file_info, | 168 void OnUploadLocationReceived(scoped_ptr<UploadFileInfo> upload_file_info, |
| 168 GDataErrorCode code, | 169 GDataErrorCode code, |
| 169 const GURL& upload_location); | 170 const GURL& upload_location); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 197 | 198 |
| 198 // Note: This should remain the last member so it'll be destroyed and | 199 // Note: This should remain the last member so it'll be destroyed and |
| 199 // invalidate its weak pointers before any other members are destroyed. | 200 // invalidate its weak pointers before any other members are destroyed. |
| 200 base::WeakPtrFactory<DriveUploader> weak_ptr_factory_; | 201 base::WeakPtrFactory<DriveUploader> weak_ptr_factory_; |
| 201 DISALLOW_COPY_AND_ASSIGN(DriveUploader); | 202 DISALLOW_COPY_AND_ASSIGN(DriveUploader); |
| 202 }; | 203 }; |
| 203 | 204 |
| 204 } // namespace google_apis | 205 } // namespace google_apis |
| 205 | 206 |
| 206 #endif // CHROME_BROWSER_GOOGLE_APIS_DRIVE_UPLOADER_H_ | 207 #endif // CHROME_BROWSER_GOOGLE_APIS_DRIVE_UPLOADER_H_ |
| OLD | NEW |