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

Side by Side Diff: chrome/browser/google_apis/drive_uploader.cc

Issue 17227003: Change google_apis::DriveUploader interface to return CancelCallback. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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 | Annotate | Revision Log
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 "chrome/browser/google_apis/drive_uploader.h" 5 #include "chrome/browser/google_apis/drive_uploader.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 scoped_ptr<content::PowerSaveBlocker> power_save_blocker; 99 scoped_ptr<content::PowerSaveBlocker> power_save_blocker;
100 }; 100 };
101 101
102 DriveUploader::DriveUploader(DriveServiceInterface* drive_service) 102 DriveUploader::DriveUploader(DriveServiceInterface* drive_service)
103 : drive_service_(drive_service), 103 : drive_service_(drive_service),
104 weak_ptr_factory_(this) { 104 weak_ptr_factory_(this) {
105 } 105 }
106 106
107 DriveUploader::~DriveUploader() {} 107 DriveUploader::~DriveUploader() {}
108 108
109 void DriveUploader::UploadNewFile(const std::string& parent_resource_id, 109 CancelCallback DriveUploader::UploadNewFile(
110 const base::FilePath& drive_file_path, 110 const std::string& parent_resource_id,
111 const base::FilePath& local_file_path, 111 const base::FilePath& drive_file_path,
112 const std::string& title, 112 const base::FilePath& local_file_path,
113 const std::string& content_type, 113 const std::string& title,
114 const UploadCompletionCallback& callback, 114 const std::string& content_type,
115 const ProgressCallback& progress_callback) { 115 const UploadCompletionCallback& callback,
116 const ProgressCallback& progress_callback) {
116 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 117 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
117 DCHECK(!parent_resource_id.empty()); 118 DCHECK(!parent_resource_id.empty());
118 DCHECK(!drive_file_path.empty()); 119 DCHECK(!drive_file_path.empty());
119 DCHECK(!local_file_path.empty()); 120 DCHECK(!local_file_path.empty());
120 DCHECK(!title.empty()); 121 DCHECK(!title.empty());
121 DCHECK(!content_type.empty()); 122 DCHECK(!content_type.empty());
122 DCHECK(!callback.is_null()); 123 DCHECK(!callback.is_null());
123 124
124 StartUploadFile( 125 StartUploadFile(
125 scoped_ptr<UploadFileInfo>(new UploadFileInfo(drive_file_path, 126 scoped_ptr<UploadFileInfo>(new UploadFileInfo(drive_file_path,
126 local_file_path, 127 local_file_path,
127 content_type, 128 content_type,
128 callback, 129 callback,
129 progress_callback)), 130 progress_callback)),
130 base::Bind(&DriveUploader::StartInitiateUploadNewFile, 131 base::Bind(&DriveUploader::StartInitiateUploadNewFile,
131 weak_ptr_factory_.GetWeakPtr(), 132 weak_ptr_factory_.GetWeakPtr(),
132 parent_resource_id, 133 parent_resource_id,
133 title)); 134 title));
135 // TODO(kinaba): crbug.com/250712 Return a proper CancelCallback.
136 return CancelCallback();
134 } 137 }
135 138
136 void DriveUploader::UploadExistingFile( 139 CancelCallback DriveUploader::UploadExistingFile(
137 const std::string& resource_id, 140 const std::string& resource_id,
138 const base::FilePath& drive_file_path, 141 const base::FilePath& drive_file_path,
139 const base::FilePath& local_file_path, 142 const base::FilePath& local_file_path,
140 const std::string& content_type, 143 const std::string& content_type,
141 const std::string& etag, 144 const std::string& etag,
142 const UploadCompletionCallback& callback, 145 const UploadCompletionCallback& callback,
143 const ProgressCallback& progress_callback) { 146 const ProgressCallback& progress_callback) {
144 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 147 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
145 DCHECK(!resource_id.empty()); 148 DCHECK(!resource_id.empty());
146 DCHECK(!drive_file_path.empty()); 149 DCHECK(!drive_file_path.empty());
147 DCHECK(!local_file_path.empty()); 150 DCHECK(!local_file_path.empty());
148 DCHECK(!content_type.empty()); 151 DCHECK(!content_type.empty());
149 DCHECK(!callback.is_null()); 152 DCHECK(!callback.is_null());
150 153
151 StartUploadFile( 154 StartUploadFile(
152 scoped_ptr<UploadFileInfo>(new UploadFileInfo(drive_file_path, 155 scoped_ptr<UploadFileInfo>(new UploadFileInfo(drive_file_path,
153 local_file_path, 156 local_file_path,
154 content_type, 157 content_type,
155 callback, 158 callback,
156 progress_callback)), 159 progress_callback)),
157 base::Bind(&DriveUploader::StartInitiateUploadExistingFile, 160 base::Bind(&DriveUploader::StartInitiateUploadExistingFile,
158 weak_ptr_factory_.GetWeakPtr(), 161 weak_ptr_factory_.GetWeakPtr(),
159 resource_id, 162 resource_id,
160 etag)); 163 etag));
164 // TODO(kinaba): crbug.com/250712 Return a proper CancelCallback.
165 return CancelCallback();
161 } 166 }
162 167
163 void DriveUploader::ResumeUploadFile( 168 CancelCallback DriveUploader::ResumeUploadFile(
164 const GURL& upload_location, 169 const GURL& upload_location,
165 const base::FilePath& drive_file_path, 170 const base::FilePath& drive_file_path,
166 const base::FilePath& local_file_path, 171 const base::FilePath& local_file_path,
167 const std::string& content_type, 172 const std::string& content_type,
168 const UploadCompletionCallback& callback, 173 const UploadCompletionCallback& callback,
169 const ProgressCallback& progress_callback) { 174 const ProgressCallback& progress_callback) {
170 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 175 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
171 DCHECK(!drive_file_path.empty()); 176 DCHECK(!drive_file_path.empty());
172 DCHECK(!local_file_path.empty()); 177 DCHECK(!local_file_path.empty());
173 DCHECK(!content_type.empty()); 178 DCHECK(!content_type.empty());
174 DCHECK(!callback.is_null()); 179 DCHECK(!callback.is_null());
175 180
176 scoped_ptr<UploadFileInfo> upload_file_info(new UploadFileInfo( 181 scoped_ptr<UploadFileInfo> upload_file_info(new UploadFileInfo(
177 drive_file_path, local_file_path, content_type, 182 drive_file_path, local_file_path, content_type,
178 callback, progress_callback)); 183 callback, progress_callback));
179 upload_file_info->upload_location = upload_location; 184 upload_file_info->upload_location = upload_location;
180 185
181 StartUploadFile( 186 StartUploadFile(
182 upload_file_info.Pass(), 187 upload_file_info.Pass(),
183 base::Bind(&DriveUploader::StartGetUploadStatus, 188 base::Bind(&DriveUploader::StartGetUploadStatus,
184 weak_ptr_factory_.GetWeakPtr())); 189 weak_ptr_factory_.GetWeakPtr()));
190 // TODO(kinaba): crbug.com/250712 Return a proper CancelCallback.
191 return CancelCallback();
185 } 192 }
186 193
187 void DriveUploader::StartUploadFile( 194 void DriveUploader::StartUploadFile(
188 scoped_ptr<UploadFileInfo> upload_file_info, 195 scoped_ptr<UploadFileInfo> upload_file_info,
189 const StartInitiateUploadCallback& start_initiate_upload_callback) { 196 const StartInitiateUploadCallback& start_initiate_upload_callback) {
190 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 197 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
191 DVLOG(1) << "Uploading file: " << upload_file_info->DebugString(); 198 DVLOG(1) << "Uploading file: " << upload_file_info->DebugString();
192 199
193 // Passing a raw net::FileStream* to the blocking pool is safe, because it is 200 // Passing a raw net::FileStream* to the blocking pool is safe, because it is
194 // owned by |upload_file_info| in the reply callback. 201 // owned by |upload_file_info| in the reply callback.
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 GDataErrorCode error) { 414 GDataErrorCode error) {
408 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 415 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
409 416
410 LOG(ERROR) << "Upload failed " << upload_file_info->DebugString(); 417 LOG(ERROR) << "Upload failed " << upload_file_info->DebugString();
411 418
412 upload_file_info->completion_callback.Run( 419 upload_file_info->completion_callback.Run(
413 error, upload_file_info->upload_location, scoped_ptr<ResourceEntry>()); 420 error, upload_file_info->upload_location, scoped_ptr<ResourceEntry>());
414 } 421 }
415 422
416 } // namespace google_apis 423 } // namespace google_apis
OLDNEW
« no previous file with comments | « chrome/browser/google_apis/drive_uploader.h ('k') | chrome/browser/sync_file_system/drive/api_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698