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..2c075bd6f0650c8979a3e553e7818b2288752e5c 100644 |
--- a/services/preferences/public/cpp/pref_observer_store.cc |
+++ b/services/preferences/public/cpp/pref_observer_store.cc |
@@ -9,20 +9,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, |
@@ -86,16 +88,17 @@ 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(); |
- } |
} |
+ |
+} // namespace preferences |