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

Side by Side Diff: net/url_request/url_request_context_builder.h

Issue 1239393003: Refactor main URLRequestContext creation to use URLRequestContextBuilder Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 5 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
« no previous file with comments | « net/url_request/url_request_context.cc ('k') | net/url_request/url_request_context_builder.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // This class is useful for building a simple URLRequestContext. Most creators 5 // This class is useful for building a simple URLRequestContext. Most creators
6 // of new URLRequestContexts should use this helper class to construct it. Call 6 // of new URLRequestContexts should use this helper class to construct it. Call
7 // any configuration params, and when done, invoke Build() to construct the 7 // any configuration params, and when done, invoke Build() to construct the
8 // URLRequestContext. This URLRequestContext will own all its own storage. 8 // URLRequestContext. This URLRequestContext will own all its own storage.
9 // 9 //
10 // URLRequestContextBuilder and its associated params classes are initially 10 // URLRequestContextBuilder and its associated params classes are initially
11 // populated with "sane" default values. Read through the comments to figure out 11 // populated with "sane" default values. Read through the comments to figure out
12 // what these are. 12 // what these are.
13 13
14 #ifndef NET_URL_REQUEST_URL_REQUEST_CONTEXT_BUILDER_H_ 14 #ifndef NET_URL_REQUEST_URL_REQUEST_CONTEXT_BUILDER_H_
15 #define NET_URL_REQUEST_URL_REQUEST_CONTEXT_BUILDER_H_ 15 #define NET_URL_REQUEST_URL_REQUEST_CONTEXT_BUILDER_H_
16 16
17 #include <string> 17 #include <string>
18 #include <vector> 18 #include <vector>
19 19
20 #include "base/basictypes.h" 20 #include "base/basictypes.h"
21 #include "base/callback.h"
21 #include "base/files/file_path.h" 22 #include "base/files/file_path.h"
22 #include "base/memory/ref_counted.h" 23 #include "base/memory/ref_counted.h"
23 #include "base/memory/scoped_ptr.h" 24 #include "base/memory/scoped_ptr.h"
24 #include "base/memory/scoped_vector.h" 25 #include "base/memory/scoped_vector.h"
25 #include "build/build_config.h" 26 #include "build/build_config.h"
26 #include "net/base/net_export.h" 27 #include "net/base/net_export.h"
27 #include "net/base/network_delegate.h" 28 #include "net/base/network_delegate.h"
28 #include "net/dns/host_resolver.h" 29 #include "net/dns/host_resolver.h"
29 #include "net/proxy/proxy_config_service.h" 30 #include "net/proxy/proxy_config_service.h"
30 #include "net/proxy/proxy_service.h" 31 #include "net/proxy/proxy_service.h"
31 #include "net/quic/quic_protocol.h" 32 #include "net/quic/quic_protocol.h"
32 #include "net/socket/next_proto.h" 33 #include "net/socket/next_proto.h"
33 34
34 namespace base { 35 namespace base {
35 class SingleThreadTaskRunner; 36 class SingleThreadTaskRunner;
36 } 37 }
37 38
38 namespace net { 39 namespace net {
39 40
41 class CertVerifier;
40 class ChannelIDService; 42 class ChannelIDService;
41 class CookieStore; 43 class CookieStore;
44 class CTVerifier;
45 class FraudulentCertificateReporter;
42 class FtpTransactionFactory; 46 class FtpTransactionFactory;
43 class HostMappingRules; 47 class HostMappingRules;
44 class HttpAuthHandlerFactory; 48 class HttpAuthHandlerFactory;
49 class HttpServerProperties;
50 class HttpTransactionFactory;
51 class HttpUserAgentSettings;
52 class NetworkQualityEstimator;
45 class ProxyConfigService; 53 class ProxyConfigService;
54 class SSLConfigService;
55 class SdchManager;
56 class TransportSecurityState;
46 class URLRequestContext; 57 class URLRequestContext;
47 class URLRequestInterceptor; 58 class URLRequestInterceptor;
59 class URLRequestJobFactory;
60
61 // The next threee classes are interfaces to allow callbacks during the
62 // construction of a main context.
63 // TODO(wjmaclean): Should these be combined into a single Delegate class,
64 // to be implemented by the creator of the main context?
65 class FraudulentCertificateReporterFactory {
66 public:
67 FraudulentCertificateReporterFactory() {}
68
69 virtual FraudulentCertificateReporter* Create(
70 URLRequestContext* context) const = 0;
71 };
72
73 class HttpTransactionFactoryFactory {
74 public:
75 HttpTransactionFactoryFactory() {}
76 virtual ~HttpTransactionFactoryFactory() {}
77
78 virtual HttpTransactionFactory* Create(URLRequestContext* context) = 0;
79 };
80
81 class CertVerifierDelegate {
82 public:
83 CertVerifierDelegate() {}
84 virtual ~CertVerifierDelegate() {}
85
86 virtual CertVerifier* Get(URLRequestContext* context) = 0;
87 };
48 88
49 class NET_EXPORT URLRequestContextBuilder { 89 class NET_EXPORT URLRequestContextBuilder {
50 public: 90 public:
51 struct NET_EXPORT HttpCacheParams { 91 struct NET_EXPORT HttpCacheParams {
52 enum Type { 92 enum Type {
53 IN_MEMORY, 93 IN_MEMORY,
54 DISK, 94 DISK,
55 }; 95 };
56 96
57 HttpCacheParams(); 97 HttpCacheParams();
(...skipping 30 matching lines...) Expand all
88 ~URLRequestContextBuilder(); 128 ~URLRequestContextBuilder();
89 129
90 // These functions are mutually exclusive. The ProxyConfigService, if 130 // These functions are mutually exclusive. The ProxyConfigService, if
91 // set, will be used to construct a ProxyService. 131 // set, will be used to construct a ProxyService.
92 void set_proxy_config_service(ProxyConfigService* proxy_config_service) { 132 void set_proxy_config_service(ProxyConfigService* proxy_config_service) {
93 proxy_config_service_.reset(proxy_config_service); 133 proxy_config_service_.reset(proxy_config_service);
94 } 134 }
95 void set_proxy_service(ProxyService* proxy_service) { 135 void set_proxy_service(ProxyService* proxy_service) {
96 proxy_service_.reset(proxy_service); 136 proxy_service_.reset(proxy_service);
97 } 137 }
138 void set_proxy_service_unowned(ProxyService* proxy_service) {
139 proxy_service_unowned_ = proxy_service;
140 }
141
142 void set_ssl_config_service(SSLConfigService* service) {
143 ssl_config_service_ = service;
144 }
98 145
99 // Call these functions to specify hard-coded Accept-Language 146 // Call these functions to specify hard-coded Accept-Language
100 // or User-Agent header values for all requests that don't 147 // or User-Agent header values for all requests that don't
101 // have the headers already set. 148 // have the headers already set.
102 void set_accept_language(const std::string& accept_language) { 149 void set_accept_language(const std::string& accept_language) {
103 accept_language_ = accept_language; 150 accept_language_ = accept_language;
104 } 151 }
105 void set_user_agent(const std::string& user_agent) { 152 void set_user_agent(const std::string& user_agent) {
106 user_agent_ = user_agent; 153 user_agent_ = user_agent;
107 } 154 }
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 249
203 // Note that if SDCH is enabled without a policy object observing 250 // Note that if SDCH is enabled without a policy object observing
204 // the SDCH manager and handling at least Get-Dictionary events, the 251 // the SDCH manager and handling at least Get-Dictionary events, the
205 // result will be "Content-Encoding: sdch" advertisements, but no 252 // result will be "Content-Encoding: sdch" advertisements, but no
206 // dictionaries fetches and no specific dictionaries advertised. 253 // dictionaries fetches and no specific dictionaries advertised.
207 // SdchOwner in net/sdch/sdch_owner.h is a simple policy object. 254 // SdchOwner in net/sdch/sdch_owner.h is a simple policy object.
208 void set_sdch_enabled(bool enable) { sdch_enabled_ = enable; } 255 void set_sdch_enabled(bool enable) { sdch_enabled_ = enable; }
209 256
210 URLRequestContext* Build(); 257 URLRequestContext* Build();
211 258
259 // Functions specific to building a main context.
260 void set_fraudulent_certificate_reporter_factory(
261 const FraudulentCertificateReporterFactory* factory) {
262 fraudulent_certificate_reporter_factory_ = factory;
263 }
264
265 void set_net_log_unowned(NetLog* net_log) {
266 net_log_unowned_= net_log;
267 }
268
269 void set_transport_security_state(TransportSecurityState* state){
270 transport_security_state_.reset(state);
271 }
272
273 void set_http_user_agent_settings_unowned(HttpUserAgentSettings* settings) {
274 http_user_agent_settings_unowned_ = settings;
275 }
276
277 void set_http_transaction_factory_factory(
278 HttpTransactionFactoryFactory* factory) {
279 http_transaction_factory_factory_.reset(factory);
280 }
281
282 void set_cert_verifier_delegate(CertVerifierDelegate* cert_verifier_delegate) {
283 cert_verifier_delegate_.reset(cert_verifier_delegate);
284 }
285
286 void set_host_resolver_unowned(HostResolver* host_resolver) {
287 host_resolver_unowned_ = host_resolver;
288 }
289
290 void set_cert_transparency_verifier_unowned(CTVerifier* ct_verifier) {
291 cert_transparency_verifier_unowned_ = ct_verifier;
292 }
293
294 void set_http_server_properties(
295 const base::WeakPtr<HttpServerProperties>& http_server_properties) {
296 http_server_properties_ = http_server_properties;
297 }
298
299 void set_http_auth_handler_factory_unowned(
300 HttpAuthHandlerFactory* http_auth_handler_factory) {
301 http_auth_handler_factory_unowned_ = http_auth_handler_factory;
302 }
303
304 void set_sdch_manager(SdchManager* manager);
305
306 void set_job_factory(scoped_ptr<URLRequestJobFactory> factory);
307
308 void set_network_quality_estimator_unowned(
309 NetworkQualityEstimator* network_quality_estimator) {
310 network_quality_estimator_unowned_ = network_quality_estimator;
311 }
312
313 URLRequestContext* BuildMainContext();
314
212 private: 315 private:
213 struct NET_EXPORT SchemeFactory { 316 struct NET_EXPORT SchemeFactory {
214 SchemeFactory(const std::string& scheme, HttpAuthHandlerFactory* factory); 317 SchemeFactory(const std::string& scheme, HttpAuthHandlerFactory* factory);
215 ~SchemeFactory(); 318 ~SchemeFactory();
216 319
217 std::string scheme; 320 std::string scheme;
218 HttpAuthHandlerFactory* factory; 321 HttpAuthHandlerFactory* factory;
219 }; 322 };
220 323
221 std::string accept_language_; 324 std::string accept_language_;
(...skipping 20 matching lines...) Expand all
242 scoped_ptr<HostResolver> host_resolver_; 345 scoped_ptr<HostResolver> host_resolver_;
243 scoped_ptr<ChannelIDService> channel_id_service_; 346 scoped_ptr<ChannelIDService> channel_id_service_;
244 scoped_ptr<ProxyConfigService> proxy_config_service_; 347 scoped_ptr<ProxyConfigService> proxy_config_service_;
245 scoped_ptr<ProxyService> proxy_service_; 348 scoped_ptr<ProxyService> proxy_service_;
246 scoped_ptr<NetworkDelegate> network_delegate_; 349 scoped_ptr<NetworkDelegate> network_delegate_;
247 scoped_refptr<CookieStore> cookie_store_; 350 scoped_refptr<CookieStore> cookie_store_;
248 scoped_ptr<FtpTransactionFactory> ftp_transaction_factory_; 351 scoped_ptr<FtpTransactionFactory> ftp_transaction_factory_;
249 std::vector<SchemeFactory> extra_http_auth_handlers_; 352 std::vector<SchemeFactory> extra_http_auth_handlers_;
250 ScopedVector<URLRequestInterceptor> url_request_interceptors_; 353 ScopedVector<URLRequestInterceptor> url_request_interceptors_;
251 354
355 // Member variables specific to building a main context.
356 // Names ending in 'unowned' indicate variables that will not be owned by
357 // the main context, If this ownership status changes, then the variable
358 // in question should be renamed.
359 const FraudulentCertificateReporterFactory*
360 fraudulent_certificate_reporter_factory_;
361 NetLog* net_log_unowned_;
362 scoped_ptr<TransportSecurityState> transport_security_state_;
363 HttpUserAgentSettings* http_user_agent_settings_unowned_;
364 scoped_ptr<HttpTransactionFactoryFactory> http_transaction_factory_factory_;
365 scoped_ptr<CertVerifierDelegate> cert_verifier_delegate_;
366 HostResolver* host_resolver_unowned_;
367 CTVerifier* cert_transparency_verifier_unowned_;
368 base::WeakPtr<HttpServerProperties> http_server_properties_;
369 HttpAuthHandlerFactory* http_auth_handler_factory_unowned_;
370 scoped_ptr<SdchManager> sdch_manager_;
371 scoped_ptr<URLRequestJobFactory> job_factory_;
372 NetworkQualityEstimator* network_quality_estimator_unowned_;
373 scoped_refptr<SSLConfigService> ssl_config_service_;
374 ProxyService* proxy_service_unowned_;
375
252 DISALLOW_COPY_AND_ASSIGN(URLRequestContextBuilder); 376 DISALLOW_COPY_AND_ASSIGN(URLRequestContextBuilder);
253 }; 377 };
254 378
255 } // namespace net 379 } // namespace net
256 380
257 #endif // NET_URL_REQUEST_URL_REQUEST_CONTEXT_BUILDER_H_ 381 #endif // NET_URL_REQUEST_URL_REQUEST_CONTEXT_BUILDER_H_
OLDNEW
« no previous file with comments | « net/url_request/url_request_context.cc ('k') | net/url_request/url_request_context_builder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698