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