Index: services/preferences/public/cpp/persistent_pref_store_client.h |
diff --git a/services/preferences/public/cpp/persistent_pref_store_client.h b/services/preferences/public/cpp/persistent_pref_store_client.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..0bc3254de9cf630e978dde1046ca12a0ad670030 |
--- /dev/null |
+++ b/services/preferences/public/cpp/persistent_pref_store_client.h |
@@ -0,0 +1,94 @@ |
+// Copyright 2017 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef SERVICES_PREFERENCES_PUBLIC_CPP_PERSISTENT_PREF_STORE_CLIENT_H_ |
+#define SERVICES_PREFERENCES_PUBLIC_CPP_PERSISTENT_PREF_STORE_CLIENT_H_ |
+ |
+#include <memory> |
+#include <string> |
+ |
+#include "base/macros.h" |
+#include "base/observer_list.h" |
+#include "components/prefs/persistent_pref_store.h" |
+#include "mojo/public/cpp/bindings/binding.h" |
+#include "services/preferences/public/interfaces/preferences.mojom.h" |
+ |
+namespace base { |
+class Value; |
+class DictionaryValue; |
+} |
+ |
+namespace prefs { |
+ |
+// An implementation of PersistentPrefStore which uses |
+// mojom::PersistentPrefStore as the backing of the preferences. |
+// XXX: Dedupe this with prefs::PrefStoreClient. |
+class PersistentPrefStoreClient : public PersistentPrefStore, |
+ public mojom::PrefStoreObserver { |
+ public: |
+ explicit PersistentPrefStoreClient( |
+ mojom::PersistentPrefStoreConnectorPtr connector); |
+ |
+ // PrefStore: |
+ bool GetValue(const std::string& key, |
+ const base::Value** value) const override; |
+ std::unique_ptr<base::DictionaryValue> GetValues() const override; |
+ void AddObserver(PrefStore::Observer* observer) override; |
+ void RemoveObserver(PrefStore::Observer* observer) override; |
+ bool HasObservers() const override; |
+ bool IsInitializationComplete() const override; |
+ |
+ // WriteablePrefStore: |
+ void SetValue(const std::string& key, |
+ std::unique_ptr<base::Value> value, |
+ uint32_t flags) override; |
+ void RemoveValue(const std::string& key, uint32_t flags) override; |
+ bool GetMutableValue(const std::string& key, base::Value** result) override; |
+ void ReportValueChanged(const std::string& key, uint32_t flags) override; |
+ void SetValueSilently(const std::string& key, |
+ std::unique_ptr<base::Value> value, |
+ uint32_t flags) override; |
+ |
+ // PersistentPrefStore: |
+ bool ReadOnly() const override; |
+ PrefReadError GetReadError() const override; |
+ PrefReadError ReadPrefs() override; |
+ void ReadPrefsAsync(ReadErrorDelegate* error_delegate) override; |
+ void CommitPendingWrite() override; |
+ void SchedulePendingLossyWrites() override; |
+ void ClearMutableValues() override; |
+ |
+ protected: |
+ // base::RefCounted<PrefStore>: |
+ ~PersistentPrefStoreClient() override; |
+ |
+ private: |
+ void OnCreateComplete(PrefReadError read_error, |
+ bool read_only, |
+ std::unique_ptr<base::DictionaryValue> local_prefs, |
+ mojom::PersistentPrefStorePtr pref_store, |
+ mojom::PrefStoreObserverRequest observer_request); |
+ |
+ void OnInitializationCompleted(bool success) override; |
+ void OnPrefChanged(const std::string& key, |
+ std::unique_ptr<base::Value> value) override; |
+ |
+ mojom::PersistentPrefStoreConnectorPtr connector_; |
+ bool read_only_ = false; |
+ PrefReadError read_error_ = PersistentPrefStore::PREF_READ_ERROR_NONE; |
+ mojom::PersistentPrefStorePtr pref_store_; |
+ mojom::PersistentPrefStoreRequest pref_store_request_; |
+ |
+ std::unique_ptr<base::DictionaryValue> cached_prefs_; |
+ |
+ std::unique_ptr<ReadErrorDelegate> error_delegate_; |
+ base::ObserverList<PrefStore::Observer, true> observers_; |
+ mojo::Binding<mojom::PrefStoreObserver> observer_binding_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(PersistentPrefStoreClient); |
+}; |
+ |
+} // namespace prefs |
+ |
+#endif // SERVICES_PREFERENCES_PUBLIC_CPP_PERSISTENT_PREF_STORE_CLIENT_H_ |