Chromium Code Reviews| Index: google_apis/drive/drive_api_requests.cc |
| diff --git a/google_apis/drive/drive_api_requests.cc b/google_apis/drive/drive_api_requests.cc |
| index 89f3b7b8bb8059a264a0e31646d48ff0a8825b2d..3d61d53f87a7e7fb78b03216a968a71f8a2ba0b6 100644 |
| --- a/google_apis/drive/drive_api_requests.cc |
| +++ b/google_apis/drive/drive_api_requests.cc |
| @@ -1168,6 +1168,7 @@ BatchUploadRequest::BatchUploadRequest( |
| sender_(sender), |
| url_generator_(url_generator), |
| committed_(false), |
| + last_progress_value_(0), |
| weak_ptr_factory_(this) { |
| } |
| @@ -1255,7 +1256,7 @@ void BatchUploadRequest::MayCompletePrepare() { |
| // Build multipart body here. |
| std::vector<ContentTypeAndData> parts; |
| - for (const auto& child : child_requests_) { |
| + for (auto& child : child_requests_) { |
| std::string type; |
| std::string data; |
| const bool result = child.request->GetContentData(&type, &data); |
| @@ -1275,16 +1276,26 @@ void BatchUploadRequest::MayCompletePrepare() { |
| NOTREACHED(); |
| break; |
| } |
| + const std::string header = base::StringPrintf( |
| + kBatchUploadRequestFormat, method.c_str(), url.path().c_str(), |
| + url_generator_.GetBatchUploadUrl().host().c_str(), type.c_str()); |
| + |
| + child.data_position = header.size(); |
| + child.data_size = data.size(); |
| parts.push_back(ContentTypeAndData()); |
| parts.back().type = kHttpContentType; |
| - parts.back().data = base::StringPrintf( |
| - kBatchUploadRequestFormat, method.c_str(), url.path().c_str(), |
| - url_generator_.GetBatchUploadUrl().host().c_str(), type.c_str()); |
| + parts.back().data = header; |
| parts.back().data.append(data); |
| } |
| - GenerateMultipartBody(MULTIPART_MIXED, boundary_, parts, &upload_content_); |
| + std::vector<uint64> part_data_positions; |
| + GenerateMultipartBody(MULTIPART_MIXED, boundary_, parts, &upload_content_, |
| + &part_data_positions); |
| + DCHECK(part_data_positions.size() == child_requests_.size()); |
| + for (size_t i = 0; i < child_requests_.size(); ++i) { |
| + child_requests_[i].data_position += part_data_positions[i]; |
|
kinaba
2015/05/11 13:17:35
position + position sounds a bit strange to me (th
hirono
2015/05/12 03:42:17
Done.
|
| + } |
| prepare_callback_.Run(HTTP_SUCCESS); |
| } |
| @@ -1351,5 +1362,21 @@ void BatchUploadRequest::RunCallbackOnPrematureFailure(DriveApiErrorCode code) { |
| child_requests_.clear(); |
| } |
| +void BatchUploadRequest::OnURLFetchUploadProgress(const net::URLFetcher* source, |
| + int64 current, |
| + int64 total) { |
| + for (auto child : child_requests_) { |
| + if (child.data_position <= current && |
| + current <= child.data_position + child.data_size) { |
| + child.request->OnURLFetchUploadProgress( |
| + source, current - child.data_position, child.data_size); |
| + } else if (last_progress_value_ < child.data_position + child.data_size && |
| + child.data_position + child.data_size < current) { |
| + child.request->OnURLFetchUploadProgress(source, child.data_size, |
| + child.data_size); |
| + } |
| + } |
| + last_progress_value_ = current; |
| +} |
| } // namespace drive |
| } // namespace google_apis |