| 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 "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 263 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  274     UploadFailed(upload_file_info.Pass(), code); |  274     UploadFailed(upload_file_info.Pass(), code); | 
|  275     return; |  275     return; | 
|  276   } |  276   } | 
|  277  |  277  | 
|  278   upload_file_info->upload_location = upload_location; |  278   upload_file_info->upload_location = upload_location; | 
|  279  |  279  | 
|  280   // Start the upload from the beginning of the file. |  280   // Start the upload from the beginning of the file. | 
|  281   // PostTask is necessary because we have to finish |  281   // PostTask is necessary because we have to finish | 
|  282   // InitiateUpload's callback before calling ResumeUpload, due to the |  282   // InitiateUpload's callback before calling ResumeUpload, due to the | 
|  283   // implementation of OperationRegistry. (http://crbug.com/134814) |  283   // implementation of OperationRegistry. (http://crbug.com/134814) | 
|  284   MessageLoop::current()->PostTask( |  284   base::MessageLoop::current()->PostTask( | 
|  285       FROM_HERE, |  285       FROM_HERE, | 
|  286       base::Bind(&DriveUploader::UploadNextChunk, |  286       base::Bind(&DriveUploader::UploadNextChunk, | 
|  287                  weak_ptr_factory_.GetWeakPtr(), |  287                  weak_ptr_factory_.GetWeakPtr(), | 
|  288                  base::Passed(&upload_file_info), |  288                  base::Passed(&upload_file_info), | 
|  289                  0));  // Upload from the beginning of the file. |  289                  0));  // Upload from the beginning of the file. | 
|  290 } |  290 } | 
|  291  |  291  | 
|  292 void DriveUploader::StartGetUploadStatus( |  292 void DriveUploader::StartGetUploadStatus( | 
|  293     scoped_ptr<UploadFileInfo> upload_file_info) { |  293     scoped_ptr<UploadFileInfo> upload_file_info) { | 
|  294   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |  294   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  379  |  379  | 
|  380   DVLOG(1) << "Received range " << response.start_position_received |  380   DVLOG(1) << "Received range " << response.start_position_received | 
|  381            << "-" << response.end_position_received |  381            << "-" << response.end_position_received | 
|  382            << " for [" << upload_file_info->drive_path.value() << "]"; |  382            << " for [" << upload_file_info->drive_path.value() << "]"; | 
|  383  |  383  | 
|  384   // Continue uploading the remaining chunk. The start position of the |  384   // Continue uploading the remaining chunk. The start position of the | 
|  385   // remaining data is |response.end_position_received|. |  385   // remaining data is |response.end_position_received|. | 
|  386   // PostTask is necessary because we have to finish previous ResumeUpload's |  386   // PostTask is necessary because we have to finish previous ResumeUpload's | 
|  387   // callback before calling ResumeUpload again, due to the implementation of |  387   // callback before calling ResumeUpload again, due to the implementation of | 
|  388   // OperationRegistry. (http://crbug.com/134814) |  388   // OperationRegistry. (http://crbug.com/134814) | 
|  389   MessageLoop::current()->PostTask( |  389   base::MessageLoop::current()->PostTask( | 
|  390       FROM_HERE, |  390       FROM_HERE, | 
|  391       base::Bind(&DriveUploader::UploadNextChunk, |  391       base::Bind(&DriveUploader::UploadNextChunk, | 
|  392                  weak_ptr_factory_.GetWeakPtr(), |  392                  weak_ptr_factory_.GetWeakPtr(), | 
|  393                  base::Passed(&upload_file_info), |  393                  base::Passed(&upload_file_info), | 
|  394                  response.end_position_received)); |  394                  response.end_position_received)); | 
|  395 } |  395 } | 
|  396  |  396  | 
|  397 void DriveUploader::OnUploadProgress(const ProgressCallback& callback, |  397 void DriveUploader::OnUploadProgress(const ProgressCallback& callback, | 
|  398                                      int64 start_position, |  398                                      int64 start_position, | 
|  399                                      int64 total_size, |  399                                      int64 total_size, | 
|  400                                      int64 progress_of_chunk, |  400                                      int64 progress_of_chunk, | 
|  401                                      int64 total_of_chunk) { |  401                                      int64 total_of_chunk) { | 
|  402   if (!callback.is_null()) |  402   if (!callback.is_null()) | 
|  403     callback.Run(start_position + progress_of_chunk, total_size); |  403     callback.Run(start_position + progress_of_chunk, total_size); | 
|  404 } |  404 } | 
|  405  |  405  | 
|  406 void DriveUploader::UploadFailed(scoped_ptr<UploadFileInfo> upload_file_info, |  406 void DriveUploader::UploadFailed(scoped_ptr<UploadFileInfo> upload_file_info, | 
|  407                                  GDataErrorCode error) { |  407                                  GDataErrorCode error) { | 
|  408   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |  408   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 
|  409  |  409  | 
|  410   LOG(ERROR) << "Upload failed " << upload_file_info->DebugString(); |  410   LOG(ERROR) << "Upload failed " << upload_file_info->DebugString(); | 
|  411  |  411  | 
|  412   upload_file_info->completion_callback.Run( |  412   upload_file_info->completion_callback.Run( | 
|  413       error, upload_file_info->upload_location, scoped_ptr<ResourceEntry>()); |  413       error, upload_file_info->upload_location, scoped_ptr<ResourceEntry>()); | 
|  414 } |  414 } | 
|  415  |  415  | 
|  416 }  // namespace google_apis |  416 }  // namespace google_apis | 
| OLD | NEW |