Chromium Code Reviews| OLD | NEW | 
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef SERVICES_PREFERENCES_PUBLIC_CPP_PREF_STORE_CLIENT_H_ | |
| 6 #define SERVICES_PREFERENCES_PUBLIC_CPP_PREF_STORE_CLIENT_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 | |
| 10 #include "base/macros.h" | |
| 11 #include "base/observer_list.h" | |
| 12 #include "base/values.h" | |
| 13 #include "components/prefs/pref_store.h" | |
| 14 #include "components/prefs/pref_value_map.h" | |
| 15 #include "mojo/public/cpp/bindings/binding.h" | |
| 16 #include "services/preferences/public/cpp/pref_store_manager_impl.h" | |
| 17 #include "services/preferences/public/interfaces/preferences.mojom.h" | |
| 18 | |
| 19 namespace prefs { | |
| 20 | |
| 21 // TODO(tibell): Make PrefObserverStore use PrefStoreClient as a base class. | |
| 22 | |
| 23 // An implementation of PrefStore which uses prefs::mojom::PrefStore as | |
| 24 // the backing store of the preferences. | |
| 25 // | |
| 26 // PrefStoreClient provides synchronous access to the preferences stored by the | |
| 27 // backing store by caching them locally. | |
| 28 class PrefStoreClient : public ::PrefStore, public mojom::PrefStoreObserver { | |
| 29 public: | |
| 30 explicit PrefStoreClient(mojom::PrefStoreConnectionPtr connection); | |
| 31 | |
| 32 // PrefStore: | |
| 33 void AddObserver(PrefStore::Observer* observer) override; | |
| 34 void RemoveObserver(PrefStore::Observer* observer) override; | |
| 35 bool HasObservers() const override; | |
| 36 bool IsInitializationComplete() const override; | |
| 37 bool GetValue(const std::string& key, | |
| 38 const base::Value** result) const override; | |
| 39 std::unique_ptr<base::DictionaryValue> GetValues() const override; | |
| 40 | |
| 41 private: | |
| 42 friend class PrefStoreClientTest; | |
| 43 | |
| 44 ~PrefStoreClient() override; | |
| 45 | |
| 46 void OnConnected(); | |
| 47 | |
| 48 // prefs::mojom::PreferenceObserver: | |
| 49 void OnPreferencesChanged( | |
| 50 std::unique_ptr<base::DictionaryValue> preferences) override; | |
| 51 void OnInitializationCompleted(bool succeeded) override; | |
| 52 | |
| 53 // Cached preferences. | |
| 54 PrefValueMap prefs_; | |
| 
 
Sam McNally
2017/02/24 04:14:53
How about cached_prefs_?
 
tibell
2017/02/27 00:02:54
Done.
 
 | |
| 55 | |
| 56 base::ObserverList<PrefStore::Observer, true> observers_; | |
| 57 | |
| 58 // Has the PrefStore we're observing been initialized? | |
| 
 
Sam McNally
2017/02/24 04:14:53
Is this necessary?
 
tibell
2017/02/27 00:02:54
Needed for IsInitializationComplete (part of the P
 
 | |
| 59 bool initialized_; | |
| 60 | |
| 61 mojo::Binding<mojom::PrefStoreObserver> observer_binding_; | |
| 62 | |
| 63 DISALLOW_COPY_AND_ASSIGN(PrefStoreClient); | |
| 64 }; | |
| 65 | |
| 66 } // namespace prefs | |
| 67 | |
| 68 #endif // SERVICES_PREFERENCES_PUBLIC_CPP_PREF_STORE_CLIENT_H_ | |
| OLD | NEW |