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 PushMessagingService
;
43 class ResourceContext
;
45 class StoragePartition
;
46 class SSLHostStateDelegate
;
48 // This class holds the context needed for a browsing session.
49 // It lives on the UI thread. All these methods must only be called on the UI
51 class CONTENT_EXPORT BrowserContext
: public base::SupportsUserData
{
53 static DownloadManager
* GetDownloadManager(BrowserContext
* browser_context
);
55 // Returns BrowserContext specific external mount points. It may return
56 // nullptr if the context doesn't have any BrowserContext specific external
57 // mount points. Currenty, non-nullptr value is returned only on ChromeOS.
58 static storage::ExternalMountPoints
* GetMountPoints(BrowserContext
* context
);
60 static content::StoragePartition
* GetStoragePartition(
61 BrowserContext
* browser_context
, SiteInstance
* site_instance
);
62 static content::StoragePartition
* GetStoragePartitionForSite(
63 BrowserContext
* browser_context
, const GURL
& site
);
64 typedef base::Callback
<void(StoragePartition
*)> StoragePartitionCallback
;
65 static void ForEachStoragePartition(
66 BrowserContext
* browser_context
,
67 const StoragePartitionCallback
& callback
);
68 static void AsyncObliterateStoragePartition(
69 BrowserContext
* browser_context
,
71 const base::Closure
& on_gc_required
);
73 // This function clears the contents of |active_paths| but does not take
74 // ownership of the pointer.
75 static void GarbageCollectStoragePartitions(
76 BrowserContext
* browser_context
,
77 scoped_ptr
<base::hash_set
<base::FilePath
> > active_paths
,
78 const base::Closure
& done
);
80 // DON'T USE THIS. GetDefaultStoragePartition() is going away.
81 // Use GetStoragePartition() instead. Ask ajwong@ if you have problems.
82 static content::StoragePartition
* GetDefaultStoragePartition(
83 BrowserContext
* browser_context
);
85 typedef base::Callback
<void(scoped_ptr
<BlobHandle
>)> BlobCallback
;
87 // |callback| returns a nullptr scoped_ptr on failure.
88 static void CreateMemoryBackedBlob(BrowserContext
* browser_context
,
89 const char* data
, size_t length
,
90 const BlobCallback
& callback
);
92 // |callback| returns a nullptr scoped_ptr on failure.
93 static void CreateFileBackedBlob(BrowserContext
* browser_context
,
94 const base::FilePath
& path
,
97 const base::Time
& expected_modification_time
,
98 const BlobCallback
& callback
);
100 // Delivers a push message with |data| to the Service Worker identified by
101 // |origin| and |service_worker_registration_id|.
102 static void DeliverPushMessage(
103 BrowserContext
* browser_context
,
105 int64 service_worker_registration_id
,
106 const std::string
& data
,
107 const base::Callback
<void(PushDeliveryStatus
)>& callback
);
109 static void NotifyWillBeDestroyed(BrowserContext
* browser_context
);
111 // Ensures that the corresponding ResourceContext is initialized. Normally the
112 // BrowserContext initializs the corresponding getters when its objects are
113 // created, but if the embedder wants to pass the ResourceContext to another
114 // thread before they use BrowserContext, they should call this to make sure
115 // that the ResourceContext is ready.
116 static void EnsureResourceContextInitialized(BrowserContext
* browser_context
);
118 // Tells the HTML5 objects on this context to persist their session state
119 // across the next restart.
120 static void SaveSessionState(BrowserContext
* browser_context
);
122 ~BrowserContext() override
;
124 // Creates a delegate to initialize a HostZoomMap and persist its information.
125 // This is called during creation of each StoragePartition.
126 virtual scoped_ptr
<ZoomLevelDelegate
> CreateZoomLevelDelegate(
127 const base::FilePath
& partition_path
) = 0;
129 // Returns the path of the directory where this context's data is stored.
130 virtual base::FilePath
GetPath() const = 0;
132 // Return whether this context is incognito. Default is false.
133 virtual bool IsOffTheRecord() const = 0;
135 // Returns the request context information associated with this context. Call
136 // this only on the UI thread, since it can send notifications that should
137 // happen on the UI thread.
138 // TODO(creis): Remove this version in favor of the one below.
139 virtual net::URLRequestContextGetter
* GetRequestContext() = 0;
141 // Returns the request context appropriate for the given renderer. If the
142 // renderer process doesn't have an associated installed app, or if the
143 // installed app doesn't have isolated storage, this is equivalent to calling
144 // GetRequestContext().
145 virtual net::URLRequestContextGetter
* GetRequestContextForRenderProcess(
146 int renderer_child_id
) = 0;
148 // Returns the default request context for media resources associated with
150 // TODO(creis): Remove this version in favor of the one below.
151 virtual net::URLRequestContextGetter
* GetMediaRequestContext() = 0;
153 // Returns the request context for media resources associated with this
154 // context and renderer process.
155 virtual net::URLRequestContextGetter
* GetMediaRequestContextForRenderProcess(
156 int renderer_child_id
) = 0;
157 virtual net::URLRequestContextGetter
*
158 GetMediaRequestContextForStoragePartition(
159 const base::FilePath
& partition_path
,
162 // Returns the resource context.
163 virtual ResourceContext
* GetResourceContext() = 0;
165 // Returns the DownloadManagerDelegate for this context. This will be called
166 // once per context. The embedder owns the delegate and is responsible for
167 // ensuring that it outlives DownloadManager. It's valid to return nullptr.
168 virtual DownloadManagerDelegate
* GetDownloadManagerDelegate() = 0;
170 // Returns the guest manager for this context.
171 virtual BrowserPluginGuestManager
* GetGuestManager() = 0;
173 // Returns a special storage policy implementation, or nullptr.
174 virtual storage::SpecialStoragePolicy
* GetSpecialStoragePolicy() = 0;
176 // Returns a push messaging service. The embedder owns the service, and is
177 // responsible for ensuring that it outlives RenderProcessHost. It's valid to
179 virtual PushMessagingService
* GetPushMessagingService() = 0;
181 // Returns the SSL host state decisions for this context. The context may
182 // return nullptr, implementing the default exception storage strategy.
183 virtual SSLHostStateDelegate
* GetSSLHostStateDelegate() = 0;
186 } // namespace content
188 #endif // CONTENT_PUBLIC_BROWSER_BROWSER_CONTEXT_H_