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.
5 #ifndef ANDROID_WEBVIEW_BROWSER_NET_AW_URL_REQUEST_CONTEXT_GETTER_H_
6 #define ANDROID_WEBVIEW_BROWSER_NET_AW_URL_REQUEST_CONTEXT_GETTER_H_
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"
19 class HttpTransactionFactory
;
20 class HttpUserAgentSettings
;
22 class ProxyConfigService
;
23 class URLRequestContext
;
24 class URLRequestJobFactory
;
27 namespace android_webview
{
29 class AwNetworkDelegate
;
31 class AwURLRequestContextGetter
: public net::URLRequestContextGetter
{
33 AwURLRequestContextGetter(
34 const base::FilePath
& cache_path
,
35 net::CookieStore
* cookie_store
,
36 scoped_ptr
<net::ProxyConfigService
> config_service
);
38 // net::URLRequestContextGetter implementation.
39 net::URLRequestContext
* GetURLRequestContext() override
;
40 scoped_refptr
<base::SingleThreadTaskRunner
> GetNetworkTaskRunner()
43 // NetLog is thread-safe, so clients can call this method from arbitrary
44 // threads (UI and IO).
45 net::NetLog
* GetNetLog();
47 // This should be called before the network stack is ever used. It can be
48 // called again afterwards if the key updates.
49 void SetKeyOnIO(const std::string
& key
);
52 friend class AwBrowserContext
;
53 ~AwURLRequestContextGetter() override
;
55 // Prior to GetURLRequestContext() being called, this is called to hand over
56 // the objects that GetURLRequestContext() will later install into
57 // |job_factory_|. This ordering is enforced by having
58 // AwBrowserContext::CreateRequestContext() call this method.
59 // This method is necessary because the passed in objects are created
60 // on the UI thread while |job_factory_| must be created on the IO thread.
61 void SetHandlersAndInterceptors(
62 content::ProtocolHandlerMap
* protocol_handlers
,
63 content::URLRequestInterceptorScopedVector request_interceptors
);
65 void InitializeURLRequestContext();
67 const base::FilePath cache_path_
;
68 scoped_refptr
<net::CookieStore
> cookie_store_
;
69 scoped_ptr
<net::NetLog
> net_log_
;
70 scoped_ptr
<net::URLRequestContext
> url_request_context_
;
71 scoped_ptr
<net::ProxyConfigService
> proxy_config_service_
;
72 scoped_ptr
<net::URLRequestJobFactory
> job_factory_
;
73 scoped_ptr
<net::HttpTransactionFactory
> main_http_factory_
;
74 scoped_ptr
<net::HttpUserAgentSettings
> http_user_agent_settings_
;
76 // ProtocolHandlers and interceptors are stored here between
77 // SetHandlersAndInterceptors() and the first GetURLRequestContext() call.
78 content::ProtocolHandlerMap protocol_handlers_
;
79 content::URLRequestInterceptorScopedVector request_interceptors_
;
81 DISALLOW_COPY_AND_ASSIGN(AwURLRequestContextGetter
);
84 } // namespace android_webview
86 #endif // ANDROID_WEBVIEW_BROWSER_NET_AW_URL_REQUEST_CONTEXT_GETTER_H_