- add sources.
[platform/framework/web/crosswalk.git] / src / android_webview / browser / net / aw_url_request_context_getter.h
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 ProxyConfigService;
21 class URLRequestContext;
22 class URLRequestJobFactory;
23 }
24
25 namespace android_webview {
26
27 class AwNetworkDelegate;
28
29 class AwURLRequestContextGetter : public net::URLRequestContextGetter {
30  public:
31   AwURLRequestContextGetter(const base::FilePath& partition_path,
32                             net::CookieStore* cookie_store);
33
34   void InitializeOnNetworkThread();
35
36   // net::URLRequestContextGetter implementation.
37   virtual net::URLRequestContext* GetURLRequestContext() OVERRIDE;
38   virtual scoped_refptr<base::SingleThreadTaskRunner>
39       GetNetworkTaskRunner() const OVERRIDE;
40
41  private:
42   friend class AwBrowserContext;
43   virtual ~AwURLRequestContextGetter();
44
45   // Prior to GetURLRequestContext() being called, SetProtocolHandlers() is
46   // called to hand over the ProtocolHandlers that GetURLRequestContext() will
47   // later install into |job_factory_|.  This ordering is enforced by having
48   // AwBrowserContext::CreateRequestContext() call SetProtocolHandlers().
49   // SetProtocolHandlers() is necessary because the ProtocolHandlers are created
50   // on the UI thread while |job_factory_| must be created on the IO thread.
51   void SetProtocolHandlers(content::ProtocolHandlerMap* protocol_handlers);
52
53   void InitializeURLRequestContext();
54
55   const base::FilePath partition_path_;
56   scoped_refptr<net::CookieStore> cookie_store_;
57   scoped_ptr<net::URLRequestContext> url_request_context_;
58   scoped_ptr<net::ProxyConfigService> proxy_config_service_;
59   scoped_ptr<net::URLRequestJobFactory> job_factory_;
60   scoped_ptr<net::HttpTransactionFactory> main_http_factory_;
61
62   // ProtocolHandlers are stored here between SetProtocolHandlers() and the
63   // first GetURLRequestContext() call.
64   content::ProtocolHandlerMap protocol_handlers_;
65
66   DISALLOW_COPY_AND_ASSIGN(AwURLRequestContextGetter);
67 };
68
69 }  // namespace android_webview
70
71 #endif  // ANDROID_WEBVIEW_BROWSER_NET_AW_URL_REQUEST_CONTEXT_GETTER_H_