Separate Simple Backend creation from initialization.
[chromium-blink-merge.git] / android_webview / browser / net / aw_url_request_context_getter.h
blob418e921f2cdc94b6229e603715eeb7b2a2b23d80
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/memory/scoped_ptr.h"
11 #include "content/public/browser/browser_thread_delegate.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"
17 namespace net {
18 class HttpTransactionFactory;
19 class ProxyConfigService;
20 class URLRequestContext;
21 class URLRequestJobFactory;
24 namespace android_webview {
26 class AwBrowserContext;
27 class AwNetworkDelegate;
29 class AwURLRequestContextGetter : public net::URLRequestContextGetter,
30 public content::BrowserThreadDelegate {
31 public:
32 explicit AwURLRequestContextGetter(AwBrowserContext* browser_context);
34 void InitializeOnNetworkThread();
36 // content::BrowserThreadDelegate implementation.
37 virtual void Init() OVERRIDE;
38 virtual void CleanUp() OVERRIDE {}
40 // net::URLRequestContextGetter implementation.
41 virtual net::URLRequestContext* GetURLRequestContext() OVERRIDE;
42 virtual scoped_refptr<base::SingleThreadTaskRunner>
43 GetNetworkTaskRunner() const OVERRIDE;
45 private:
46 friend class AwBrowserContext;
48 virtual ~AwURLRequestContextGetter();
50 // Prior to GetURLRequestContext() being called, SetProtocolHandlers() is
51 // called to hand over the ProtocolHandlers that GetURLRequestContext() will
52 // later install into |job_factory_|. This ordering is enforced by having
53 // AwBrowserContext::CreateRequestContext() call SetProtocolHandlers().
54 // SetProtocolHandlers() is necessary because the ProtocolHandlers are created
55 // on the UI thread while |job_factory_| must be created on the IO thread.
56 void SetProtocolHandlers(content::ProtocolHandlerMap* protocol_handlers);
58 void PopulateNetworkSessionParams(net::HttpNetworkSession::Params* params);
60 AwBrowserContext* browser_context_; // weak
61 scoped_ptr<net::URLRequestContext> url_request_context_;
62 scoped_ptr<net::ProxyConfigService> proxy_config_service_;
63 scoped_ptr<net::URLRequestJobFactory> job_factory_;
64 scoped_ptr<net::HttpTransactionFactory> main_http_factory_;
66 // ProtocolHandlers are stored here between SetProtocolHandlers() and the
67 // first GetURLRequestContext() call.
68 content::ProtocolHandlerMap protocol_handlers_;
70 DISALLOW_COPY_AND_ASSIGN(AwURLRequestContextGetter);
73 } // namespace android_webview
75 #endif // ANDROID_WEBVIEW_BROWSER_NET_AW_URL_REQUEST_CONTEXT_GETTER_H_