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

Unified Diff: google_apis/drive/drive_api_requests.cc

Issue 1130183003: Notify upload progress from batch request to its child requests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments and fix msan test. Created 5 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « google_apis/drive/drive_api_requests.h ('k') | google_apis/drive/drive_api_requests_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..ce07586ab3c19c18e374f7a11b38f53987dba6c7 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_offset = 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_offset;
+ GenerateMultipartBody(MULTIPART_MIXED, boundary_, parts, &upload_content_,
+ &part_data_offset);
+ DCHECK(part_data_offset.size() == child_requests_.size());
+ for (size_t i = 0; i < child_requests_.size(); ++i) {
+ child_requests_[i].data_offset += part_data_offset[i];
+ }
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_offset <= current &&
+ current <= child.data_offset + child.data_size) {
+ child.request->OnURLFetchUploadProgress(
+ source, current - child.data_offset, child.data_size);
+ } else if (last_progress_value_ < child.data_offset + child.data_size &&
+ child.data_offset + child.data_size < current) {
+ child.request->OnURLFetchUploadProgress(source, child.data_size,
+ child.data_size);
+ }
+ }
+ last_progress_value_ = current;
+}
} // namespace drive
} // namespace google_apis
« no previous file with comments | « google_apis/drive/drive_api_requests.h ('k') | google_apis/drive/drive_api_requests_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698