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 "url_request_adapter.h" |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
13 #include "components/cronet/android/url_request_context_adapter.h" | 13 #include "components/cronet/android/url_request_context_adapter.h" |
14 #include "components/cronet/android/wrapped_channel_upload_element_reader.h" | 14 #include "components/cronet/android/wrapped_channel_upload_element_reader.h" |
15 #include "net/base/load_flags.h" | 15 #include "net/base/load_flags.h" |
16 #include "net/base/upload_bytes_element_reader.h" | 16 #include "net/base/upload_bytes_element_reader.h" |
17 #include "net/http/http_status_code.h" | 17 #include "net/http/http_status_code.h" |
18 | 18 |
19 namespace cronet { | 19 namespace cronet { |
20 | 20 |
21 static const size_t kBufferSizeIncrement = 8192; | 21 static const size_t kBufferSizeIncrement = 8192; |
22 | 22 |
23 URLRequestAdapter::URLRequestAdapter(URLRequestContextAdapter* context, | 23 URLRequestAdapter::URLRequestAdapter(URLRequestContextAdapter* context, |
24 URLRequestAdapterDelegate* delegate, | 24 URLRequestAdapterDelegate* delegate, |
25 GURL url, | 25 GURL url, |
26 net::RequestPriority priority) | 26 net::RequestPriority priority) |
27 : method_("GET"), | 27 : method_("GET"), |
28 url_request_(NULL), | |
29 read_buffer_(new net::GrowableIOBuffer()), | 28 read_buffer_(new net::GrowableIOBuffer()), |
30 bytes_read_(0), | 29 bytes_read_(0), |
31 total_bytes_read_(0), | 30 total_bytes_read_(0), |
32 error_code_(0), | 31 error_code_(0), |
33 http_status_code_(0), | 32 http_status_code_(0), |
34 canceled_(false), | 33 canceled_(false), |
35 expected_size_(0), | 34 expected_size_(0), |
36 chunked_upload_(false) { | 35 chunked_upload_(false) { |
37 context_ = context; | 36 context_ = context; |
38 delegate_ = delegate; | 37 delegate_ = delegate; |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
114 } | 113 } |
115 | 114 |
116 void URLRequestAdapter::OnInitiateConnection() { | 115 void URLRequestAdapter::OnInitiateConnection() { |
117 if (canceled_) { | 116 if (canceled_) { |
118 return; | 117 return; |
119 } | 118 } |
120 | 119 |
121 VLOG(1) << "Starting chromium request: " | 120 VLOG(1) << "Starting chromium request: " |
122 << url_.possibly_invalid_spec().c_str() | 121 << url_.possibly_invalid_spec().c_str() |
123 << " priority: " << RequestPriorityToString(priority_); | 122 << " priority: " << RequestPriorityToString(priority_); |
124 url_request_ = new net::URLRequest( | 123 url_request_ = context_->GetURLRequestContext()->CreateRequest( |
125 url_, net::DEFAULT_PRIORITY, this, context_->GetURLRequestContext()); | 124 url_, net::DEFAULT_PRIORITY, this, NULL); |
126 url_request_->SetLoadFlags(net::LOAD_DISABLE_CACHE | | 125 url_request_->SetLoadFlags(net::LOAD_DISABLE_CACHE | |
127 net::LOAD_DO_NOT_SAVE_COOKIES | | 126 net::LOAD_DO_NOT_SAVE_COOKIES | |
128 net::LOAD_DO_NOT_SEND_COOKIES); | 127 net::LOAD_DO_NOT_SEND_COOKIES); |
129 url_request_->set_method(method_); | 128 url_request_->set_method(method_); |
130 url_request_->SetExtraRequestHeaders(headers_); | 129 url_request_->SetExtraRequestHeaders(headers_); |
131 if (!headers_.HasHeader(net::HttpRequestHeaders::kUserAgent)) { | 130 if (!headers_.HasHeader(net::HttpRequestHeaders::kUserAgent)) { |
132 std::string user_agent; | 131 std::string user_agent; |
133 user_agent = context_->GetUserAgent(url_); | 132 user_agent = context_->GetUserAgent(url_); |
134 url_request_->SetExtraRequestHeaderByName( | 133 url_request_->SetExtraRequestHeaderByName( |
135 net::HttpRequestHeaders::kUserAgent, user_agent, true /* override */); | 134 net::HttpRequestHeaders::kUserAgent, user_agent, true /* override */); |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
274 << " and error: " << net::ErrorToString(error_code_); | 273 << " and error: " << net::ErrorToString(error_code_); |
275 OnRequestCompleted(); | 274 OnRequestCompleted(); |
276 } | 275 } |
277 | 276 |
278 void URLRequestAdapter::OnRequestCanceled() { | 277 void URLRequestAdapter::OnRequestCanceled() { |
279 OnRequestCompleted(); | 278 OnRequestCompleted(); |
280 } | 279 } |
281 | 280 |
282 void URLRequestAdapter::OnRequestCompleted() { | 281 void URLRequestAdapter::OnRequestCompleted() { |
283 VLOG(1) << "Completed: " << url_.possibly_invalid_spec(); | 282 VLOG(1) << "Completed: " << url_.possibly_invalid_spec(); |
284 if (url_request_ != NULL) { | 283 url_request_.reset(); |
mmenke
2014/08/25 19:46:44
Amusingly, I made this exact change in my CL to fi
mef
2014/08/25 20:26:18
Excellent!
| |
285 delete url_request_; | |
286 url_request_ = NULL; | |
287 } | |
288 | 284 |
289 delegate_->OnBytesRead(this); | 285 delegate_->OnBytesRead(this); |
290 delegate_->OnRequestFinished(this); | 286 delegate_->OnRequestFinished(this); |
291 } | 287 } |
292 | 288 |
293 unsigned char* URLRequestAdapter::Data() const { | 289 unsigned char* URLRequestAdapter::Data() const { |
294 return reinterpret_cast<unsigned char*>(read_buffer_->StartOfBuffer()); | 290 return reinterpret_cast<unsigned char*>(read_buffer_->StartOfBuffer()); |
295 } | 291 } |
296 | 292 |
297 } // namespace cronet | 293 } // namespace cronet |
OLD | NEW |