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

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

Issue 2978443002: Make ProfileIOData use URLRequestContextBuilder (Closed)
Patch Set: Fix ChromeOS, extension throttles, merge Created 3 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
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 <stdint.h> 17 #include <stdint.h>
18 18
19 #include <map> 19 #include <map>
20 #include <memory> 20 #include <memory>
21 #include <string> 21 #include <string>
22 #include <unordered_map> 22 #include <unordered_map>
23 #include <utility> 23 #include <utility>
24 #include <vector> 24 #include <vector>
25 25
26 #include "base/callback.h"
26 #include "base/files/file_path.h" 27 #include "base/files/file_path.h"
27 #include "base/macros.h" 28 #include "base/macros.h"
28 #include "base/memory/ref_counted.h" 29 #include "base/memory/ref_counted.h"
29 #include "base/task_scheduler/task_traits.h" 30 #include "base/task_scheduler/task_traits.h"
30 #include "build/build_config.h" 31 #include "build/build_config.h"
31 #include "build/buildflag.h" 32 #include "build/buildflag.h"
32 #include "net/base/net_export.h" 33 #include "net/base/net_export.h"
33 #include "net/base/network_delegate.h" 34 #include "net/base/network_delegate.h"
34 #include "net/base/proxy_delegate.h" 35 #include "net/base/proxy_delegate.h"
35 #include "net/dns/host_resolver.h" 36 #include "net/dns/host_resolver.h"
(...skipping 11 matching lines...) Expand all
47 } 48 }
48 49
49 namespace net { 50 namespace net {
50 51
51 class CertVerifier; 52 class CertVerifier;
52 class ChannelIDService; 53 class ChannelIDService;
53 class CookieStore; 54 class CookieStore;
54 class CTPolicyEnforcer; 55 class CTPolicyEnforcer;
55 class CTVerifier; 56 class CTVerifier;
56 class HttpAuthHandlerFactory; 57 class HttpAuthHandlerFactory;
58 class HttpUserAgentSettings;
57 class HttpServerProperties; 59 class HttpServerProperties;
58 class NetworkQualityEstimator; 60 class NetworkQualityEstimator;
59 class ProxyConfigService; 61 class ProxyConfigService;
60 struct ReportingPolicy; 62 struct ReportingPolicy;
61 class URLRequestContext; 63 class URLRequestContext;
62 class URLRequestInterceptor; 64 class URLRequestInterceptor;
63 65
64 // A URLRequestContextBuilder creates a single URLRequestContext. It provides 66 // A URLRequestContextBuilder creates a single URLRequestContext. It provides
65 // methods to manage various URLRequestContext components which should be called 67 // methods to manage various URLRequestContext components which should be called
66 // before creating the Context. Once configuration is complete, calling Build() 68 // before creating the Context. Once configuration is complete, calling Build()
67 // will create a URLRequestContext with the specified configuration. Components 69 // will create a URLRequestContext with the specified configuration. Components
68 // that are not explicitly configured will use reasonable in-memory defaults. 70 // that are not explicitly configured will use reasonable in-memory defaults.
69 // 71 //
70 // The returned URLRequestContext is self-contained: Deleting it will safely 72 // The returned URLRequestContext is self-contained: Deleting it will safely
71 // shut down all of the URLRequests owned by its internal components, and then 73 // shut down all of the URLRequests owned by its internal components, and then
72 // tear down those components. The only exception to this are objects not owned 74 // tear down those components. The only exception to this are objects not owned
73 // by URLRequestContext. This includes components passed in to the methods that 75 // by URLRequestContext. This includes components passed in to the methods that
74 // take raw pointers, and objects that components passed in to the Builder have 76 // take raw pointers, and objects that components passed in to the Builder have
75 // raw pointers to. 77 // raw pointers to.
76 // 78 //
77 // A Builder should be destroyed after calling Build, and there is no need to 79 // A Builder should be destroyed after calling Build, and there is no need to
78 // keep it around for the lifetime of the created URLRequestContext. Each 80 // keep it around for the lifetime of the created URLRequestContext. Each
79 // Builder may be used to create only a single URLRequestContext. 81 // Builder may be used to create only a single URLRequestContext.
80 class NET_EXPORT URLRequestContextBuilder { 82 class NET_EXPORT URLRequestContextBuilder {
81 public: 83 public:
84 using CreateInterceptingJobFactory =
85 base::OnceCallback<std::unique_ptr<net::URLRequestJobFactory>(
86 std::unique_ptr<net::URLRequestJobFactory> inner_job_factory)>;
87
82 struct NET_EXPORT HttpCacheParams { 88 struct NET_EXPORT HttpCacheParams {
83 enum Type { 89 enum Type {
84 // In-memory cache. 90 // In-memory cache.
85 IN_MEMORY, 91 IN_MEMORY,
86 // Disk cache using "default" backend. 92 // Disk cache using "default" backend.
87 DISK, 93 DISK,
94 // Disk cache using "blockfile" backend (BackendImpl).
95 DISK_BLOCKFILE,
88 // Disk cache using "simple" backend (SimpleBackendImpl). 96 // Disk cache using "simple" backend (SimpleBackendImpl).
89 DISK_SIMPLE, 97 DISK_SIMPLE,
90 }; 98 };
91 99
92 HttpCacheParams(); 100 HttpCacheParams();
93 ~HttpCacheParams(); 101 ~HttpCacheParams();
94 102
95 // The type of HTTP cache. Default is IN_MEMORY. 103 // The type of HTTP cache. Default is IN_MEMORY.
96 Type type; 104 Type type;
97 105
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 } 167 }
160 168
161 void set_ssl_config_service( 169 void set_ssl_config_service(
162 scoped_refptr<net::SSLConfigService> ssl_config_service) { 170 scoped_refptr<net::SSLConfigService> ssl_config_service) {
163 ssl_config_service_ = std::move(ssl_config_service); 171 ssl_config_service_ = std::move(ssl_config_service);
164 } 172 }
165 173
166 // Call these functions to specify hard-coded Accept-Language 174 // Call these functions to specify hard-coded Accept-Language
167 // or User-Agent header values for all requests that don't 175 // or User-Agent header values for all requests that don't
168 // have the headers already set. 176 // have the headers already set.
169 void set_accept_language(const std::string& accept_language) { 177 void set_accept_language(const std::string& accept_language);
170 accept_language_ = accept_language; 178 void set_user_agent(const std::string& user_agent);
171 } 179 // Makes the created URLRequestContext use a shared HttpUserAgentSettings
172 void set_user_agent(const std::string& user_agent) { 180 // object. Not compatible with set_accept_language() / set_user_agent().
173 user_agent_ = user_agent; 181 // TODO(mmenke): Take ownership of the object instead.
174 } 182 void set_shared_http_user_agent_settings(
183 HttpUserAgentSettings* shared_http_user_agent_settings);
175 184
176 // Control support for data:// requests. By default it's disabled. 185 // Control support for data:// requests. By default it's disabled.
177 void set_data_enabled(bool enable) { 186 void set_data_enabled(bool enable) {
178 data_enabled_ = enable; 187 data_enabled_ = enable;
179 } 188 }
180 189
181 #if !BUILDFLAG(DISABLE_FILE_SUPPORT) 190 #if !BUILDFLAG(DISABLE_FILE_SUPPORT)
182 // Control support for file:// requests. By default it's disabled. 191 // Control support for file:// requests. By default it's disabled.
183 void set_file_enabled(bool enable) { 192 void set_file_enabled(bool enable) {
184 file_enabled_ = enable; 193 file_enabled_ = enable;
(...skipping 13 matching lines...) Expand all
198 const std::string& scheme, 207 const std::string& scheme,
199 std::unique_ptr<URLRequestJobFactory::ProtocolHandler> protocol_handler); 208 std::unique_ptr<URLRequestJobFactory::ProtocolHandler> protocol_handler);
200 209
201 // Unlike the other setters, the builder does not take ownership of the 210 // Unlike the other setters, the builder does not take ownership of the
202 // NetLog. 211 // NetLog.
203 // TODO(mmenke): Probably makes sense to get rid of this, and have consumers 212 // TODO(mmenke): Probably makes sense to get rid of this, and have consumers
204 // set their own NetLog::Observers instead. 213 // set their own NetLog::Observers instead.
205 void set_net_log(NetLog* net_log) { net_log_ = net_log; } 214 void set_net_log(NetLog* net_log) { net_log_ = net_log; }
206 215
207 // By default host_resolver is constructed with CreateDefaultResolver. 216 // By default host_resolver is constructed with CreateDefaultResolver.
208 void set_host_resolver(std::unique_ptr<HostResolver> host_resolver) { 217 void set_host_resolver(std::unique_ptr<HostResolver> host_resolver);
209 host_resolver_ = std::move(host_resolver); 218 // Allows sharing the HostResolver with other URLRequestContexts. Should not
210 } 219 // be used if set_host_resolver() is used.
220 // TODO(mmenke): Figure out the cost/benefits of not supporting HostResolvers
221 // between URLRequestContexts.
222 void set_shared_host_resolver(HostResolver* host_resolver);
211 223
212 // Uses BasicNetworkDelegate by default. Note that calling Build will unset 224 // Uses BasicNetworkDelegate by default. Note that calling Build will unset
213 // any custom delegate in builder, so this must be called each time before 225 // any custom delegate in builder, so this must be called each time before
214 // Build is called. 226 // Build is called.
215 void set_network_delegate(std::unique_ptr<NetworkDelegate> delegate) { 227 void set_network_delegate(std::unique_ptr<NetworkDelegate> delegate) {
216 network_delegate_ = std::move(delegate); 228 network_delegate_ = std::move(delegate);
217 } 229 }
218 230
219 // Temporarily stores a ProxyDelegate. Ownership is transferred to 231 // Sets the ProxyDelegate.
220 // UrlRequestContextStorage during Build. 232 void set_proxy_delegate(std::unique_ptr<ProxyDelegate> proxy_delegate);
221 void set_proxy_delegate(std::unique_ptr<ProxyDelegate> delegate) { 233 // Allows sharing the PreoxyDelegates with other URLRequestContexts. Should
222 proxy_delegate_ = std::move(delegate); 234 // not be used if set_proxy_delegate() is used.
223 } 235 // TODO(mmenke): Remove this (And update consumers).
236 void set_shared_proxy_delegate(ProxyDelegate* shared_proxy_delegate);
224 237
225 // Sets a specific HttpAuthHandlerFactory to be used by the URLRequestContext 238 // Sets a specific HttpAuthHandlerFactory to be used by the URLRequestContext
226 // rather than the default |HttpAuthHandlerRegistryFactory|. The builder 239 // rather than the default |HttpAuthHandlerRegistryFactory|. The builder
227 // takes ownership of the factory and will eventually transfer it to the new 240 // takes ownership of the factory and will eventually transfer it to the new
228 // URLRequestContext. Note that since Build will transfer ownership, the 241 // URLRequestContext.
229 // custom factory will be unset and this must be called before the next Build
230 // to set another custom one.
231 void SetHttpAuthHandlerFactory( 242 void SetHttpAuthHandlerFactory(
232 std::unique_ptr<HttpAuthHandlerFactory> factory); 243 std::unique_ptr<HttpAuthHandlerFactory> factory);
244 // Makes the created URLRequestContext use a shared HttpAuthHandlerFactory
245 // object. Not compatible with SetHttpAuthHandlerFactory().
246 // TODO(mmenke): Evaluate if sharing is really needed.
247 void set_shared_http_auth_handler_factory(
248 HttpAuthHandlerFactory* shared_http_auth_handler_factory);
233 249
234 // By default HttpCache is enabled with a default constructed HttpCacheParams. 250 // By default HttpCache is enabled with a default constructed HttpCacheParams.
235 void EnableHttpCache(const HttpCacheParams& params); 251 void EnableHttpCache(const HttpCacheParams& params);
236 void DisableHttpCache(); 252 void DisableHttpCache();
237 253
238 // Override default HttpNetworkSession::Params settings. 254 // Override default HttpNetworkSession::Params settings.
239 void set_http_network_session_params( 255 void set_http_network_session_params(
240 const HttpNetworkSession::Params& http_network_session_params) { 256 const HttpNetworkSession::Params& http_network_session_params) {
241 http_network_session_params_ = http_network_session_params; 257 http_network_session_params_ = http_network_session_params;
242 } 258 }
243 259
244 void set_transport_security_persister_path( 260 void set_transport_security_persister_path(
245 const base::FilePath& transport_security_persister_path) { 261 const base::FilePath& transport_security_persister_path) {
246 transport_security_persister_path_ = transport_security_persister_path; 262 transport_security_persister_path_ = transport_security_persister_path;
247 } 263 }
248 264
265 // Sets whether the TransportSecurityPersister only reads persisted
266 // information, or also writes it. By default, it both reads and writes.
267 // TODO(mmenke): Consider merging this with the above method.
268 void set_transport_security_persister_readonly(
269 bool transport_security_persister_readonly) {
270 transport_security_persister_readonly_ =
271 transport_security_persister_readonly;
272 }
273
249 void SetSpdyAndQuicEnabled(bool spdy_enabled, 274 void SetSpdyAndQuicEnabled(bool spdy_enabled,
250 bool quic_enabled); 275 bool quic_enabled);
251 276
252 void set_throttling_enabled(bool throttling_enabled) { 277 void set_throttling_enabled(bool throttling_enabled) {
253 throttling_enabled_ = throttling_enabled; 278 throttling_enabled_ = throttling_enabled;
254 } 279 }
255 280
256 void set_ct_verifier(std::unique_ptr<CTVerifier> ct_verifier); 281 void set_ct_verifier(std::unique_ptr<CTVerifier> ct_verifier);
257 void set_ct_policy_enforcer( 282 void set_ct_policy_enforcer(
258 std::unique_ptr<CTPolicyEnforcer> ct_policy_enforcer); 283 std::unique_ptr<CTPolicyEnforcer> ct_policy_enforcer);
259 284
260 void SetCertVerifier(std::unique_ptr<CertVerifier> cert_verifier); 285 void SetCertVerifier(std::unique_ptr<CertVerifier> cert_verifier);
261 286
287 // Makes the created URLRequestContext use a shared CertVerifier object.
288 // Should not be used it SetCertVerifier() is used.
289 // TODO(mmenke): Figure out if this can take ownership of the object instead.
290 void set_shared_cert_verifier(CertVerifier* shared_cert_verifier);
291
262 #if BUILDFLAG(ENABLE_REPORTING) 292 #if BUILDFLAG(ENABLE_REPORTING)
263 void set_reporting_policy( 293 void set_reporting_policy(
264 std::unique_ptr<net::ReportingPolicy> reporting_policy); 294 std::unique_ptr<net::ReportingPolicy> reporting_policy);
265 #endif // BUILDFLAG(ENABLE_REPORTING) 295 #endif // BUILDFLAG(ENABLE_REPORTING)
266 296
267 void SetInterceptors(std::vector<std::unique_ptr<URLRequestInterceptor>> 297 void SetInterceptors(std::vector<std::unique_ptr<URLRequestInterceptor>>
268 url_request_interceptors); 298 url_request_interceptors);
269 299
300 // Sets a callback that is passed ownership of the URLRequestJobFactory, and
301 // can wrap it in another URLRequestJobFactory. URLRequestInterceptors can't
302 // handle intercepting unsupported protocols, while this case.
303 // TODO(mmenke): Remove this, once it's no longer needed.
304 void set_create_intercepting_job_factory(
305 CreateInterceptingJobFactory create_intercepting_job_factory);
306
270 // Override the default in-memory cookie store and channel id service. 307 // Override the default in-memory cookie store and channel id service.
271 // If both |cookie_store| and |channel_id_service| are NULL, CookieStore and 308 // If both |cookie_store| and |channel_id_service| are NULL, CookieStore and
272 // ChannelIDService will be disabled for this context. 309 // ChannelIDService will be disabled for this context.
273 // If |cookie_store| is not NULL and |channel_id_service| is NULL, 310 // If |cookie_store| is not NULL and |channel_id_service| is NULL,
274 // only ChannelIdService is disabled for this context. 311 // only ChannelIdService is disabled for this context.
275 // Note that a persistent cookie store should not be used with an in-memory 312 // Note that a persistent cookie store should not be used with an in-memory
276 // channel id service, and one cookie store should not be shared between 313 // channel id service, and one cookie store should not be shared between
277 // multiple channel-id stores (or used both with and without a channel id 314 // multiple channel-id stores (or used both with and without a channel id
278 // store). 315 // store).
279 void SetCookieAndChannelIdStores( 316 void SetCookieAndChannelIdStores(
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 NetworkDelegate* network_delegate, 352 NetworkDelegate* network_delegate,
316 NetLog* net_log); 353 NetLog* net_log);
317 354
318 private: 355 private:
319 const char* name_; 356 const char* name_;
320 bool enable_brotli_; 357 bool enable_brotli_;
321 NetworkQualityEstimator* network_quality_estimator_; 358 NetworkQualityEstimator* network_quality_estimator_;
322 359
323 std::string accept_language_; 360 std::string accept_language_;
324 std::string user_agent_; 361 std::string user_agent_;
362 HttpUserAgentSettings* shared_http_user_agent_settings_;
363
325 // Include support for data:// requests. 364 // Include support for data:// requests.
326 bool data_enabled_; 365 bool data_enabled_;
327 #if !BUILDFLAG(DISABLE_FILE_SUPPORT) 366 #if !BUILDFLAG(DISABLE_FILE_SUPPORT)
328 // Include support for file:// requests. 367 // Include support for file:// requests.
329 bool file_enabled_; 368 bool file_enabled_;
330 #endif 369 #endif
331 #if !BUILDFLAG(DISABLE_FTP_SUPPORT) 370 #if !BUILDFLAG(DISABLE_FTP_SUPPORT)
332 // Include support for ftp:// requests. 371 // Include support for ftp:// requests.
333 bool ftp_enabled_; 372 bool ftp_enabled_;
334 #endif 373 #endif
335 bool http_cache_enabled_; 374 bool http_cache_enabled_;
336 bool throttling_enabled_; 375 bool throttling_enabled_;
337 bool sdch_enabled_; 376 bool sdch_enabled_;
338 bool cookie_store_set_by_client_; 377 bool cookie_store_set_by_client_;
339 378
340 scoped_refptr<base::SingleThreadTaskRunner> cache_thread_task_runner_; 379 scoped_refptr<base::SingleThreadTaskRunner> cache_thread_task_runner_;
341 HttpCacheParams http_cache_params_; 380 HttpCacheParams http_cache_params_;
342 HttpNetworkSession::Params http_network_session_params_; 381 HttpNetworkSession::Params http_network_session_params_;
343 base::FilePath transport_security_persister_path_; 382 base::FilePath transport_security_persister_path_;
383 bool transport_security_persister_readonly_;
344 NetLog* net_log_; 384 NetLog* net_log_;
345 std::unique_ptr<HostResolver> host_resolver_; 385 std::unique_ptr<HostResolver> host_resolver_;
386 net::HostResolver* shared_host_resolver_;
346 std::unique_ptr<ChannelIDService> channel_id_service_; 387 std::unique_ptr<ChannelIDService> channel_id_service_;
347 std::unique_ptr<ProxyConfigService> proxy_config_service_; 388 std::unique_ptr<ProxyConfigService> proxy_config_service_;
348 bool pac_quick_check_enabled_; 389 bool pac_quick_check_enabled_;
349 ProxyService::SanitizeUrlPolicy pac_sanitize_url_policy_; 390 ProxyService::SanitizeUrlPolicy pac_sanitize_url_policy_;
350 std::unique_ptr<ProxyService> proxy_service_; 391 std::unique_ptr<ProxyService> proxy_service_;
351 scoped_refptr<net::SSLConfigService> ssl_config_service_; 392 scoped_refptr<net::SSLConfigService> ssl_config_service_;
352 std::unique_ptr<NetworkDelegate> network_delegate_; 393 std::unique_ptr<NetworkDelegate> network_delegate_;
353 std::unique_ptr<ProxyDelegate> proxy_delegate_; 394 std::unique_ptr<ProxyDelegate> proxy_delegate_;
395 ProxyDelegate* shared_proxy_delegate_;
354 std::unique_ptr<CookieStore> cookie_store_; 396 std::unique_ptr<CookieStore> cookie_store_;
355 std::unique_ptr<HttpAuthHandlerFactory> http_auth_handler_factory_; 397 std::unique_ptr<HttpAuthHandlerFactory> http_auth_handler_factory_;
398 HttpAuthHandlerFactory* shared_http_auth_handler_factory_;
356 std::unique_ptr<CertVerifier> cert_verifier_; 399 std::unique_ptr<CertVerifier> cert_verifier_;
400 CertVerifier* shared_cert_verifier_;
357 std::unique_ptr<CTVerifier> ct_verifier_; 401 std::unique_ptr<CTVerifier> ct_verifier_;
358 std::unique_ptr<CTPolicyEnforcer> ct_policy_enforcer_; 402 std::unique_ptr<CTPolicyEnforcer> ct_policy_enforcer_;
359 #if BUILDFLAG(ENABLE_REPORTING) 403 #if BUILDFLAG(ENABLE_REPORTING)
360 std::unique_ptr<net::ReportingPolicy> reporting_policy_; 404 std::unique_ptr<net::ReportingPolicy> reporting_policy_;
361 #endif // BUILDFLAG(ENABLE_REPORTING) 405 #endif // BUILDFLAG(ENABLE_REPORTING)
362 std::vector<std::unique_ptr<URLRequestInterceptor>> url_request_interceptors_; 406 std::vector<std::unique_ptr<URLRequestInterceptor>> url_request_interceptors_;
407 CreateInterceptingJobFactory create_intercepting_job_factory_;
363 std::unique_ptr<HttpServerProperties> http_server_properties_; 408 std::unique_ptr<HttpServerProperties> http_server_properties_;
364 std::map<std::string, std::unique_ptr<URLRequestJobFactory::ProtocolHandler>> 409 std::map<std::string, std::unique_ptr<URLRequestJobFactory::ProtocolHandler>>
365 protocol_handlers_; 410 protocol_handlers_;
366 411
367 DISALLOW_COPY_AND_ASSIGN(URLRequestContextBuilder); 412 DISALLOW_COPY_AND_ASSIGN(URLRequestContextBuilder);
368 }; 413 };
369 414
370 } // namespace net 415 } // namespace net
371 416
372 #endif // NET_URL_REQUEST_URL_REQUEST_CONTEXT_BUILDER_H_ 417 #endif // NET_URL_REQUEST_URL_REQUEST_CONTEXT_BUILDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698