browser_context.h revision c2e0dbddbe15c98d52c4786dac06cb8952a8ae6d
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#include "ui/base/clipboard/clipboard_sourcetag.h" 14 15class GURL; 16 17namespace base { 18class FilePath; 19} 20 21namespace fileapi { 22class ExternalMountPoints; 23} 24 25namespace net { 26class URLRequestContextGetter; 27} 28 29namespace quota { 30class SpecialStoragePolicy; 31} 32 33namespace content { 34 35class DownloadManager; 36class DownloadManagerDelegate; 37class GeolocationPermissionContext; 38class IndexedDBContext; 39class ResourceContext; 40class SiteInstance; 41class SpeechRecognitionPreferences; 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 // Used in ForEachStoragePartition(). The first argument is the partition id. 50 // The second argument is the StoragePartition object for that partition id. 51 typedef base::Callback<void(StoragePartition*)> StoragePartitionCallback; 52 53 static DownloadManager* GetDownloadManager(BrowserContext* browser_context); 54 55 // Returns BrowserContext specific external mount points. It may return NULL 56 // if the context doesn't have any BrowserContext specific external mount 57 // points. Currenty, non-NULL value is returned only on ChromeOS. 58 static fileapi::ExternalMountPoints* GetMountPoints(BrowserContext* context); 59 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 static void ForEachStoragePartition( 65 BrowserContext* browser_context, 66 const StoragePartitionCallback& callback); 67 static void AsyncObliterateStoragePartition( 68 BrowserContext* browser_context, 69 const GURL& site, 70 const base::Closure& on_gc_required); 71 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); 78 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); 83 84 // Ensures that the corresponding ResourceContext is initialized. Normally the 85 // BrowserContext initializs the corresponding getters when its objects are 86 // created, but if the embedder wants to pass the ResourceContext to another 87 // thread before they use BrowserContext, they should call this to make sure 88 // that the ResourceContext is ready. 89 static void EnsureResourceContextInitialized(BrowserContext* browser_context); 90 91 // Tells the HTML5 objects on this context to persist their session state 92 // across the next restart. 93 static void SaveSessionState(BrowserContext* browser_context); 94 95 // Tells the HTML5 objects on this context to purge any uneeded memory. 96 static void PurgeMemory(BrowserContext* browser_context); 97 98 // Returns a Clipboard::SourceTag (pointer) if |context| is OffTheRecord 99 // context. Otherwise, NULL. If the clipboard contains that SourceTag at the 100 // time of |context| destruction it will be flushed. 101 static ui::SourceTag GetMarkerForOffTheRecordContext(BrowserContext* context); 102 103 virtual ~BrowserContext(); 104 105 // Returns the path of the directory where this context's data is stored. 106 virtual base::FilePath GetPath() = 0; 107 108 // Return whether this context is incognito. Default is false. 109 virtual bool IsOffTheRecord() const = 0; 110 111 // Returns the request context information associated with this context. Call 112 // this only on the UI thread, since it can send notifications that should 113 // happen on the UI thread. 114 // TODO(creis): Remove this version in favor of the one below. 115 virtual net::URLRequestContextGetter* GetRequestContext() = 0; 116 117 // Returns the request context appropriate for the given renderer. If the 118 // renderer process doesn't have an associated installed app, or if the 119 // installed app doesn't have isolated storage, this is equivalent to calling 120 // GetRequestContext(). 121 virtual net::URLRequestContextGetter* GetRequestContextForRenderProcess( 122 int renderer_child_id) = 0; 123 124 // Returns the default request context for media resources associated with 125 // this context. 126 // TODO(creis): Remove this version in favor of the one below. 127 virtual net::URLRequestContextGetter* GetMediaRequestContext() = 0; 128 129 // Returns the request context for media resources associated with this 130 // context and renderer process. 131 virtual net::URLRequestContextGetter* GetMediaRequestContextForRenderProcess( 132 int renderer_child_id) = 0; 133 virtual net::URLRequestContextGetter* 134 GetMediaRequestContextForStoragePartition( 135 const base::FilePath& partition_path, 136 bool in_memory) = 0; 137 138 // Returns the resource context. 139 virtual ResourceContext* GetResourceContext() = 0; 140 141 // Returns the DownloadManagerDelegate for this context. This will be called 142 // once per context. The embedder owns the delegate and is responsible for 143 // ensuring that it outlives DownloadManager. It's valid to return NULL. 144 virtual DownloadManagerDelegate* GetDownloadManagerDelegate() = 0; 145 146 // Returns the geolocation permission context for this context. It's valid to 147 // return NULL, in which case geolocation requests will always be allowed. 148 virtual GeolocationPermissionContext* GetGeolocationPermissionContext() = 0; 149 150 // Returns the speech input preferences. SpeechRecognitionPreferences is a 151 // ref counted class, so callers should take a reference if needed. It's valid 152 // to return NULL. 153 virtual SpeechRecognitionPreferences* GetSpeechRecognitionPreferences() = 0; 154 155 // Returns a special storage policy implementation, or NULL. 156 virtual quota::SpecialStoragePolicy* GetSpecialStoragePolicy() = 0; 157}; 158 159} // namespace content 160 161#if defined(COMPILER_GCC) 162namespace BASE_HASH_NAMESPACE { 163 164template<> 165struct hash<content::BrowserContext*> { 166 std::size_t operator()(content::BrowserContext* const& p) const { 167 return reinterpret_cast<std::size_t>(p); 168 } 169}; 170 171} // namespace BASE_HASH_NAMESPACE 172#endif 173 174#endif // CONTENT_PUBLIC_BROWSER_BROWSER_CONTEXT_H_ 175