OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 SERVICES_PREFERENCES_PUBLIC_CPP_PREF_STORE_IMPL_H_ | 5 #ifndef SERVICES_PREFERENCES_PUBLIC_CPP_PREF_STORE_IMPL_H_ |
6 #define SERVICES_PREFERENCES_PUBLIC_CPP_PREF_STORE_IMPL_H_ | 6 #define SERVICES_PREFERENCES_PUBLIC_CPP_PREF_STORE_IMPL_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "components/prefs/pref_store.h" | 12 #include "components/prefs/pref_store.h" |
13 #include "components/prefs/pref_value_store.h" | 13 #include "components/prefs/pref_value_store.h" |
14 #include "mojo/public/cpp/bindings/binding.h" | 14 #include "mojo/public/cpp/bindings/binding.h" |
15 #include "services/preferences/public/interfaces/preferences.mojom.h" | 15 #include "services/preferences/public/interfaces/preferences.mojom.h" |
16 | 16 |
17 namespace prefs { | 17 namespace prefs { |
18 | 18 |
19 // Wraps an actual PrefStore implementation and exposes it as a | 19 // Wraps an actual PrefStore implementation and exposes it as a |
20 // mojom::PrefStore interface. | 20 // mojom::PrefStore interface. |
21 class PrefStoreImpl : public ::PrefStore::Observer, public mojom::PrefStore { | 21 class PrefStoreImpl : public ::PrefStore::Observer, public mojom::PrefStore { |
22 public: | 22 public: |
23 PrefStoreImpl(scoped_refptr<::PrefStore> pref_store, | 23 PrefStoreImpl(scoped_refptr<::PrefStore> pref_store, |
24 mojom::PrefStoreRequest request); | 24 mojom::PrefStoreRequest request); |
25 ~PrefStoreImpl() override; | 25 ~PrefStoreImpl() override; |
26 | 26 |
27 // The created instance is registered in and owned by the | 27 // The created instance is registered in and owned by the |
28 // |mojom::PrefStoreRegistry|. | 28 // |mojom::PrefStoreRegistry|. |
29 static std::unique_ptr<PrefStoreImpl> Create( | 29 static std::unique_ptr<PrefStoreImpl> Create( |
30 mojom::PrefStoreRegistryPtr registry_ptr, | 30 mojom::PrefStoreRegistry* registry_ptr, |
31 scoped_refptr<::PrefStore> pref_store, | 31 scoped_refptr<::PrefStore> pref_store, |
32 PrefValueStore::PrefStoreType type); | 32 PrefValueStore::PrefStoreType type); |
33 | 33 |
34 private: | 34 private: |
| 35 class Observer; |
| 36 |
35 // PrefStore::Observer: | 37 // PrefStore::Observer: |
36 void OnPrefValueChanged(const std::string& key) override; | 38 void OnPrefValueChanged(const std::string& key) override; |
37 void OnInitializationCompleted(bool succeeded) override; | 39 void OnInitializationCompleted(bool succeeded) override; |
38 | 40 |
39 // prefs::mojom::PrefStore: | 41 // prefs::mojom::PrefStore: |
40 void AddObserver(const AddObserverCallback& callback) override; | 42 void AddObserver(const std::vector<std::string>& prefs_to_observe, |
| 43 const AddObserverCallback& callback) override; |
41 | 44 |
42 // The backing store we observer for changes. | 45 // The backing store we observer for changes. |
43 scoped_refptr<::PrefStore> backing_pref_store_; | 46 scoped_refptr<::PrefStore> backing_pref_store_; |
44 | 47 |
45 // Observers we notify when |backing_pref_store_| changes. | 48 // Observers we notify when |backing_pref_store_| changes. |
46 std::vector<mojom::PrefStoreObserverPtr> observers_; | 49 std::vector<std::unique_ptr<Observer>> observers_; |
47 | 50 |
48 // True when the |backing_pref_store_| is initialized, either because it was | 51 // True when the |backing_pref_store_| is initialized, either because it was |
49 // passed already initialized in the constructor or after | 52 // passed already initialized in the constructor or after |
50 // OnInitializationCompleted was called. | 53 // OnInitializationCompleted was called. |
51 bool backing_pref_store_initialized_; | 54 bool backing_pref_store_initialized_; |
52 | 55 |
53 mojo::Binding<mojom::PrefStore> binding_; | 56 mojo::Binding<mojom::PrefStore> binding_; |
54 | 57 |
55 DISALLOW_COPY_AND_ASSIGN(PrefStoreImpl); | 58 DISALLOW_COPY_AND_ASSIGN(PrefStoreImpl); |
56 }; | 59 }; |
57 | 60 |
58 } // namespace prefs | 61 } // namespace prefs |
59 | 62 |
60 #endif // SERVICES_PREFERENCES_PUBLIC_CPP_PREF_STORE_IMPL_H_ | 63 #endif // SERVICES_PREFERENCES_PUBLIC_CPP_PREF_STORE_IMPL_H_ |
OLD | NEW |