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 5 #ifndef CHROMECAST_SHELL_BROWSER_URL_REQUEST_CONTEXT_FACTORY_H_ 6 #define CHROMECAST_SHELL_BROWSER_URL_REQUEST_CONTEXT_FACTORY_H_ 7 8 #include "content/public/browser/content_browser_client.h" 9 #include "net/http/http_network_session.h" 10 11 namespace net { 12 class HttpTransactionFactory; 13 class HttpUserAgentSettings; 14 class ProxyConfigService; 15 class URLRequestJobFactory; 16 } // namespace net 17 18 namespace chromecast { 19 namespace shell { 20 21 class URLRequestContextFactory { 22 public: 23 URLRequestContextFactory(); 24 ~URLRequestContextFactory(); 25 26 // Some members must be initialized on UI thread. 27 void InitializeOnUIThread(); 28 29 // Since main context requires a bunch of input params, if these get called 30 // multiple times, either multiple main contexts should be supported/managed 31 // or the input params need to be the same as before. So to be safe, 32 // the CreateMainGetter function currently DCHECK to make sure it is not 33 // called more than once. 34 // The media and system getters however, do not need input, so it is actually 35 // safe to call these multiple times. The impl create only 1 getter of each 36 // type and return the same instance each time the methods are called, thus 37 // the name difference. 38 net::URLRequestContextGetter* GetSystemGetter(); 39 net::URLRequestContextGetter* CreateMainGetter( 40 content::BrowserContext* browser_context, 41 content::ProtocolHandlerMap* protocol_handlers, 42 content::URLRequestInterceptorScopedVector request_interceptors); 43 net::URLRequestContextGetter* GetMainGetter(); 44 net::URLRequestContextGetter* GetMediaGetter(); 45 46 private: 47 class URLRequestContextGetter; 48 class MainURLRequestContextGetter; 49 friend class URLRequestContextGetter; 50 friend class MainURLRequestContextGetter; 51 52 void InitializeSystemContextDependencies(); 53 void InitializeMainContextDependencies( 54 net::HttpTransactionFactory* factory, 55 content::ProtocolHandlerMap* protocol_handlers, 56 content::URLRequestInterceptorScopedVector request_interceptors); 57 void InitializeMediaContextDependencies(net::HttpTransactionFactory* factory); 58 59 void PopulateNetworkSessionParams(bool ignore_certificate_errors, 60 net::HttpNetworkSession::Params* params); 61 62 // These are called by the RequestContextGetters to create each 63 // RequestContext. 64 // They must be called on the IO thread. 65 net::URLRequestContext* CreateSystemRequestContext(); 66 net::URLRequestContext* CreateMediaRequestContext(); 67 net::URLRequestContext* CreateMainRequestContext( 68 content::BrowserContext* browser_context, 69 content::ProtocolHandlerMap* protocol_handlers, 70 content::URLRequestInterceptorScopedVector request_interceptors); 71 72 scoped_refptr<net::URLRequestContextGetter> system_getter_; 73 scoped_refptr<net::URLRequestContextGetter> media_getter_; 74 scoped_refptr<net::URLRequestContextGetter> main_getter_; 75 76 // Shared objects for all contexts. 77 // The URLRequestContextStorage class is not used as owner to these objects 78 // since they are shared between the different URLRequestContexts. 79 // The URLRequestContextStorage class manages dependent resources for a single 80 // instance of URLRequestContext only. 81 bool system_dependencies_initialized_; 82 scoped_ptr<net::HostResolver> host_resolver_; 83 scoped_ptr<net::ChannelIDService> channel_id_service_; 84 scoped_ptr<net::CertVerifier> cert_verifier_; 85 scoped_refptr<net::SSLConfigService> ssl_config_service_; 86 scoped_ptr<net::TransportSecurityState> transport_security_state_; 87 scoped_ptr<net::ProxyConfigService> proxy_config_service_; 88 scoped_ptr<net::ProxyService> proxy_service_; 89 scoped_ptr<net::HttpAuthHandlerFactory> http_auth_handler_factory_; 90 scoped_ptr<net::HttpServerProperties> http_server_properties_; 91 scoped_ptr<net::HttpUserAgentSettings> http_user_agent_settings_; 92 scoped_ptr<net::HttpTransactionFactory> system_transaction_factory_; 93 scoped_ptr<net::URLRequestJobFactory> system_job_factory_; 94 95 bool main_dependencies_initialized_; 96 scoped_ptr<net::HttpTransactionFactory> main_transaction_factory_; 97 scoped_ptr<net::URLRequestJobFactory> main_job_factory_; 98 99 bool media_dependencies_initialized_; 100 scoped_ptr<net::HttpTransactionFactory> media_transaction_factory_; 101 }; 102 103 } // namespace shell 104 } // namespace chromecast 105 106 #endif // CHROMECAST_SHELL_BROWSER_URL_REQUEST_CONTEXT_FACTORY_H_ 107