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
21class GURL;
22class PrefService;
23
24namespace content {
25class ResourceContext;
26class WebContents;
27}
28
29namespace data_reduction_proxy {
30class DataReductionProxySettings;
31}
32
33namespace net {
34class CookieStore;
35}
36
37namespace visitedlink {
38class VisitedLinkMaster;
39}
40
41using data_reduction_proxy::DataReductionProxySettings;
42
43namespace android_webview {
44
45class AwFormDatabaseService;
46class AwQuotaManagerBridge;
47class AwURLRequestContextGetter;
48class JniDependencyFactory;
49
50class AwBrowserContext : public content::BrowserContext,
51                         public visitedlink::VisitedLinkDelegate {
52 public:
53
54  AwBrowserContext(const base::FilePath path,
55                   JniDependencyFactory* native_factory);
56  virtual ~AwBrowserContext();
57
58  // Currently only one instance per process is supported.
59  static AwBrowserContext* GetDefault();
60
61  // Convenience method to returns the AwBrowserContext corresponding to the
62  // given WebContents.
63  static AwBrowserContext* FromWebContents(
64      content::WebContents* web_contents);
65
66  static void SetDataReductionProxyEnabled(bool enabled);
67
68  // Maps to BrowserMainParts::PreMainMessageLoopRun.
69  void PreMainMessageLoopRun();
70
71  // These methods map to Add methods in visitedlink::VisitedLinkMaster.
72  void AddVisitedURLs(const std::vector<GURL>& urls);
73
74  net::URLRequestContextGetter* CreateRequestContext(
75      content::ProtocolHandlerMap* protocol_handlers,
76      content::URLRequestInterceptorScopedVector request_interceptors);
77  net::URLRequestContextGetter* CreateRequestContextForStoragePartition(
78      const base::FilePath& partition_path,
79      bool in_memory,
80      content::ProtocolHandlerMap* protocol_handlers,
81      content::URLRequestInterceptorScopedVector request_interceptors);
82
83  AwQuotaManagerBridge* GetQuotaManagerBridge();
84
85  AwFormDatabaseService* GetFormDatabaseService();
86
87  DataReductionProxySettings* GetDataReductionProxySettings();
88
89  void CreateUserPrefServiceIfNecessary();
90
91  // content::BrowserContext implementation.
92  virtual base::FilePath GetPath() const OVERRIDE;
93  virtual bool IsOffTheRecord() const OVERRIDE;
94  virtual net::URLRequestContextGetter* GetRequestContext() OVERRIDE;
95  virtual net::URLRequestContextGetter* GetRequestContextForRenderProcess(
96      int renderer_child_id) OVERRIDE;
97  virtual net::URLRequestContextGetter* GetMediaRequestContext() OVERRIDE;
98  virtual net::URLRequestContextGetter* GetMediaRequestContextForRenderProcess(
99      int renderer_child_id) OVERRIDE;
100  virtual net::URLRequestContextGetter*
101      GetMediaRequestContextForStoragePartition(
102          const base::FilePath& partition_path, bool in_memory) OVERRIDE;
103  virtual content::ResourceContext* GetResourceContext() OVERRIDE;
104  virtual content::DownloadManagerDelegate*
105      GetDownloadManagerDelegate() OVERRIDE;
106  virtual content::BrowserPluginGuestManager* GetGuestManager() OVERRIDE;
107  virtual quota::SpecialStoragePolicy* GetSpecialStoragePolicy() OVERRIDE;
108  virtual content::PushMessagingService* GetPushMessagingService() OVERRIDE;
109
110  // visitedlink::VisitedLinkDelegate implementation.
111  virtual void RebuildTable(
112      const scoped_refptr<URLEnumerator>& enumerator) OVERRIDE;
113
114 private:
115  static bool data_reduction_proxy_enabled_;
116
117  // The file path where data for this context is persisted.
118  base::FilePath context_storage_path_;
119
120  JniDependencyFactory* native_factory_;
121  scoped_refptr<net::CookieStore> cookie_store_;
122  scoped_refptr<AwURLRequestContextGetter> url_request_context_getter_;
123  scoped_refptr<AwQuotaManagerBridge> quota_manager_bridge_;
124  scoped_ptr<AwFormDatabaseService> form_database_service_;
125
126  AwDownloadManagerDelegate download_manager_delegate_;
127
128  scoped_ptr<visitedlink::VisitedLinkMaster> visitedlink_master_;
129  scoped_ptr<content::ResourceContext> resource_context_;
130
131  scoped_ptr<PrefService> user_pref_service_;
132
133  scoped_ptr<DataReductionProxySettings> data_reduction_proxy_settings_;
134
135  DISALLOW_COPY_AND_ASSIGN(AwBrowserContext);
136};
137
138}  // namespace android_webview
139
140#endif  // ANDROID_WEBVIEW_BROWSER_AW_BROWSER_CONTEXT_H_
141