1559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org// Copyright (c) 2012 The Chromium Authors. All rights reserved.
2559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org// Use of this source code is governed by a BSD-style license that can be
3559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org// found in the LICENSE file.
4559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org
5559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org#ifndef CONTENT_PUBLIC_BROWSER_BROWSER_CONTEXT_H_
6559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org#define CONTENT_PUBLIC_BROWSER_BROWSER_CONTEXT_H_
7559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org
8559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org#include "base/callback_forward.h"
9559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org#include "base/containers/hash_tables.h"
10559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org#include "base/memory/scoped_ptr.h"
11559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org#include "base/supports_user_data.h"
12559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org#include "content/common/content_export.h"
13559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org#include "content/public/common/push_messaging_status.h"
14559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org
15559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.orgclass GURL;
16559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org
17559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.orgnamespace base {
18559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.orgclass FilePath;
19559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org}
20559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org
21559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.orgnamespace storage {
22559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.orgclass ExternalMountPoints;
23559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org}
24559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org
25559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.orgnamespace net {
26559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.orgclass URLRequestContextGetter;
27559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org}
28559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org
29559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.orgnamespace storage {
30559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.orgclass SpecialStoragePolicy;
31559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org}
32559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org
33559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.orgnamespace content {
34559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org
35559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.orgclass BlobHandle;
36559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.orgclass BrowserPluginGuestManager;
37559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.orgclass DownloadManager;
38559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.orgclass DownloadManagerDelegate;
39559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.orgclass IndexedDBContext;
40559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.orgclass PushMessagingService;
41559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.orgclass ResourceContext;
42559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.orgclass SiteInstance;
43559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.orgclass StoragePartition;
44559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.orgclass SSLHostStateDelegate;
45559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org
46559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org// This class holds the context needed for a browsing session.
47559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org// It lives on the UI thread. All these methods must only be called on the UI
48559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org// thread.
49559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.orgclass CONTENT_EXPORT BrowserContext : public base::SupportsUserData {
50559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org public:
51559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org  static DownloadManager* GetDownloadManager(BrowserContext* browser_context);
52559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org
53559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org  // Returns BrowserContext specific external mount points. It may return NULL
54559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org  // if the context doesn't have any BrowserContext specific external mount
55559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org  // points. Currenty, non-NULL value is returned only on ChromeOS.
56559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org  static storage::ExternalMountPoints* GetMountPoints(BrowserContext* context);
57559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org
58559a8833f0eae4af37dc0ffc3ee97e1fb14817b1commit-bot@chromium.org  static content::StoragePartition* GetStoragePartition(
59      BrowserContext* browser_context, SiteInstance* site_instance);
60  static content::StoragePartition* GetStoragePartitionForSite(
61      BrowserContext* browser_context, const GURL& site);
62  typedef base::Callback<void(StoragePartition*)> StoragePartitionCallback;
63  static void ForEachStoragePartition(
64      BrowserContext* browser_context,
65      const StoragePartitionCallback& callback);
66  static void AsyncObliterateStoragePartition(
67      BrowserContext* browser_context,
68      const GURL& site,
69      const base::Closure& on_gc_required);
70
71  // This function clears the contents of |active_paths| but does not take
72  // ownership of the pointer.
73  static void GarbageCollectStoragePartitions(
74      BrowserContext* browser_context,
75      scoped_ptr<base::hash_set<base::FilePath> > active_paths,
76      const base::Closure& done);
77
78  // DON'T USE THIS. GetDefaultStoragePartition() is going away.
79  // Use GetStoragePartition() instead. Ask ajwong@ if you have problems.
80  static content::StoragePartition* GetDefaultStoragePartition(
81      BrowserContext* browser_context);
82
83  typedef base::Callback<void(scoped_ptr<BlobHandle>)> BlobCallback;
84
85  // |callback| returns a NULL scoped_ptr on failure.
86  static void CreateMemoryBackedBlob(BrowserContext* browser_context,
87                                     const char* data, size_t length,
88                                     const BlobCallback& callback);
89
90  // Delivers a push message with |data| to the Service Worker identified by
91  // |origin| and |service_worker_registration_id|.
92  static void DeliverPushMessage(
93      BrowserContext* browser_context,
94      const GURL& origin,
95      int64 service_worker_registration_id,
96      const std::string& data,
97      const base::Callback<void(PushMessagingStatus)>& callback);
98
99  // Ensures that the corresponding ResourceContext is initialized. Normally the
100  // BrowserContext initializs the corresponding getters when its objects are
101  // created, but if the embedder wants to pass the ResourceContext to another
102  // thread before they use BrowserContext, they should call this to make sure
103  // that the ResourceContext is ready.
104  static void EnsureResourceContextInitialized(BrowserContext* browser_context);
105
106  // Tells the HTML5 objects on this context to persist their session state
107  // across the next restart.
108  static void SaveSessionState(BrowserContext* browser_context);
109
110  virtual ~BrowserContext();
111
112  // Returns the path of the directory where this context's data is stored.
113  virtual base::FilePath GetPath() const = 0;
114
115  // Return whether this context is incognito. Default is false.
116  virtual bool IsOffTheRecord() const = 0;
117
118  // Returns the request context information associated with this context.  Call
119  // this only on the UI thread, since it can send notifications that should
120  // happen on the UI thread.
121  // TODO(creis): Remove this version in favor of the one below.
122  virtual net::URLRequestContextGetter* GetRequestContext() = 0;
123
124  // Returns the request context appropriate for the given renderer. If the
125  // renderer process doesn't have an associated installed app, or if the
126  // installed app doesn't have isolated storage, this is equivalent to calling
127  // GetRequestContext().
128  virtual net::URLRequestContextGetter* GetRequestContextForRenderProcess(
129      int renderer_child_id) = 0;
130
131  // Returns the default request context for media resources associated with
132  // this context.
133  // TODO(creis): Remove this version in favor of the one below.
134  virtual net::URLRequestContextGetter* GetMediaRequestContext() = 0;
135
136  // Returns the request context for media resources associated with this
137  // context and renderer process.
138  virtual net::URLRequestContextGetter* GetMediaRequestContextForRenderProcess(
139      int renderer_child_id) = 0;
140  virtual net::URLRequestContextGetter*
141      GetMediaRequestContextForStoragePartition(
142          const base::FilePath& partition_path,
143          bool in_memory) = 0;
144
145  // Returns the resource context.
146  virtual ResourceContext* GetResourceContext() = 0;
147
148  // Returns the DownloadManagerDelegate for this context. This will be called
149  // once per context. The embedder owns the delegate and is responsible for
150  // ensuring that it outlives DownloadManager. It's valid to return NULL.
151  virtual DownloadManagerDelegate* GetDownloadManagerDelegate() = 0;
152
153  // Returns the guest manager for this context.
154  virtual BrowserPluginGuestManager* GetGuestManager() = 0;
155
156  // Returns a special storage policy implementation, or NULL.
157  virtual storage::SpecialStoragePolicy* GetSpecialStoragePolicy() = 0;
158
159  // Returns a push messaging service. The embedder owns the service, and is
160  // responsible for ensuring that it outlives RenderProcessHost. It's valid to
161  // return NULL.
162  virtual PushMessagingService* GetPushMessagingService() = 0;
163
164  // Returns the SSL host state decisions for this context. The context may
165  // return NULL, implementing the default exception storage strategy.
166  virtual SSLHostStateDelegate* GetSSLHostStateDelegate() = 0;
167};
168
169}  // namespace content
170
171#if defined(COMPILER_GCC)
172namespace BASE_HASH_NAMESPACE {
173
174template<>
175struct hash<content::BrowserContext*> {
176  std::size_t operator()(content::BrowserContext* const& p) const {
177    return reinterpret_cast<std::size_t>(p);
178  }
179};
180
181}  // namespace BASE_HASH_NAMESPACE
182#endif
183
184#endif  // CONTENT_PUBLIC_BROWSER_BROWSER_CONTEXT_H_
185