Chromium Code Reviews| 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..e0b23643cbc253c94e0d3062ddceb9e5bea3ad50 100644 |
| --- a/components/cronet/android/url_request_adapter.cc |
| +++ b/components/cronet/android/url_request_adapter.cc |
| @@ -23,15 +23,16 @@ URLRequestAdapter::URLRequestAdapter(URLRequestContextAdapter* context, |
| url_request_(NULL), |
| read_buffer_(new net::GrowableIOBuffer()), |
| bytes_read_(0), |
| total_bytes_read_(0), |
| error_code_(0), |
| http_status_code_(0), |
| canceled_(false), |
| - expected_size_(0) { |
| + expected_size_(0), |
| + chunked_upload_(false) { |
| context_ = context; |
| delegate_ = delegate; |
| url_ = url; |
| priority_ = priority; |
| } |
| URLRequestAdapter::~URLRequestAdapter() { |
| @@ -58,14 +59,30 @@ void URLRequestAdapter::SetUploadContent(const char* bytes, int bytes_len) { |
| void URLRequestAdapter::SetUploadChannel(JNIEnv* env, int64 content_length) { |
| scoped_ptr<net::UploadElementReader> reader( |
| new WrappedChannelElementReader(delegate_, content_length)); |
| upload_data_stream_.reset( |
| net::UploadDataStream::CreateWithReader(reader.Pass(), 0)); |
| } |
| +void URLRequestAdapter::EnableChunkedUpload() { |
| + chunked_upload_ = true; |
| +} |
| + |
| +void URLRequestAdapter::AppendChunk(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) { |
| url_request_->GetResponseHeaderByName(name, &value); |
| } |
| return value; |
| } |
| @@ -73,21 +90,36 @@ std::string URLRequestAdapter::GetHeader(const std::string& name) const { |
| net::HttpResponseHeaders* URLRequestAdapter::GetResponseHeaders() const { |
| if (url_request_ == NULL) { |
| return NULL; |
| } |
| return url_request_->response_headers(); |
| } |
| +bool URLRequestAdapter::GetFullRequestHeaders( |
| + net::HttpRequestHeaders* headers) const { |
| + if (url_request_ == NULL) { |
| + return false; |
| + } |
| + return url_request_->GetFullRequestHeaders(headers); |
| +} |
| + |
| void URLRequestAdapter::Start() { |
| context_->GetNetworkTaskRunner()->PostTask( |
| FROM_HERE, |
| base::Bind(&URLRequestAdapter::OnInitiateConnection, |
| base::Unretained(this))); |
| } |
| +void URLRequestAdapter::OnAppendChunk(const char* bytes, int bytes_len, |
| + bool is_last_chunk) { |
| + CHECK(url_request_ != NULL); |
|
mmenke
2014/08/15 15:30:21
Not needed. We'd crash on the next line if this i
mdumitrescu
2014/08/15 15:50:20
Done.
|
| + url_request_->AppendChunkToUpload(bytes, bytes_len, is_last_chunk); |
| + delegate_->OnAppendChunkCompleted(this); |
| +} |
| + |
| void URLRequestAdapter::OnInitiateConnection() { |
| if (canceled_) { |
| return; |
| } |
| VLOG(1) << "Starting chromium request: " |
| << url_.possibly_invalid_spec().c_str() |
| @@ -102,16 +134,19 @@ void URLRequestAdapter::OnInitiateConnection() { |
| if (!headers_.HasHeader(net::HttpRequestHeaders::kUserAgent)) { |
| std::string user_agent; |
| user_agent = context_->GetUserAgent(url_); |
| url_request_->SetExtraRequestHeaderByName( |
| 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_); |
| url_request_->Start(); |
| } |
| void URLRequestAdapter::Cancel() { |