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_DRIVE_DRIVE_UPLOADER_H_ | 5 #ifndef CHROME_BROWSER_DRIVE_DRIVE_UPLOADER_H_ |
6 #define CHROME_BROWSER_DRIVE_DRIVE_UPLOADER_H_ | 6 #define CHROME_BROWSER_DRIVE_DRIVE_UPLOADER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 25 matching lines...) Expand all Loading... |
36 typedef base::Callback<void( | 36 typedef base::Callback<void( |
37 google_apis::DriveApiErrorCode error, | 37 google_apis::DriveApiErrorCode error, |
38 const GURL& upload_location, | 38 const GURL& upload_location, |
39 scoped_ptr<google_apis::FileResource> resource_entry)> | 39 scoped_ptr<google_apis::FileResource> resource_entry)> |
40 UploadCompletionCallback; | 40 UploadCompletionCallback; |
41 | 41 |
42 class DriveUploaderInterface { | 42 class DriveUploaderInterface { |
43 public: | 43 public: |
44 virtual ~DriveUploaderInterface() {} | 44 virtual ~DriveUploaderInterface() {} |
45 | 45 |
| 46 // Starts batch processing for upload requests. All requests which upload |
| 47 // small files (less than kMaxMultipartUploadSize) between |
| 48 // |StartBatchProcessing| and |StopBatchProcessing| are sent as a single batch |
| 49 // request. |
| 50 virtual void StartBatchProcessing() = 0; |
| 51 |
| 52 // Stops batch processing. Must be called after calling |StartBatchProcessing| |
| 53 // to commit requests. |
| 54 virtual void StopBatchProcessing() = 0; |
| 55 |
46 // Uploads a new file to a directory specified by |upload_location|. | 56 // Uploads a new file to a directory specified by |upload_location|. |
47 // Returns a callback for cancelling the uploading job. | 57 // Returns a callback for cancelling the uploading job. |
48 // | 58 // |
49 // parent_resource_id: | 59 // parent_resource_id: |
50 // resource id of the destination directory. | 60 // resource id of the destination directory. |
51 // | 61 // |
52 // local_file_path: | 62 // local_file_path: |
53 // The path to the local file to be uploaded. | 63 // The path to the local file to be uploaded. |
54 // | 64 // |
55 // title: | 65 // title: |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 const google_apis::ProgressCallback& progress_callback) = 0; | 117 const google_apis::ProgressCallback& progress_callback) = 0; |
108 }; | 118 }; |
109 | 119 |
110 class DriveUploader : public DriveUploaderInterface { | 120 class DriveUploader : public DriveUploaderInterface { |
111 public: | 121 public: |
112 DriveUploader(DriveServiceInterface* drive_service, | 122 DriveUploader(DriveServiceInterface* drive_service, |
113 const scoped_refptr<base::TaskRunner>& blocking_task_runner); | 123 const scoped_refptr<base::TaskRunner>& blocking_task_runner); |
114 ~DriveUploader() override; | 124 ~DriveUploader() override; |
115 | 125 |
116 // DriveUploaderInterface overrides. | 126 // DriveUploaderInterface overrides. |
| 127 void StartBatchProcessing() override; |
| 128 void StopBatchProcessing() override; |
117 google_apis::CancelCallback UploadNewFile( | 129 google_apis::CancelCallback UploadNewFile( |
118 const std::string& parent_resource_id, | 130 const std::string& parent_resource_id, |
119 const base::FilePath& local_file_path, | 131 const base::FilePath& local_file_path, |
120 const std::string& title, | 132 const std::string& title, |
121 const std::string& content_type, | 133 const std::string& content_type, |
122 const UploadNewFileOptions& options, | 134 const UploadNewFileOptions& options, |
123 const UploadCompletionCallback& callback, | 135 const UploadCompletionCallback& callback, |
124 const google_apis::ProgressCallback& progress_callback) override; | 136 const google_apis::ProgressCallback& progress_callback) override; |
125 google_apis::CancelCallback UploadExistingFile( | 137 google_apis::CancelCallback UploadExistingFile( |
126 const std::string& resource_id, | 138 const std::string& resource_id, |
127 const base::FilePath& local_file_path, | 139 const base::FilePath& local_file_path, |
128 const std::string& content_type, | 140 const std::string& content_type, |
129 const UploadExistingFileOptions& options, | 141 const UploadExistingFileOptions& options, |
130 const UploadCompletionCallback& callback, | 142 const UploadCompletionCallback& callback, |
131 const google_apis::ProgressCallback& progress_callback) override; | 143 const google_apis::ProgressCallback& progress_callback) override; |
132 google_apis::CancelCallback ResumeUploadFile( | 144 google_apis::CancelCallback ResumeUploadFile( |
133 const GURL& upload_location, | 145 const GURL& upload_location, |
134 const base::FilePath& local_file_path, | 146 const base::FilePath& local_file_path, |
135 const std::string& content_type, | 147 const std::string& content_type, |
136 const UploadCompletionCallback& callback, | 148 const UploadCompletionCallback& callback, |
137 const google_apis::ProgressCallback& progress_callback) override; | 149 const google_apis::ProgressCallback& progress_callback) override; |
138 | 150 |
139 private: | 151 private: |
| 152 class RefCountedBatchRequest; |
140 struct UploadFileInfo; | 153 struct UploadFileInfo; |
141 typedef base::Callback<void(scoped_ptr<UploadFileInfo> upload_file_info)> | 154 typedef base::Callback<void(scoped_ptr<UploadFileInfo> upload_file_info)> |
142 StartInitiateUploadCallback; | 155 StartInitiateUploadCallback; |
143 | 156 |
144 // Starts uploading a file with |upload_file_info|. | 157 // Starts uploading a file with |upload_file_info|. |
145 google_apis::CancelCallback StartUploadFile( | 158 google_apis::CancelCallback StartUploadFile( |
146 scoped_ptr<UploadFileInfo> upload_file_info, | 159 scoped_ptr<UploadFileInfo> upload_file_info, |
147 const StartInitiateUploadCallback& start_initiate_upload_callback); | 160 const StartInitiateUploadCallback& start_initiate_upload_callback); |
148 void StartUploadFileAfterGetFileSize( | 161 void StartUploadFileAfterGetFileSize( |
149 scoped_ptr<UploadFileInfo> upload_file_info, | 162 scoped_ptr<UploadFileInfo> upload_file_info, |
150 const StartInitiateUploadCallback& start_initiate_upload_callback, | 163 const StartInitiateUploadCallback& start_initiate_upload_callback, |
151 bool get_file_size_result); | 164 bool get_file_size_result); |
152 | 165 |
153 // Checks file size and call InitiateUploadNewFile or MultipartUploadNewFile | 166 // Checks file size and call InitiateUploadNewFile or MultipartUploadNewFile |
154 // API. Upon completion, OnUploadLocationReceived (for InitiateUploadNewFile) | 167 // API. Upon completion, OnUploadLocationReceived (for InitiateUploadNewFile) |
155 // or OnMultipartUploadComplete (for MultipartUploadNewFile) should be called. | 168 // or OnMultipartUploadComplete (for MultipartUploadNewFile) should be called. |
156 void CallUploadServiceAPINewFile(const std::string& parent_resource_id, | 169 // If |batch_request| is non-null, it calls the API function on the batch |
157 const std::string& title, | 170 // request. |
158 const UploadNewFileOptions& options, | 171 void CallUploadServiceAPINewFile( |
159 scoped_ptr<UploadFileInfo> upload_file_info); | 172 const std::string& parent_resource_id, |
| 173 const std::string& title, |
| 174 const UploadNewFileOptions& options, |
| 175 const scoped_refptr<RefCountedBatchRequest>& batch_request, |
| 176 scoped_ptr<UploadFileInfo> upload_file_info); |
160 | 177 |
161 // Checks file size and call InitiateUploadExistingFile or | 178 // Checks file size and call InitiateUploadExistingFile or |
162 // MultipartUploadExistingFile API. Upon completion, OnUploadLocationReceived | 179 // MultipartUploadExistingFile API. Upon completion, OnUploadLocationReceived |
163 // (for InitiateUploadExistingFile) or OnMultipartUploadComplete (for | 180 // (for InitiateUploadExistingFile) or OnMultipartUploadComplete (for |
164 // MultipartUploadExistingFile) should be called. | 181 // MultipartUploadExistingFile) should be called. |
| 182 // If |batch_request| is non-null, it calls the API function on the batch |
| 183 // request. |
165 void CallUploadServiceAPIExistingFile( | 184 void CallUploadServiceAPIExistingFile( |
166 const std::string& resource_id, | 185 const std::string& resource_id, |
167 const UploadExistingFileOptions& options, | 186 const UploadExistingFileOptions& options, |
| 187 const scoped_refptr<RefCountedBatchRequest>& batch_request, |
168 scoped_ptr<UploadFileInfo> upload_file_info); | 188 scoped_ptr<UploadFileInfo> upload_file_info); |
169 | 189 |
170 // DriveService callback for InitiateUpload. | 190 // DriveService callback for InitiateUpload. |
171 void OnUploadLocationReceived(scoped_ptr<UploadFileInfo> upload_file_info, | 191 void OnUploadLocationReceived(scoped_ptr<UploadFileInfo> upload_file_info, |
172 google_apis::DriveApiErrorCode code, | 192 google_apis::DriveApiErrorCode code, |
173 const GURL& upload_location); | 193 const GURL& upload_location); |
174 | 194 |
175 // Starts to get the current upload status for the file uploading. | 195 // Starts to get the current upload status for the file uploading. |
176 // Upon completion, OnUploadRangeResponseReceived should be called. | 196 // Upon completion, OnUploadRangeResponseReceived should be called. |
177 void StartGetUploadStatus(scoped_ptr<UploadFileInfo> upload_file_info); | 197 void StartGetUploadStatus(scoped_ptr<UploadFileInfo> upload_file_info); |
(...skipping 22 matching lines...) Expand all Loading... |
200 scoped_ptr<google_apis::FileResource> entry); | 220 scoped_ptr<google_apis::FileResource> entry); |
201 | 221 |
202 // The class is expected to run on UI thread. | 222 // The class is expected to run on UI thread. |
203 base::ThreadChecker thread_checker_; | 223 base::ThreadChecker thread_checker_; |
204 | 224 |
205 // The lifetime of this object should be guaranteed to exceed that of the | 225 // The lifetime of this object should be guaranteed to exceed that of the |
206 // DriveUploader instance. | 226 // DriveUploader instance. |
207 DriveServiceInterface* drive_service_; // Not owned by this class. | 227 DriveServiceInterface* drive_service_; // Not owned by this class. |
208 | 228 |
209 scoped_refptr<base::TaskRunner> blocking_task_runner_; | 229 scoped_refptr<base::TaskRunner> blocking_task_runner_; |
| 230 scoped_refptr<RefCountedBatchRequest> current_batch_request_; |
210 | 231 |
211 // Note: This should remain the last member so it'll be destroyed and | 232 // Note: This should remain the last member so it'll be destroyed and |
212 // invalidate its weak pointers before any other members are destroyed. | 233 // invalidate its weak pointers before any other members are destroyed. |
213 base::WeakPtrFactory<DriveUploader> weak_ptr_factory_; | 234 base::WeakPtrFactory<DriveUploader> weak_ptr_factory_; |
214 DISALLOW_COPY_AND_ASSIGN(DriveUploader); | 235 DISALLOW_COPY_AND_ASSIGN(DriveUploader); |
215 }; | 236 }; |
216 | 237 |
217 } // namespace drive | 238 } // namespace drive |
218 | 239 |
219 #endif // CHROME_BROWSER_DRIVE_DRIVE_UPLOADER_H_ | 240 #endif // CHROME_BROWSER_DRIVE_DRIVE_UPLOADER_H_ |
OLD | NEW |