| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/callback.h" | 9 #include "base/callback.h" |
| 9 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 10 #include "base/lazy_instance.h" | 11 #include "base/lazy_instance.h" |
| 11 #include "base/memory/singleton.h" | 12 #include "base/memory/singleton.h" |
| 12 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
| 13 #include "base/metrics/stats_counters.h" | 14 #include "base/metrics/stats_counters.h" |
| 14 #include "base/synchronization/lock.h" | 15 #include "base/synchronization/lock.h" |
| 15 #include "net/base/auth.h" | 16 #include "net/base/auth.h" |
| 16 #include "net/base/host_port_pair.h" | 17 #include "net/base/host_port_pair.h" |
| 17 #include "net/base/load_flags.h" | 18 #include "net/base/load_flags.h" |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 : url_chain_(1, url), | 142 : url_chain_(1, url), |
| 142 method_("GET"), | 143 method_("GET"), |
| 143 load_flags_(LOAD_NORMAL), | 144 load_flags_(LOAD_NORMAL), |
| 144 delegate_(delegate), | 145 delegate_(delegate), |
| 145 is_pending_(false), | 146 is_pending_(false), |
| 146 redirect_limit_(kMaxRedirects), | 147 redirect_limit_(kMaxRedirects), |
| 147 final_upload_progress_(0), | 148 final_upload_progress_(0), |
| 148 priority_(LOWEST), | 149 priority_(LOWEST), |
| 149 identifier_(GenerateURLRequestIdentifier()), | 150 identifier_(GenerateURLRequestIdentifier()), |
| 150 blocked_on_delegate_(false), | 151 blocked_on_delegate_(false), |
| 151 ALLOW_THIS_IN_INITIALIZER_LIST( | 152 ALLOW_THIS_IN_INITIALIZER_LIST(before_request_callback_( |
| 152 before_request_callback_(this, &URLRequest::BeforeRequestComplete)), | 153 base::Bind(&URLRequest::BeforeRequestComplete, |
| 154 base::Unretained(this)))), |
| 153 has_notified_completion_(false) { | 155 has_notified_completion_(false) { |
| 154 SIMPLE_STATS_COUNTER("URLRequestCount"); | 156 SIMPLE_STATS_COUNTER("URLRequestCount"); |
| 155 | 157 |
| 156 // Sanity check out environment. | 158 // Sanity check out environment. |
| 157 DCHECK(MessageLoop::current()) << | 159 DCHECK(MessageLoop::current()) << |
| 158 "The current MessageLoop must exist"; | 160 "The current MessageLoop must exist"; |
| 159 DCHECK_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()) << | 161 DCHECK_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()) << |
| 160 "The current MessageLoop must be TYPE_IO"; | 162 "The current MessageLoop must be TYPE_IO"; |
| 161 } | 163 } |
| 162 | 164 |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 410 void URLRequest::set_delegate(Delegate* delegate) { | 412 void URLRequest::set_delegate(Delegate* delegate) { |
| 411 delegate_ = delegate; | 413 delegate_ = delegate; |
| 412 } | 414 } |
| 413 | 415 |
| 414 void URLRequest::Start() { | 416 void URLRequest::Start() { |
| 415 response_info_.request_time = Time::Now(); | 417 response_info_.request_time = Time::Now(); |
| 416 | 418 |
| 417 // Only notify the delegate for the initial request. | 419 // Only notify the delegate for the initial request. |
| 418 if (context_ && context_->network_delegate()) { | 420 if (context_ && context_->network_delegate()) { |
| 419 int error = context_->network_delegate()->NotifyBeforeURLRequest( | 421 int error = context_->network_delegate()->NotifyBeforeURLRequest( |
| 420 this, &before_request_callback_, &delegate_redirect_url_); | 422 this, before_request_callback_, &delegate_redirect_url_); |
| 421 if (error != net::OK) { | 423 if (error != net::OK) { |
| 422 if (error == net::ERR_IO_PENDING) { | 424 if (error == net::ERR_IO_PENDING) { |
| 423 // Paused on the delegate, will invoke |before_request_callback_| later. | 425 // Paused on the delegate, will invoke |before_request_callback_| later. |
| 424 SetBlockedOnDelegate(); | 426 SetBlockedOnDelegate(); |
| 425 } else { | 427 } else { |
| 426 // The delegate immediately returned some error code. | 428 // The delegate immediately returned some error code. |
| 427 BeforeRequestComplete(error); | 429 BeforeRequestComplete(error); |
| 428 } | 430 } |
| 429 return; | 431 return; |
| 430 } | 432 } |
| (...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 892 | 894 |
| 893 void URLRequest::SetUnblockedOnDelegate() { | 895 void URLRequest::SetUnblockedOnDelegate() { |
| 894 if (!blocked_on_delegate_) | 896 if (!blocked_on_delegate_) |
| 895 return; | 897 return; |
| 896 blocked_on_delegate_ = false; | 898 blocked_on_delegate_ = false; |
| 897 load_state_param_.clear(); | 899 load_state_param_.clear(); |
| 898 net_log_.EndEvent(NetLog::TYPE_URL_REQUEST_BLOCKED_ON_DELEGATE, NULL); | 900 net_log_.EndEvent(NetLog::TYPE_URL_REQUEST_BLOCKED_ON_DELEGATE, NULL); |
| 899 } | 901 } |
| 900 | 902 |
| 901 } // namespace net | 903 } // namespace net |
| OLD | NEW |