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