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

Side by Side Diff: chrome/browser/chromeos/gdata/gdata_uploader.cc

Issue 10837061: gdata: Make WeakPtrFactory the last parameter (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase and reorder Created 8 years, 4 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/chromeos/gdata/gdata_uploader.h" 5 #include "chrome/browser/chromeos/gdata/gdata_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 15 matching lines...) Expand all
26 // Maximum number of times we try to open a file before giving up. 26 // Maximum number of times we try to open a file before giving up.
27 const int kMaxFileOpenTries = 5; 27 const int kMaxFileOpenTries = 5;
28 28
29 } // namespace 29 } // namespace
30 30
31 namespace gdata { 31 namespace gdata {
32 32
33 GDataUploader::GDataUploader(DocumentsServiceInterface* documents_service) 33 GDataUploader::GDataUploader(DocumentsServiceInterface* documents_service)
34 : documents_service_(documents_service), 34 : documents_service_(documents_service),
35 next_upload_id_(0), 35 next_upload_id_(0),
36 ALLOW_THIS_IN_INITIALIZER_LIST(uploader_factory_(this)) { 36 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) {
37 } 37 }
38 38
39 GDataUploader::~GDataUploader() { 39 GDataUploader::~GDataUploader() {
40 } 40 }
41 41
42 int GDataUploader::UploadNewFile(scoped_ptr<UploadFileInfo> upload_file_info) { 42 int GDataUploader::UploadNewFile(scoped_ptr<UploadFileInfo> upload_file_info) {
43 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 43 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
44 DCHECK(upload_file_info.get()); 44 DCHECK(upload_file_info.get());
45 DCHECK_EQ(upload_file_info->upload_id, -1); 45 DCHECK_EQ(upload_file_info->upload_id, -1);
46 DCHECK(!upload_file_info->file_path.empty()); 46 DCHECK(!upload_file_info->file_path.empty());
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 } 187 }
188 188
189 void GDataUploader::OpenFile(UploadFileInfo* upload_file_info) { 189 void GDataUploader::OpenFile(UploadFileInfo* upload_file_info) {
190 // Open the file asynchronously. 190 // Open the file asynchronously.
191 const int rv = upload_file_info->file_stream->Open( 191 const int rv = upload_file_info->file_stream->Open(
192 upload_file_info->file_path, 192 upload_file_info->file_path,
193 base::PLATFORM_FILE_OPEN | 193 base::PLATFORM_FILE_OPEN |
194 base::PLATFORM_FILE_READ | 194 base::PLATFORM_FILE_READ |
195 base::PLATFORM_FILE_ASYNC, 195 base::PLATFORM_FILE_ASYNC,
196 base::Bind(&GDataUploader::OpenCompletionCallback, 196 base::Bind(&GDataUploader::OpenCompletionCallback,
197 uploader_factory_.GetWeakPtr(), 197 weak_ptr_factory_.GetWeakPtr(),
198 upload_file_info->upload_id)); 198 upload_file_info->upload_id));
199 DCHECK_EQ(net::ERR_IO_PENDING, rv); 199 DCHECK_EQ(net::ERR_IO_PENDING, rv);
200 } 200 }
201 201
202 void GDataUploader::OpenCompletionCallback(int upload_id, int result) { 202 void GDataUploader::OpenCompletionCallback(int upload_id, int result) {
203 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 203 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
204 204
205 UploadFileInfo* upload_file_info = GetUploadFileInfo(upload_id); 205 UploadFileInfo* upload_file_info = GetUploadFileInfo(upload_id);
206 if (!upload_file_info) 206 if (!upload_file_info)
207 return; 207 return;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 return; 240 return;
241 } 241 }
242 documents_service_->InitiateUpload( 242 documents_service_->InitiateUpload(
243 InitiateUploadParams(upload_file_info->upload_mode, 243 InitiateUploadParams(upload_file_info->upload_mode,
244 upload_file_info->title, 244 upload_file_info->title,
245 upload_file_info->content_type, 245 upload_file_info->content_type,
246 upload_file_info->content_length, 246 upload_file_info->content_length,
247 upload_file_info->initial_upload_location, 247 upload_file_info->initial_upload_location,
248 upload_file_info->gdata_path), 248 upload_file_info->gdata_path),
249 base::Bind(&GDataUploader::OnUploadLocationReceived, 249 base::Bind(&GDataUploader::OnUploadLocationReceived,
250 uploader_factory_.GetWeakPtr(), 250 weak_ptr_factory_.GetWeakPtr(),
251 upload_file_info->upload_id)); 251 upload_file_info->upload_id));
252 } 252 }
253 253
254 void GDataUploader::OnUploadLocationReceived( 254 void GDataUploader::OnUploadLocationReceived(
255 int upload_id, 255 int upload_id,
256 GDataErrorCode code, 256 GDataErrorCode code,
257 const GURL& upload_location) { 257 const GURL& upload_location) {
258 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 258 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
259 259
260 UploadFileInfo* upload_file_info = GetUploadFileInfo(upload_id); 260 UploadFileInfo* upload_file_info = GetUploadFileInfo(upload_id);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 // proceeds to ResumeUpload. 314 // proceeds to ResumeUpload.
315 // TODO(kinaba): http://crbug.com/134814 315 // TODO(kinaba): http://crbug.com/134814
316 // Replace the following PostTask() to an direct method call. This is needed 316 // Replace the following PostTask() to an direct method call. This is needed
317 // because we have to ResumeUpload after the previous InitiateUpload or 317 // because we have to ResumeUpload after the previous InitiateUpload or
318 // ResumeUpload is completely finished; at this point, we are inside the 318 // ResumeUpload is completely finished; at this point, we are inside the
319 // callback function from the previous operation, which is not treated as 319 // callback function from the previous operation, which is not treated as
320 // finished yet. 320 // finished yet.
321 base::MessageLoopProxy::current()->PostTask( 321 base::MessageLoopProxy::current()->PostTask(
322 FROM_HERE, 322 FROM_HERE,
323 base::Bind(&GDataUploader::ResumeUpload, 323 base::Bind(&GDataUploader::ResumeUpload,
324 uploader_factory_.GetWeakPtr(), 324 weak_ptr_factory_.GetWeakPtr(),
325 upload_file_info->upload_id)); 325 upload_file_info->upload_id));
326 return; 326 return;
327 } 327 }
328 328
329 upload_file_info->file_stream->Read( 329 upload_file_info->file_stream->Read(
330 upload_file_info->buf, 330 upload_file_info->buf,
331 bytes_to_read, 331 bytes_to_read,
332 base::Bind(&GDataUploader::ReadCompletionCallback, 332 base::Bind(&GDataUploader::ReadCompletionCallback,
333 uploader_factory_.GetWeakPtr(), 333 weak_ptr_factory_.GetWeakPtr(),
334 upload_file_info->upload_id, 334 upload_file_info->upload_id,
335 bytes_to_read)); 335 bytes_to_read));
336 } 336 }
337 337
338 void GDataUploader::ReadCompletionCallback( 338 void GDataUploader::ReadCompletionCallback(
339 int upload_id, 339 int upload_id,
340 int bytes_to_read, 340 int bytes_to_read,
341 int bytes_read) { 341 int bytes_read) {
342 // The Read is asynchronously executed on BrowserThread::UI, where 342 // The Read is asynchronously executed on BrowserThread::UI, where
343 // Read() was called. 343 // Read() was called.
(...skipping 24 matching lines...) Expand all
368 documents_service_->ResumeUpload( 368 documents_service_->ResumeUpload(
369 ResumeUploadParams(upload_file_info->upload_mode, 369 ResumeUploadParams(upload_file_info->upload_mode,
370 upload_file_info->start_range, 370 upload_file_info->start_range,
371 upload_file_info->end_range, 371 upload_file_info->end_range,
372 upload_file_info->content_length, 372 upload_file_info->content_length,
373 upload_file_info->content_type, 373 upload_file_info->content_type,
374 upload_file_info->buf, 374 upload_file_info->buf,
375 upload_file_info->upload_location, 375 upload_file_info->upload_location,
376 upload_file_info->gdata_path), 376 upload_file_info->gdata_path),
377 base::Bind(&GDataUploader::OnResumeUploadResponseReceived, 377 base::Bind(&GDataUploader::OnResumeUploadResponseReceived,
378 uploader_factory_.GetWeakPtr(), 378 weak_ptr_factory_.GetWeakPtr(),
379 upload_file_info->upload_id)); 379 upload_file_info->upload_id));
380 } 380 }
381 381
382 void GDataUploader::OnResumeUploadResponseReceived( 382 void GDataUploader::OnResumeUploadResponseReceived(
383 int upload_id, 383 int upload_id,
384 const ResumeUploadResponse& response, 384 const ResumeUploadResponse& response,
385 scoped_ptr<DocumentEntry> entry) { 385 scoped_ptr<DocumentEntry> entry) {
386 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 386 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
387 387
388 UploadFileInfo* upload_file_info = GetUploadFileInfo(upload_id); 388 UploadFileInfo* upload_file_info = GetUploadFileInfo(upload_id);
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 if (!callback.is_null()) 452 if (!callback.is_null())
453 callback.Run(error, upload_file_info.Pass()); 453 callback.Run(error, upload_file_info.Pass());
454 } 454 }
455 455
456 void GDataUploader::RemoveUpload(int upload_id) { 456 void GDataUploader::RemoveUpload(int upload_id) {
457 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 457 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
458 pending_uploads_.erase(upload_id); 458 pending_uploads_.erase(upload_id);
459 } 459 }
460 460
461 } // namespace gdata 461 } // namespace gdata
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/gdata/gdata_uploader.h ('k') | chrome/browser/chromeos/gdata/operations_base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698