OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "net/url_request/url_request.h" | 5 #include "net/url_request/url_request.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 request->Cancel(); | 191 request->Cancel(); |
192 } | 192 } |
193 | 193 |
194 void URLRequest::Delegate::OnBeforeNetworkStart(URLRequest* request, | 194 void URLRequest::Delegate::OnBeforeNetworkStart(URLRequest* request, |
195 bool* defer) { | 195 bool* defer) { |
196 } | 196 } |
197 | 197 |
198 /////////////////////////////////////////////////////////////////////////////// | 198 /////////////////////////////////////////////////////////////////////////////// |
199 // URLRequest | 199 // URLRequest |
200 | 200 |
201 URLRequest::URLRequest(const GURL& url, | |
202 RequestPriority priority, | |
203 Delegate* delegate, | |
204 const URLRequestContext* context, | |
205 CookieStore* cookie_store, | |
206 NetworkDelegate* network_delegate) | |
207 : context_(context), | |
208 network_delegate_(network_delegate ? network_delegate | |
209 : context->network_delegate()), | |
210 net_log_(BoundNetLog::Make(context->net_log(), | |
211 NetLog::SOURCE_URL_REQUEST)), | |
212 url_chain_(1, url), | |
213 method_("GET"), | |
214 referrer_policy_(CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE), | |
215 first_party_url_policy_(NEVER_CHANGE_FIRST_PARTY_URL), | |
216 load_flags_(LOAD_NORMAL), | |
217 delegate_(delegate), | |
218 is_pending_(false), | |
219 is_redirecting_(false), | |
220 redirect_limit_(kMaxRedirects), | |
221 priority_(priority), | |
222 identifier_(GenerateURLRequestIdentifier()), | |
223 calling_delegate_(false), | |
224 use_blocked_by_as_load_param_(false), | |
225 before_request_callback_(base::Bind(&URLRequest::BeforeRequestComplete, | |
226 base::Unretained(this))), | |
227 has_notified_completion_(false), | |
228 received_response_content_length_(0), | |
229 creation_time_(base::TimeTicks::Now()), | |
230 notified_before_network_start_(false), | |
231 cookie_store_(cookie_store ? cookie_store : context->cookie_store()) { | |
232 SIMPLE_STATS_COUNTER("URLRequestCount"); | |
233 | |
234 // Sanity check out environment. | |
235 DCHECK(base::MessageLoop::current()) | |
236 << "The current base::MessageLoop must exist"; | |
237 | |
238 context->url_requests()->insert(this); | |
239 net_log_.BeginEvent(NetLog::TYPE_REQUEST_ALIVE); | |
240 } | |
241 | |
242 URLRequest::~URLRequest() { | 201 URLRequest::~URLRequest() { |
243 Cancel(); | 202 Cancel(); |
244 | 203 |
245 if (network_delegate_) { | 204 if (network_delegate_) { |
246 network_delegate_->NotifyURLRequestDestroyed(this); | 205 network_delegate_->NotifyURLRequestDestroyed(this); |
247 if (job_.get()) | 206 if (job_.get()) |
248 job_->NotifyURLRequestDestroyed(); | 207 job_->NotifyURLRequestDestroyed(); |
249 } | 208 } |
250 | 209 |
251 if (job_.get()) | 210 if (job_.get()) |
252 OrphanJob(); | 211 OrphanJob(); |
253 | 212 |
254 int deleted = context_->url_requests()->erase(this); | 213 int deleted = context_->url_requests()->erase(this); |
255 CHECK_EQ(1, deleted); | 214 CHECK_EQ(1, deleted); |
256 | 215 |
257 int net_error = OK; | 216 int net_error = OK; |
258 // Log error only on failure, not cancellation, as even successful requests | 217 // Log error only on failure, not cancellation, as even successful requests |
259 // are "cancelled" on destruction. | 218 // are "cancelled" on destruction. |
260 if (status_.status() == URLRequestStatus::FAILED) | 219 if (status_.status() == URLRequestStatus::FAILED) |
261 net_error = status_.error(); | 220 net_error = status_.error(); |
262 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_REQUEST_ALIVE, net_error); | 221 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_REQUEST_ALIVE, net_error); |
263 } | 222 } |
264 | 223 |
265 // static | |
266 void URLRequest::RegisterRequestInterceptor(Interceptor* interceptor) { | |
267 URLRequestJobManager::GetInstance()->RegisterRequestInterceptor(interceptor); | |
268 } | |
269 | |
270 // static | |
271 void URLRequest::UnregisterRequestInterceptor(Interceptor* interceptor) { | |
272 URLRequestJobManager::GetInstance()->UnregisterRequestInterceptor( | |
273 interceptor); | |
274 } | |
275 | |
276 void URLRequest::EnableChunkedUpload() { | 224 void URLRequest::EnableChunkedUpload() { |
277 DCHECK(!upload_data_stream_ || upload_data_stream_->is_chunked()); | 225 DCHECK(!upload_data_stream_ || upload_data_stream_->is_chunked()); |
278 if (!upload_data_stream_) { | 226 if (!upload_data_stream_) { |
279 upload_data_stream_.reset( | 227 upload_data_stream_.reset( |
280 new UploadDataStream(UploadDataStream::CHUNKED, 0)); | 228 new UploadDataStream(UploadDataStream::CHUNKED, 0)); |
281 } | 229 } |
282 } | 230 } |
283 | 231 |
284 void URLRequest::AppendChunkToUpload(const char* bytes, | 232 void URLRequest::AppendChunkToUpload(const char* bytes, |
285 int bytes_len, | 233 int bytes_len, |
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
627 BeforeRequestComplete(error); | 575 BeforeRequestComplete(error); |
628 return; | 576 return; |
629 } | 577 } |
630 | 578 |
631 StartJob(URLRequestJobManager::GetInstance()->CreateJob( | 579 StartJob(URLRequestJobManager::GetInstance()->CreateJob( |
632 this, network_delegate_)); | 580 this, network_delegate_)); |
633 } | 581 } |
634 | 582 |
635 /////////////////////////////////////////////////////////////////////////////// | 583 /////////////////////////////////////////////////////////////////////////////// |
636 | 584 |
| 585 URLRequest::URLRequest(const GURL& url, |
| 586 RequestPriority priority, |
| 587 Delegate* delegate, |
| 588 const URLRequestContext* context, |
| 589 CookieStore* cookie_store, |
| 590 NetworkDelegate* network_delegate) |
| 591 : context_(context), |
| 592 network_delegate_(network_delegate ? network_delegate |
| 593 : context->network_delegate()), |
| 594 net_log_(BoundNetLog::Make(context->net_log(), |
| 595 NetLog::SOURCE_URL_REQUEST)), |
| 596 url_chain_(1, url), |
| 597 method_("GET"), |
| 598 referrer_policy_(CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE), |
| 599 first_party_url_policy_(NEVER_CHANGE_FIRST_PARTY_URL), |
| 600 load_flags_(LOAD_NORMAL), |
| 601 delegate_(delegate), |
| 602 is_pending_(false), |
| 603 is_redirecting_(false), |
| 604 redirect_limit_(kMaxRedirects), |
| 605 priority_(priority), |
| 606 identifier_(GenerateURLRequestIdentifier()), |
| 607 calling_delegate_(false), |
| 608 use_blocked_by_as_load_param_(false), |
| 609 before_request_callback_(base::Bind(&URLRequest::BeforeRequestComplete, |
| 610 base::Unretained(this))), |
| 611 has_notified_completion_(false), |
| 612 received_response_content_length_(0), |
| 613 creation_time_(base::TimeTicks::Now()), |
| 614 notified_before_network_start_(false), |
| 615 cookie_store_(cookie_store ? cookie_store : context->cookie_store()) { |
| 616 SIMPLE_STATS_COUNTER("URLRequestCount"); |
| 617 |
| 618 // Sanity check out environment. |
| 619 DCHECK(base::MessageLoop::current()) |
| 620 << "The current base::MessageLoop must exist"; |
| 621 |
| 622 context->url_requests()->insert(this); |
| 623 net_log_.BeginEvent(NetLog::TYPE_REQUEST_ALIVE); |
| 624 } |
| 625 |
| 626 // static |
| 627 void URLRequest::RegisterRequestInterceptor(Interceptor* interceptor) { |
| 628 URLRequestJobManager::GetInstance()->RegisterRequestInterceptor(interceptor); |
| 629 } |
| 630 |
| 631 // static |
| 632 void URLRequest::UnregisterRequestInterceptor(Interceptor* interceptor) { |
| 633 URLRequestJobManager::GetInstance()->UnregisterRequestInterceptor( |
| 634 interceptor); |
| 635 } |
| 636 |
637 void URLRequest::BeforeRequestComplete(int error) { | 637 void URLRequest::BeforeRequestComplete(int error) { |
638 DCHECK(!job_.get()); | 638 DCHECK(!job_.get()); |
639 DCHECK_NE(ERR_IO_PENDING, error); | 639 DCHECK_NE(ERR_IO_PENDING, error); |
640 | 640 |
641 // Check that there are no callbacks to already canceled requests. | 641 // Check that there are no callbacks to already canceled requests. |
642 DCHECK_NE(URLRequestStatus::CANCELED, status_.status()); | 642 DCHECK_NE(URLRequestStatus::CANCELED, status_.status()); |
643 | 643 |
644 OnCallToDelegateComplete(); | 644 OnCallToDelegateComplete(); |
645 | 645 |
646 if (error != OK) { | 646 if (error != OK) { |
(...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1220 new base::debug::StackTrace(NULL, 0); | 1220 new base::debug::StackTrace(NULL, 0); |
1221 *stack_trace_copy = stack_trace; | 1221 *stack_trace_copy = stack_trace; |
1222 stack_trace_.reset(stack_trace_copy); | 1222 stack_trace_.reset(stack_trace_copy); |
1223 } | 1223 } |
1224 | 1224 |
1225 const base::debug::StackTrace* URLRequest::stack_trace() const { | 1225 const base::debug::StackTrace* URLRequest::stack_trace() const { |
1226 return stack_trace_.get(); | 1226 return stack_trace_.get(); |
1227 } | 1227 } |
1228 | 1228 |
1229 } // namespace net | 1229 } // namespace net |
OLD | NEW |