| 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_context.h" | 5 #include "net/url_request/url_request_context.h" |
| 6 | 6 |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/debug/alias.h" | 8 #include "base/debug/alias.h" |
| 9 #include "base/debug/stack_trace.h" | 9 #include "base/debug/stack_trace.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| 11 #include "net/base/host_resolver.h" | 11 #include "net/base/host_resolver.h" |
| 12 #include "net/cookies/cookie_store.h" | 12 #include "net/cookies/cookie_store.h" |
| 13 #include "net/ftp/ftp_transaction_factory.h" | 13 #include "net/ftp/ftp_transaction_factory.h" |
| 14 #include "net/http/http_transaction_factory.h" | 14 #include "net/http/http_transaction_factory.h" |
| 15 #include "net/url_request/http_user_agent_settings.h" |
| 15 #include "net/url_request/url_request.h" | 16 #include "net/url_request/url_request.h" |
| 16 | 17 |
| 17 namespace net { | 18 namespace net { |
| 18 | 19 |
| 19 URLRequestContext::URLRequestContext() | 20 URLRequestContext::URLRequestContext() |
| 20 : net_log_(NULL), | 21 : net_log_(NULL), |
| 21 host_resolver_(NULL), | 22 host_resolver_(NULL), |
| 22 cert_verifier_(NULL), | 23 cert_verifier_(NULL), |
| 23 server_bound_cert_service_(NULL), | 24 server_bound_cert_service_(NULL), |
| 24 fraudulent_certificate_reporter_(NULL), | 25 fraudulent_certificate_reporter_(NULL), |
| 25 http_auth_handler_factory_(NULL), | 26 http_auth_handler_factory_(NULL), |
| 26 proxy_service_(NULL), | 27 proxy_service_(NULL), |
| 27 network_delegate_(NULL), | 28 network_delegate_(NULL), |
| 28 http_server_properties_(NULL), | 29 http_server_properties_(NULL), |
| 30 http_user_agent_settings_(NULL), |
| 29 transport_security_state_(NULL), | 31 transport_security_state_(NULL), |
| 30 #if !defined(DISABLE_FTP_SUPPORT) | 32 #if !defined(DISABLE_FTP_SUPPORT) |
| 31 ftp_auth_cache_(new FtpAuthCache), | 33 ftp_auth_cache_(new FtpAuthCache), |
| 32 #endif | 34 #endif |
| 33 http_transaction_factory_(NULL), | 35 http_transaction_factory_(NULL), |
| 34 ftp_transaction_factory_(NULL), | 36 ftp_transaction_factory_(NULL), |
| 35 job_factory_(NULL), | 37 job_factory_(NULL), |
| 36 throttler_manager_(NULL), | 38 throttler_manager_(NULL), |
| 37 url_requests_(new std::set<const URLRequest*>) { | 39 url_requests_(new std::set<const URLRequest*>) { |
| 38 } | 40 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 49 set_server_bound_cert_service(other->server_bound_cert_service_); | 51 set_server_bound_cert_service(other->server_bound_cert_service_); |
| 50 set_fraudulent_certificate_reporter(other->fraudulent_certificate_reporter_); | 52 set_fraudulent_certificate_reporter(other->fraudulent_certificate_reporter_); |
| 51 set_http_auth_handler_factory(other->http_auth_handler_factory_); | 53 set_http_auth_handler_factory(other->http_auth_handler_factory_); |
| 52 set_proxy_service(other->proxy_service_); | 54 set_proxy_service(other->proxy_service_); |
| 53 set_ssl_config_service(other->ssl_config_service_); | 55 set_ssl_config_service(other->ssl_config_service_); |
| 54 set_network_delegate(other->network_delegate_); | 56 set_network_delegate(other->network_delegate_); |
| 55 set_http_server_properties(other->http_server_properties_); | 57 set_http_server_properties(other->http_server_properties_); |
| 56 set_cookie_store(other->cookie_store_); | 58 set_cookie_store(other->cookie_store_); |
| 57 set_transport_security_state(other->transport_security_state_); | 59 set_transport_security_state(other->transport_security_state_); |
| 58 // FTPAuthCache is unique per context. | 60 // FTPAuthCache is unique per context. |
| 59 set_accept_language(other->accept_language_); | |
| 60 set_accept_charset(other->accept_charset_); | |
| 61 set_http_transaction_factory(other->http_transaction_factory_); | 61 set_http_transaction_factory(other->http_transaction_factory_); |
| 62 set_ftp_transaction_factory(other->ftp_transaction_factory_); | 62 set_ftp_transaction_factory(other->ftp_transaction_factory_); |
| 63 set_job_factory(other->job_factory_); | 63 set_job_factory(other->job_factory_); |
| 64 set_throttler_manager(other->throttler_manager_); | 64 set_throttler_manager(other->throttler_manager_); |
| 65 set_http_user_agent_settings(other->http_user_agent_settings_); |
| 65 } | 66 } |
| 66 | 67 |
| 67 const HttpNetworkSession::Params* URLRequestContext::GetNetworkSessionParams( | 68 const HttpNetworkSession::Params* URLRequestContext::GetNetworkSessionParams( |
| 68 ) const { | 69 ) const { |
| 69 HttpTransactionFactory* transaction_factory = http_transaction_factory(); | 70 HttpTransactionFactory* transaction_factory = http_transaction_factory(); |
| 70 if (!transaction_factory) | 71 if (!transaction_factory) |
| 71 return NULL; | 72 return NULL; |
| 72 HttpNetworkSession* network_session = transaction_factory->GetSession(); | 73 HttpNetworkSession* network_session = transaction_factory->GetSession(); |
| 73 if (!network_session) | 74 if (!network_session) |
| 74 return NULL; | 75 return NULL; |
| 75 return &network_session->params(); | 76 return &network_session->params(); |
| 76 } | 77 } |
| 77 | 78 |
| 78 URLRequest* URLRequestContext::CreateRequest( | 79 URLRequest* URLRequestContext::CreateRequest( |
| 79 const GURL& url, URLRequest::Delegate* delegate) const { | 80 const GURL& url, URLRequest::Delegate* delegate) const { |
| 80 return new URLRequest(url, delegate, this, network_delegate_); | 81 return new URLRequest(url, delegate, this, network_delegate_); |
| 81 } | 82 } |
| 82 | 83 |
| 83 void URLRequestContext::set_cookie_store(CookieStore* cookie_store) { | 84 void URLRequestContext::set_cookie_store(CookieStore* cookie_store) { |
| 84 cookie_store_ = cookie_store; | 85 cookie_store_ = cookie_store; |
| 85 } | 86 } |
| 86 | 87 |
| 87 const std::string& URLRequestContext::GetUserAgent(const GURL& url) const { | 88 std::string URLRequestContext::GetAcceptCharset() const { |
| 88 return EmptyString(); | 89 return http_user_agent_settings_ ? |
| 90 http_user_agent_settings_->GetAcceptCharset() : EmptyString(); |
| 91 } |
| 92 |
| 93 std::string URLRequestContext::GetAcceptLanguage() const { |
| 94 return http_user_agent_settings_ ? |
| 95 http_user_agent_settings_->GetAcceptLanguage() : EmptyString(); |
| 96 } |
| 97 |
| 98 std::string URLRequestContext::GetUserAgent(const GURL& url) const { |
| 99 return http_user_agent_settings_ ? |
| 100 http_user_agent_settings_->GetUserAgent(url) : EmptyString(); |
| 89 } | 101 } |
| 90 | 102 |
| 91 void URLRequestContext::AssertNoURLRequests() const { | 103 void URLRequestContext::AssertNoURLRequests() const { |
| 92 int num_requests = url_requests_->size(); | 104 int num_requests = url_requests_->size(); |
| 93 if (num_requests != 0) { | 105 if (num_requests != 0) { |
| 94 // We're leaking URLRequests :( Dump the URL of the first one and record how | 106 // We're leaking URLRequests :( Dump the URL of the first one and record how |
| 95 // many we leaked so we have an idea of how bad it is. | 107 // many we leaked so we have an idea of how bad it is. |
| 96 char url_buf[128]; | 108 char url_buf[128]; |
| 97 const URLRequest* request = *url_requests_->begin(); | 109 const URLRequest* request = *url_requests_->begin(); |
| 98 base::strlcpy(url_buf, request->url().spec().c_str(), arraysize(url_buf)); | 110 base::strlcpy(url_buf, request->url().spec().c_str(), arraysize(url_buf)); |
| 99 bool has_delegate = request->has_delegate(); | 111 bool has_delegate = request->has_delegate(); |
| 100 int load_flags = request->load_flags(); | 112 int load_flags = request->load_flags(); |
| 101 base::debug::StackTrace stack_trace(NULL, 0); | 113 base::debug::StackTrace stack_trace(NULL, 0); |
| 102 if (request->stack_trace()) | 114 if (request->stack_trace()) |
| 103 stack_trace = *request->stack_trace(); | 115 stack_trace = *request->stack_trace(); |
| 104 base::debug::Alias(url_buf); | 116 base::debug::Alias(url_buf); |
| 105 base::debug::Alias(&num_requests); | 117 base::debug::Alias(&num_requests); |
| 106 base::debug::Alias(&has_delegate); | 118 base::debug::Alias(&has_delegate); |
| 107 base::debug::Alias(&load_flags); | 119 base::debug::Alias(&load_flags); |
| 108 base::debug::Alias(&stack_trace); | 120 base::debug::Alias(&stack_trace); |
| 109 CHECK(false) << "Leaked " << num_requests << " URLRequest(s). First URL: " | 121 CHECK(false) << "Leaked " << num_requests << " URLRequest(s). First URL: " |
| 110 << request->url().spec().c_str() << "."; | 122 << request->url().spec().c_str() << "."; |
| 111 } | 123 } |
| 112 } | 124 } |
| 113 | 125 |
| 114 } // namespace net | 126 } // namespace net |
| OLD | NEW |