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_AW_BROWSER_CONTEXT_H_
6 #define ANDROID_WEBVIEW_BROWSER_AW_BROWSER_CONTEXT_H_
10 #include "android_webview/browser/aw_download_manager_delegate.h"
11 #include "android_webview/browser/aw_message_port_service.h"
12 #include "android_webview/browser/aw_ssl_host_state_delegate.h"
13 #include "base/basictypes.h"
14 #include "base/compiler_specific.h"
15 #include "base/files/file_path.h"
16 #include "base/memory/ref_counted.h"
17 #include "base/memory/scoped_ptr.h"
18 #include "components/visitedlink/browser/visitedlink_delegate.h"
19 #include "content/public/browser/browser_context.h"
20 #include "content/public/browser/content_browser_client.h"
21 #include "net/url_request/url_request_job_factory.h"
27 class ResourceContext
;
28 class SSLHostStateDelegate
;
32 namespace data_reduction_proxy
{
33 class DataReductionProxyConfigurator
;
34 class DataReductionProxyIOData
;
35 class DataReductionProxySettings
;
42 namespace visitedlink
{
43 class VisitedLinkMaster
;
46 namespace android_webview
{
48 class AwFormDatabaseService
;
49 class AwQuotaManagerBridge
;
50 class AwURLRequestContextGetter
;
51 class JniDependencyFactory
;
53 class AwBrowserContext
: public content::BrowserContext
,
54 public visitedlink::VisitedLinkDelegate
{
57 AwBrowserContext(const base::FilePath path
,
58 JniDependencyFactory
* native_factory
);
59 ~AwBrowserContext() override
;
61 // Currently only one instance per process is supported.
62 static AwBrowserContext
* GetDefault();
64 // Convenience method to returns the AwBrowserContext corresponding to the
66 static AwBrowserContext
* FromWebContents(
67 content::WebContents
* web_contents
);
69 static void SetDataReductionProxyEnabled(bool enabled
);
70 static void SetLegacyCacheRemovalDelayForTest(int delay_ms
);
72 // Maps to BrowserMainParts::PreMainMessageLoopRun.
73 void PreMainMessageLoopRun();
75 // These methods map to Add methods in visitedlink::VisitedLinkMaster.
76 void AddVisitedURLs(const std::vector
<GURL
>& urls
);
78 net::URLRequestContextGetter
* CreateRequestContext(
79 content::ProtocolHandlerMap
* protocol_handlers
,
80 content::URLRequestInterceptorScopedVector request_interceptors
);
81 net::URLRequestContextGetter
* CreateRequestContextForStoragePartition(
82 const base::FilePath
& partition_path
,
84 content::ProtocolHandlerMap
* protocol_handlers
,
85 content::URLRequestInterceptorScopedVector request_interceptors
);
87 AwQuotaManagerBridge
* GetQuotaManagerBridge();
89 AwFormDatabaseService
* GetFormDatabaseService();
91 data_reduction_proxy::DataReductionProxySettings
*
92 GetDataReductionProxySettings();
94 data_reduction_proxy::DataReductionProxyIOData
*
95 GetDataReductionProxyIOData();
97 data_reduction_proxy::DataReductionProxyConfigurator
*
98 GetDataReductionProxyConfigurator();
100 AwURLRequestContextGetter
* GetAwURLRequestContext();
102 void CreateUserPrefServiceIfNecessary();
104 AwMessagePortService
* GetMessagePortService();
106 // content::BrowserContext implementation.
107 scoped_ptr
<content::ZoomLevelDelegate
> CreateZoomLevelDelegate(
108 const base::FilePath
& partition_path
) override
;
109 base::FilePath
GetPath() const override
;
110 bool IsOffTheRecord() const override
;
111 net::URLRequestContextGetter
* GetRequestContext() override
;
112 net::URLRequestContextGetter
* GetRequestContextForRenderProcess(
113 int renderer_child_id
) override
;
114 net::URLRequestContextGetter
* GetMediaRequestContext() override
;
115 net::URLRequestContextGetter
* GetMediaRequestContextForRenderProcess(
116 int renderer_child_id
) override
;
117 net::URLRequestContextGetter
* GetMediaRequestContextForStoragePartition(
118 const base::FilePath
& partition_path
,
119 bool in_memory
) override
;
120 content::ResourceContext
* GetResourceContext() override
;
121 content::DownloadManagerDelegate
* GetDownloadManagerDelegate() override
;
122 content::BrowserPluginGuestManager
* GetGuestManager() override
;
123 storage::SpecialStoragePolicy
* GetSpecialStoragePolicy() override
;
124 content::PushMessagingService
* GetPushMessagingService() override
;
125 content::SSLHostStateDelegate
* GetSSLHostStateDelegate() override
;
127 // visitedlink::VisitedLinkDelegate implementation.
128 void RebuildTable(const scoped_refptr
<URLEnumerator
>& enumerator
) override
;
131 void CreateDataReductionProxyStatisticsIfNecessary();
132 static bool data_reduction_proxy_enabled_
;
134 // Delay, in milliseconds, before removing the legacy cache dir.
135 // This is non-const for testing purposes.
136 static int legacy_cache_removal_delay_ms_
;
138 // The file path where data for this context is persisted.
139 base::FilePath context_storage_path_
;
141 JniDependencyFactory
* native_factory_
;
142 scoped_refptr
<net::CookieStore
> cookie_store_
;
143 scoped_refptr
<AwURLRequestContextGetter
> url_request_context_getter_
;
144 scoped_refptr
<AwQuotaManagerBridge
> quota_manager_bridge_
;
145 scoped_ptr
<AwFormDatabaseService
> form_database_service_
;
146 scoped_ptr
<AwMessagePortService
> message_port_service_
;
148 AwDownloadManagerDelegate download_manager_delegate_
;
150 scoped_ptr
<visitedlink::VisitedLinkMaster
> visitedlink_master_
;
151 scoped_ptr
<content::ResourceContext
> resource_context_
;
153 scoped_ptr
<PrefService
> user_pref_service_
;
155 scoped_ptr
<data_reduction_proxy::DataReductionProxySettings
>
156 data_reduction_proxy_settings_
;
157 scoped_ptr
<AwSSLHostStateDelegate
> ssl_host_state_delegate_
;
158 scoped_ptr
<data_reduction_proxy::DataReductionProxyIOData
>
159 data_reduction_proxy_io_data_
;
161 DISALLOW_COPY_AND_ASSIGN(AwBrowserContext
);
164 } // namespace android_webview
166 #endif // ANDROID_WEBVIEW_BROWSER_AW_BROWSER_CONTEXT_H_