Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(549)

Unified Diff: services/preferences/public/cpp/pref_store_client.h

Issue 2635153002: Pref service: expose all read-only PrefStores through Mojo (Closed)
Patch Set: Create and register service Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: services/preferences/public/cpp/pref_store_client.h
diff --git a/services/preferences/public/cpp/pref_store_client.h b/services/preferences/public/cpp/pref_store_client.h
new file mode 100644
index 0000000000000000000000000000000000000000..3bd0031fb62b89d09814bfeeb4e0938f668a7fcd
--- /dev/null
+++ b/services/preferences/public/cpp/pref_store_client.h
@@ -0,0 +1,68 @@
+// 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_PREF_STORE_CLIENT_H_
+#define SERVICES_PREFERENCES_PUBLIC_CPP_PREF_STORE_CLIENT_H_
+
+#include <string>
+
+#include "base/macros.h"
+#include "base/observer_list.h"
+#include "base/values.h"
+#include "components/prefs/pref_store.h"
+#include "components/prefs/pref_value_map.h"
+#include "mojo/public/cpp/bindings/binding.h"
+#include "services/preferences/public/cpp/pref_store_manager_impl.h"
+#include "services/preferences/public/interfaces/preferences.mojom.h"
+
+namespace prefs {
+
+// TODO(tibell): Make PrefObserverStore use PrefStoreClient as a base class.
+
+// An implementation of PrefStore which uses prefs::mojom::PrefStore as
+// the backing store of the preferences.
+//
+// PrefStoreClient provides synchronous access to the preferences stored by the
+// backing store by caching them locally.
+class PrefStoreClient : public ::PrefStore, public mojom::PrefStoreObserver {
+ public:
+ explicit PrefStoreClient(mojom::PrefStoreConnectionPtr connection);
+
+ // PrefStore:
+ void AddObserver(PrefStore::Observer* observer) override;
+ void RemoveObserver(PrefStore::Observer* observer) override;
+ bool HasObservers() const override;
+ bool IsInitializationComplete() const override;
+ bool GetValue(const std::string& key,
+ const base::Value** result) const override;
+ std::unique_ptr<base::DictionaryValue> GetValues() const override;
+
+ private:
+ friend class PrefStoreClientTest;
+
+ ~PrefStoreClient() override;
+
+ void OnConnected();
+
+ // prefs::mojom::PreferenceObserver:
+ void OnPreferencesChanged(
+ std::unique_ptr<base::DictionaryValue> preferences) override;
+ void OnInitializationCompleted(bool succeeded) override;
+
+ // Cached preferences.
+ PrefValueMap prefs_;
Sam McNally 2017/02/24 04:14:53 How about cached_prefs_?
tibell 2017/02/27 00:02:54 Done.
+
+ base::ObserverList<PrefStore::Observer, true> observers_;
+
+ // 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
+ bool initialized_;
+
+ mojo::Binding<mojom::PrefStoreObserver> observer_binding_;
+
+ DISALLOW_COPY_AND_ASSIGN(PrefStoreClient);
+};
+
+} // namespace prefs
+
+#endif // SERVICES_PREFERENCES_PUBLIC_CPP_PREF_STORE_CLIENT_H_

Powered by Google App Engine
This is Rietveld 408576698