Index: services/preferences/public/cpp/persistent_pref_store_mojo.h |
diff --git a/services/preferences/public/cpp/persistent_pref_store_mojo.h b/services/preferences/public/cpp/persistent_pref_store_mojo.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..1d43c84191ca7729e9ad3fd48093053dfc28fdd9 |
--- /dev/null |
+++ b/services/preferences/public/cpp/persistent_pref_store_mojo.h |
@@ -0,0 +1,88 @@ |
+// 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_MOJO_H_ |
+#define SERVICES_PREFERENCES_PUBLIC_CPP_PERSISTENT_PREF_STORE_MOJO_H_ |
+ |
+#include <memory> |
+#include <string> |
+ |
+#include "base/macros.h" |
+#include "base/observer_list.h" |
+#include "components/prefs/persistent_pref_store.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. |
+// |
+// TODO(sammc): Make this an implementation detail once the PrefService |
+// factory/builder is responsible for constructing the user prefs PrefStore. |
+class PersistentPrefStoreMojo : public PersistentPrefStore { |
tibell
2017/03/08 03:39:54
Can we name this PersistentPrefStoreClient to matc
|
+ public: |
+ explicit PersistentPrefStoreMojo( |
+ 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>: |
+ ~PersistentPrefStoreMojo() override; |
+ |
+ private: |
+ void OnCreateComplete(PrefReadError read_error, |
+ bool read_only, |
+ std::unique_ptr<base::DictionaryValue> local_prefs, |
+ mojom::PersistentPrefStorePtr pref_store); |
+ |
+ 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> local_prefs_; |
+ |
+ std::unique_ptr<ReadErrorDelegate> error_delegate_; |
+ base::ObserverList<PrefStore::Observer, true> observers_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(PersistentPrefStoreMojo); |
+}; |
+ |
+} // namespace prefs |
+ |
+#endif // SERVICES_PREFERENCES_PUBLIC_CPP_PERSISTENT_PREF_STORE_MOJO_H_ |