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

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

Issue 2635153002: Pref service: expose all read-only PrefStores through Mojo (Closed)
Patch Set: Merge 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_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..b93c83dd7a8de25d455252644f4945d74a964cdd
--- /dev/null
+++ b/services/preferences/public/cpp/pref_store_impl.h
@@ -0,0 +1,63 @@
+// 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:
+ // The created instance is registered in and owned by the
+ // |mojom::PrefStoreRegistry|.
+ static std::unique_ptr<PrefStoreImpl> Create(
Sam McNally 2017/03/03 03:47:58 Methods after destructors.
tibell 2017/03/07 00:52:52 Done.
+ mojom::PrefStoreRegistryPtr registry_ptr,
+ scoped_refptr<::PrefStore> pref_store,
+ PrefValueStore::PrefStoreType type);
+
+ PrefStoreImpl(scoped_refptr<::PrefStore> pref_store,
+ mojom::PrefStoreRequest request);
+ ~PrefStoreImpl() override;
+
+ 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. This a |WeakPtr| because if we
Sam McNally 2017/03/03 03:47:58 I think this comment is mostly no longer necessary
tibell 2017/03/07 00:52:52 Done.
+ // hold on to the |PrefStore| until this is torned down we mess up shutdown
+ // order, which e.g. depends on when the |Profile| is deleted. This is quite
+ // unsatisfactory.
+ 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 initialized_;
Sam McNally 2017/03/03 03:47:58 How about naming this |backing_pref_store_initiali
tibell 2017/03/07 00:52:52 Done.
+
+ mojo::Binding<mojom::PrefStore> binding_;
+
+ DISALLOW_COPY_AND_ASSIGN(PrefStoreImpl);
+};
+
+} // namespace prefs
+
+#endif // SERVICES_PREFERENCES_PUBLIC_CPP_PREF_STORE_IMPL_H_

Powered by Google App Engine
This is Rietveld 408576698