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

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

Issue 2474653003: PreferencesManager (Closed)
Patch Set: Update PreferencesManager to account for base::Value API change Created 4 years 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_observer_store.cc
diff --git a/services/preferences/public/cpp/pref_observer_store.cc b/services/preferences/public/cpp/pref_observer_store.cc
index fac38338cc1e52b0333777d099af287ebae289d9..569dcb07ae4e8351a257ece597522e8de9b22591 100644
--- a/services/preferences/public/cpp/pref_observer_store.cc
+++ b/services/preferences/public/cpp/pref_observer_store.cc
@@ -8,20 +8,22 @@
#include "mojo/public/cpp/bindings/array.h"
#include "services/service_manager/public/cpp/connector.h"
+namespace preferences {
+
PrefObserverStore::PrefObserverStore(
prefs::mojom::PreferencesManagerPtr prefs_manager_ptr)
: prefs_binding_(this),
prefs_manager_ptr_(std::move(prefs_manager_ptr)),
initialized_(false) {}
-void PrefObserverStore::Init(const std::set<std::string>& keys) {
- DCHECK(!initialized_);
- keys_ = keys;
+void PrefObserverStore::Subscribe(const std::set<std::string>& keys) {
+ if (keys_.empty())
+ prefs_manager_ptr_->AddObserver(prefs_binding_.CreateInterfacePtrAndBind());
+ keys_.insert(keys.begin(), keys.end());
std::vector<std::string> pref_array;
std::copy(keys_.begin(), keys_.end(), std::back_inserter(pref_array));
- prefs_manager_ptr_->AddObserver(pref_array,
- prefs_binding_.CreateInterfacePtrAndBind());
+ prefs_manager_ptr_->Subscribe(pref_array);
}
bool PrefObserverStore::GetValue(const std::string& key,
@@ -85,16 +87,17 @@ void PrefObserverStore::SetValueOnPreferenceManager(const std::string& key,
void PrefObserverStore::OnPreferencesChanged(
std::unique_ptr<base::DictionaryValue> preferences) {
+ if (!initialized_) {
+ initialized_ = true;
+ NotifyInitializationCompleted();
+ }
+
for (base::DictionaryValue::Iterator it(*preferences); !it.IsAtEnd();
it.Advance()) {
if (keys_.find(it.key()) == keys_.end())
continue;
- // We deliberately call the parent to avoid notifying the server again.
ValueMapPrefStore::SetValue(it.key(), it.value().CreateDeepCopy(), 0);
}
-
- if (!initialized_) {
- initialized_ = true;
- NotifyInitializationCompleted();
- }
}
+
+} // namespace preferences

Powered by Google App Engine
This is Rietveld 408576698