Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / android_webview / browser / aw_browser_context.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_AW_BROWSER_CONTEXT_H_
6 #define ANDROID_WEBVIEW_BROWSER_AW_BROWSER_CONTEXT_H_
7
8 #include <vector>
9
10 #include "android_webview/browser/aw_download_manager_delegate.h"
11 #include "base/basictypes.h"
12 #include "base/compiler_specific.h"
13 #include "base/files/file_path.h"
14 #include "base/memory/ref_counted.h"
15 #include "base/memory/scoped_ptr.h"
16 #include "components/visitedlink/browser/visitedlink_delegate.h"
17 #include "content/public/browser/browser_context.h"
18 #include "content/public/browser/content_browser_client.h"
19 #include "net/url_request/url_request_job_factory.h"
20
21 class GURL;
22 class PrefService;
23
24 namespace content {
25 class ResourceContext;
26 class SSLHostStateDelegate;
27 class WebContents;
28 }
29
30 namespace data_reduction_proxy {
31 class DataReductionProxyConfigurator;
32 class DataReductionProxySettings;
33 class DataReductionProxyStatisticsPrefs;
34 }
35
36 namespace net {
37 class CookieStore;
38 }
39
40 namespace visitedlink {
41 class VisitedLinkMaster;
42 }
43
44 namespace android_webview {
45
46 class AwFormDatabaseService;
47 class AwQuotaManagerBridge;
48 class AwURLRequestContextGetter;
49 class JniDependencyFactory;
50
51 class AwBrowserContext : public content::BrowserContext,
52                          public visitedlink::VisitedLinkDelegate {
53  public:
54
55   AwBrowserContext(const base::FilePath path,
56                    JniDependencyFactory* native_factory);
57   virtual ~AwBrowserContext();
58
59   // Currently only one instance per process is supported.
60   static AwBrowserContext* GetDefault();
61
62   // Convenience method to returns the AwBrowserContext corresponding to the
63   // given WebContents.
64   static AwBrowserContext* FromWebContents(
65       content::WebContents* web_contents);
66
67   static void SetDataReductionProxyEnabled(bool enabled);
68   static void SetLegacyCacheRemovalDelayForTest(int delay_ms);
69
70   // Maps to BrowserMainParts::PreMainMessageLoopRun.
71   void PreMainMessageLoopRun();
72
73   // These methods map to Add methods in visitedlink::VisitedLinkMaster.
74   void AddVisitedURLs(const std::vector<GURL>& urls);
75
76   net::URLRequestContextGetter* CreateRequestContext(
77       content::ProtocolHandlerMap* protocol_handlers,
78       content::URLRequestInterceptorScopedVector request_interceptors);
79   net::URLRequestContextGetter* CreateRequestContextForStoragePartition(
80       const base::FilePath& partition_path,
81       bool in_memory,
82       content::ProtocolHandlerMap* protocol_handlers,
83       content::URLRequestInterceptorScopedVector request_interceptors);
84
85   AwQuotaManagerBridge* GetQuotaManagerBridge();
86
87   AwFormDatabaseService* GetFormDatabaseService();
88
89   data_reduction_proxy::DataReductionProxySettings*
90       GetDataReductionProxySettings();
91
92   AwURLRequestContextGetter* GetAwURLRequestContext();
93
94   void CreateUserPrefServiceIfNecessary();
95
96   // content::BrowserContext implementation.
97   virtual base::FilePath GetPath() const override;
98   virtual bool IsOffTheRecord() const override;
99   virtual net::URLRequestContextGetter* GetRequestContext() override;
100   virtual net::URLRequestContextGetter* GetRequestContextForRenderProcess(
101       int renderer_child_id) override;
102   virtual net::URLRequestContextGetter* GetMediaRequestContext() override;
103   virtual net::URLRequestContextGetter* GetMediaRequestContextForRenderProcess(
104       int renderer_child_id) override;
105   virtual net::URLRequestContextGetter*
106       GetMediaRequestContextForStoragePartition(
107           const base::FilePath& partition_path, bool in_memory) override;
108   virtual content::ResourceContext* GetResourceContext() override;
109   virtual content::DownloadManagerDelegate*
110       GetDownloadManagerDelegate() override;
111   virtual content::BrowserPluginGuestManager* GetGuestManager() override;
112   virtual storage::SpecialStoragePolicy* GetSpecialStoragePolicy() override;
113   virtual content::PushMessagingService* GetPushMessagingService() override;
114   virtual content::SSLHostStateDelegate* GetSSLHostStateDelegate() override;
115
116   // visitedlink::VisitedLinkDelegate implementation.
117   virtual void RebuildTable(
118       const scoped_refptr<URLEnumerator>& enumerator) override;
119
120  private:
121   void CreateDataReductionProxyStatisticsIfNecessary();
122   static bool data_reduction_proxy_enabled_;
123
124   // Delay, in milliseconds, before removing the legacy cache dir.
125   // This is non-const for testing purposes.
126   static int legacy_cache_removal_delay_ms_;
127
128   // The file path where data for this context is persisted.
129   base::FilePath context_storage_path_;
130
131   JniDependencyFactory* native_factory_;
132   scoped_refptr<net::CookieStore> cookie_store_;
133   scoped_refptr<AwURLRequestContextGetter> url_request_context_getter_;
134   scoped_refptr<AwQuotaManagerBridge> quota_manager_bridge_;
135   scoped_ptr<AwFormDatabaseService> form_database_service_;
136
137   AwDownloadManagerDelegate download_manager_delegate_;
138
139   scoped_ptr<visitedlink::VisitedLinkMaster> visitedlink_master_;
140   scoped_ptr<content::ResourceContext> resource_context_;
141
142   scoped_ptr<PrefService> user_pref_service_;
143
144   scoped_ptr<data_reduction_proxy::DataReductionProxyConfigurator>
145       data_reduction_proxy_configurator_;
146   scoped_ptr<data_reduction_proxy::DataReductionProxyStatisticsPrefs>
147       data_reduction_proxy_statistics_;
148   scoped_ptr<data_reduction_proxy::DataReductionProxySettings>
149       data_reduction_proxy_settings_;
150
151   DISALLOW_COPY_AND_ASSIGN(AwBrowserContext);
152 };
153
154 }  // namespace android_webview
155
156 #endif  // ANDROID_WEBVIEW_BROWSER_AW_BROWSER_CONTEXT_H_