1 // Copyright 2014 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_BROWSER_CACHE_STORAGE_CACHE_STORAGE_MANAGER_H_ 6 #define CONTENT_BROWSER_CACHE_STORAGE_CACHE_STORAGE_MANAGER_H_ 7 8 #include <string> 9 10 #include "base/macros.h" 11 #include "content/browser/blob_storage/blob_storage_context_wrapper.h" 12 #include "content/browser/cache_storage/cache_storage_handle.h" 13 #include "content/common/content_export.h" 14 #include "content/public/browser/browser_thread.h" 15 #include "content/public/browser/cache_storage_context.h" 16 #include "content/public/browser/storage_usage_info.h" 17 #include "storage/browser/quota/quota_client.h" 18 19 namespace url { 20 class Origin; 21 } 22 23 namespace content { 24 25 enum class CacheStorageOwner { 26 kMinValue, 27 28 // Caches that can be accessed by the JS CacheStorage API (developer facing). 29 kCacheAPI = kMinValue, 30 31 // Private cache to store background fetch downloads. 32 kBackgroundFetch, 33 34 kMaxValue = kBackgroundFetch 35 }; 36 37 // Keeps track of a CacheStorage per origin. There is one CacheStorageManager 38 // per CacheStorageOwner. Created and accessed from a single sequence. 39 // TODO(jkarlin): Remove CacheStorage from memory once they're no 40 // longer in active use. 41 class CONTENT_EXPORT CacheStorageManager 42 : public base::RefCounted<CacheStorageManager> { 43 public: 44 // Open the CacheStorage for the given origin and owner. A reference counting 45 // handle is returned which can be stored and used similar to a weak pointer. 46 virtual CacheStorageHandle OpenCacheStorage(const url::Origin& origin, 47 CacheStorageOwner owner) = 0; 48 49 // QuotaClient and Browsing Data Deletion support. 50 virtual void GetAllOriginsUsage( 51 CacheStorageOwner owner, 52 CacheStorageContext::GetUsageInfoCallback callback) = 0; 53 virtual void GetOriginUsage( 54 const url::Origin& origin_url, 55 CacheStorageOwner owner, 56 storage::QuotaClient::GetUsageCallback callback) = 0; 57 virtual void GetOrigins( 58 CacheStorageOwner owner, 59 storage::QuotaClient::GetOriginsCallback callback) = 0; 60 virtual void GetOriginsForHost( 61 const std::string& host, 62 CacheStorageOwner owner, 63 storage::QuotaClient::GetOriginsCallback callback) = 0; 64 virtual void DeleteOriginData( 65 const url::Origin& origin, 66 CacheStorageOwner owner, 67 storage::QuotaClient::DeletionCallback callback) = 0; 68 virtual void DeleteOriginData(const url::Origin& origin, 69 CacheStorageOwner owner) = 0; 70 71 // This must be called before any of the public Cache functions above. 72 virtual void SetBlobParametersForCache( 73 scoped_refptr<BlobStorageContextWrapper> blob_storage_context) = 0; 74 75 static bool IsValidQuotaOrigin(const url::Origin& origin); 76 77 protected: 78 friend class base::RefCounted<CacheStorageManager>; 79 80 CacheStorageManager() = default; 81 virtual ~CacheStorageManager() = default; 82 }; 83 84 } // namespace content 85 86 #endif // CONTENT_BROWSER_CACHE_STORAGE_CACHE_STORAGE_MANAGER_H_ 87