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

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: Change to returning strings by value Created 8 years, 2 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/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),
29 transport_security_state_(NULL), 30 transport_security_state_(NULL),
30 #if !defined(DISABLE_FTP_SUPPORT) 31 #if !defined(DISABLE_FTP_SUPPORT)
31 ftp_auth_cache_(new FtpAuthCache), 32 ftp_auth_cache_(new FtpAuthCache),
32 #endif 33 #endif
33 http_transaction_factory_(NULL), 34 http_transaction_factory_(NULL),
34 ftp_transaction_factory_(NULL), 35 ftp_transaction_factory_(NULL),
35 job_factory_(NULL), 36 job_factory_(NULL),
36 throttler_manager_(NULL), 37 throttler_manager_(NULL),
38 http_user_agent_settings_(NULL),
37 url_requests_(new std::set<const URLRequest*>) { 39 url_requests_(new std::set<const URLRequest*>) {
38 } 40 }
39 41
40 URLRequestContext::~URLRequestContext() { 42 URLRequestContext::~URLRequestContext() {
41 AssertNoURLRequests(); 43 AssertNoURLRequests();
42 } 44 }
43 45
44 void URLRequestContext::CopyFrom(const URLRequestContext* other) { 46 void URLRequestContext::CopyFrom(const URLRequestContext* other) {
45 // Copy URLRequestContext parameters. 47 // Copy URLRequestContext parameters.
46 set_net_log(other->net_log_); 48 set_net_log(other->net_log_);
47 set_host_resolver(other->host_resolver_); 49 set_host_resolver(other->host_resolver_);
48 set_cert_verifier(other->cert_verifier_); 50 set_cert_verifier(other->cert_verifier_);
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_); 61 set_http_user_agent_settings(other->http_user_agent_settings_);
mmenke 2012/10/05 20:08:51 nit: Move below set_throttler_manager, so they're
60 set_accept_charset(other->accept_charset_);
61 set_referrer_charset(other->referrer_charset_); 62 set_referrer_charset(other->referrer_charset_);
62 set_http_transaction_factory(other->http_transaction_factory_); 63 set_http_transaction_factory(other->http_transaction_factory_);
63 set_ftp_transaction_factory(other->ftp_transaction_factory_); 64 set_ftp_transaction_factory(other->ftp_transaction_factory_);
64 set_job_factory(other->job_factory_); 65 set_job_factory(other->job_factory_);
65 set_throttler_manager(other->throttler_manager_); 66 set_throttler_manager(other->throttler_manager_);
66 } 67 }
67 68
68 const HttpNetworkSession::Params* URLRequestContext::GetNetworkSessionParams( 69 const HttpNetworkSession::Params* URLRequestContext::GetNetworkSessionParams(
69 ) const { 70 ) const {
70 HttpTransactionFactory* transaction_factory = http_transaction_factory(); 71 HttpTransactionFactory* transaction_factory = http_transaction_factory();
71 if (!transaction_factory) 72 if (!transaction_factory)
72 return NULL; 73 return NULL;
73 HttpNetworkSession* network_session = transaction_factory->GetSession(); 74 HttpNetworkSession* network_session = transaction_factory->GetSession();
74 if (!network_session) 75 if (!network_session)
75 return NULL; 76 return NULL;
76 return &network_session->params(); 77 return &network_session->params();
77 } 78 }
78 79
79 URLRequest* URLRequestContext::CreateRequest( 80 URLRequest* URLRequestContext::CreateRequest(
80 const GURL& url, URLRequest::Delegate* delegate) const { 81 const GURL& url, URLRequest::Delegate* delegate) const {
81 return new URLRequest(url, delegate, this, network_delegate_); 82 return new URLRequest(url, delegate, this, network_delegate_);
82 } 83 }
83 84
84 void URLRequestContext::set_cookie_store(CookieStore* cookie_store) { 85 void URLRequestContext::set_cookie_store(CookieStore* cookie_store) {
85 cookie_store_ = cookie_store; 86 cookie_store_ = cookie_store;
86 } 87 }
87 88
88 const std::string& URLRequestContext::GetUserAgent(const GURL& url) const { 89 std::string URLRequestContext::GetAcceptCharset() const {
89 return EmptyString(); 90 return http_user_agent_settings_ ?
91 http_user_agent_settings_->GetAcceptCharset() : EmptyString();
92 }
93
94 std::string URLRequestContext::GetAcceptLanguage() const {
95 return http_user_agent_settings_ ?
96 http_user_agent_settings_->GetAcceptLanguage() : EmptyString();
97 }
98
99 std::string URLRequestContext::GetUserAgent(const GURL& url) const {
100 return http_user_agent_settings_ ?
101 http_user_agent_settings_->GetUserAgent(url) : EmptyString();
90 } 102 }
91 103
92 void URLRequestContext::AssertNoURLRequests() const { 104 void URLRequestContext::AssertNoURLRequests() const {
93 int num_requests = url_requests_->size(); 105 int num_requests = url_requests_->size();
94 if (num_requests != 0) { 106 if (num_requests != 0) {
95 // We're leaking URLRequests :( Dump the URL of the first one and record how 107 // 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. 108 // many we leaked so we have an idea of how bad it is.
97 char url_buf[128]; 109 char url_buf[128];
98 const URLRequest* request = *url_requests_->begin(); 110 const URLRequest* request = *url_requests_->begin();
99 base::strlcpy(url_buf, request->url().spec().c_str(), arraysize(url_buf)); 111 base::strlcpy(url_buf, request->url().spec().c_str(), arraysize(url_buf));
100 bool has_delegate = request->has_delegate(); 112 bool has_delegate = request->has_delegate();
101 int load_flags = request->load_flags(); 113 int load_flags = request->load_flags();
102 base::debug::StackTrace stack_trace(NULL, 0); 114 base::debug::StackTrace stack_trace(NULL, 0);
103 if (request->stack_trace()) 115 if (request->stack_trace())
104 stack_trace = *request->stack_trace(); 116 stack_trace = *request->stack_trace();
105 base::debug::Alias(url_buf); 117 base::debug::Alias(url_buf);
106 base::debug::Alias(&num_requests); 118 base::debug::Alias(&num_requests);
107 base::debug::Alias(&has_delegate); 119 base::debug::Alias(&has_delegate);
108 base::debug::Alias(&load_flags); 120 base::debug::Alias(&load_flags);
109 base::debug::Alias(&stack_trace); 121 base::debug::Alias(&stack_trace);
110 CHECK(false) << "Leaked " << num_requests << " URLRequest(s). First URL: " 122 CHECK(false) << "Leaked " << num_requests << " URLRequest(s). First URL: "
111 << request->url().spec().c_str() << "."; 123 << request->url().spec().c_str() << ".";
112 } 124 }
113 } 125 }
114 126
115 } // namespace net 127 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698