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 5a5f9cb1671cee05034994489f8af7ea0ab80bf0..54c5fc9484a8b800aff32b1c976fe236ec65aad4 100644 |
--- a/services/preferences/public/cpp/pref_observer_store.cc |
+++ b/services/preferences/public/cpp/pref_observer_store.cc |
@@ -15,14 +15,14 @@ PrefObserverStore::PrefObserverStore( |
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, |
@@ -72,7 +72,9 @@ void PrefObserverStore::SetValueSilently(const std::string& key, |
ValueMapPrefStore::SetValueSilently(key, std::move(value), flags); |
} |
-PrefObserverStore::~PrefObserverStore() {} |
+PrefObserverStore::~PrefObserverStore() { |
+ ClearObservers(); |
sadrul
2016/11/29 17:25:49
Why is this needed?
jonross
2016/11/30 01:01:31
It was a workaround for ValueMapPrefStore enforcin
|
+} |
void PrefObserverStore::SetValueOnPreferenceManager(const std::string& key, |
const base::Value& value) { |
@@ -86,16 +88,15 @@ void PrefObserverStore::SetValueOnPreferenceManager(const std::string& key, |
void PrefObserverStore::OnPreferencesChanged( |
const 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(); |
- } |
} |