| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "url_request_adapter.h" | 5 #include "components/cronet/android/url_request_adapter.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <string.h> | 8 #include <string.h> |
| 9 #include <utility> |
| 9 | 10 |
| 10 #include "base/bind.h" | 11 #include "base/bind.h" |
| 11 #include "base/location.h" | 12 #include "base/location.h" |
| 12 #include "base/logging.h" | 13 #include "base/logging.h" |
| 13 #include "base/single_thread_task_runner.h" | 14 #include "base/single_thread_task_runner.h" |
| 14 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
| 15 #include "components/cronet/android/url_request_context_adapter.h" | 16 #include "components/cronet/android/url_request_context_adapter.h" |
| 16 #include "components/cronet/android/wrapped_channel_upload_element_reader.h" | 17 #include "components/cronet/android/wrapped_channel_upload_element_reader.h" |
| 17 #include "net/base/elements_upload_data_stream.h" | 18 #include "net/base/elements_upload_data_stream.h" |
| 18 #include "net/base/load_flags.h" | 19 #include "net/base/load_flags.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 void URLRequestAdapter::AddHeader(const std::string& name, | 56 void URLRequestAdapter::AddHeader(const std::string& name, |
| 56 const std::string& value) { | 57 const std::string& value) { |
| 57 headers_.SetHeader(name, value); | 58 headers_.SetHeader(name, value); |
| 58 } | 59 } |
| 59 | 60 |
| 60 void URLRequestAdapter::SetUploadContent(const char* bytes, int bytes_len) { | 61 void URLRequestAdapter::SetUploadContent(const char* bytes, int bytes_len) { |
| 61 std::vector<char> data(bytes, bytes + bytes_len); | 62 std::vector<char> data(bytes, bytes + bytes_len); |
| 62 scoped_ptr<net::UploadElementReader> reader( | 63 scoped_ptr<net::UploadElementReader> reader( |
| 63 new net::UploadOwnedBytesElementReader(&data)); | 64 new net::UploadOwnedBytesElementReader(&data)); |
| 64 upload_data_stream_ = | 65 upload_data_stream_ = |
| 65 net::ElementsUploadDataStream::CreateWithReader(reader.Pass(), 0); | 66 net::ElementsUploadDataStream::CreateWithReader(std::move(reader), 0); |
| 66 } | 67 } |
| 67 | 68 |
| 68 void URLRequestAdapter::SetUploadChannel(JNIEnv* env, int64_t content_length) { | 69 void URLRequestAdapter::SetUploadChannel(JNIEnv* env, int64_t content_length) { |
| 69 scoped_ptr<net::UploadElementReader> reader( | 70 scoped_ptr<net::UploadElementReader> reader( |
| 70 new WrappedChannelElementReader(delegate_, content_length)); | 71 new WrappedChannelElementReader(delegate_, content_length)); |
| 71 upload_data_stream_ = | 72 upload_data_stream_ = |
| 72 net::ElementsUploadDataStream::CreateWithReader(reader.Pass(), 0); | 73 net::ElementsUploadDataStream::CreateWithReader(std::move(reader), 0); |
| 73 } | 74 } |
| 74 | 75 |
| 75 void URLRequestAdapter::DisableRedirects() { | 76 void URLRequestAdapter::DisableRedirects() { |
| 76 disable_redirect_ = true; | 77 disable_redirect_ = true; |
| 77 } | 78 } |
| 78 | 79 |
| 79 void URLRequestAdapter::EnableChunkedUpload() { | 80 void URLRequestAdapter::EnableChunkedUpload() { |
| 80 chunked_upload_ = true; | 81 chunked_upload_ = true; |
| 81 } | 82 } |
| 82 | 83 |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 url_request_->set_method(method_); | 157 url_request_->set_method(method_); |
| 157 url_request_->SetExtraRequestHeaders(headers_); | 158 url_request_->SetExtraRequestHeaders(headers_); |
| 158 if (!headers_.HasHeader(net::HttpRequestHeaders::kUserAgent)) { | 159 if (!headers_.HasHeader(net::HttpRequestHeaders::kUserAgent)) { |
| 159 std::string user_agent; | 160 std::string user_agent; |
| 160 user_agent = context_->GetUserAgent(url_); | 161 user_agent = context_->GetUserAgent(url_); |
| 161 url_request_->SetExtraRequestHeaderByName( | 162 url_request_->SetExtraRequestHeaderByName( |
| 162 net::HttpRequestHeaders::kUserAgent, user_agent, true /* override */); | 163 net::HttpRequestHeaders::kUserAgent, user_agent, true /* override */); |
| 163 } | 164 } |
| 164 | 165 |
| 165 if (upload_data_stream_) { | 166 if (upload_data_stream_) { |
| 166 url_request_->set_upload(upload_data_stream_.Pass()); | 167 url_request_->set_upload(std::move(upload_data_stream_)); |
| 167 } else if (chunked_upload_) { | 168 } else if (chunked_upload_) { |
| 168 url_request_->EnableChunkedUpload(); | 169 url_request_->EnableChunkedUpload(); |
| 169 } | 170 } |
| 170 | 171 |
| 171 url_request_->SetPriority(priority_); | 172 url_request_->SetPriority(priority_); |
| 172 | 173 |
| 173 url_request_->Start(); | 174 url_request_->Start(); |
| 174 } | 175 } |
| 175 | 176 |
| 176 void URLRequestAdapter::Cancel() { | 177 void URLRequestAdapter::Cancel() { |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 unsigned char* URLRequestAdapter::Data() const { | 321 unsigned char* URLRequestAdapter::Data() const { |
| 321 DCHECK(OnNetworkThread()); | 322 DCHECK(OnNetworkThread()); |
| 322 return reinterpret_cast<unsigned char*>(read_buffer_->data()); | 323 return reinterpret_cast<unsigned char*>(read_buffer_->data()); |
| 323 } | 324 } |
| 324 | 325 |
| 325 bool URLRequestAdapter::OnNetworkThread() const { | 326 bool URLRequestAdapter::OnNetworkThread() const { |
| 326 return context_->GetNetworkTaskRunner()->BelongsToCurrentThread(); | 327 return context_->GetNetworkTaskRunner()->BelongsToCurrentThread(); |
| 327 } | 328 } |
| 328 | 329 |
| 329 } // namespace cronet | 330 } // namespace cronet |
| OLD | NEW |