browser_context.h revision cedac228d2dd51db4b79ea1e72c7f249408ee061
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. 4 5#ifndef CONTENT_PUBLIC_BROWSER_BROWSER_CONTEXT_H_ 6#define CONTENT_PUBLIC_BROWSER_BROWSER_CONTEXT_H_ 7 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 14class GURL; 15 16namespace base { 17class FilePath; 18} 19 20namespace fileapi { 21class ExternalMountPoints; 22} 23 24namespace net { 25class URLRequestContextGetter; 26} 27 28namespace quota { 29class SpecialStoragePolicy; 30} 31 32namespace content { 33 34class BlobHandle; 35class BrowserPluginGuestManager; 36class DownloadManager; 37class DownloadManagerDelegate; 38class GeolocationPermissionContext; 39class IndexedDBContext; 40class ResourceContext; 41class SiteInstance; 42class StoragePartition; 43 44// This class holds the context needed for a browsing session. 45// It lives on the UI thread. All these methods must only be called on the UI 46// thread. 47class CONTENT_EXPORT BrowserContext : public base::SupportsUserData { 48 public: 49 static DownloadManager* GetDownloadManager(BrowserContext* browser_context); 50 51 // Returns BrowserContext specific external mount points. It may return NULL 52 // if the context doesn't have any BrowserContext specific external mount 53 // points. Currenty, non-NULL value is returned only on ChromeOS. 54 static fileapi::ExternalMountPoints* GetMountPoints(BrowserContext* context); 55 56 static content::StoragePartition* GetStoragePartition( 57 BrowserContext* browser_context, SiteInstance* site_instance); 58 static content::StoragePartition* GetStoragePartitionForSite( 59 BrowserContext* browser_context, const GURL& site); 60 typedef base::Callback<void(StoragePartition*)> StoragePartitionCallback; 61 static void ForEachStoragePartition( 62 BrowserContext* browser_context, 63 const StoragePartitionCallback& callback); 64 static void AsyncObliterateStoragePartition( 65 BrowserContext* browser_context, 66 const GURL& site, 67 const base::Closure& on_gc_required); 68 69 // This function clears the contents of |active_paths| but does not take 70 // ownership of the pointer. 71 static void GarbageCollectStoragePartitions( 72 BrowserContext* browser_context, 73 scoped_ptr<base::hash_set<base::FilePath> > active_paths, 74 const base::Closure& done); 75 76 // DON'T USE THIS. GetDefaultStoragePartition() is going away. 77 // Use GetStoragePartition() instead. Ask ajwong@ if you have problems. 78 static content::StoragePartition* GetDefaultStoragePartition( 79 BrowserContext* browser_context); 80 81 typedef base::Callback<void(scoped_ptr<BlobHandle>)> BlobCallback; 82 83 // |callback| returns a NULL scoped_ptr on failure. 84 static void CreateMemoryBackedBlob(BrowserContext* browser_context, 85 const char* data, size_t length, 86 const BlobCallback& callback); 87 88 // Ensures that the corresponding ResourceContext is initialized. Normally the 89 // BrowserContext initializs the corresponding getters when its objects are 90 // created, but if the embedder wants to pass the ResourceContext to another 91 // thread before they use BrowserContext, they should call this to make sure 92 // that the ResourceContext is ready. 93 static void EnsureResourceContextInitialized(BrowserContext* browser_context); 94 95 // Tells the HTML5 objects on this context to persist their session state 96 // across the next restart. 97 static void SaveSessionState(BrowserContext* browser_context); 98 99 virtual ~BrowserContext(); 100 101 // Returns the path of the directory where this context's data is stored. 102 virtual base::FilePath GetPath() const = 0; 103 104 // Return whether this context is incognito. Default is false. 105 virtual bool IsOffTheRecord() const = 0; 106 107 // Returns the request context information associated with this context. Call 108 // this only on the UI thread, since it can send notifications that should 109 // happen on the UI thread. 110 // TODO(creis): Remove this version in favor of the one below. 111 virtual net::URLRequestContextGetter* GetRequestContext() = 0; 112 113 // Returns the request context appropriate for the given renderer. If the 114 // renderer process doesn't have an associated installed app, or if the 115 // installed app doesn't have isolated storage, this is equivalent to calling 116 // GetRequestContext(). 117 virtual net::URLRequestContextGetter* GetRequestContextForRenderProcess( 118 int renderer_child_id) = 0; 119 120 // Returns the default request context for media resources associated with 121 // this context. 122 // TODO(creis): Remove this version in favor of the one below. 123 virtual net::URLRequestContextGetter* GetMediaRequestContext() = 0; 124 125 // Returns the request context for media resources associated with this 126 // context and renderer process. 127 virtual net::URLRequestContextGetter* GetMediaRequestContextForRenderProcess( 128 int renderer_child_id) = 0; 129 virtual net::URLRequestContextGetter* 130 GetMediaRequestContextForStoragePartition( 131 const base::FilePath& partition_path, 132 bool in_memory) = 0; 133 134 typedef base::Callback<void(bool)> MidiSysExPermissionCallback; 135 136 // Requests a permission to use system exclusive messages in MIDI events. 137 // |callback| will be invoked when the request is resolved. 138 virtual void RequestMidiSysExPermission( 139 int render_process_id, 140 int render_view_id, 141 int bridge_id, 142 const GURL& requesting_frame, 143 bool user_gesture, 144 const MidiSysExPermissionCallback& callback) = 0; 145 146 // Cancels a pending MIDI permission request. 147 virtual void CancelMidiSysExPermissionRequest( 148 int render_process_id, 149 int render_view_id, 150 int bridge_id, 151 const GURL& requesting_frame) = 0; 152 153 typedef base::Callback<void(bool)> ProtectedMediaIdentifierPermissionCallback; 154 155 // Request permission to access protected media identifier. The callback will 156 // tell whether it's permitted. 157 virtual void RequestProtectedMediaIdentifierPermission( 158 int render_process_id, 159 int render_view_id, 160 const GURL& origin, 161 const ProtectedMediaIdentifierPermissionCallback& callback) = 0; 162 163 // Cancels pending protected media identifier permission requests. 164 virtual void CancelProtectedMediaIdentifierPermissionRequests( 165 int render_process_id, 166 int render_view_id, 167 const GURL& origin) = 0; 168 169 // Returns the resource context. 170 virtual ResourceContext* GetResourceContext() = 0; 171 172 // Returns the DownloadManagerDelegate for this context. This will be called 173 // once per context. The embedder owns the delegate and is responsible for 174 // ensuring that it outlives DownloadManager. It's valid to return NULL. 175 virtual DownloadManagerDelegate* GetDownloadManagerDelegate() = 0; 176 177 // Returns the geolocation permission context for this context. It's valid to 178 // return NULL, in which case geolocation requests will always be allowed. 179 virtual GeolocationPermissionContext* GetGeolocationPermissionContext() = 0; 180 181 // Returns the guest manager for this context. 182 virtual BrowserPluginGuestManager* GetGuestManager() = 0; 183 184 // Returns a special storage policy implementation, or NULL. 185 virtual quota::SpecialStoragePolicy* GetSpecialStoragePolicy() = 0; 186}; 187 188} // namespace content 189 190#if defined(COMPILER_GCC) 191namespace BASE_HASH_NAMESPACE { 192 193template<> 194struct hash<content::BrowserContext*> { 195 std::size_t operator()(content::BrowserContext* const& p) const { 196 return reinterpret_cast<std::size_t>(p); 197 } 198}; 199 200} // namespace BASE_HASH_NAMESPACE 201#endif 202 203#endif // CONTENT_PUBLIC_BROWSER_BROWSER_CONTEXT_H_ 204