Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(798)

Side by Side Diff: net/url_request/url_request_context.cc

Issue 10918279: Provide mutable members of UrlRequestContext via pure-virtual interface (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/url_request.h" 15 #include "net/url_request/url_request.h"
16 16
17 namespace net { 17 namespace net {
18 18
19 ConstHttpAcceptLanguageAndCharset::ConstHttpAcceptLanguageAndCharset(
erikwright (departed) 2012/09/21 15:06:33 move.
20 const std::string& accept_language, const std::string& accept_charset) :
21 accept_language_(accept_language),
22 accept_charset_(accept_charset) {}
erikwright (departed) 2012/09/21 15:06:33 Feel free to check prior-art and tell me what is p
23
24 const std::string& ConstHttpAcceptLanguageAndCharset::GetAcceptLanguage() {
25 return accept_language_;
26 }
27
28 const std::string& ConstHttpAcceptLanguageAndCharset::GetAcceptCharset() {
29 return accept_charset_;
30 }
31
32 ConstHttpUserAgentSettings::ConstHttpUserAgentSettings(
33 const std::string& accept_language, const std::string& accept_charset,
34 const std::string& user_agent) :
35 ConstHttpAcceptLanguageAndCharset(accept_language, accept_charset),
36 user_agent_(user_agent) {}
37
38 const std::string& ConstHttpUserAgentSettings::GetUserAgent(const GURL& url) {
39 return user_agent_;
40 }
41
19 URLRequestContext::URLRequestContext() 42 URLRequestContext::URLRequestContext()
20 : net_log_(NULL), 43 : net_log_(NULL),
21 host_resolver_(NULL), 44 host_resolver_(NULL),
22 cert_verifier_(NULL), 45 cert_verifier_(NULL),
23 server_bound_cert_service_(NULL), 46 server_bound_cert_service_(NULL),
24 fraudulent_certificate_reporter_(NULL), 47 fraudulent_certificate_reporter_(NULL),
25 http_auth_handler_factory_(NULL), 48 http_auth_handler_factory_(NULL),
26 proxy_service_(NULL), 49 proxy_service_(NULL),
27 network_delegate_(NULL), 50 network_delegate_(NULL),
28 http_server_properties_(NULL), 51 http_server_properties_(NULL),
29 transport_security_state_(NULL), 52 transport_security_state_(NULL),
30 #if !defined(DISABLE_FTP_SUPPORT) 53 #if !defined(DISABLE_FTP_SUPPORT)
31 ftp_auth_cache_(new FtpAuthCache), 54 ftp_auth_cache_(new FtpAuthCache),
32 #endif 55 #endif
33 http_transaction_factory_(NULL), 56 http_transaction_factory_(NULL),
34 ftp_transaction_factory_(NULL), 57 ftp_transaction_factory_(NULL),
35 job_factory_(NULL), 58 job_factory_(NULL),
36 throttler_manager_(NULL), 59 throttler_manager_(NULL),
60 http_user_agent_settings_(NULL),
37 url_requests_(new std::set<const URLRequest*>) { 61 url_requests_(new std::set<const URLRequest*>) {
38 } 62 }
39 63
40 URLRequestContext::~URLRequestContext() { 64 URLRequestContext::~URLRequestContext() {
41 AssertNoURLRequests(); 65 AssertNoURLRequests();
42 } 66 }
43 67
44 void URLRequestContext::CopyFrom(const URLRequestContext* other) { 68 void URLRequestContext::CopyFrom(const URLRequestContext* other) {
45 // Copy URLRequestContext parameters. 69 // Copy URLRequestContext parameters.
46 set_net_log(other->net_log_); 70 set_net_log(other->net_log_);
47 set_host_resolver(other->host_resolver_); 71 set_host_resolver(other->host_resolver_);
48 set_cert_verifier(other->cert_verifier_); 72 set_cert_verifier(other->cert_verifier_);
49 set_server_bound_cert_service(other->server_bound_cert_service_); 73 set_server_bound_cert_service(other->server_bound_cert_service_);
50 set_fraudulent_certificate_reporter(other->fraudulent_certificate_reporter_); 74 set_fraudulent_certificate_reporter(other->fraudulent_certificate_reporter_);
51 set_http_auth_handler_factory(other->http_auth_handler_factory_); 75 set_http_auth_handler_factory(other->http_auth_handler_factory_);
52 set_proxy_service(other->proxy_service_); 76 set_proxy_service(other->proxy_service_);
53 set_ssl_config_service(other->ssl_config_service_); 77 set_ssl_config_service(other->ssl_config_service_);
54 set_network_delegate(other->network_delegate_); 78 set_network_delegate(other->network_delegate_);
55 set_http_server_properties(other->http_server_properties_); 79 set_http_server_properties(other->http_server_properties_);
56 set_cookie_store(other->cookie_store_); 80 set_cookie_store(other->cookie_store_);
57 set_transport_security_state(other->transport_security_state_); 81 set_transport_security_state(other->transport_security_state_);
58 // FTPAuthCache is unique per context. 82 // FTPAuthCache is unique per context.
59 set_accept_language(other->accept_language_); 83 set_http_user_agent_settings(other->http_user_agent_settings_);
60 set_accept_charset(other->accept_charset_);
61 set_referrer_charset(other->referrer_charset_); 84 set_referrer_charset(other->referrer_charset_);
62 set_http_transaction_factory(other->http_transaction_factory_); 85 set_http_transaction_factory(other->http_transaction_factory_);
63 set_ftp_transaction_factory(other->ftp_transaction_factory_); 86 set_ftp_transaction_factory(other->ftp_transaction_factory_);
64 set_job_factory(other->job_factory_); 87 set_job_factory(other->job_factory_);
65 set_throttler_manager(other->throttler_manager_); 88 set_throttler_manager(other->throttler_manager_);
66 } 89 }
67 90
68 const HttpNetworkSession::Params* URLRequestContext::GetNetworkSessionParams( 91 const HttpNetworkSession::Params* URLRequestContext::GetNetworkSessionParams(
69 ) const { 92 ) const {
70 HttpTransactionFactory* transaction_factory = http_transaction_factory(); 93 HttpTransactionFactory* transaction_factory = http_transaction_factory();
71 if (!transaction_factory) 94 if (!transaction_factory)
72 return NULL; 95 return NULL;
73 HttpNetworkSession* network_session = transaction_factory->GetSession(); 96 HttpNetworkSession* network_session = transaction_factory->GetSession();
74 if (!network_session) 97 if (!network_session)
75 return NULL; 98 return NULL;
76 return &network_session->params(); 99 return &network_session->params();
77 } 100 }
78 101
79 URLRequest* URLRequestContext::CreateRequest( 102 URLRequest* URLRequestContext::CreateRequest(
80 const GURL& url, URLRequest::Delegate* delegate) const { 103 const GURL& url, URLRequest::Delegate* delegate) const {
81 return new URLRequest(url, delegate, this, network_delegate_); 104 return new URLRequest(url, delegate, this, network_delegate_);
82 } 105 }
83 106
84 void URLRequestContext::set_cookie_store(CookieStore* cookie_store) { 107 void URLRequestContext::set_cookie_store(CookieStore* cookie_store) {
85 cookie_store_ = cookie_store; 108 cookie_store_ = cookie_store;
86 } 109 }
87 110
111 // Gets the value of 'Accept-Charset' header field.
erikwright (departed) 2012/09/21 15:06:33 no implementation comment necessary.
112 const std::string& URLRequestContext::accept_charset() const {
113 if (!http_user_agent_settings_)
erikwright (departed) 2012/09/21 15:06:33 nit: return http_user_agent_settings_ ? ht
114 return EmptyString();
115 return http_user_agent_settings_->GetAcceptCharset();
116 }
117
118 // Gets the value of 'Accept-Language' header field.
119 const std::string& URLRequestContext::accept_language() const {
120 if (!http_user_agent_settings_)
121 return EmptyString();
122 return http_user_agent_settings_->GetAcceptLanguage();
123 }
124
88 const std::string& URLRequestContext::GetUserAgent(const GURL& url) const { 125 const std::string& URLRequestContext::GetUserAgent(const GURL& url) const {
89 return EmptyString(); 126 if (!http_user_agent_settings_)
127 return EmptyString();
128 return http_user_agent_settings_->GetUserAgent(url);
90 } 129 }
91 130
92 void URLRequestContext::AssertNoURLRequests() const { 131 void URLRequestContext::AssertNoURLRequests() const {
93 int num_requests = url_requests_->size(); 132 int num_requests = url_requests_->size();
94 if (num_requests != 0) { 133 if (num_requests != 0) {
95 // We're leaking URLRequests :( Dump the URL of the first one and record how 134 // We're leaking URLRequests :( Dump the URL of the first one and record how
96 // many we leaked so we have an idea of how bad it is. 135 // many we leaked so we have an idea of how bad it is.
97 char url_buf[128]; 136 char url_buf[128];
98 const URLRequest* request = *url_requests_->begin(); 137 const URLRequest* request = *url_requests_->begin();
99 base::strlcpy(url_buf, request->url().spec().c_str(), arraysize(url_buf)); 138 base::strlcpy(url_buf, request->url().spec().c_str(), arraysize(url_buf));
100 bool has_delegate = request->has_delegate(); 139 bool has_delegate = request->has_delegate();
101 int load_flags = request->load_flags(); 140 int load_flags = request->load_flags();
102 base::debug::StackTrace stack_trace(NULL, 0); 141 base::debug::StackTrace stack_trace(NULL, 0);
103 if (request->stack_trace()) 142 if (request->stack_trace())
104 stack_trace = *request->stack_trace(); 143 stack_trace = *request->stack_trace();
105 base::debug::Alias(url_buf); 144 base::debug::Alias(url_buf);
106 base::debug::Alias(&num_requests); 145 base::debug::Alias(&num_requests);
107 base::debug::Alias(&has_delegate); 146 base::debug::Alias(&has_delegate);
108 base::debug::Alias(&load_flags); 147 base::debug::Alias(&load_flags);
109 base::debug::Alias(&stack_trace); 148 base::debug::Alias(&stack_trace);
110 CHECK(false) << "Leaked " << num_requests << " URLRequest(s). First URL: " 149 CHECK(false) << "Leaked " << num_requests << " URLRequest(s). First URL: "
111 << request->url().spec().c_str() << "."; 150 << request->url().spec().c_str() << ".";
112 } 151 }
113 } 152 }
114 153
115 } // namespace net 154 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698