• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/memory/ref_counted.h"
13 #include "extensions/browser/api/storage/settings_storage_quota_enforcer.h"
14 #include "extensions/browser/api/storage/value_store_cache.h"
15 
16 namespace value_store {
17 class ValueStoreFactory;
18 }
19 
20 namespace extensions {
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(
29       scoped_refptr<value_store::ValueStoreFactory> factory);
30 
31   SyncValueStoreCache(const SyncValueStoreCache&) = delete;
32   SyncValueStoreCache& operator=(const SyncValueStoreCache&) = delete;
33 
34   ~SyncValueStoreCache() override;
35 
36   // ValueStoreCache implementation:
37   void RunWithValueStoreForExtension(
38       StorageCallback callback,
39       scoped_refptr<const Extension> extension) override;
40   void DeleteStorageSoon(const std::string& extension_id) override;
41 
42  private:
43   using StorageMap =
44       std::map<std::string, std::unique_ptr<value_store::ValueStore>>;
45 
46   value_store::ValueStore* GetStorage(const Extension* extension);
47 
48   // The Factory to use for creating new ValueStores.
49   const scoped_refptr<value_store::ValueStoreFactory> storage_factory_;
50 
51   // Quota limits (see SettingsStorageQuotaEnforcer).
52   const SettingsStorageQuotaEnforcer::Limits quota_;
53 
54   // The collection of ValueStores for local storage.
55   StorageMap storage_map_;
56 };
57 
58 }  // namespace cef
59 }  // namespace extensions
60 
61 #endif  // CEF_LIBCEF_BROWSER_EXTENSIONS_API_STORAGE_SYNC_VALUE_STORE_CACHE_H_
62