Chromium Code Reviews| 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 57 // This lock protects g_next_url_request_identifier. | 57 // This lock protects g_next_url_request_identifier. |
| 58 base::LazyInstance<base::Lock>::Leaky | 58 base::LazyInstance<base::Lock>::Leaky |
| 59 g_next_url_request_identifier_lock = LAZY_INSTANCE_INITIALIZER; | 59 g_next_url_request_identifier_lock = LAZY_INSTANCE_INITIALIZER; |
| 60 | 60 |
| 61 // Returns an prior unused identifier for URL requests. | 61 // Returns an prior unused identifier for URL requests. |
| 62 uint64 GenerateURLRequestIdentifier() { | 62 uint64 GenerateURLRequestIdentifier() { |
| 63 base::AutoLock lock(g_next_url_request_identifier_lock.Get()); | 63 base::AutoLock lock(g_next_url_request_identifier_lock.Get()); |
| 64 return g_next_url_request_identifier++; | 64 return g_next_url_request_identifier++; |
| 65 } | 65 } |
| 66 | 66 |
| 67 // True once the first URLRequest was started. | |
| 68 bool g_url_requests_started = false; | |
| 69 | |
| 70 // True if cookies are accepted by default. | |
| 71 bool g_default_cookie_policy = true; | |
|
wtc
2012/03/28 17:51:05
This variable name does not sound like a boolean.
jochen (gone - plz use gerrit)
2012/03/29 18:33:24
Done.
| |
| 72 | |
| 67 } // namespace | 73 } // namespace |
| 68 | 74 |
| 69 URLRequest::ProtocolFactory* | 75 URLRequest::ProtocolFactory* |
| 70 URLRequest::Deprecated::RegisterProtocolFactory(const std::string& scheme, | 76 URLRequest::Deprecated::RegisterProtocolFactory(const std::string& scheme, |
| 71 ProtocolFactory* factory) { | 77 ProtocolFactory* factory) { |
| 72 return URLRequest::RegisterProtocolFactory(scheme, factory); | 78 return URLRequest::RegisterProtocolFactory(scheme, factory); |
| 73 } | 79 } |
| 74 | 80 |
| 75 void URLRequest::Deprecated::RegisterRequestInterceptor( | 81 void URLRequest::Deprecated::RegisterRequestInterceptor( |
| 76 Interceptor* interceptor) { | 82 Interceptor* interceptor) { |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 314 DCHECK(job_); | 320 DCHECK(job_); |
| 315 job_->GetCharset(charset); | 321 job_->GetCharset(charset); |
| 316 } | 322 } |
| 317 | 323 |
| 318 int URLRequest::GetResponseCode() { | 324 int URLRequest::GetResponseCode() { |
| 319 DCHECK(job_); | 325 DCHECK(job_); |
| 320 return job_->GetResponseCode(); | 326 return job_->GetResponseCode(); |
| 321 } | 327 } |
| 322 | 328 |
| 323 // static | 329 // static |
| 330 void URLRequest::SetDefaultCookiePolicyToBlock() { | |
| 331 CHECK(!g_url_requests_started); | |
| 332 g_default_cookie_policy = false; | |
| 333 } | |
| 334 | |
| 335 // static | |
| 324 bool URLRequest::IsHandledProtocol(const std::string& scheme) { | 336 bool URLRequest::IsHandledProtocol(const std::string& scheme) { |
| 325 return URLRequestJobManager::GetInstance()->SupportsScheme(scheme); | 337 return URLRequestJobManager::GetInstance()->SupportsScheme(scheme); |
| 326 } | 338 } |
| 327 | 339 |
| 328 // static | 340 // static |
| 329 bool URLRequest::IsHandledURL(const GURL& url) { | 341 bool URLRequest::IsHandledURL(const GURL& url) { |
| 330 if (!url.is_valid()) { | 342 if (!url.is_valid()) { |
| 331 // We handle error cases. | 343 // We handle error cases. |
| 332 return true; | 344 return true; |
| 333 } | 345 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 372 } | 384 } |
| 373 | 385 |
| 374 return ret; | 386 return ret; |
| 375 } | 387 } |
| 376 | 388 |
| 377 void URLRequest::set_delegate(Delegate* delegate) { | 389 void URLRequest::set_delegate(Delegate* delegate) { |
| 378 delegate_ = delegate; | 390 delegate_ = delegate; |
| 379 } | 391 } |
| 380 | 392 |
| 381 void URLRequest::Start() { | 393 void URLRequest::Start() { |
| 394 g_url_requests_started = true; | |
| 382 response_info_.request_time = Time::Now(); | 395 response_info_.request_time = Time::Now(); |
| 383 | 396 |
| 384 // Only notify the delegate for the initial request. | 397 // Only notify the delegate for the initial request. |
| 385 if (context_ && context_->network_delegate()) { | 398 if (context_ && context_->network_delegate()) { |
| 386 int error = context_->network_delegate()->NotifyBeforeURLRequest( | 399 int error = context_->network_delegate()->NotifyBeforeURLRequest( |
| 387 this, before_request_callback_, &delegate_redirect_url_); | 400 this, before_request_callback_, &delegate_redirect_url_); |
| 388 if (error != net::OK) { | 401 if (error != net::OK) { |
| 389 if (error == net::ERR_IO_PENDING) { | 402 if (error == net::ERR_IO_PENDING) { |
| 390 // Paused on the delegate, will invoke |before_request_callback_| later. | 403 // Paused on the delegate, will invoke |before_request_callback_| later. |
| 391 SetBlockedOnDelegate(); | 404 SetBlockedOnDelegate(); |
| (...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 812 if (delegate_) | 825 if (delegate_) |
| 813 delegate_->OnSSLCertificateError(this, ssl_info, fatal); | 826 delegate_->OnSSLCertificateError(this, ssl_info, fatal); |
| 814 } | 827 } |
| 815 | 828 |
| 816 bool URLRequest::CanGetCookies(const CookieList& cookie_list) const { | 829 bool URLRequest::CanGetCookies(const CookieList& cookie_list) const { |
| 817 DCHECK(!(load_flags_ & LOAD_DO_NOT_SEND_COOKIES)); | 830 DCHECK(!(load_flags_ & LOAD_DO_NOT_SEND_COOKIES)); |
| 818 if (context_ && context_->network_delegate()) { | 831 if (context_ && context_->network_delegate()) { |
| 819 return context_->network_delegate()->NotifyReadingCookies(this, | 832 return context_->network_delegate()->NotifyReadingCookies(this, |
| 820 cookie_list); | 833 cookie_list); |
| 821 } | 834 } |
| 822 return false; | 835 return g_default_cookie_policy; |
|
wtc
2012/03/28 17:51:05
IMPORTANT: this means the original code is more st
| |
| 823 } | 836 } |
| 824 | 837 |
| 825 bool URLRequest::CanSetCookie(const std::string& cookie_line, | 838 bool URLRequest::CanSetCookie(const std::string& cookie_line, |
| 826 CookieOptions* options) const { | 839 CookieOptions* options) const { |
| 827 DCHECK(!(load_flags_ & LOAD_DO_NOT_SAVE_COOKIES)); | 840 DCHECK(!(load_flags_ & LOAD_DO_NOT_SAVE_COOKIES)); |
| 828 if (context_ && context_->network_delegate()) { | 841 if (context_ && context_->network_delegate()) { |
| 829 return context_->network_delegate()->NotifySettingCookie(this, | 842 return context_->network_delegate()->NotifySettingCookie(this, |
| 830 cookie_line, | 843 cookie_line, |
| 831 options); | 844 options); |
| 832 } | 845 } |
| 833 return false; | 846 return g_default_cookie_policy; |
| 834 } | 847 } |
| 835 | 848 |
| 836 | 849 |
| 837 void URLRequest::NotifyReadCompleted(int bytes_read) { | 850 void URLRequest::NotifyReadCompleted(int bytes_read) { |
| 838 // Notify in case the entire URL Request has been finished. | 851 // Notify in case the entire URL Request has been finished. |
| 839 if (bytes_read <= 0) | 852 if (bytes_read <= 0) |
| 840 NotifyRequestCompleted(); | 853 NotifyRequestCompleted(); |
| 841 | 854 |
| 842 if (delegate_) | 855 if (delegate_) |
| 843 delegate_->OnReadCompleted(this, bytes_read); | 856 delegate_->OnReadCompleted(this, bytes_read); |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 864 | 877 |
| 865 void URLRequest::SetUnblockedOnDelegate() { | 878 void URLRequest::SetUnblockedOnDelegate() { |
| 866 if (!blocked_on_delegate_) | 879 if (!blocked_on_delegate_) |
| 867 return; | 880 return; |
| 868 blocked_on_delegate_ = false; | 881 blocked_on_delegate_ = false; |
| 869 load_state_param_.clear(); | 882 load_state_param_.clear(); |
| 870 net_log_.EndEvent(NetLog::TYPE_URL_REQUEST_BLOCKED_ON_DELEGATE, NULL); | 883 net_log_.EndEvent(NetLog::TYPE_URL_REQUEST_BLOCKED_ON_DELEGATE, NULL); |
| 871 } | 884 } |
| 872 | 885 |
| 873 } // namespace net | 886 } // namespace net |
| OLD | NEW |