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 ~BrowserContext() override
;
125 // Creates a delegate to initialize a HostZoomMap and persist its information.
126 // This is called during creation of each StoragePartition.
127 virtual scoped_ptr
<ZoomLevelDelegate
> CreateZoomLevelDelegate(
128 const base::FilePath
& partition_path
) = 0;
130 // Returns the path of the directory where this context's data is stored.
131 virtual base::FilePath
GetPath() const = 0;
133 // Return whether this context is incognito. Default is false.
134 virtual bool IsOffTheRecord() const = 0;
136 // Returns the request context information associated with this context. Call
137 // this only on the UI thread, since it can send notifications that should
138 // happen on the UI thread.
139 // TODO(creis): Remove this version in favor of the one below.
140 virtual net::URLRequestContextGetter
* GetRequestContext() = 0;
142 // Returns the request context appropriate for the given renderer. If the
143 // renderer process doesn't have an associated installed app, or if the
144 // installed app doesn't have isolated storage, this is equivalent to calling
145 // GetRequestContext().
146 virtual net::URLRequestContextGetter
* GetRequestContextForRenderProcess(
147 int renderer_child_id
) = 0;
149 // Returns the default request context for media resources associated with
151 // TODO(creis): Remove this version in favor of the one below.
152 virtual net::URLRequestContextGetter
* GetMediaRequestContext() = 0;
154 // Returns the request context for media resources associated with this
155 // context and renderer process.
156 virtual net::URLRequestContextGetter
* GetMediaRequestContextForRenderProcess(
157 int renderer_child_id
) = 0;
158 virtual net::URLRequestContextGetter
*
159 GetMediaRequestContextForStoragePartition(
160 const base::FilePath
& partition_path
,
163 // Returns the resource context.
164 virtual ResourceContext
* GetResourceContext() = 0;
166 // Returns the DownloadManagerDelegate for this context. This will be called
167 // once per context. The embedder owns the delegate and is responsible for
168 // ensuring that it outlives DownloadManager. It's valid to return nullptr.
169 virtual DownloadManagerDelegate
* GetDownloadManagerDelegate() = 0;
171 // Returns the guest manager for this context.
172 virtual BrowserPluginGuestManager
* GetGuestManager() = 0;
174 // Returns a special storage policy implementation, or nullptr.
175 virtual storage::SpecialStoragePolicy
* GetSpecialStoragePolicy() = 0;
177 // Returns a push messaging service. The embedder owns the service, and is
178 // responsible for ensuring that it outlives RenderProcessHost. It's valid to
180 virtual PushMessagingService
* GetPushMessagingService() = 0;
182 // Returns the SSL host state decisions for this context. The context may
183 // return nullptr, implementing the default exception storage strategy.
184 virtual SSLHostStateDelegate
* GetSSLHostStateDelegate() = 0;
186 // Returns the PermissionManager associated with that context if any, nullptr
188 virtual PermissionManager
* GetPermissionManager() = 0;
191 } // namespace content
193 #endif // CONTENT_PUBLIC_BROWSER_BROWSER_CONTEXT_H_