blob: 85814a4f61c1086298bfd8eb2cc34374a0e48bb6 [file] [log] [blame]
[email protected]844ac63d2014-07-11 02:44:291// Copyright 2014 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
gunschf44ffcb2014-10-13 23:01:455#ifndef CHROMECAST_BROWSER_URL_REQUEST_CONTEXT_FACTORY_H_
6#define CHROMECAST_BROWSER_URL_REQUEST_CONTEXT_FACTORY_H_
[email protected]844ac63d2014-07-11 02:44:297
almasryminadfb5b362017-02-08 03:34:098#include <memory>
9
jam547f2672016-04-07 21:16:2210#include "content/public/browser/browser_context.h"
[email protected]844ac63d2014-07-11 02:44:2911#include "content/public/browser/content_browser_client.h"
12#include "net/http/http_network_session.h"
13
almasryminadfb5b362017-02-08 03:34:0914class PrefProxyConfigTracker;
15
jlevasseur4681757a2017-02-08 22:09:0316namespace base {
17class FilePath;
18}
19
[email protected]844ac63d2014-07-11 02:44:2920namespace net {
mmenke606c59c2016-03-07 18:20:5521class CookieStore;
[email protected]844ac63d2014-07-11 02:44:2922class HttpTransactionFactory;
23class HttpUserAgentSettings;
derekjchow8ac56a22015-06-26 18:50:2224class NetLog;
gunsch407189f2014-09-11 22:03:4125class ProxyConfigService;
[email protected]844ac63d2014-07-11 02:44:2926class URLRequestJobFactory;
27} // namespace net
28
29namespace chromecast {
30namespace shell {
gunschdacd4f6f2014-09-27 00:01:1031class CastNetworkDelegate;
[email protected]844ac63d2014-07-11 02:44:2932
33class URLRequestContextFactory {
34 public:
35 URLRequestContextFactory();
36 ~URLRequestContextFactory();
37
38 // Some members must be initialized on UI thread.
derekjchow8ac56a22015-06-26 18:50:2239 void InitializeOnUIThread(net::NetLog* net_log);
[email protected]844ac63d2014-07-11 02:44:2940
41 // Since main context requires a bunch of input params, if these get called
42 // multiple times, either multiple main contexts should be supported/managed
43 // or the input params need to be the same as before. So to be safe,
44 // the CreateMainGetter function currently DCHECK to make sure it is not
45 // called more than once.
46 // The media and system getters however, do not need input, so it is actually
47 // safe to call these multiple times. The impl create only 1 getter of each
48 // type and return the same instance each time the methods are called, thus
49 // the name difference.
50 net::URLRequestContextGetter* GetSystemGetter();
51 net::URLRequestContextGetter* CreateMainGetter(
52 content::BrowserContext* browser_context,
53 content::ProtocolHandlerMap* protocol_handlers,
54 content::URLRequestInterceptorScopedVector request_interceptors);
55 net::URLRequestContextGetter* GetMainGetter();
56 net::URLRequestContextGetter* GetMediaGetter();
57
gunschdacd4f6f2014-09-27 00:01:1058 CastNetworkDelegate* app_network_delegate() const {
59 return app_network_delegate_.get();
60 }
61
gunsche49c69202014-12-11 20:54:2562 net::HostResolver* host_resolver() const {
63 return host_resolver_.get();
64 }
65
gunschdacd4f6f2014-09-27 00:01:1066 // Initialize the CastNetworkDelegate objects. This needs to be done
67 // after the CastService is created, but before any URL requests are made.
68 void InitializeNetworkDelegates();
69
[email protected]844ac63d2014-07-11 02:44:2970 private:
71 class URLRequestContextGetter;
72 class MainURLRequestContextGetter;
73 friend class URLRequestContextGetter;
74 friend class MainURLRequestContextGetter;
75
76 void InitializeSystemContextDependencies();
77 void InitializeMainContextDependencies(
78 net::HttpTransactionFactory* factory,
79 content::ProtocolHandlerMap* protocol_handlers,
80 content::URLRequestInterceptorScopedVector request_interceptors);
81 void InitializeMediaContextDependencies(net::HttpTransactionFactory* factory);
82
mmenke6ddfbea2017-05-31 21:48:4183 void PopulateNetworkSessionParams(
84 bool ignore_certificate_errors,
85 net::HttpNetworkSession::Params* session_params,
86 net::HttpNetworkSession::Context* session_context);
[email protected]844ac63d2014-07-11 02:44:2987
88 // These are called by the RequestContextGetters to create each
89 // RequestContext.
90 // They must be called on the IO thread.
91 net::URLRequestContext* CreateSystemRequestContext();
92 net::URLRequestContext* CreateMediaRequestContext();
93 net::URLRequestContext* CreateMainRequestContext(
jlevasseur4681757a2017-02-08 22:09:0394 const base::FilePath& cookie_path,
[email protected]844ac63d2014-07-11 02:44:2995 content::ProtocolHandlerMap* protocol_handlers,
96 content::URLRequestInterceptorScopedVector request_interceptors);
97
98 scoped_refptr<net::URLRequestContextGetter> system_getter_;
99 scoped_refptr<net::URLRequestContextGetter> media_getter_;
100 scoped_refptr<net::URLRequestContextGetter> main_getter_;
dcheng3c3c93d52016-04-08 05:12:31101 std::unique_ptr<CastNetworkDelegate> app_network_delegate_;
102 std::unique_ptr<CastNetworkDelegate> system_network_delegate_;
[email protected]844ac63d2014-07-11 02:44:29103
104 // Shared objects for all contexts.
105 // The URLRequestContextStorage class is not used as owner to these objects
106 // since they are shared between the different URLRequestContexts.
107 // The URLRequestContextStorage class manages dependent resources for a single
108 // instance of URLRequestContext only.
109 bool system_dependencies_initialized_;
dcheng3c3c93d52016-04-08 05:12:31110 std::unique_ptr<net::HostResolver> host_resolver_;
111 std::unique_ptr<net::ChannelIDService> channel_id_service_;
112 std::unique_ptr<net::CertVerifier> cert_verifier_;
[email protected]844ac63d2014-07-11 02:44:29113 scoped_refptr<net::SSLConfigService> ssl_config_service_;
dcheng3c3c93d52016-04-08 05:12:31114 std::unique_ptr<net::TransportSecurityState> transport_security_state_;
rsleevid6de8302016-06-21 01:33:20115 std::unique_ptr<net::CTVerifier> cert_transparency_verifier_;
116 std::unique_ptr<net::CTPolicyEnforcer> ct_policy_enforcer_;
dcheng3c3c93d52016-04-08 05:12:31117 std::unique_ptr<net::ProxyConfigService> proxy_config_service_;
118 std::unique_ptr<net::ProxyService> proxy_service_;
119 std::unique_ptr<net::HttpAuthHandlerFactory> http_auth_handler_factory_;
120 std::unique_ptr<net::HttpServerProperties> http_server_properties_;
121 std::unique_ptr<net::HttpUserAgentSettings> http_user_agent_settings_;
122 std::unique_ptr<net::HttpTransactionFactory> system_transaction_factory_;
123 std::unique_ptr<net::CookieStore> system_cookie_store_;
124 std::unique_ptr<net::URLRequestJobFactory> system_job_factory_;
[email protected]844ac63d2014-07-11 02:44:29125
126 bool main_dependencies_initialized_;
dcheng3c3c93d52016-04-08 05:12:31127 std::unique_ptr<net::HttpTransactionFactory> main_transaction_factory_;
128 std::unique_ptr<net::CookieStore> main_cookie_store_;
129 std::unique_ptr<net::URLRequestJobFactory> main_job_factory_;
[email protected]844ac63d2014-07-11 02:44:29130
131 bool media_dependencies_initialized_;
dcheng3c3c93d52016-04-08 05:12:31132 std::unique_ptr<net::HttpTransactionFactory> media_transaction_factory_;
derekjchow8ac56a22015-06-26 18:50:22133
almasryminadfb5b362017-02-08 03:34:09134 std::unique_ptr<PrefProxyConfigTracker> pref_proxy_config_tracker_impl_;
135
derekjchow8ac56a22015-06-26 18:50:22136 net::NetLog* net_log_;
[email protected]844ac63d2014-07-11 02:44:29137};
138
139} // namespace shell
140} // namespace chromecast
141
gunschf44ffcb2014-10-13 23:01:45142#endif // CHROMECAST_BROWSER_URL_REQUEST_CONTEXT_FACTORY_H_