| 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 // This lock protects g_next_url_request_identifier. | 58 // This lock protects g_next_url_request_identifier. |
| 59 base::LazyInstance<base::Lock>::Leaky | 59 base::LazyInstance<base::Lock>::Leaky |
| 60 g_next_url_request_identifier_lock = LAZY_INSTANCE_INITIALIZER; | 60 g_next_url_request_identifier_lock = LAZY_INSTANCE_INITIALIZER; |
| 61 | 61 |
| 62 // Returns an prior unused identifier for URL requests. | 62 // Returns an prior unused identifier for URL requests. |
| 63 uint64 GenerateURLRequestIdentifier() { | 63 uint64 GenerateURLRequestIdentifier() { |
| 64 base::AutoLock lock(g_next_url_request_identifier_lock.Get()); | 64 base::AutoLock lock(g_next_url_request_identifier_lock.Get()); |
| 65 return g_next_url_request_identifier++; | 65 return g_next_url_request_identifier++; |
| 66 } | 66 } |
| 67 | 67 |
| 68 // True once the first URLRequest was started. |
| 69 bool g_url_requests_started = false; |
| 70 |
| 71 // True if cookies are accepted by default. |
| 72 bool g_default_can_use_cookies = true; |
| 73 |
| 68 } // namespace | 74 } // namespace |
| 69 | 75 |
| 70 URLRequest::ProtocolFactory* | 76 URLRequest::ProtocolFactory* |
| 71 URLRequest::Deprecated::RegisterProtocolFactory(const std::string& scheme, | 77 URLRequest::Deprecated::RegisterProtocolFactory(const std::string& scheme, |
| 72 ProtocolFactory* factory) { | 78 ProtocolFactory* factory) { |
| 73 return URLRequest::RegisterProtocolFactory(scheme, factory); | 79 return URLRequest::RegisterProtocolFactory(scheme, factory); |
| 74 } | 80 } |
| 75 | 81 |
| 76 void URLRequest::Deprecated::RegisterRequestInterceptor( | 82 void URLRequest::Deprecated::RegisterRequestInterceptor( |
| 77 Interceptor* interceptor) { | 83 Interceptor* interceptor) { |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 DCHECK(job_); | 321 DCHECK(job_); |
| 316 job_->GetCharset(charset); | 322 job_->GetCharset(charset); |
| 317 } | 323 } |
| 318 | 324 |
| 319 int URLRequest::GetResponseCode() { | 325 int URLRequest::GetResponseCode() { |
| 320 DCHECK(job_); | 326 DCHECK(job_); |
| 321 return job_->GetResponseCode(); | 327 return job_->GetResponseCode(); |
| 322 } | 328 } |
| 323 | 329 |
| 324 // static | 330 // static |
| 331 void URLRequest::SetDefaultCookiePolicyToBlock() { |
| 332 CHECK(!g_url_requests_started); |
| 333 g_default_can_use_cookies = false; |
| 334 } |
| 335 |
| 336 // static |
| 325 bool URLRequest::IsHandledProtocol(const std::string& scheme) { | 337 bool URLRequest::IsHandledProtocol(const std::string& scheme) { |
| 326 return URLRequestJobManager::GetInstance()->SupportsScheme(scheme); | 338 return URLRequestJobManager::GetInstance()->SupportsScheme(scheme); |
| 327 } | 339 } |
| 328 | 340 |
| 329 // static | 341 // static |
| 330 bool URLRequest::IsHandledURL(const GURL& url) { | 342 bool URLRequest::IsHandledURL(const GURL& url) { |
| 331 if (!url.is_valid()) { | 343 if (!url.is_valid()) { |
| 332 // We handle error cases. | 344 // We handle error cases. |
| 333 return true; | 345 return true; |
| 334 } | 346 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 } | 385 } |
| 374 | 386 |
| 375 return ret; | 387 return ret; |
| 376 } | 388 } |
| 377 | 389 |
| 378 void URLRequest::set_delegate(Delegate* delegate) { | 390 void URLRequest::set_delegate(Delegate* delegate) { |
| 379 delegate_ = delegate; | 391 delegate_ = delegate; |
| 380 } | 392 } |
| 381 | 393 |
| 382 void URLRequest::Start() { | 394 void URLRequest::Start() { |
| 395 g_url_requests_started = true; |
| 383 response_info_.request_time = Time::Now(); | 396 response_info_.request_time = Time::Now(); |
| 384 | 397 |
| 385 // Only notify the delegate for the initial request. | 398 // Only notify the delegate for the initial request. |
| 386 if (context_ && context_->network_delegate()) { | 399 if (context_ && context_->network_delegate()) { |
| 387 int error = context_->network_delegate()->NotifyBeforeURLRequest( | 400 int error = context_->network_delegate()->NotifyBeforeURLRequest( |
| 388 this, before_request_callback_, &delegate_redirect_url_); | 401 this, before_request_callback_, &delegate_redirect_url_); |
| 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(); |
| 392 } else { | 405 } else { |
| (...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 824 if (delegate_) | 837 if (delegate_) |
| 825 delegate_->OnSSLCertificateError(this, ssl_info, fatal); | 838 delegate_->OnSSLCertificateError(this, ssl_info, fatal); |
| 826 } | 839 } |
| 827 | 840 |
| 828 bool URLRequest::CanGetCookies(const CookieList& cookie_list) const { | 841 bool URLRequest::CanGetCookies(const CookieList& cookie_list) const { |
| 829 DCHECK(!(load_flags_ & LOAD_DO_NOT_SEND_COOKIES)); | 842 DCHECK(!(load_flags_ & LOAD_DO_NOT_SEND_COOKIES)); |
| 830 if (context_ && context_->network_delegate()) { | 843 if (context_ && context_->network_delegate()) { |
| 831 return context_->network_delegate()->NotifyReadingCookies(this, | 844 return context_->network_delegate()->NotifyReadingCookies(this, |
| 832 cookie_list); | 845 cookie_list); |
| 833 } | 846 } |
| 834 return false; | 847 return g_default_can_use_cookies; |
| 835 } | 848 } |
| 836 | 849 |
| 837 bool URLRequest::CanSetCookie(const std::string& cookie_line, | 850 bool URLRequest::CanSetCookie(const std::string& cookie_line, |
| 838 CookieOptions* options) const { | 851 CookieOptions* options) const { |
| 839 DCHECK(!(load_flags_ & LOAD_DO_NOT_SAVE_COOKIES)); | 852 DCHECK(!(load_flags_ & LOAD_DO_NOT_SAVE_COOKIES)); |
| 840 if (context_ && context_->network_delegate()) { | 853 if (context_ && context_->network_delegate()) { |
| 841 return context_->network_delegate()->NotifySettingCookie(this, | 854 return context_->network_delegate()->NotifySettingCookie(this, |
| 842 cookie_line, | 855 cookie_line, |
| 843 options); | 856 options); |
| 844 } | 857 } |
| 845 return false; | 858 return g_default_can_use_cookies; |
| 846 } | 859 } |
| 847 | 860 |
| 848 | 861 |
| 849 void URLRequest::NotifyReadCompleted(int bytes_read) { | 862 void URLRequest::NotifyReadCompleted(int bytes_read) { |
| 850 // Notify in case the entire URL Request has been finished. | 863 // Notify in case the entire URL Request has been finished. |
| 851 if (bytes_read <= 0) | 864 if (bytes_read <= 0) |
| 852 NotifyRequestCompleted(); | 865 NotifyRequestCompleted(); |
| 853 | 866 |
| 854 if (delegate_) | 867 if (delegate_) |
| 855 delegate_->OnReadCompleted(this, bytes_read); | 868 delegate_->OnReadCompleted(this, bytes_read); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 876 | 889 |
| 877 void URLRequest::SetUnblockedOnDelegate() { | 890 void URLRequest::SetUnblockedOnDelegate() { |
| 878 if (!blocked_on_delegate_) | 891 if (!blocked_on_delegate_) |
| 879 return; | 892 return; |
| 880 blocked_on_delegate_ = false; | 893 blocked_on_delegate_ = false; |
| 881 load_state_param_.clear(); | 894 load_state_param_.clear(); |
| 882 net_log_.EndEvent(NetLog::TYPE_URL_REQUEST_BLOCKED_ON_DELEGATE, NULL); | 895 net_log_.EndEvent(NetLog::TYPE_URL_REQUEST_BLOCKED_ON_DELEGATE, NULL); |
| 883 } | 896 } |
| 884 | 897 |
| 885 } // namespace net | 898 } // namespace net |
| OLD | NEW |