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_STORAGE_PARTITION_H_ 6 #define CONTENT_PUBLIC_BROWSER_STORAGE_PARTITION_H_ 7 8 #include <stdint.h> 9 10 #include <set> 11 #include <string> 12 13 #include "base/callback_forward.h" 14 #include "base/files/file_path.h" 15 #include "base/time/time.h" 16 #include "components/services/storage/public/mojom/indexed_db_control.mojom-forward.h" 17 #include "content/common/content_export.h" 18 #include "services/network/public/cpp/shared_url_loader_factory.h" 19 #include "services/network/public/mojom/cookie_manager.mojom-forward.h" 20 #include "services/network/public/mojom/restricted_cookie_manager.mojom-forward.h" 21 22 class GURL; 23 24 namespace base { 25 class Time; 26 } 27 28 namespace storage { 29 class FileSystemContext; 30 } 31 32 namespace leveldb_proto { 33 class ProtoDatabaseProvider; 34 } 35 36 namespace network { 37 namespace mojom { 38 class CookieManager; 39 class NetworkContext; 40 } 41 } // namespace network 42 43 namespace storage { 44 class QuotaManager; 45 class SpecialStoragePolicy; 46 struct QuotaSettings; 47 } 48 49 namespace storage { 50 class DatabaseTracker; 51 } 52 53 namespace content { 54 55 class AppCacheService; 56 class BackgroundSyncContext; 57 class BrowserContext; 58 class CacheStorageContext; 59 class ContentIndexContext; 60 class DedicatedWorkerService; 61 class DevToolsBackgroundServicesContext; 62 class DOMStorageContext; 63 class GeneratedCodeCacheContext; 64 class NativeFileSystemEntryFactory; 65 class PlatformNotificationContext; 66 class ServiceWorkerContext; 67 class SharedWorkerService; 68 69 #if !defined(OS_ANDROID) 70 class HostZoomLevelContext; 71 class HostZoomMap; 72 class ZoomLevelDelegate; 73 #endif // !defined(OS_ANDROID) 74 75 // Defines what persistent state a child process can access. 76 // 77 // The StoragePartition defines the view each child process has of the 78 // persistent state inside the BrowserContext. This is used to implement 79 // isolated storage where a renderer with isolated storage cannot see 80 // the cookies, localStorage, etc., that normal web renderers have access to. 81 class CONTENT_EXPORT StoragePartition { 82 public: 83 virtual base::FilePath GetPath() = 0; 84 85 // Returns a raw mojom::NetworkContext pointer. When network service crashes 86 // or restarts, the raw pointer will not be valid or safe to use. Therefore, 87 // caller should not hold onto this pointer beyond the same message loop task. 88 virtual network::mojom::NetworkContext* GetNetworkContext() = 0; 89 90 // Returns a pointer/info to a URLLoaderFactory/CookieManager owned by 91 // the storage partition. Prefer to use this instead of creating a new 92 // URLLoaderFactory when issuing requests from the Browser process, to 93 // share resources and preserve ordering. 94 // The returned info from |GetURLLoaderFactoryForBrowserProcessIOThread()| 95 // must be consumed on the IO thread to get the actual factory, and is safe to 96 // use after StoragePartition has gone. 97 // The returned SharedURLLoaderFactory can be held on and will work across 98 // network process restarts. 99 virtual scoped_refptr<network::SharedURLLoaderFactory> 100 GetURLLoaderFactoryForBrowserProcess() = 0; 101 virtual scoped_refptr<network::SharedURLLoaderFactory> 102 GetURLLoaderFactoryForBrowserProcessWithCORBEnabled() = 0; 103 virtual std::unique_ptr<network::PendingSharedURLLoaderFactory> 104 GetURLLoaderFactoryForBrowserProcessIOThread() = 0; 105 virtual network::mojom::CookieManager* 106 GetCookieManagerForBrowserProcess() = 0; 107 108 // See documentation for 109 // ContentBrowserClient::WillCreateRestrictedCookieManager for description of 110 // the parameters. The method here is expected pass things through that hook 111 // and then go to the NetworkContext if needed. 112 virtual void CreateRestrictedCookieManager( 113 network::mojom::RestrictedCookieManagerRole role, 114 const url::Origin& origin, 115 const net::SiteForCookies& site_for_cookies, 116 const url::Origin& top_frame_origin, 117 bool is_service_worker, 118 int process_id, 119 int routing_id, 120 mojo::PendingReceiver<network::mojom::RestrictedCookieManager> 121 receiver) = 0; 122 123 virtual storage::QuotaManager* GetQuotaManager() = 0; 124 virtual AppCacheService* GetAppCacheService() = 0; 125 virtual BackgroundSyncContext* GetBackgroundSyncContext() = 0; 126 virtual storage::FileSystemContext* GetFileSystemContext() = 0; 127 virtual storage::DatabaseTracker* GetDatabaseTracker() = 0; 128 virtual DOMStorageContext* GetDOMStorageContext() = 0; 129 virtual storage::mojom::IndexedDBControl& GetIndexedDBControl() = 0; 130 virtual NativeFileSystemEntryFactory* GetNativeFileSystemEntryFactory() = 0; 131 virtual ServiceWorkerContext* GetServiceWorkerContext() = 0; 132 virtual DedicatedWorkerService* GetDedicatedWorkerService() = 0; 133 virtual SharedWorkerService* GetSharedWorkerService() = 0; 134 virtual CacheStorageContext* GetCacheStorageContext() = 0; 135 virtual GeneratedCodeCacheContext* GetGeneratedCodeCacheContext() = 0; 136 virtual DevToolsBackgroundServicesContext* 137 GetDevToolsBackgroundServicesContext() = 0; 138 virtual ContentIndexContext* GetContentIndexContext() = 0; 139 #if !defined(OS_ANDROID) 140 virtual HostZoomMap* GetHostZoomMap() = 0; 141 virtual HostZoomLevelContext* GetHostZoomLevelContext() = 0; 142 virtual ZoomLevelDelegate* GetZoomLevelDelegate() = 0; 143 #endif // !defined(OS_ANDROID) 144 virtual PlatformNotificationContext* GetPlatformNotificationContext() = 0; 145 146 virtual leveldb_proto::ProtoDatabaseProvider* GetProtoDatabaseProvider() = 0; 147 // Must be set before the first call to GetProtoDatabaseProvider(), or a new 148 // one will be created by get. 149 virtual void SetProtoDatabaseProvider( 150 std::unique_ptr<leveldb_proto::ProtoDatabaseProvider> 151 optional_proto_db_provider) = 0; 152 153 enum : uint32_t { 154 REMOVE_DATA_MASK_APPCACHE = 1 << 0, 155 REMOVE_DATA_MASK_COOKIES = 1 << 1, 156 REMOVE_DATA_MASK_FILE_SYSTEMS = 1 << 2, 157 REMOVE_DATA_MASK_INDEXEDDB = 1 << 3, 158 REMOVE_DATA_MASK_LOCAL_STORAGE = 1 << 4, 159 REMOVE_DATA_MASK_SHADER_CACHE = 1 << 5, 160 REMOVE_DATA_MASK_WEBSQL = 1 << 6, 161 REMOVE_DATA_MASK_SERVICE_WORKERS = 1 << 7, 162 REMOVE_DATA_MASK_CACHE_STORAGE = 1 << 8, 163 REMOVE_DATA_MASK_PLUGIN_PRIVATE_DATA = 1 << 9, 164 REMOVE_DATA_MASK_BACKGROUND_FETCH = 1 << 10, 165 REMOVE_DATA_MASK_ALL = 0xFFFFFFFF, 166 167 // Corresponds to storage::kStorageTypeTemporary. 168 QUOTA_MANAGED_STORAGE_MASK_TEMPORARY = 1 << 0, 169 // Corresponds to storage::kStorageTypePersistent. 170 QUOTA_MANAGED_STORAGE_MASK_PERSISTENT = 1 << 1, 171 // Corresponds to storage::kStorageTypeSyncable. 172 QUOTA_MANAGED_STORAGE_MASK_SYNCABLE = 1 << 2, 173 QUOTA_MANAGED_STORAGE_MASK_ALL = 0xFFFFFFFF, 174 }; 175 176 // Starts an asynchronous task that does a best-effort clear the data 177 // corresponding to the given |remove_mask| and |quota_storage_remove_mask| 178 // inside this StoragePartition for the given |storage_origin|. 179 // Note session dom storage is not cleared even if you specify 180 // REMOVE_DATA_MASK_LOCAL_STORAGE. 181 // No notification is dispatched upon completion. 182 // 183 // TODO(ajwong): Right now, the embedder may have some 184 // URLRequestContextGetter objects that the StoragePartition does not know 185 // about. This will no longer be the case when we resolve 186 // http://crbug.com/159193. Remove |request_context_getter| when that bug 187 // is fixed. 188 virtual void ClearDataForOrigin(uint32_t remove_mask, 189 uint32_t quota_storage_remove_mask, 190 const GURL& storage_origin) = 0; 191 192 // A callback type to check if a given origin matches a storage policy. 193 // Can be passed empty/null where used, which means the origin will always 194 // match. 195 using OriginMatcherFunction = 196 base::RepeatingCallback<bool(const url::Origin&, 197 storage::SpecialStoragePolicy*)>; 198 199 // Similar to ClearDataForOrigin(). 200 // Deletes all data out for the StoragePartition if |storage_origin| is empty. 201 // |callback| is called when data deletion is done or at least the deletion is 202 // scheduled. 203 virtual void ClearData(uint32_t remove_mask, 204 uint32_t quota_storage_remove_mask, 205 const GURL& storage_origin, 206 const base::Time begin, 207 const base::Time end, 208 base::OnceClosure callback) = 0; 209 210 // Similar to ClearData(). 211 // Deletes all data out for the StoragePartition. 212 // * |origin_matcher| is present if special storage policy is to be handled, 213 // otherwise the callback should be null (base::Callback::is_null()==true). 214 // The origin matcher does not apply to cookies, instead use: 215 // * |cookie_deletion_filter| identifies the cookies to delete and will be 216 // used if |remove_mask| has the REMOVE_DATA_MASK_COOKIES bit set. Note: 217 // CookieDeletionFilterPtr also contains a time interval 218 // (created_after_time/created_before_time), so when deleting cookies 219 // |begin| and |end| will be used ignoring the interval in 220 // |cookie_deletion_filter|. 221 // If |perform_storage_cleanup| is true, the storage will try to remove 222 // traces about deleted data from disk. This is an expensive operation that 223 // should only be performed if we are sure that almost all data will be 224 // deleted anyway. 225 // * |callback| is called when data deletion is done or at least the deletion 226 // is scheduled. 227 // Note: Make sure you know what you are doing before clearing cookies 228 // selectively. You don't want to break the web. 229 virtual void ClearData( 230 uint32_t remove_mask, 231 uint32_t quota_storage_remove_mask, 232 OriginMatcherFunction origin_matcher, 233 network::mojom::CookieDeletionFilterPtr cookie_deletion_filter, 234 bool perform_storage_cleanup, 235 const base::Time begin, 236 const base::Time end, 237 base::OnceClosure callback) = 0; 238 239 // Clears code caches associated with this StoragePartition. 240 // If |begin| and |end| are not null, only entries with 241 // timestamps inbetween are deleted. If |url_matcher| is not null, only 242 // entries with URLs for which the |url_matcher| returns true are deleted. 243 virtual void ClearCodeCaches( 244 base::Time begin, 245 base::Time end, 246 const base::RepeatingCallback<bool(const GURL&)>& url_matcher, 247 base::OnceClosure callback) = 0; 248 249 // Write any unwritten data to disk. 250 // Note: this method does not sync the data - it only ensures that any 251 // unwritten data has been written out to the filesystem. 252 virtual void Flush() = 0; 253 254 // Resets all URLLoaderFactories bound to this partition's network context. 255 virtual void ResetURLLoaderFactories() = 0; 256 257 // Clear the bluetooth allowed devices map. For test use only. 258 virtual void ClearBluetoothAllowedDevicesMapForTesting() = 0; 259 260 // Call |FlushForTesting()| on Network Service related interfaces. For test 261 // use only. 262 virtual void FlushNetworkInterfaceForTesting() = 0; 263 264 // Wait until all deletions tasks are finished. For test use only. 265 virtual void WaitForDeletionTasksForTesting() = 0; 266 267 // Wait until code cache's shutdown is complete. For test use only. 268 virtual void WaitForCodeCacheShutdownForTesting() = 0; 269 270 // The value pointed to by |settings| should remain valid until the 271 // the function is called again with a new value or a nullptr. 272 static void SetDefaultQuotaSettingsForTesting( 273 const storage::QuotaSettings* settings); 274 275 static bool IsAppCacheEnabled(); 276 277 protected: ~StoragePartition()278 virtual ~StoragePartition() {} 279 }; 280 281 } // namespace content 282 283 #endif // CONTENT_PUBLIC_BROWSER_STORAGE_PARTITION_H_ 284