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/browser/zoom_level_delegate.h"
14 #include "content/public/common/push_messaging_status.h"
24 class ExternalMountPoints
;
28 class URLRequestContextGetter
;
32 class SpecialStoragePolicy
;
38 class BrowserPluginGuestManager
;
39 class DownloadManager
;
40 class DownloadManagerDelegate
;
41 class IndexedDBContext
;
42 class PermissionManager
;
43 class PushMessagingService
;
44 class ResourceContext
;
46 class StoragePartition
;
47 class SSLHostStateDelegate
;
49 // This class holds the context needed for a browsing session.
50 // It lives on the UI thread. All these methods must only be called on the UI
52 class CONTENT_EXPORT BrowserContext
: public base::SupportsUserData
{
54 static DownloadManager
* GetDownloadManager(BrowserContext
* browser_context
);
56 // Returns BrowserContext specific external mount points. It may return
57 // nullptr if the context doesn't have any BrowserContext specific external
58 // mount points. Currenty, non-nullptr value is returned only on ChromeOS.
59 static storage::ExternalMountPoints
* GetMountPoints(BrowserContext
* context
);
61 static content::StoragePartition
* GetStoragePartition(
62 BrowserContext
* browser_context
, SiteInstance
* site_instance
);
63 static content::StoragePartition
* GetStoragePartitionForSite(
64 BrowserContext
* browser_context
, const GURL
& site
);
65 typedef base::Callback
<void(StoragePartition
*)> StoragePartitionCallback
;
66 static void ForEachStoragePartition(
67 BrowserContext
* browser_context
,
68 const StoragePartitionCallback
& callback
);
69 static void AsyncObliterateStoragePartition(
70 BrowserContext
* browser_context
,
72 const base::Closure
& on_gc_required
);
74 // This function clears the contents of |active_paths| but does not take
75 // ownership of the pointer.
76 static void GarbageCollectStoragePartitions(
77 BrowserContext
* browser_context
,
78 scoped_ptr
<base::hash_set
<base::FilePath
> > active_paths
,
79 const base::Closure
& done
);
81 // DON'T USE THIS. GetDefaultStoragePartition() is going away.
82 // Use GetStoragePartition() instead. Ask ajwong@ if you have problems.
83 static content::StoragePartition
* GetDefaultStoragePartition(
84 BrowserContext
* browser_context
);
86 typedef base::Callback
<void(scoped_ptr
<BlobHandle
>)> BlobCallback
;
88 // |callback| returns a nullptr scoped_ptr on failure.
89 static void CreateMemoryBackedBlob(BrowserContext
* browser_context
,
90 const char* data
, size_t length
,
91 const BlobCallback
& callback
);
93 // |callback| returns a nullptr scoped_ptr on failure.
94 static void CreateFileBackedBlob(BrowserContext
* browser_context
,
95 const base::FilePath
& path
,
98 const base::Time
& expected_modification_time
,
99 const BlobCallback
& callback
);
101 // Delivers a push message with |data| to the Service Worker identified by
102 // |origin| and |service_worker_registration_id|.
103 static void DeliverPushMessage(
104 BrowserContext
* browser_context
,
106 int64 service_worker_registration_id
,
107 const std::string
& data
,
108 const base::Callback
<void(PushDeliveryStatus
)>& callback
);
110 static void NotifyWillBeDestroyed(BrowserContext
* browser_context
);
112 // Ensures that the corresponding ResourceContext is initialized. Normally the
113 // BrowserContext initializs the corresponding getters when its objects are
114 // created, but if the embedder wants to pass the ResourceContext to another
115 // thread before they use BrowserContext, they should call this to make sure
116 // that the ResourceContext is ready.
117 static void EnsureResourceContextInitialized(BrowserContext
* browser_context
);
119 // Tells the HTML5 objects on this context to persist their session state
120 // across the next restart.
121 static void SaveSessionState(BrowserContext
* browser_context
);
123 static void SetDownloadManagerForTesting(BrowserContext
* browser_context
,
124 DownloadManager
* download_manager
);
126 ~BrowserContext() override
;
128 // Creates a delegate to initialize a HostZoomMap and persist its information.
129 // This is called during creation of each StoragePartition.
130 virtual scoped_ptr
<ZoomLevelDelegate
> CreateZoomLevelDelegate(
131 const base::FilePath
& partition_path
) = 0;
133 // Returns the path of the directory where this context's data is stored.
134 virtual base::FilePath
GetPath() const = 0;
136 // Return whether this context is incognito. Default is false.
137 virtual bool IsOffTheRecord() const = 0;
139 // Returns the request context information associated with this context. Call
140 // this only on the UI thread, since it can send notifications that should
141 // happen on the UI thread.
142 // TODO(creis): Remove this version in favor of the one below.
143 virtual net::URLRequestContextGetter
* GetRequestContext() = 0;
145 // Returns the request context appropriate for the given renderer. If the
146 // renderer process doesn't have an associated installed app, or if the
147 // installed app doesn't have isolated storage, this is equivalent to calling
148 // GetRequestContext().
149 virtual net::URLRequestContextGetter
* GetRequestContextForRenderProcess(
150 int renderer_child_id
) = 0;
152 // Returns the default request context for media resources associated with
154 // TODO(creis): Remove this version in favor of the one below.
155 virtual net::URLRequestContextGetter
* GetMediaRequestContext() = 0;
157 // Returns the request context for media resources associated with this
158 // context and renderer process.
159 virtual net::URLRequestContextGetter
* GetMediaRequestContextForRenderProcess(
160 int renderer_child_id
) = 0;
161 virtual net::URLRequestContextGetter
*
162 GetMediaRequestContextForStoragePartition(
163 const base::FilePath
& partition_path
,
166 // Returns the resource context.
167 virtual ResourceContext
* GetResourceContext() = 0;
169 // Returns the DownloadManagerDelegate for this context. This will be called
170 // once per context. The embedder owns the delegate and is responsible for
171 // ensuring that it outlives DownloadManager. It's valid to return nullptr.
172 virtual DownloadManagerDelegate
* GetDownloadManagerDelegate() = 0;
174 // Returns the guest manager for this context.
175 virtual BrowserPluginGuestManager
* GetGuestManager() = 0;
177 // Returns a special storage policy implementation, or nullptr.
178 virtual storage::SpecialStoragePolicy
* GetSpecialStoragePolicy() = 0;
180 // Returns a push messaging service. The embedder owns the service, and is
181 // responsible for ensuring that it outlives RenderProcessHost. It's valid to
183 virtual PushMessagingService
* GetPushMessagingService() = 0;
185 // Returns the SSL host state decisions for this context. The context may
186 // return nullptr, implementing the default exception storage strategy.
187 virtual SSLHostStateDelegate
* GetSSLHostStateDelegate() = 0;
189 // Returns the PermissionManager associated with that context if any, nullptr
191 virtual PermissionManager
* GetPermissionManager() = 0;
194 } // namespace content
196 #endif // CONTENT_PUBLIC_BROWSER_BROWSER_CONTEXT_H_