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

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

Issue 2743563003: Pref service: add persistent pref store frontend and backend. (Closed)
Patch Set: rebase 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_client.cc
diff --git a/services/preferences/public/cpp/pref_store_client.cc b/services/preferences/public/cpp/pref_store_client.cc
index fd6708cd679f9822def4979d6eec8615e1e797b8..441e8154589af80d25a0cb0419e07ffd8e1503a5 100644
--- a/services/preferences/public/cpp/pref_store_client.cc
+++ b/services/preferences/public/cpp/pref_store_client.cc
@@ -3,75 +3,16 @@
// found in the LICENSE file.
#include "services/preferences/public/cpp/pref_store_client.h"
-#include "mojo/public/cpp/bindings/strong_binding.h"
-#include "services/preferences/public/cpp/pref_store_impl.h"
-namespace prefs {
-
-PrefStoreClient::PrefStoreClient(mojom::PrefStoreConnectionPtr connection)
- : cached_prefs_(std::move(connection->initial_prefs)),
- initialized_(connection->is_initialized),
- observer_binding_(this, std::move(connection->observer)) {}
-
-void PrefStoreClient::AddObserver(PrefStore::Observer* observer) {
- observers_.AddObserver(observer);
-}
-
-void PrefStoreClient::RemoveObserver(PrefStore::Observer* observer) {
- observers_.RemoveObserver(observer);
-}
-
-bool PrefStoreClient::HasObservers() const {
- return observers_.might_have_observers();
-}
+#include <utility>
-bool PrefStoreClient::IsInitializationComplete() const {
- return initialized_;
-}
-
-bool PrefStoreClient::GetValue(const std::string& key,
- const base::Value** result) const {
- DCHECK(initialized_);
- return cached_prefs_->Get(key, result);
-}
+namespace prefs {
-std::unique_ptr<base::DictionaryValue> PrefStoreClient::GetValues() const {
- DCHECK(initialized_);
- return cached_prefs_->CreateDeepCopy();
+PrefStoreClient::PrefStoreClient(mojom::PrefStoreConnectionPtr connection) {
+ Init(std::move(connection->initial_prefs), connection->is_initialized,
+ std::move(connection->observer));
}
PrefStoreClient::~PrefStoreClient() = default;
-void PrefStoreClient::OnPrefChanged(const std::string& key,
- std::unique_ptr<base::Value> value) {
- bool changed = false;
- if (!value) { // Delete
- if (cached_prefs_->RemovePath(key, nullptr))
- changed = true;
- } else {
- const base::Value* prev;
- if (cached_prefs_->Get(key, &prev)) {
- if (!prev->Equals(value.get())) {
- cached_prefs_->Set(key, std::move(value));
- changed = true;
- }
- } else {
- cached_prefs_->Set(key, std::move(value));
- changed = true;
- }
- }
- if (changed) {
- for (Observer& observer : observers_)
- observer.OnPrefValueChanged(key);
- }
-}
-
-void PrefStoreClient::OnInitializationCompleted(bool succeeded) {
- if (!initialized_) {
- initialized_ = true;
- for (Observer& observer : observers_)
- observer.OnInitializationCompleted(true);
- }
-}
-
} // namespace prefs
« no previous file with comments | « services/preferences/public/cpp/pref_store_client.h ('k') | services/preferences/public/cpp/pref_store_client_mixin.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698