| 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" |
| 11 #include "base/callback_forward.h" | 11 #include "base/callback_forward.h" |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 14 #include "base/threading/thread_checker.h" | 14 #include "base/threading/thread_checker.h" |
| 15 #include "chrome/browser/drive/drive_service_interface.h" | 15 #include "chrome/browser/drive/drive_service_interface.h" |
| 16 #include "google_apis/drive/gdata_errorcode.h" | 16 #include "google_apis/drive/drive_api_error_codes.h" |
| 17 | 17 |
| 18 class GURL; | 18 class GURL; |
| 19 | 19 |
| 20 namespace base { | 20 namespace base { |
| 21 class FilePath; | 21 class FilePath; |
| 22 class TaskRunner; | 22 class TaskRunner; |
| 23 } | 23 } |
| 24 | 24 |
| 25 namespace google_apis { | 25 namespace google_apis { |
| 26 struct UploadRangeResponse; | 26 struct UploadRangeResponse; |
| 27 } | 27 } |
| 28 | 28 |
| 29 namespace drive { | 29 namespace drive { |
| 30 class DriveServiceInterface; | 30 class DriveServiceInterface; |
| 31 | 31 |
| 32 // Callback to be invoked once the upload has completed. | 32 // Callback to be invoked once the upload has completed. |
| 33 // |upload_location| will be returned when the uploading process is started but | 33 // |upload_location| will be returned when the uploading process is started but |
| 34 // terminated before the completion due to some errors. It can be used to | 34 // terminated before the completion due to some errors. It can be used to |
| 35 // resume it. | 35 // resume it. |
| 36 typedef base::Callback<void( | 36 typedef base::Callback<void( |
| 37 google_apis::GDataErrorCode 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 typedef DriveServiceInterface::UploadNewFileOptions UploadNewFileOptions; | 44 typedef DriveServiceInterface::UploadNewFileOptions UploadNewFileOptions; |
| 45 typedef DriveServiceInterface::UploadExistingFileOptions | 45 typedef DriveServiceInterface::UploadExistingFileOptions |
| 46 UploadExistingFileOptions; | 46 UploadExistingFileOptions; |
| 47 | 47 |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 // MultipartUploadExistingFile API. Upon completion, OnUploadLocationReceived | 166 // MultipartUploadExistingFile API. Upon completion, OnUploadLocationReceived |
| 167 // (for InitiateUploadExistingFile) or OnMultipartUploadComplete (for | 167 // (for InitiateUploadExistingFile) or OnMultipartUploadComplete (for |
| 168 // MultipartUploadExistingFile) should be called. | 168 // MultipartUploadExistingFile) should be called. |
| 169 void CallUploadServiceAPIExistingFile( | 169 void CallUploadServiceAPIExistingFile( |
| 170 const std::string& resource_id, | 170 const std::string& resource_id, |
| 171 const UploadExistingFileOptions& options, | 171 const UploadExistingFileOptions& options, |
| 172 scoped_ptr<UploadFileInfo> upload_file_info); | 172 scoped_ptr<UploadFileInfo> upload_file_info); |
| 173 | 173 |
| 174 // DriveService callback for InitiateUpload. | 174 // DriveService callback for InitiateUpload. |
| 175 void OnUploadLocationReceived(scoped_ptr<UploadFileInfo> upload_file_info, | 175 void OnUploadLocationReceived(scoped_ptr<UploadFileInfo> upload_file_info, |
| 176 google_apis::GDataErrorCode code, | 176 google_apis::DriveApiErrorCode code, |
| 177 const GURL& upload_location); | 177 const GURL& upload_location); |
| 178 | 178 |
| 179 // Starts to get the current upload status for the file uploading. | 179 // Starts to get the current upload status for the file uploading. |
| 180 // Upon completion, OnUploadRangeResponseReceived should be called. | 180 // Upon completion, OnUploadRangeResponseReceived should be called. |
| 181 void StartGetUploadStatus(scoped_ptr<UploadFileInfo> upload_file_info); | 181 void StartGetUploadStatus(scoped_ptr<UploadFileInfo> upload_file_info); |
| 182 | 182 |
| 183 // Uploads the next chunk of data from the file. | 183 // Uploads the next chunk of data from the file. |
| 184 void UploadNextChunk(scoped_ptr<UploadFileInfo> upload_file_info); | 184 void UploadNextChunk(scoped_ptr<UploadFileInfo> upload_file_info); |
| 185 | 185 |
| 186 // DriveService callback for ResumeUpload. | 186 // DriveService callback for ResumeUpload. |
| 187 void OnUploadRangeResponseReceived( | 187 void OnUploadRangeResponseReceived( |
| 188 scoped_ptr<UploadFileInfo> upload_file_info, | 188 scoped_ptr<UploadFileInfo> upload_file_info, |
| 189 const google_apis::UploadRangeResponse& response, | 189 const google_apis::UploadRangeResponse& response, |
| 190 scoped_ptr<google_apis::FileResource> entry); | 190 scoped_ptr<google_apis::FileResource> entry); |
| 191 void OnUploadProgress(const google_apis::ProgressCallback& callback, | 191 void OnUploadProgress(const google_apis::ProgressCallback& callback, |
| 192 int64 start_position, | 192 int64 start_position, |
| 193 int64 total_size, | 193 int64 total_size, |
| 194 int64 progress_of_chunk, | 194 int64 progress_of_chunk, |
| 195 int64 total_of_chunk); | 195 int64 total_of_chunk); |
| 196 | 196 |
| 197 // Handles failed uploads. | 197 // Handles failed uploads. |
| 198 void UploadFailed(scoped_ptr<UploadFileInfo> upload_file_info, | 198 void UploadFailed(scoped_ptr<UploadFileInfo> upload_file_info, |
| 199 google_apis::GDataErrorCode error); | 199 google_apis::DriveApiErrorCode error); |
| 200 | 200 |
| 201 // Handles completion/error of multipart uploading. | 201 // Handles completion/error of multipart uploading. |
| 202 void OnMultipartUploadComplete(scoped_ptr<UploadFileInfo> upload_file_info, | 202 void OnMultipartUploadComplete(scoped_ptr<UploadFileInfo> upload_file_info, |
| 203 google_apis::GDataErrorCode error, | 203 google_apis::DriveApiErrorCode error, |
| 204 scoped_ptr<google_apis::FileResource> entry); | 204 scoped_ptr<google_apis::FileResource> entry); |
| 205 | 205 |
| 206 // The class is expected to run on UI thread. | 206 // The class is expected to run on UI thread. |
| 207 base::ThreadChecker thread_checker_; | 207 base::ThreadChecker thread_checker_; |
| 208 | 208 |
| 209 // The lifetime of this object should be guaranteed to exceed that of the | 209 // The lifetime of this object should be guaranteed to exceed that of the |
| 210 // DriveUploader instance. | 210 // DriveUploader instance. |
| 211 DriveServiceInterface* drive_service_; // Not owned by this class. | 211 DriveServiceInterface* drive_service_; // Not owned by this class. |
| 212 | 212 |
| 213 scoped_refptr<base::TaskRunner> blocking_task_runner_; | 213 scoped_refptr<base::TaskRunner> blocking_task_runner_; |
| 214 | 214 |
| 215 // Note: This should remain the last member so it'll be destroyed and | 215 // Note: This should remain the last member so it'll be destroyed and |
| 216 // invalidate its weak pointers before any other members are destroyed. | 216 // invalidate its weak pointers before any other members are destroyed. |
| 217 base::WeakPtrFactory<DriveUploader> weak_ptr_factory_; | 217 base::WeakPtrFactory<DriveUploader> weak_ptr_factory_; |
| 218 DISALLOW_COPY_AND_ASSIGN(DriveUploader); | 218 DISALLOW_COPY_AND_ASSIGN(DriveUploader); |
| 219 }; | 219 }; |
| 220 | 220 |
| 221 } // namespace drive | 221 } // namespace drive |
| 222 | 222 |
| 223 #endif // CHROME_BROWSER_DRIVE_DRIVE_UPLOADER_H_ | 223 #endif // CHROME_BROWSER_DRIVE_DRIVE_UPLOADER_H_ |
| OLD | NEW |