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 3 // found in the LICENSE file. 4 5 #ifndef ANDROID_WEBVIEW_BROWSER_NET_AW_URL_REQUEST_CONTEXT_GETTER_H_ 6 #define ANDROID_WEBVIEW_BROWSER_NET_AW_URL_REQUEST_CONTEXT_GETTER_H_ 7 8 #include "base/basictypes.h" 9 #include "base/compiler_specific.h" 10 #include "base/files/file_path.h" 11 #include "base/memory/scoped_ptr.h" 12 #include "content/public/browser/content_browser_client.h" 13 #include "net/http/http_network_session.h" 14 #include "net/url_request/url_request_context_getter.h" 15 #include "net/url_request/url_request_job_factory.h" 16 17 namespace net { 18 class CookieStore; 19 class HttpTransactionFactory; 20 class NetLog; 21 class ProxyConfigService; 22 class URLRequestContext; 23 class URLRequestJobFactory; 24 } 25 26 namespace data_reduction_proxy { 27 class DataReductionProxyAuthRequestHandler; 28 class DataReductionProxyConfigService; 29 } 30 31 namespace android_webview { 32 33 class AwNetworkDelegate; 34 35 class AwURLRequestContextGetter : public net::URLRequestContextGetter { 36 public: 37 AwURLRequestContextGetter( 38 const base::FilePath& partition_path, 39 net::CookieStore* cookie_store, 40 scoped_ptr<data_reduction_proxy::DataReductionProxyConfigService> 41 config_service); 42 43 // net::URLRequestContextGetter implementation. 44 virtual net::URLRequestContext* GetURLRequestContext() OVERRIDE; 45 virtual scoped_refptr<base::SingleThreadTaskRunner> 46 GetNetworkTaskRunner() const OVERRIDE; 47 48 data_reduction_proxy::DataReductionProxyAuthRequestHandler* 49 GetDataReductionProxyAuthRequestHandler() const; 50 51 // NetLog is thread-safe, so clients can call this method from arbitrary 52 // threads (UI and IO). 53 net::NetLog* GetNetLog(); 54 55 // This should be called before the network stack is ever used. It can be 56 // called again afterwards if the key updates. 57 void SetKeyOnIO(const std::string& key); 58 59 private: 60 friend class AwBrowserContext; 61 virtual ~AwURLRequestContextGetter(); 62 63 // Prior to GetURLRequestContext() being called, this is called to hand over 64 // the objects that GetURLRequestContext() will later install into 65 // |job_factory_|. This ordering is enforced by having 66 // AwBrowserContext::CreateRequestContext() call this method. 67 // This method is necessary because the passed in objects are created 68 // on the UI thread while |job_factory_| must be created on the IO thread. 69 void SetHandlersAndInterceptors( 70 content::ProtocolHandlerMap* protocol_handlers, 71 content::URLRequestInterceptorScopedVector request_interceptors); 72 73 void InitializeURLRequestContext(); 74 75 const base::FilePath partition_path_; 76 scoped_refptr<net::CookieStore> cookie_store_; 77 scoped_ptr<net::NetLog> net_log_; 78 scoped_ptr<net::URLRequestContext> url_request_context_; 79 scoped_ptr<data_reduction_proxy::DataReductionProxyConfigService> 80 data_reduction_proxy_config_service_; 81 scoped_ptr<data_reduction_proxy::DataReductionProxyAuthRequestHandler> 82 data_reduction_proxy_auth_request_handler_; 83 scoped_ptr<net::URLRequestJobFactory> job_factory_; 84 scoped_ptr<net::HttpTransactionFactory> main_http_factory_; 85 86 // ProtocolHandlers and interceptors are stored here between 87 // SetHandlersAndInterceptors() and the first GetURLRequestContext() call. 88 content::ProtocolHandlerMap protocol_handlers_; 89 content::URLRequestInterceptorScopedVector request_interceptors_; 90 91 DISALLOW_COPY_AND_ASSIGN(AwURLRequestContextGetter); 92 }; 93 94 } // namespace android_webview 95 96 #endif // ANDROID_WEBVIEW_BROWSER_NET_AW_URL_REQUEST_CONTEXT_GETTER_H_ 97