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 CONTENT_PUBLIC_BROWSER_BROWSER_CONTEXT_H_
6 #define CONTENT_PUBLIC_BROWSER_BROWSER_CONTEXT_H_
8 #include "base/callback_forward.h"
9 #include "base/containers/hash_tables.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/supports_user_data.h"
12 #include "content/common/content_export.h"
21 class ExternalMountPoints;
25 class URLRequestContextGetter;
29 class SpecialStoragePolicy;
34 class BrowserPluginGuestManagerDelegate;
35 class DownloadManager;
36 class DownloadManagerDelegate;
37 class GeolocationPermissionContext;
38 class IndexedDBContext;
39 class ResourceContext;
41 class StoragePartition;
43 // This class holds the context needed for a browsing session.
44 // It lives on the UI thread. All these methods must only be called on the UI
46 class CONTENT_EXPORT BrowserContext : public base::SupportsUserData {
48 static DownloadManager* GetDownloadManager(BrowserContext* browser_context);
50 // Returns BrowserContext specific external mount points. It may return NULL
51 // if the context doesn't have any BrowserContext specific external mount
52 // points. Currenty, non-NULL value is returned only on ChromeOS.
53 static fileapi::ExternalMountPoints* GetMountPoints(BrowserContext* context);
55 static content::StoragePartition* GetStoragePartition(
56 BrowserContext* browser_context, SiteInstance* site_instance);
57 static content::StoragePartition* GetStoragePartitionForSite(
58 BrowserContext* browser_context, const GURL& site);
59 typedef base::Callback<void(StoragePartition*)> StoragePartitionCallback;
60 static void ForEachStoragePartition(
61 BrowserContext* browser_context,
62 const StoragePartitionCallback& callback);
63 static void AsyncObliterateStoragePartition(
64 BrowserContext* browser_context,
66 const base::Closure& on_gc_required);
68 // This function clears the contents of |active_paths| but does not take
69 // ownership of the pointer.
70 static void GarbageCollectStoragePartitions(
71 BrowserContext* browser_context,
72 scoped_ptr<base::hash_set<base::FilePath> > active_paths,
73 const base::Closure& done);
75 // DON'T USE THIS. GetDefaultStoragePartition() is going away.
76 // Use GetStoragePartition() instead. Ask ajwong@ if you have problems.
77 static content::StoragePartition* GetDefaultStoragePartition(
78 BrowserContext* browser_context);
80 // Ensures that the corresponding ResourceContext is initialized. Normally the
81 // BrowserContext initializs the corresponding getters when its objects are
82 // created, but if the embedder wants to pass the ResourceContext to another
83 // thread before they use BrowserContext, they should call this to make sure
84 // that the ResourceContext is ready.
85 static void EnsureResourceContextInitialized(BrowserContext* browser_context);
87 // Tells the HTML5 objects on this context to persist their session state
88 // across the next restart.
89 static void SaveSessionState(BrowserContext* browser_context);
91 virtual ~BrowserContext();
93 // Returns the path of the directory where this context's data is stored.
94 virtual base::FilePath GetPath() const = 0;
96 // Return whether this context is incognito. Default is false.
97 virtual bool IsOffTheRecord() const = 0;
99 // Returns the request context information associated with this context. Call
100 // this only on the UI thread, since it can send notifications that should
101 // happen on the UI thread.
102 // TODO(creis): Remove this version in favor of the one below.
103 virtual net::URLRequestContextGetter* GetRequestContext() = 0;
105 // Returns the request context appropriate for the given renderer. If the
106 // renderer process doesn't have an associated installed app, or if the
107 // installed app doesn't have isolated storage, this is equivalent to calling
108 // GetRequestContext().
109 virtual net::URLRequestContextGetter* GetRequestContextForRenderProcess(
110 int renderer_child_id) = 0;
112 // Returns the default request context for media resources associated with
114 // TODO(creis): Remove this version in favor of the one below.
115 virtual net::URLRequestContextGetter* GetMediaRequestContext() = 0;
117 // Returns the request context for media resources associated with this
118 // context and renderer process.
119 virtual net::URLRequestContextGetter* GetMediaRequestContextForRenderProcess(
120 int renderer_child_id) = 0;
121 virtual net::URLRequestContextGetter*
122 GetMediaRequestContextForStoragePartition(
123 const base::FilePath& partition_path,
126 typedef base::Callback<void(bool)> MidiSysExPermissionCallback;
128 // Requests a permission to use system exclusive messages in MIDI events.
129 // |callback| will be invoked when the request is resolved.
130 virtual void RequestMidiSysExPermission(
131 int render_process_id,
134 const GURL& requesting_frame,
136 const MidiSysExPermissionCallback& callback) = 0;
138 // Cancels a pending MIDI permission request.
139 virtual void CancelMidiSysExPermissionRequest(
140 int render_process_id,
143 const GURL& requesting_frame) = 0;
145 typedef base::Callback<void(bool)> ProtectedMediaIdentifierPermissionCallback;
147 // Request permission to access protected media identifier. The callback will
148 // tell whether it's permitted.
149 virtual void RequestProtectedMediaIdentifierPermission(
150 int render_process_id,
154 const GURL& requesting_frame,
155 const ProtectedMediaIdentifierPermissionCallback& callback) = 0;
157 // Cancels pending protected media identifier permission requests.
158 virtual void CancelProtectedMediaIdentifierPermissionRequests(
161 // Returns the resource context.
162 virtual ResourceContext* GetResourceContext() = 0;
164 // Returns the DownloadManagerDelegate for this context. This will be called
165 // once per context. The embedder owns the delegate and is responsible for
166 // ensuring that it outlives DownloadManager. It's valid to return NULL.
167 virtual DownloadManagerDelegate* GetDownloadManagerDelegate() = 0;
169 // Returns the geolocation permission context for this context. It's valid to
170 // return NULL, in which case geolocation requests will always be allowed.
171 virtual GeolocationPermissionContext* GetGeolocationPermissionContext() = 0;
173 // Returns the guest manager delegate for this context.
174 virtual content::BrowserPluginGuestManagerDelegate*
175 GetGuestManagerDelegate() = 0;
177 // Returns a special storage policy implementation, or NULL.
178 virtual quota::SpecialStoragePolicy* GetSpecialStoragePolicy() = 0;
181 } // namespace content
183 #if defined(COMPILER_GCC)
184 namespace BASE_HASH_NAMESPACE {
187 struct hash<content::BrowserContext*> {
188 std::size_t operator()(content::BrowserContext* const& p) const {
189 return reinterpret_cast<std::size_t>(p);
193 } // namespace BASE_HASH_NAMESPACE
196 #endif // CONTENT_PUBLIC_BROWSER_BROWSER_CONTEXT_H_