browser_context.h revision 5821806d5e7f356e8fa4b058a389a808ea183019
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/supports_user_data.h" 11#include "content/common/content_export.h" 12 13namespace net { 14class URLRequestContextGetter; 15} 16 17namespace quota { 18class SpecialStoragePolicy; 19} 20 21class FilePath; 22class GURL; 23 24namespace content { 25 26class DownloadManager; 27class DownloadManagerDelegate; 28class GeolocationPermissionContext; 29class IndexedDBContext; 30class ResourceContext; 31class SiteInstance; 32class SpeechRecognitionPreferences; 33class StoragePartition; 34 35// This class holds the context needed for a browsing session. 36// It lives on the UI thread. All these methods must only be called on the UI 37// thread. 38class CONTENT_EXPORT BrowserContext : public base::SupportsUserData { 39 public: 40 // Used in ForEachStoragePartition(). The first argument is the partition id. 41 // The second argument is the StoragePartition object for that partition id. 42 typedef base::Callback<void(StoragePartition*)> StoragePartitionCallback; 43 44 static DownloadManager* GetDownloadManager(BrowserContext* browser_context); 45 46 static content::StoragePartition* GetStoragePartition( 47 BrowserContext* browser_context, SiteInstance* site_instance); 48 static content::StoragePartition* GetStoragePartitionForSite( 49 BrowserContext* browser_context, const GURL& site); 50 static void ForEachStoragePartition( 51 BrowserContext* browser_context, 52 const StoragePartitionCallback& callback); 53 54 // DON'T USE THIS. GetDefaultStoragePartition() is going away. 55 // Use GetStoragePartition() instead. Ask ajwong@ if you have problems. 56 static content::StoragePartition* GetDefaultStoragePartition( 57 BrowserContext* browser_context); 58 59 // Ensures that the corresponding ResourceContext is initialized. Normally the 60 // BrowserContext initializs the corresponding getters when its objects are 61 // created, but if the embedder wants to pass the ResourceContext to another 62 // thread before they use BrowserContext, they should call this to make sure 63 // that the ResourceContext is ready. 64 static void EnsureResourceContextInitialized(BrowserContext* browser_context); 65 66 // Tells the HTML5 objects on this context to persist their session state 67 // across the next restart. 68 static void SaveSessionState(BrowserContext* browser_context); 69 70 // Tells the HTML5 objects on this context to purge any uneeded memory. 71 static void PurgeMemory(BrowserContext* browser_context); 72 73 virtual ~BrowserContext(); 74 75 // Returns the path of the directory where this context's data is stored. 76 virtual FilePath GetPath() = 0; 77 78 // Return whether this context is incognito. Default is false. 79 // This doesn't belong here; http://crbug.com/89628 80 virtual bool IsOffTheRecord() const = 0; 81 82 // Returns the request context information associated with this context. Call 83 // this only on the UI thread, since it can send notifications that should 84 // happen on the UI thread. 85 // TODO(creis): Remove this version in favor of the one below. 86 virtual net::URLRequestContextGetter* GetRequestContext() = 0; 87 88 // Returns the request context appropriate for the given renderer. If the 89 // renderer process doesn't have an associated installed app, or if the 90 // installed app's is_storage_isolated() returns false, this is equivalent to 91 // calling GetRequestContext(). 92 virtual net::URLRequestContextGetter* GetRequestContextForRenderProcess( 93 int renderer_child_id) = 0; 94 95 virtual net::URLRequestContextGetter* GetRequestContextForStoragePartition( 96 const FilePath& partition_path, 97 bool in_memory) = 0; 98 99 // Returns the default request context for media resources associated with 100 // this context. 101 // TODO(creis): Remove this version in favor of the one below. 102 virtual net::URLRequestContextGetter* GetMediaRequestContext() = 0; 103 104 // Returns the request context for media resources associated with this 105 // context and renderer process. 106 virtual net::URLRequestContextGetter* GetMediaRequestContextForRenderProcess( 107 int renderer_child_id) = 0; 108 virtual net::URLRequestContextGetter* 109 GetMediaRequestContextForStoragePartition( 110 const FilePath& partition_path, 111 bool in_memory) = 0; 112 113 // Returns the resource context. 114 virtual ResourceContext* GetResourceContext() = 0; 115 116 // Returns the DownloadManagerDelegate for this context. This will be called 117 // once per context. The embedder owns the delegate and is responsible for 118 // ensuring that it outlives DownloadManager. It's valid to return NULL. 119 virtual DownloadManagerDelegate* GetDownloadManagerDelegate() = 0; 120 121 // Returns the geolocation permission context for this context. It's valid to 122 // return NULL, in which case geolocation requests will always be allowed. 123 virtual GeolocationPermissionContext* GetGeolocationPermissionContext() = 0; 124 125 // Returns the speech input preferences. SpeechRecognitionPreferences is a 126 // ref counted class, so callers should take a reference if needed. It's valid 127 // to return NULL. 128 virtual SpeechRecognitionPreferences* GetSpeechRecognitionPreferences() = 0; 129 130 // Returns a special storage policy implementation, or NULL. 131 virtual quota::SpecialStoragePolicy* GetSpecialStoragePolicy() = 0; 132}; 133 134} // namespace content 135 136#if defined(COMPILER_GCC) 137namespace BASE_HASH_NAMESPACE { 138 139template<> 140struct hash<content::BrowserContext*> { 141 std::size_t operator()(content::BrowserContext* const& p) const { 142 return reinterpret_cast<std::size_t>(p); 143 } 144}; 145 146} // namespace BASE_HASH_NAMESPACE 147#endif 148 149#endif // CONTENT_PUBLIC_BROWSER_BROWSER_CONTEXT_H_ 150