1 // Copyright 2017 The Chromium Embedded Framework Authors. 2 // Portions copyright 2014 The Chromium Authors. All rights reserved. 3 // Use of this source code is governed by a BSD-style license that can be 4 // found in the LICENSE file. 5 6 #ifndef CEF_LIBCEF_BROWSER_EXTENSIONS_API_STORAGE_SYNC_VALUE_STORE_CACHE_H_ 7 #define CEF_LIBCEF_BROWSER_EXTENSIONS_API_STORAGE_SYNC_VALUE_STORE_CACHE_H_ 8 9 #include <memory> 10 11 #include "base/compiler_specific.h" 12 #include "base/macros.h" 13 #include "base/memory/ref_counted.h" 14 #include "extensions/browser/api/storage/settings_storage_quota_enforcer.h" 15 #include "extensions/browser/api/storage/value_store_cache.h" 16 17 namespace extensions { 18 19 class ValueStoreFactory; 20 21 namespace cef { 22 23 // Based on LocalValueStoreCache 24 // ValueStoreCache for the SYNC namespace. It owns a backend for apps and 25 // another for extensions. Each backend takes care of persistence. 26 class SyncValueStoreCache : public ValueStoreCache { 27 public: 28 explicit SyncValueStoreCache(const scoped_refptr<ValueStoreFactory>& factory); 29 ~SyncValueStoreCache() override; 30 31 // ValueStoreCache implementation: 32 void RunWithValueStoreForExtension( 33 StorageCallback callback, 34 scoped_refptr<const Extension> extension) override; 35 void DeleteStorageSoon(const std::string& extension_id) override; 36 37 private: 38 using StorageMap = std::map<std::string, std::unique_ptr<ValueStore>>; 39 40 ValueStore* GetStorage(const Extension* extension); 41 42 // The Factory to use for creating new ValueStores. 43 const scoped_refptr<ValueStoreFactory> storage_factory_; 44 45 // Quota limits (see SettingsStorageQuotaEnforcer). 46 const SettingsStorageQuotaEnforcer::Limits quota_; 47 48 // The collection of ValueStores for local storage. 49 StorageMap storage_map_; 50 51 DISALLOW_COPY_AND_ASSIGN(SyncValueStoreCache); 52 }; 53 } // namespace cef 54 } // namespace extensions 55 56 #endif // CEF_LIBCEF_BROWSER_EXTENSIONS_API_STORAGE_SYNC_VALUE_STORE_CACHE_H_ 57