OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_EXTENSIONS_API_STORAGE_SYNC_VALUE_STORE_CACHE_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_STORAGE_SYNC_VALUE_STORE_CACHE_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_API_STORAGE_SYNC_VALUE_STORE_CACHE_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_API_STORAGE_SYNC_VALUE_STORE_CACHE_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <string> | |
10 | 9 |
11 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
12 #include "base/macros.h" | 11 #include "base/macros.h" |
13 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
14 #include "base/memory/weak_ptr.h" | |
15 #include "components/sync/model/syncable_service.h" | 13 #include "components/sync/model/syncable_service.h" |
16 #include "extensions/browser/api/storage/settings_observer.h" | 14 #include "extensions/browser/api/storage/settings_observer.h" |
17 #include "extensions/browser/api/storage/value_store_cache.h" | 15 #include "extensions/browser/api/storage/value_store_cache.h" |
18 | 16 |
19 namespace base { | 17 namespace base { |
20 class FilePath; | 18 class FilePath; |
21 } | 19 } |
22 | 20 |
23 namespace syncer { | 21 namespace syncer { |
24 class SyncableService; | 22 class SyncableService; |
25 } | 23 } |
26 | 24 |
27 namespace extensions { | 25 namespace extensions { |
28 | 26 |
29 class SyncStorageBackend; | 27 class SyncStorageBackend; |
30 class ValueStoreFactory; | 28 class ValueStoreFactory; |
31 | 29 |
32 // ValueStoreCache for the SYNC namespace. It owns a backend for apps and | 30 // ValueStoreCache for the SYNC namespace. It owns a backend for apps and |
33 // another for extensions. Each backend takes care of persistence and syncing. | 31 // another for extensions. Each backend takes care of persistence and syncing. |
34 class SyncValueStoreCache : public ValueStoreCache { | 32 class SyncValueStoreCache : public ValueStoreCache { |
35 public: | 33 public: |
36 SyncValueStoreCache(const scoped_refptr<ValueStoreFactory>& factory, | 34 SyncValueStoreCache(const scoped_refptr<ValueStoreFactory>& factory, |
37 const scoped_refptr<SettingsObserverList>& observers, | 35 const scoped_refptr<SettingsObserverList>& observers, |
38 const base::FilePath& profile_path); | 36 const base::FilePath& profile_path); |
39 ~SyncValueStoreCache() override; | 37 ~SyncValueStoreCache() override; |
40 | 38 |
41 base::WeakPtr<SyncValueStoreCache> AsWeakPtr(); | |
42 | |
43 syncer::SyncableService* GetSyncableService(syncer::ModelType type) const; | 39 syncer::SyncableService* GetSyncableService(syncer::ModelType type) const; |
44 | 40 |
45 // ValueStoreCache implementation: | 41 // ValueStoreCache implementation: |
46 void RunWithValueStoreForExtension( | 42 void RunWithValueStoreForExtension( |
47 const StorageCallback& callback, | 43 const StorageCallback& callback, |
48 scoped_refptr<const Extension> extension) override; | 44 scoped_refptr<const Extension> extension) override; |
49 void DeleteStorageSoon(const std::string& extension_id) override; | 45 void DeleteStorageSoon(const std::string& extension_id) override; |
50 | 46 |
51 private: | 47 private: |
52 void InitOnFileThread(const scoped_refptr<ValueStoreFactory>& factory, | 48 void InitOnFileThread(const scoped_refptr<ValueStoreFactory>& factory, |
53 const scoped_refptr<SettingsObserverList>& observers, | 49 const scoped_refptr<SettingsObserverList>& observers, |
54 const base::FilePath& profile_path); | 50 const base::FilePath& profile_path); |
55 | 51 |
56 bool initialized_; | 52 bool initialized_; |
57 std::unique_ptr<SyncStorageBackend> app_backend_; | 53 std::unique_ptr<SyncStorageBackend> app_backend_; |
58 std::unique_ptr<SyncStorageBackend> extension_backend_; | 54 std::unique_ptr<SyncStorageBackend> extension_backend_; |
59 base::WeakPtrFactory<SyncValueStoreCache> weak_ptr_factory_; | |
60 | 55 |
61 DISALLOW_COPY_AND_ASSIGN(SyncValueStoreCache); | 56 DISALLOW_COPY_AND_ASSIGN(SyncValueStoreCache); |
62 }; | 57 }; |
63 | 58 |
64 } // namespace extensions | 59 } // namespace extensions |
65 | 60 |
66 #endif // CHROME_BROWSER_EXTENSIONS_API_STORAGE_SYNC_VALUE_STORE_CACHE_H_ | 61 #endif // CHROME_BROWSER_EXTENSIONS_API_STORAGE_SYNC_VALUE_STORE_CACHE_H_ |
OLD | NEW |