[email protected] | 844ac63d | 2014-07-11 02:44:29 | [diff] [blame] | 1 | // 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 | |
gunsch | f44ffcb | 2014-10-13 23:01:45 | [diff] [blame] | 5 | #ifndef CHROMECAST_BROWSER_URL_REQUEST_CONTEXT_FACTORY_H_ |
| 6 | #define CHROMECAST_BROWSER_URL_REQUEST_CONTEXT_FACTORY_H_ |
[email protected] | 844ac63d | 2014-07-11 02:44:29 | [diff] [blame] | 7 | |
almasrymina | dfb5b36 | 2017-02-08 03:34:09 | [diff] [blame] | 8 | #include <memory> |
| 9 | |
jam | 547f267 | 2016-04-07 21:16:22 | [diff] [blame] | 10 | #include "content/public/browser/browser_context.h" |
[email protected] | 844ac63d | 2014-07-11 02:44:29 | [diff] [blame] | 11 | #include "content/public/browser/content_browser_client.h" |
| 12 | #include "net/http/http_network_session.h" |
| 13 | |
almasrymina | dfb5b36 | 2017-02-08 03:34:09 | [diff] [blame] | 14 | class PrefProxyConfigTracker; |
| 15 | |
jlevasseur | 4681757a | 2017-02-08 22:09:03 | [diff] [blame] | 16 | namespace base { |
| 17 | class FilePath; |
| 18 | } |
| 19 | |
[email protected] | 844ac63d | 2014-07-11 02:44:29 | [diff] [blame] | 20 | namespace net { |
mmenke | 606c59c | 2016-03-07 18:20:55 | [diff] [blame] | 21 | class CookieStore; |
[email protected] | 844ac63d | 2014-07-11 02:44:29 | [diff] [blame] | 22 | class HttpTransactionFactory; |
| 23 | class HttpUserAgentSettings; |
derekjchow | 8ac56a2 | 2015-06-26 18:50:22 | [diff] [blame] | 24 | class NetLog; |
gunsch | 407189f | 2014-09-11 22:03:41 | [diff] [blame] | 25 | class ProxyConfigService; |
[email protected] | 844ac63d | 2014-07-11 02:44:29 | [diff] [blame] | 26 | class URLRequestJobFactory; |
| 27 | } // namespace net |
| 28 | |
| 29 | namespace chromecast { |
| 30 | namespace shell { |
gunsch | dacd4f6f | 2014-09-27 00:01:10 | [diff] [blame] | 31 | class CastNetworkDelegate; |
[email protected] | 844ac63d | 2014-07-11 02:44:29 | [diff] [blame] | 32 | |
| 33 | class URLRequestContextFactory { |
| 34 | public: |
| 35 | URLRequestContextFactory(); |
| 36 | ~URLRequestContextFactory(); |
| 37 | |
| 38 | // Some members must be initialized on UI thread. |
derekjchow | 8ac56a2 | 2015-06-26 18:50:22 | [diff] [blame] | 39 | void InitializeOnUIThread(net::NetLog* net_log); |
[email protected] | 844ac63d | 2014-07-11 02:44:29 | [diff] [blame] | 40 | |
| 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 | |
gunsch | dacd4f6f | 2014-09-27 00:01:10 | [diff] [blame] | 58 | CastNetworkDelegate* app_network_delegate() const { |
| 59 | return app_network_delegate_.get(); |
| 60 | } |
| 61 | |
gunsch | e49c6920 | 2014-12-11 20:54:25 | [diff] [blame] | 62 | net::HostResolver* host_resolver() const { |
| 63 | return host_resolver_.get(); |
| 64 | } |
| 65 | |
gunsch | dacd4f6f | 2014-09-27 00:01:10 | [diff] [blame] | 66 | // 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] | 844ac63d | 2014-07-11 02:44:29 | [diff] [blame] | 70 | 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 | |
mmenke | 6ddfbea | 2017-05-31 21:48:41 | [diff] [blame] | 83 | void PopulateNetworkSessionParams( |
| 84 | bool ignore_certificate_errors, |
| 85 | net::HttpNetworkSession::Params* session_params, |
| 86 | net::HttpNetworkSession::Context* session_context); |
[email protected] | 844ac63d | 2014-07-11 02:44:29 | [diff] [blame] | 87 | |
| 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( |
jlevasseur | 4681757a | 2017-02-08 22:09:03 | [diff] [blame] | 94 | const base::FilePath& cookie_path, |
[email protected] | 844ac63d | 2014-07-11 02:44:29 | [diff] [blame] | 95 | 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_; |
dcheng | 3c3c93d5 | 2016-04-08 05:12:31 | [diff] [blame] | 101 | std::unique_ptr<CastNetworkDelegate> app_network_delegate_; |
| 102 | std::unique_ptr<CastNetworkDelegate> system_network_delegate_; |
[email protected] | 844ac63d | 2014-07-11 02:44:29 | [diff] [blame] | 103 | |
| 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_; |
dcheng | 3c3c93d5 | 2016-04-08 05:12:31 | [diff] [blame] | 110 | 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] | 844ac63d | 2014-07-11 02:44:29 | [diff] [blame] | 113 | scoped_refptr<net::SSLConfigService> ssl_config_service_; |
dcheng | 3c3c93d5 | 2016-04-08 05:12:31 | [diff] [blame] | 114 | std::unique_ptr<net::TransportSecurityState> transport_security_state_; |
rsleevi | d6de830 | 2016-06-21 01:33:20 | [diff] [blame] | 115 | std::unique_ptr<net::CTVerifier> cert_transparency_verifier_; |
| 116 | std::unique_ptr<net::CTPolicyEnforcer> ct_policy_enforcer_; |
dcheng | 3c3c93d5 | 2016-04-08 05:12:31 | [diff] [blame] | 117 | 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] | 844ac63d | 2014-07-11 02:44:29 | [diff] [blame] | 125 | |
| 126 | bool main_dependencies_initialized_; |
dcheng | 3c3c93d5 | 2016-04-08 05:12:31 | [diff] [blame] | 127 | 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] | 844ac63d | 2014-07-11 02:44:29 | [diff] [blame] | 130 | |
| 131 | bool media_dependencies_initialized_; |
dcheng | 3c3c93d5 | 2016-04-08 05:12:31 | [diff] [blame] | 132 | std::unique_ptr<net::HttpTransactionFactory> media_transaction_factory_; |
derekjchow | 8ac56a2 | 2015-06-26 18:50:22 | [diff] [blame] | 133 | |
almasrymina | dfb5b36 | 2017-02-08 03:34:09 | [diff] [blame] | 134 | std::unique_ptr<PrefProxyConfigTracker> pref_proxy_config_tracker_impl_; |
| 135 | |
derekjchow | 8ac56a2 | 2015-06-26 18:50:22 | [diff] [blame] | 136 | net::NetLog* net_log_; |
[email protected] | 844ac63d | 2014-07-11 02:44:29 | [diff] [blame] | 137 | }; |
| 138 | |
| 139 | } // namespace shell |
| 140 | } // namespace chromecast |
| 141 | |
gunsch | f44ffcb | 2014-10-13 23:01:45 | [diff] [blame] | 142 | #endif // CHROMECAST_BROWSER_URL_REQUEST_CONTEXT_FACTORY_H_ |