| Index: chrome/browser/drive/drive_uploader.cc
|
| diff --git a/chrome/browser/drive/drive_uploader.cc b/chrome/browser/drive/drive_uploader.cc
|
| index 493a76343a90d04daf05f6c5792c77d391dcbf54..30808a5ef333b87dc29397125703f0395fcd8a78 100644
|
| --- a/chrome/browser/drive/drive_uploader.cc
|
| +++ b/chrome/browser/drive/drive_uploader.cc
|
| @@ -55,6 +55,7 @@ struct DriveUploader::UploadFileInfo {
|
| completion_callback(callback),
|
| progress_callback(progress_callback),
|
| content_length(0),
|
| + next_start_position(-1),
|
| power_save_blocker(content::PowerSaveBlocker::Create(
|
| content::PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension,
|
| "Upload in progress")),
|
| @@ -97,6 +98,8 @@ struct DriveUploader::UploadFileInfo {
|
| // Header content-Length.
|
| int64 content_length;
|
|
|
| + int64 next_start_position;
|
| +
|
| // Blocks system suspend while upload is in progress.
|
| scoped_ptr<content::PowerSaveBlocker> power_save_blocker;
|
|
|
| @@ -295,7 +298,8 @@ void DriveUploader::OnUploadLocationReceived(
|
| }
|
|
|
| upload_file_info->upload_location = upload_location;
|
| - UploadNextChunk(upload_file_info.Pass(), 0); // start_position
|
| + upload_file_info->next_start_position = 0;
|
| + UploadNextChunk(upload_file_info.Pass());
|
| }
|
|
|
| void DriveUploader::StartGetUploadStatus(
|
| @@ -313,12 +317,12 @@ void DriveUploader::StartGetUploadStatus(
|
| }
|
|
|
| void DriveUploader::UploadNextChunk(
|
| - scoped_ptr<UploadFileInfo> upload_file_info,
|
| - int64 start_position) {
|
| + scoped_ptr<UploadFileInfo> upload_file_info) {
|
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| DCHECK(upload_file_info);
|
| - DCHECK_GE(start_position, 0);
|
| - DCHECK_LE(start_position, upload_file_info->content_length);
|
| + DCHECK_GE(upload_file_info->next_start_position, 0);
|
| + DCHECK_LE(upload_file_info->next_start_position,
|
| + upload_file_info->content_length);
|
|
|
| if (upload_file_info->cancelled) {
|
| UploadFailed(upload_file_info.Pass(), GDATA_CANCELLED);
|
| @@ -326,13 +330,14 @@ void DriveUploader::UploadNextChunk(
|
| }
|
|
|
| // Limit the size of data uploaded per each request by kUploadChunkSize.
|
| - const int64 end_position = std::min(upload_file_info->content_length,
|
| - start_position + kUploadChunkSize);
|
| + const int64 end_position = std::min(
|
| + upload_file_info->content_length,
|
| + upload_file_info->next_start_position + kUploadChunkSize);
|
|
|
| UploadFileInfo* info_ptr = upload_file_info.get();
|
| info_ptr->cancel_callback = drive_service_->ResumeUpload(
|
| info_ptr->upload_location,
|
| - start_position,
|
| + info_ptr->next_start_position,
|
| end_position,
|
| info_ptr->content_length,
|
| info_ptr->content_type,
|
| @@ -343,7 +348,7 @@ void DriveUploader::UploadNextChunk(
|
| base::Bind(&DriveUploader::OnUploadProgress,
|
| weak_ptr_factory_.GetWeakPtr(),
|
| info_ptr->progress_callback,
|
| - start_position,
|
| + info_ptr->next_start_position,
|
| info_ptr->content_length));
|
| }
|
|
|
| @@ -397,7 +402,8 @@ void DriveUploader::OnUploadRangeResponseReceived(
|
| << "-" << response.end_position_received
|
| << " for [" << upload_file_info->file_path.value() << "]";
|
|
|
| - UploadNextChunk(upload_file_info.Pass(), response.end_position_received);
|
| + upload_file_info->next_start_position = response.end_position_received;
|
| + UploadNextChunk(upload_file_info.Pass());
|
| }
|
|
|
| void DriveUploader::OnUploadProgress(const ProgressCallback& callback,
|
| @@ -415,6 +421,12 @@ void DriveUploader::UploadFailed(scoped_ptr<UploadFileInfo> upload_file_info,
|
|
|
| LOG(ERROR) << "Upload failed " << upload_file_info->DebugString();
|
|
|
| + if (upload_file_info->next_start_position < 0) {
|
| + // Discard the upload location because no request could succeed with it.
|
| + // Maybe it's obsolete.
|
| + upload_file_info->upload_location = GURL();
|
| + }
|
| +
|
| upload_file_info->completion_callback.Run(
|
| error, upload_file_info->upload_location, scoped_ptr<ResourceEntry>());
|
| }
|
|
|