Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(33)

Side by Side Diff: components/drive/drive_uploader.cc

Issue 2075153002: Reland of 'Move content/browser/power_save_blocker to //device/power_save_blocker' (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: missing libs for component mac Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/drive/DEPS ('k') | content/app/DEPS » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/power_save_blocker_factory.h" 18 #include "content/public/browser/browser_thread.h"
19 #include "device/power_save_blocker/power_save_blocker.h"
19 #include "google_apis/drive/drive_api_parser.h" 20 #include "google_apis/drive/drive_api_parser.h"
20 21
21 using google_apis::CancelCallback; 22 using google_apis::CancelCallback;
22 using google_apis::FileResource; 23 using google_apis::FileResource;
23 using google_apis::DRIVE_CANCELLED; 24 using google_apis::DRIVE_CANCELLED;
24 using google_apis::DriveApiErrorCode; 25 using google_apis::DriveApiErrorCode;
25 using google_apis::DRIVE_NO_SPACE; 26 using google_apis::DRIVE_NO_SPACE;
26 using google_apis::HTTP_CONFLICT; 27 using google_apis::HTTP_CONFLICT;
27 using google_apis::HTTP_CREATED; 28 using google_apis::HTTP_CREATED;
28 using google_apis::HTTP_FORBIDDEN; 29 using google_apis::HTTP_FORBIDDEN;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 UploadFileInfo(const base::FilePath& local_path, 92 UploadFileInfo(const base::FilePath& local_path,
92 const std::string& content_type, 93 const std::string& content_type,
93 const UploadCompletionCallback& callback, 94 const UploadCompletionCallback& callback,
94 const ProgressCallback& progress_callback) 95 const ProgressCallback& progress_callback)
95 : file_path(local_path), 96 : file_path(local_path),
96 content_type(content_type), 97 content_type(content_type),
97 completion_callback(callback), 98 completion_callback(callback),
98 progress_callback(progress_callback), 99 progress_callback(progress_callback),
99 content_length(0), 100 content_length(0),
100 next_start_position(-1), 101 next_start_position(-1),
101 power_save_blocker(content::CreatePowerSaveBlocker( 102 power_save_blocker(device::PowerSaveBlocker::CreateWithTaskRunners(
102 content::PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, 103 device::PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension,
103 content::PowerSaveBlocker::kReasonOther, 104 device::PowerSaveBlocker::kReasonOther,
104 "Upload in progress")), 105 "Upload in progress",
106 content::BrowserThread::GetMessageLoopProxyForThread(
107 content::BrowserThread::UI),
108 content::BrowserThread::GetMessageLoopProxyForThread(
109 content::BrowserThread::FILE))),
105 cancelled(false), 110 cancelled(false),
106 weak_ptr_factory_(this) {} 111 weak_ptr_factory_(this) {}
107 112
108 ~UploadFileInfo() { 113 ~UploadFileInfo() {
109 } 114 }
110 115
111 // Useful for printf debugging. 116 // Useful for printf debugging.
112 std::string DebugString() const { 117 std::string DebugString() const {
113 return "file_path=[" + file_path.AsUTF8Unsafe() + 118 return "file_path=[" + file_path.AsUTF8Unsafe() +
114 "], content_type=[" + content_type + 119 "], content_type=[" + content_type +
(...skipping 21 matching lines...) Expand all
136 // Location URL where file is to be uploaded to, returned from 141 // Location URL where file is to be uploaded to, returned from
137 // InitiateUpload. Used for the subsequent ResumeUpload requests. 142 // InitiateUpload. Used for the subsequent ResumeUpload requests.
138 GURL upload_location; 143 GURL upload_location;
139 144
140 // Header content-Length. 145 // Header content-Length.
141 int64_t content_length; 146 int64_t content_length;
142 147
143 int64_t next_start_position; 148 int64_t next_start_position;
144 149
145 // Blocks system suspend while upload is in progress. 150 // Blocks system suspend while upload is in progress.
146 std::unique_ptr<content::PowerSaveBlocker> power_save_blocker; 151 std::unique_ptr<device::PowerSaveBlocker> power_save_blocker;
147 152
148 // Fields for implementing cancellation. |cancel_callback| is non-null if 153 // Fields for implementing cancellation. |cancel_callback| is non-null if
149 // there is an in-flight HTTP request. In that case, |cancell_callback| will 154 // there is an in-flight HTTP request. In that case, |cancell_callback| will
150 // cancel the operation. |cancelled| is initially false and turns to true 155 // cancel the operation. |cancelled| is initially false and turns to true
151 // once Cancel() is called. DriveUploader will check this field before after 156 // once Cancel() is called. DriveUploader will check this field before after
152 // an async task other than HTTP requests and cancels the subsequent requests 157 // an async task other than HTTP requests and cancels the subsequent requests
153 // if this is flagged to true. 158 // if this is flagged to true.
154 CancelCallback cancel_callback; 159 CancelCallback cancel_callback;
155 bool cancelled; 160 bool cancelled;
156 161
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
528 DVLOG(1) << "Upload failed " << upload_file_info->DebugString(); 533 DVLOG(1) << "Upload failed " << upload_file_info->DebugString();
529 if (error == HTTP_PRECONDITION) 534 if (error == HTTP_PRECONDITION)
530 error = HTTP_CONFLICT; // ETag mismatch. 535 error = HTTP_CONFLICT; // ETag mismatch.
531 upload_file_info->completion_callback.Run(error, 536 upload_file_info->completion_callback.Run(error,
532 upload_file_info->upload_location, 537 upload_file_info->upload_location,
533 std::unique_ptr<FileResource>()); 538 std::unique_ptr<FileResource>());
534 } 539 }
535 } 540 }
536 541
537 } // namespace drive 542 } // namespace drive
OLDNEW
« no previous file with comments | « components/drive/DEPS ('k') | content/app/DEPS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698