| 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 #include "components/drive/drive_uploader.h" | 5 #include "components/drive/drive_uploader.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/files/file_util.h" | 12 #include "base/files/file_util.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/metrics/histogram_macros.h" | 14 #include "base/metrics/histogram_macros.h" |
| 15 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
| 16 #include "base/task_runner_util.h" | 16 #include "base/task_runner_util.h" |
| 17 #include "components/drive/service/drive_service_interface.h" | 17 #include "components/drive/service/drive_service_interface.h" |
| 18 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/power_save_blocker_factory.h" |
| 19 #include "device/power_save_blocker/power_save_blocker.h" | |
| 20 #include "google_apis/drive/drive_api_parser.h" | 19 #include "google_apis/drive/drive_api_parser.h" |
| 21 | 20 |
| 22 using google_apis::CancelCallback; | 21 using google_apis::CancelCallback; |
| 23 using google_apis::FileResource; | 22 using google_apis::FileResource; |
| 24 using google_apis::DRIVE_CANCELLED; | 23 using google_apis::DRIVE_CANCELLED; |
| 25 using google_apis::DriveApiErrorCode; | 24 using google_apis::DriveApiErrorCode; |
| 26 using google_apis::DRIVE_NO_SPACE; | 25 using google_apis::DRIVE_NO_SPACE; |
| 27 using google_apis::HTTP_CONFLICT; | 26 using google_apis::HTTP_CONFLICT; |
| 28 using google_apis::HTTP_CREATED; | 27 using google_apis::HTTP_CREATED; |
| 29 using google_apis::HTTP_FORBIDDEN; | 28 using google_apis::HTTP_FORBIDDEN; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 UploadFileInfo(const base::FilePath& local_path, | 91 UploadFileInfo(const base::FilePath& local_path, |
| 93 const std::string& content_type, | 92 const std::string& content_type, |
| 94 const UploadCompletionCallback& callback, | 93 const UploadCompletionCallback& callback, |
| 95 const ProgressCallback& progress_callback) | 94 const ProgressCallback& progress_callback) |
| 96 : file_path(local_path), | 95 : file_path(local_path), |
| 97 content_type(content_type), | 96 content_type(content_type), |
| 98 completion_callback(callback), | 97 completion_callback(callback), |
| 99 progress_callback(progress_callback), | 98 progress_callback(progress_callback), |
| 100 content_length(0), | 99 content_length(0), |
| 101 next_start_position(-1), | 100 next_start_position(-1), |
| 102 power_save_blocker(device::PowerSaveBlocker::CreateWithTaskRunners( | 101 power_save_blocker(content::CreatePowerSaveBlocker( |
| 103 device::PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, | 102 content::PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, |
| 104 device::PowerSaveBlocker::kReasonOther, | 103 content::PowerSaveBlocker::kReasonOther, |
| 105 "Upload in progress", | 104 "Upload in progress")), |
| 106 content::BrowserThread::GetMessageLoopProxyForThread( | |
| 107 content::BrowserThread::UI), | |
| 108 content::BrowserThread::GetMessageLoopProxyForThread( | |
| 109 content::BrowserThread::FILE))), | |
| 110 cancelled(false), | 105 cancelled(false), |
| 111 weak_ptr_factory_(this) {} | 106 weak_ptr_factory_(this) {} |
| 112 | 107 |
| 113 ~UploadFileInfo() { | 108 ~UploadFileInfo() { |
| 114 } | 109 } |
| 115 | 110 |
| 116 // Useful for printf debugging. | 111 // Useful for printf debugging. |
| 117 std::string DebugString() const { | 112 std::string DebugString() const { |
| 118 return "file_path=[" + file_path.AsUTF8Unsafe() + | 113 return "file_path=[" + file_path.AsUTF8Unsafe() + |
| 119 "], content_type=[" + content_type + | 114 "], content_type=[" + content_type + |
| (...skipping 21 matching lines...) Expand all Loading... |
| 141 // Location URL where file is to be uploaded to, returned from | 136 // Location URL where file is to be uploaded to, returned from |
| 142 // InitiateUpload. Used for the subsequent ResumeUpload requests. | 137 // InitiateUpload. Used for the subsequent ResumeUpload requests. |
| 143 GURL upload_location; | 138 GURL upload_location; |
| 144 | 139 |
| 145 // Header content-Length. | 140 // Header content-Length. |
| 146 int64_t content_length; | 141 int64_t content_length; |
| 147 | 142 |
| 148 int64_t next_start_position; | 143 int64_t next_start_position; |
| 149 | 144 |
| 150 // Blocks system suspend while upload is in progress. | 145 // Blocks system suspend while upload is in progress. |
| 151 std::unique_ptr<device::PowerSaveBlocker> power_save_blocker; | 146 std::unique_ptr<content::PowerSaveBlocker> power_save_blocker; |
| 152 | 147 |
| 153 // Fields for implementing cancellation. |cancel_callback| is non-null if | 148 // Fields for implementing cancellation. |cancel_callback| is non-null if |
| 154 // there is an in-flight HTTP request. In that case, |cancell_callback| will | 149 // there is an in-flight HTTP request. In that case, |cancell_callback| will |
| 155 // cancel the operation. |cancelled| is initially false and turns to true | 150 // cancel the operation. |cancelled| is initially false and turns to true |
| 156 // once Cancel() is called. DriveUploader will check this field before after | 151 // once Cancel() is called. DriveUploader will check this field before after |
| 157 // an async task other than HTTP requests and cancels the subsequent requests | 152 // an async task other than HTTP requests and cancels the subsequent requests |
| 158 // if this is flagged to true. | 153 // if this is flagged to true. |
| 159 CancelCallback cancel_callback; | 154 CancelCallback cancel_callback; |
| 160 bool cancelled; | 155 bool cancelled; |
| 161 | 156 |
| (...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 533 DVLOG(1) << "Upload failed " << upload_file_info->DebugString(); | 528 DVLOG(1) << "Upload failed " << upload_file_info->DebugString(); |
| 534 if (error == HTTP_PRECONDITION) | 529 if (error == HTTP_PRECONDITION) |
| 535 error = HTTP_CONFLICT; // ETag mismatch. | 530 error = HTTP_CONFLICT; // ETag mismatch. |
| 536 upload_file_info->completion_callback.Run(error, | 531 upload_file_info->completion_callback.Run(error, |
| 537 upload_file_info->upload_location, | 532 upload_file_info->upload_location, |
| 538 std::unique_ptr<FileResource>()); | 533 std::unique_ptr<FileResource>()); |
| 539 } | 534 } |
| 540 } | 535 } |
| 541 | 536 |
| 542 } // namespace drive | 537 } // namespace drive |
| OLD | NEW |