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_PERSISTENT_PREF_STORE_CLIENT_H_ |
| 6 #define SERVICES_PREFERENCES_PUBLIC_CPP_PERSISTENT_PREF_STORE_CLIENT_H_ |
| 7 |
| 8 #include <memory> |
| 9 #include <string> |
| 10 |
| 11 #include "base/macros.h" |
| 12 #include "base/observer_list.h" |
| 13 #include "components/prefs/persistent_pref_store.h" |
| 14 #include "mojo/public/cpp/bindings/binding.h" |
| 15 #include "services/preferences/public/interfaces/preferences.mojom.h" |
| 16 |
| 17 namespace base { |
| 18 class Value; |
| 19 class DictionaryValue; |
| 20 } |
| 21 |
| 22 namespace prefs { |
| 23 |
| 24 // An implementation of PersistentPrefStore which uses |
| 25 // mojom::PersistentPrefStore as the backing of the preferences. |
| 26 // XXX: Dedupe this with prefs::PrefStoreClient. |
| 27 class PersistentPrefStoreClient : public PersistentPrefStore, |
| 28 public mojom::PrefStoreObserver { |
| 29 public: |
| 30 explicit PersistentPrefStoreClient( |
| 31 mojom::PersistentPrefStoreConnectorPtr connector); |
| 32 |
| 33 // PrefStore: |
| 34 bool GetValue(const std::string& key, |
| 35 const base::Value** value) const override; |
| 36 std::unique_ptr<base::DictionaryValue> GetValues() const override; |
| 37 void AddObserver(PrefStore::Observer* observer) override; |
| 38 void RemoveObserver(PrefStore::Observer* observer) override; |
| 39 bool HasObservers() const override; |
| 40 bool IsInitializationComplete() const override; |
| 41 |
| 42 // WriteablePrefStore: |
| 43 void SetValue(const std::string& key, |
| 44 std::unique_ptr<base::Value> value, |
| 45 uint32_t flags) override; |
| 46 void RemoveValue(const std::string& key, uint32_t flags) override; |
| 47 bool GetMutableValue(const std::string& key, base::Value** result) override; |
| 48 void ReportValueChanged(const std::string& key, uint32_t flags) override; |
| 49 void SetValueSilently(const std::string& key, |
| 50 std::unique_ptr<base::Value> value, |
| 51 uint32_t flags) override; |
| 52 |
| 53 // PersistentPrefStore: |
| 54 bool ReadOnly() const override; |
| 55 PrefReadError GetReadError() const override; |
| 56 PrefReadError ReadPrefs() override; |
| 57 void ReadPrefsAsync(ReadErrorDelegate* error_delegate) override; |
| 58 void CommitPendingWrite() override; |
| 59 void SchedulePendingLossyWrites() override; |
| 60 void ClearMutableValues() override; |
| 61 |
| 62 protected: |
| 63 // base::RefCounted<PrefStore>: |
| 64 ~PersistentPrefStoreClient() override; |
| 65 |
| 66 private: |
| 67 void OnCreateComplete(PrefReadError read_error, |
| 68 bool read_only, |
| 69 std::unique_ptr<base::DictionaryValue> local_prefs, |
| 70 mojom::PersistentPrefStorePtr pref_store, |
| 71 mojom::PrefStoreObserverRequest observer_request); |
| 72 |
| 73 void OnInitializationCompleted(bool success) override; |
| 74 void OnPrefChanged(const std::string& key, |
| 75 std::unique_ptr<base::Value> value) override; |
| 76 |
| 77 mojom::PersistentPrefStoreConnectorPtr connector_; |
| 78 bool read_only_ = false; |
| 79 PrefReadError read_error_ = PersistentPrefStore::PREF_READ_ERROR_NONE; |
| 80 mojom::PersistentPrefStorePtr pref_store_; |
| 81 mojom::PersistentPrefStoreRequest pref_store_request_; |
| 82 |
| 83 std::unique_ptr<base::DictionaryValue> cached_prefs_; |
| 84 |
| 85 std::unique_ptr<ReadErrorDelegate> error_delegate_; |
| 86 base::ObserverList<PrefStore::Observer, true> observers_; |
| 87 mojo::Binding<mojom::PrefStoreObserver> observer_binding_; |
| 88 |
| 89 DISALLOW_COPY_AND_ASSIGN(PersistentPrefStoreClient); |
| 90 }; |
| 91 |
| 92 } // namespace prefs |
| 93 |
| 94 #endif // SERVICES_PREFERENCES_PUBLIC_CPP_PERSISTENT_PREF_STORE_CLIENT_H_ |
OLD | NEW |