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"
13 #include "content/public/common/push_messaging_status.h"
22 class ExternalMountPoints;
26 class URLRequestContextGetter;
30 class SpecialStoragePolicy;
36 class BrowserPluginGuestManager;
37 class DownloadManager;
38 class DownloadManagerDelegate;
39 class IndexedDBContext;
40 class PushMessagingService;
41 class ResourceContext;
43 class StoragePartition;
44 class SSLHostStateDelegate;
46 // This class holds the context needed for a browsing session.
47 // It lives on the UI thread. All these methods must only be called on the UI
49 class CONTENT_EXPORT BrowserContext : public base::SupportsUserData {
51 static DownloadManager* GetDownloadManager(BrowserContext* browser_context);
53 // Returns BrowserContext specific external mount points. It may return NULL
54 // if the context doesn't have any BrowserContext specific external mount
55 // points. Currenty, non-NULL value is returned only on ChromeOS.
56 static storage::ExternalMountPoints* GetMountPoints(BrowserContext* context);
58 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,
69 const base::Closure& on_gc_required);
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);
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);
83 typedef base::Callback<void(scoped_ptr<BlobHandle>)> BlobCallback;
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);
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,
95 int64 service_worker_registration_id,
96 const std::string& data,
97 const base::Callback<void(PushDeliveryStatus)>& callback);
99 static void NotifyWillBeDestroyed(BrowserContext* browser_context);
101 // Ensures that the corresponding ResourceContext is initialized. Normally the
102 // BrowserContext initializs the corresponding getters when its objects are
103 // created, but if the embedder wants to pass the ResourceContext to another
104 // thread before they use BrowserContext, they should call this to make sure
105 // that the ResourceContext is ready.
106 static void EnsureResourceContextInitialized(BrowserContext* browser_context);
108 // Tells the HTML5 objects on this context to persist their session state
109 // across the next restart.
110 static void SaveSessionState(BrowserContext* browser_context);
112 ~BrowserContext() override;
114 // Returns the path of the directory where this context's data is stored.
115 virtual base::FilePath GetPath() const = 0;
117 // Return whether this context is incognito. Default is false.
118 virtual bool IsOffTheRecord() const = 0;
120 // Returns the request context information associated with this context. Call
121 // this only on the UI thread, since it can send notifications that should
122 // happen on the UI thread.
123 // TODO(creis): Remove this version in favor of the one below.
124 virtual net::URLRequestContextGetter* GetRequestContext() = 0;
126 // Returns the request context appropriate for the given renderer. If the
127 // renderer process doesn't have an associated installed app, or if the
128 // installed app doesn't have isolated storage, this is equivalent to calling
129 // GetRequestContext().
130 virtual net::URLRequestContextGetter* GetRequestContextForRenderProcess(
131 int renderer_child_id) = 0;
133 // Returns the default request context for media resources associated with
135 // TODO(creis): Remove this version in favor of the one below.
136 virtual net::URLRequestContextGetter* GetMediaRequestContext() = 0;
138 // Returns the request context for media resources associated with this
139 // context and renderer process.
140 virtual net::URLRequestContextGetter* GetMediaRequestContextForRenderProcess(
141 int renderer_child_id) = 0;
142 virtual net::URLRequestContextGetter*
143 GetMediaRequestContextForStoragePartition(
144 const base::FilePath& partition_path,
147 // Returns the resource context.
148 virtual ResourceContext* GetResourceContext() = 0;
150 // Returns the DownloadManagerDelegate for this context. This will be called
151 // once per context. The embedder owns the delegate and is responsible for
152 // ensuring that it outlives DownloadManager. It's valid to return NULL.
153 virtual DownloadManagerDelegate* GetDownloadManagerDelegate() = 0;
155 // Returns the guest manager for this context.
156 virtual BrowserPluginGuestManager* GetGuestManager() = 0;
158 // Returns a special storage policy implementation, or NULL.
159 virtual storage::SpecialStoragePolicy* GetSpecialStoragePolicy() = 0;
161 // Returns a push messaging service. The embedder owns the service, and is
162 // responsible for ensuring that it outlives RenderProcessHost. It's valid to
164 virtual PushMessagingService* GetPushMessagingService() = 0;
166 // Returns the SSL host state decisions for this context. The context may
167 // return NULL, implementing the default exception storage strategy.
168 virtual SSLHostStateDelegate* GetSSLHostStateDelegate() = 0;
171 } // namespace content
173 #endif // CONTENT_PUBLIC_BROWSER_BROWSER_CONTEXT_H_