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