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 EXTENSIONS_BROWSER_API_STORAGE_LOCAL_VALUE_STORE_CACHE_H_ 6 #define EXTENSIONS_BROWSER_API_STORAGE_LOCAL_VALUE_STORE_CACHE_H_ 7 8 #include "base/basictypes.h" 9 #include "base/compiler_specific.h" 10 #include "base/files/file_path.h" 11 #include "base/memory/linked_ptr.h" 12 #include "base/memory/ref_counted.h" 13 #include "base/memory/scoped_ptr.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 SettingsStorageFactory; 20 21 // ValueStoreCache for the LOCAL namespace. It owns a backend for apps and 22 // another for extensions. Each backend takes care of persistence. 23 class LocalValueStoreCache : public ValueStoreCache { 24 public: 25 LocalValueStoreCache(const scoped_refptr<SettingsStorageFactory>& factory, 26 const base::FilePath& profile_path); 27 virtual ~LocalValueStoreCache(); 28 29 // ValueStoreCache implementation: 30 virtual void RunWithValueStoreForExtension( 31 const StorageCallback& callback, 32 scoped_refptr<const Extension> extension) OVERRIDE; 33 virtual void DeleteStorageSoon(const std::string& extension_id) OVERRIDE; 34 35 private: 36 typedef std::map<std::string, linked_ptr<ValueStore> > StorageMap; 37 38 ValueStore* GetStorage(scoped_refptr<const Extension> extension); 39 40 // The Factory to use for creating new ValueStores. 41 const scoped_refptr<SettingsStorageFactory> storage_factory_; 42 43 // The base path to use for extensions when creating new ValueStores. 44 const base::FilePath extension_base_path_; 45 46 // The base path to use for apps when creating new ValueStores. 47 const base::FilePath app_base_path_; 48 49 // Quota limits (see SettingsStorageQuotaEnforcer). 50 const SettingsStorageQuotaEnforcer::Limits quota_; 51 52 // The collection of ValueStores for local storage. 53 StorageMap storage_map_; 54 55 DISALLOW_COPY_AND_ASSIGN(LocalValueStoreCache); 56 }; 57 58 } // namespace extensions 59 60 #endif // EXTENSIONS_BROWSER_API_STORAGE_LOCAL_VALUE_STORE_CACHE_H_ 61