| OLD | NEW | 
|---|
|  | (Empty) | 
| 1 // Copyright 2016 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_PREFS_CLIENT_STORE_H_ |  | 
| 6 #define SERVICES_PREFERENCES_PUBLIC_CPP_PREFS_CLIENT_STORE_H_ |  | 
| 7 |  | 
| 8 #include <set> |  | 
| 9 |  | 
| 10 #include "base/macros.h" |  | 
| 11 #include "components/prefs/value_map_pref_store.h" |  | 
| 12 #include "mojo/public/cpp/bindings/binding.h" |  | 
| 13 #include "services/preferences/public/interfaces/preferences.mojom.h" |  | 
| 14 |  | 
| 15 namespace preferences { |  | 
| 16 |  | 
| 17 class PrefClientStoreTest; |  | 
| 18 |  | 
| 19 // An implementation of PrefStore which uses prefs::mojom::PreferenceManager as |  | 
| 20 // the backing of the preferences. |  | 
| 21 // |  | 
| 22 // PrefClientStore caches the values locally to provide synchronous access. |  | 
| 23 // The cache is empty until the first notification of OnPreferencesChanged is |  | 
| 24 // received from the prefs::mojom::PreferenceManager. Upon recieving an initial |  | 
| 25 // OnPreferencesChanged initialization will be considered as completed, and any |  | 
| 26 // PrefStore::Observer will be notified of OnInitializationCompleted. |  | 
| 27 // |  | 
| 28 // Currently this does not support RemoveValue. |  | 
| 29 class PrefClientStore : public ValueMapPrefStore, |  | 
| 30                         public prefs::mojom::PreferencesServiceClient { |  | 
| 31  public: |  | 
| 32   explicit PrefClientStore( |  | 
| 33       prefs::mojom::PreferencesServiceFactoryPtr pref_factory_ptr); |  | 
| 34 |  | 
| 35   // Adds a set of |keys| which PrefClientStore will handle. Begins listening |  | 
| 36   // for changes to these from |prefs_service_|. |  | 
| 37   void Subscribe(const std::set<std::string>& keys); |  | 
| 38 |  | 
| 39   // PrefStore: |  | 
| 40   bool GetValue(const std::string& key, |  | 
| 41                 const base::Value** value) const override; |  | 
| 42 |  | 
| 43   // ValueMapPrefStore: |  | 
| 44   void SetValue(const std::string& key, |  | 
| 45                 std::unique_ptr<base::Value> value, |  | 
| 46                 uint32_t flags) override; |  | 
| 47   void RemoveValue(const std::string& key, uint32_t flags) override; |  | 
| 48   bool GetMutableValue(const std::string& key, base::Value** value) override; |  | 
| 49   void ReportValueChanged(const std::string& key, uint32_t flags) override; |  | 
| 50   void SetValueSilently(const std::string& key, |  | 
| 51                         std::unique_ptr<base::Value> value, |  | 
| 52                         uint32_t flags) override; |  | 
| 53 |  | 
| 54  protected: |  | 
| 55   // base::RefCounted<PrefStore>: |  | 
| 56   ~PrefClientStore() override; |  | 
| 57 |  | 
| 58  private: |  | 
| 59   friend class PrefClientStoreTest; |  | 
| 60 |  | 
| 61   // Notifies |prefs_service_| of the change in |key| - |value| pair. |  | 
| 62   void SetValueOnPreferenceManager(const std::string& key, |  | 
| 63                                    base::Value const& value); |  | 
| 64 |  | 
| 65   // prefs::mojom::PreferencesServiceClient: |  | 
| 66   void OnPreferencesChanged( |  | 
| 67       std::unique_ptr<base::DictionaryValue> preferences) override; |  | 
| 68 |  | 
| 69   mojo::Binding<prefs::mojom::PreferencesServiceClient> prefs_binding_; |  | 
| 70   prefs::mojom::PreferencesServiceFactoryPtr pref_factory_ptr_; |  | 
| 71   prefs::mojom::PreferencesServicePtr prefs_service_ptr_; |  | 
| 72 |  | 
| 73   std::set<std::string> keys_; |  | 
| 74 |  | 
| 75   // True upon the first OnPreferencesChanged received after Init. |  | 
| 76   bool initialized_; |  | 
| 77 |  | 
| 78   DISALLOW_COPY_AND_ASSIGN(PrefClientStore); |  | 
| 79 }; |  | 
| 80 |  | 
| 81 }  // namespace preferences |  | 
| 82 #endif  // SERVICES_PREFERENCES_PUBLIC_CPP_PREFS_CLIENT_STORE_H_ |  | 
| OLD | NEW | 
|---|