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

Unified Diff: components/cronet/android/url_request_adapter.cc

Issue 475533003: Upstream changes to enable chunked uploads. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/cronet/android/url_request_adapter.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/cronet/android/url_request_adapter.cc
diff --git a/components/cronet/android/url_request_adapter.cc b/components/cronet/android/url_request_adapter.cc
index 8ab88a2f3cd766629e0033c3f231381992528f13..b2beefa63a5713e915f7aad2337ac40b10f0ea5a 100644
--- a/components/cronet/android/url_request_adapter.cc
+++ b/components/cronet/android/url_request_adapter.cc
@@ -27,7 +27,8 @@ URLRequestAdapter::URLRequestAdapter(URLRequestContextAdapter* context,
error_code_(0),
http_status_code_(0),
canceled_(false),
- expected_size_(0) {
+ expected_size_(0),
+ chunked_upload_(false) {
context_ = context;
delegate_ = delegate;
url_ = url;
@@ -62,6 +63,23 @@ void URLRequestAdapter::SetUploadChannel(JNIEnv* env, int64 content_length) {
net::UploadDataStream::CreateWithReader(reader.Pass(), 0));
}
+void URLRequestAdapter::EnableChunkedUpload() {
+ chunked_upload_ = true;
+}
+
+void URLRequestAdapter::AppendChunkToUpload(const char* bytes,
+ int bytes_len,
+ bool is_last_chunk) {
+ VLOG(1) << "AppendChunk, len: " << bytes_len << ", last: " << is_last_chunk;
+ context_->GetNetworkTaskRunner()->PostTask(
+ FROM_HERE,
+ base::Bind(&URLRequestAdapter::OnAppendChunk,
+ base::Unretained(this),
+ bytes,
+ bytes_len,
+ is_last_chunk));
+}
+
std::string URLRequestAdapter::GetHeader(const std::string& name) const {
std::string value;
if (url_request_ != NULL) {
@@ -84,6 +102,15 @@ void URLRequestAdapter::Start() {
base::Unretained(this)));
}
+void URLRequestAdapter::OnAppendChunk(const char* bytes,
+ int bytes_len,
+ bool is_last_chunk) {
+ if (url_request_ != NULL) {
+ url_request_->AppendChunkToUpload(bytes, bytes_len, is_last_chunk);
+ delegate_->OnAppendChunkCompleted(this);
+ }
+}
+
void URLRequestAdapter::OnInitiateConnection() {
if (canceled_) {
return;
@@ -106,8 +133,11 @@ void URLRequestAdapter::OnInitiateConnection() {
net::HttpRequestHeaders::kUserAgent, user_agent, true /* override */);
}
- if (upload_data_stream_)
+ if (upload_data_stream_) {
url_request_->set_upload(upload_data_stream_.Pass());
+ } else if (chunked_upload_) {
+ url_request_->EnableChunkedUpload();
+ }
url_request_->SetPriority(priority_);
« no previous file with comments | « components/cronet/android/url_request_adapter.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698