OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef ANDROID_WEBVIEW_BROWSER_NET_AW_URL_REQUEST_CONTEXT_GETTER_H_ | 5 #ifndef ANDROID_WEBVIEW_BROWSER_NET_AW_URL_REQUEST_CONTEXT_GETTER_H_ |
6 #define ANDROID_WEBVIEW_BROWSER_NET_AW_URL_REQUEST_CONTEXT_GETTER_H_ | 6 #define ANDROID_WEBVIEW_BROWSER_NET_AW_URL_REQUEST_CONTEXT_GETTER_H_ |
7 | 7 |
8 #include "base/basictypes.h" | |
9 #include "base/compiler_specific.h" | |
10 #include "base/memory/scoped_ptr.h" | |
8 #include "content/public/browser/browser_thread_delegate.h" | 11 #include "content/public/browser/browser_thread_delegate.h" |
9 | |
10 #include "base/memory/scoped_ptr.h" | |
11 #include "net/http/http_network_session.h" | 12 #include "net/http/http_network_session.h" |
12 #include "net/url_request/url_request_context_getter.h" | 13 #include "net/url_request/url_request_context_getter.h" |
13 | 14 #include "net/url_request/url_request_job_factory.h" |
14 namespace content { | |
15 class ResourceContext; | |
16 } | |
17 | 15 |
18 namespace net { | 16 namespace net { |
19 class HttpTransactionFactory; | 17 class HttpTransactionFactory; |
20 class ProxyConfigService; | 18 class ProxyConfigService; |
21 class URLRequestContext; | 19 class URLRequestContext; |
22 class URLRequestJobFactory; | 20 class URLRequestJobFactory; |
23 } | 21 } |
24 | 22 |
25 namespace android_webview { | 23 namespace android_webview { |
26 | 24 |
27 class AwBrowserContext; | 25 class AwBrowserContext; |
28 class AwNetworkDelegate; | 26 class AwNetworkDelegate; |
29 | 27 |
30 class AwURLRequestContextGetter : public net::URLRequestContextGetter, | 28 class AwURLRequestContextGetter : public net::URLRequestContextGetter, |
31 public content::BrowserThreadDelegate { | 29 public content::BrowserThreadDelegate { |
32 public: | 30 public: |
33 AwURLRequestContextGetter(AwBrowserContext* browser_context); | 31 explicit AwURLRequestContextGetter(AwBrowserContext* browser_context); |
34 | 32 |
35 void InitializeOnNetworkThread(); | 33 void InitializeOnNetworkThread(); |
36 | 34 |
37 content::ResourceContext* GetResourceContext(); | |
38 | |
39 // content::BrowserThreadDelegate implementation. | 35 // content::BrowserThreadDelegate implementation. |
40 virtual void Init() OVERRIDE; | 36 virtual void Init() OVERRIDE; |
41 virtual void CleanUp() OVERRIDE {} | 37 virtual void CleanUp() OVERRIDE {} |
42 | 38 |
43 // net::URLRequestContextGetter implementation. | 39 // net::URLRequestContextGetter implementation. |
44 virtual net::URLRequestContext* GetURLRequestContext() OVERRIDE; | 40 virtual net::URLRequestContext* GetURLRequestContext() OVERRIDE; |
45 virtual scoped_refptr<base::SingleThreadTaskRunner> | 41 virtual scoped_refptr<base::SingleThreadTaskRunner> |
46 GetNetworkTaskRunner() const OVERRIDE; | 42 GetNetworkTaskRunner() const OVERRIDE; |
47 | 43 |
48 private: | 44 private: |
45 friend class AwBrowserContext; | |
46 | |
49 virtual ~AwURLRequestContextGetter(); | 47 virtual ~AwURLRequestContextGetter(); |
50 | 48 |
49 // Prior to GetURLRequestContext() being called, SetProtocolHandlers() is | |
50 // called to hand over the ProtocolHandlers that GetURLRequestContext() will | |
51 // later install into |job_factory_|. This ordering is enforced by having | |
52 // AwBrowserContext::CreateRequestContext() call SetProtocolHandlers(). | |
53 // SetProtocolHandlers() is necessary because the ProtocolHandlers are created | |
54 // on the UI thread while |job_factory_| must be created on the IO thread. | |
55 void SetProtocolHandlers( | |
56 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> | |
57 blob_protocol_handler, | |
58 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> | |
59 file_system_protocol_handler, | |
60 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> | |
61 developer_protocol_handler, | |
62 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> | |
63 chrome_protocol_handler, | |
64 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> | |
65 chrome_devtools_protocol_handler); | |
66 | |
51 void PopulateNetworkSessionParams(net::HttpNetworkSession::Params* params); | 67 void PopulateNetworkSessionParams(net::HttpNetworkSession::Params* params); |
52 | 68 |
53 AwBrowserContext* browser_context_; // weak | 69 AwBrowserContext* browser_context_; // weak |
54 scoped_ptr<net::URLRequestContext> url_request_context_; | 70 scoped_ptr<net::URLRequestContext> url_request_context_; |
55 scoped_ptr<net::ProxyConfigService> proxy_config_service_; | 71 scoped_ptr<net::ProxyConfigService> proxy_config_service_; |
56 scoped_ptr<content::ResourceContext> resource_context_; | |
57 scoped_ptr<net::URLRequestJobFactory> job_factory_; | 72 scoped_ptr<net::URLRequestJobFactory> job_factory_; |
58 scoped_ptr<net::HttpTransactionFactory> main_http_factory_; | 73 scoped_ptr<net::HttpTransactionFactory> main_http_factory_; |
59 | 74 |
75 // ProtocolHandlers are stored here between SetProtocolHandlers() and | |
awong
2013/02/05 18:10:33
-> between the SetProtocolHandlers() and the first
| |
76 // GetURLRequestContext() calls. | |
77 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> blob_protocol_handler_; | |
78 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> | |
79 file_system_protocol_handler_; | |
80 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> | |
81 developer_protocol_handler_; | |
82 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> | |
83 chrome_protocol_handler_; | |
84 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> | |
85 chrome_devtools_protocol_handler_; | |
86 | |
60 DISALLOW_COPY_AND_ASSIGN(AwURLRequestContextGetter); | 87 DISALLOW_COPY_AND_ASSIGN(AwURLRequestContextGetter); |
61 }; | 88 }; |
62 | 89 |
63 } // namespace android_webview | 90 } // namespace android_webview |
64 | 91 |
65 #endif // ANDROID_WEBVIEW_BROWSER_NET_AW_URL_REQUEST_CONTEXT_GETTER_H_ | 92 #endif // ANDROID_WEBVIEW_BROWSER_NET_AW_URL_REQUEST_CONTEXT_GETTER_H_ |
OLD | NEW |