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