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

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

Issue 2635153002: Pref service: expose all read-only PrefStores through Mojo (Closed)
Patch Set: Address bauerb's review comments Created 3 years, 9 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_impl.h
diff --git a/services/preferences/public/cpp/pref_store_impl.h b/services/preferences/public/cpp/pref_store_impl.h
new file mode 100644
index 0000000000000000000000000000000000000000..ce8b68897db5eb06b8cb3a5a45b3e3ea5fd54e38
--- /dev/null
+++ b/services/preferences/public/cpp/pref_store_impl.h
@@ -0,0 +1,60 @@
+// 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_IMPL_H_
+#define SERVICES_PREFERENCES_PUBLIC_CPP_PREF_STORE_IMPL_H_
+
+#include <vector>
+
+#include "base/macros.h"
+#include "base/memory/ref_counted.h"
+#include "components/prefs/pref_store.h"
+#include "components/prefs/pref_value_store.h"
+#include "mojo/public/cpp/bindings/binding.h"
+#include "services/preferences/public/interfaces/preferences.mojom.h"
+
+namespace prefs {
+
+// Wraps an actual PrefStore implementation and exposes it as a
+// mojom::PrefStore interface.
+class PrefStoreImpl : public ::PrefStore::Observer, public mojom::PrefStore {
+ public:
+ PrefStoreImpl(scoped_refptr<::PrefStore> pref_store,
+ mojom::PrefStoreRequest request);
+ ~PrefStoreImpl() override;
+
+ // The created instance is registered in and owned by the
+ // |mojom::PrefStoreRegistry|.
+ static std::unique_ptr<PrefStoreImpl> Create(
+ mojom::PrefStoreRegistryPtr registry_ptr,
+ scoped_refptr<::PrefStore> pref_store,
+ PrefValueStore::PrefStoreType type);
+
+ private:
+ // PrefStore::Observer:
+ void OnPrefValueChanged(const std::string& key) override;
+ void OnInitializationCompleted(bool succeeded) override;
+
+ // prefs::mojom::PrefStore:
+ void AddObserver(const AddObserverCallback& callback) override;
+
+ // The backing store we observer for changes.
+ scoped_refptr<::PrefStore> backing_pref_store_;
+
+ // Observers we notify when |backing_pref_store_| changes.
+ std::vector<mojom::PrefStoreObserverPtr> observers_;
+
+ // True when the |backing_pref_store_| is initialized, either because it was
+ // passed already initialized in the constructor or after
+ // OnInitializationCompleted was called.
+ bool backing_pref_store_initialized_;
+
+ mojo::Binding<mojom::PrefStore> binding_;
+
+ DISALLOW_COPY_AND_ASSIGN(PrefStoreImpl);
+};
+
+} // namespace prefs
+
+#endif // SERVICES_PREFERENCES_PUBLIC_CPP_PREF_STORE_IMPL_H_
« no previous file with comments | « services/preferences/public/cpp/pref_store_client.cc ('k') | services/preferences/public/cpp/pref_store_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698