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

Side by Side Diff: services/preferences/public/cpp/pref_observer_store.cc

Issue 2474653003: PreferencesManager (Closed)
Patch Set: WmShell Owns PrefObserverStore Created 4 years, 1 month 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "services/preferences/public/cpp/pref_observer_store.h" 5 #include "services/preferences/public/cpp/pref_observer_store.h"
6 6
7 #include "base/values.h" 7 #include "base/values.h"
8 #include "mojo/common/common_custom_types.mojom.h" 8 #include "mojo/common/common_custom_types.mojom.h"
9 #include "mojo/public/cpp/bindings/array.h" 9 #include "mojo/public/cpp/bindings/array.h"
10 #include "services/service_manager/public/cpp/connector.h" 10 #include "services/service_manager/public/cpp/connector.h"
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 ValueMapPrefStore::ReportValueChanged(key, flags); 65 ValueMapPrefStore::ReportValueChanged(key, flags);
66 } 66 }
67 67
68 void PrefObserverStore::SetValueSilently(const std::string& key, 68 void PrefObserverStore::SetValueSilently(const std::string& key,
69 std::unique_ptr<base::Value> value, 69 std::unique_ptr<base::Value> value,
70 uint32_t flags) { 70 uint32_t flags) {
71 SetValueOnPreferenceManager(key, *value); 71 SetValueOnPreferenceManager(key, *value);
72 ValueMapPrefStore::SetValueSilently(key, std::move(value), flags); 72 ValueMapPrefStore::SetValueSilently(key, std::move(value), flags);
73 } 73 }
74 74
75 PrefObserverStore::~PrefObserverStore() {} 75 PrefObserverStore::~PrefObserverStore() {
76 ClearObservers();
77 }
76 78
77 void PrefObserverStore::SetValueOnPreferenceManager(const std::string& key, 79 void PrefObserverStore::SetValueOnPreferenceManager(const std::string& key,
78 const base::Value& value) { 80 const base::Value& value) {
79 if (keys_.find(key) == keys_.end()) 81 if (keys_.find(key) == keys_.end())
80 return; 82 return;
81 83
82 base::DictionaryValue prefs; 84 base::DictionaryValue prefs;
83 prefs.Set(key, value.CreateDeepCopy()); 85 prefs.Set(key, value.CreateDeepCopy());
84 prefs_manager_ptr_->SetPreferences(prefs); 86 prefs_manager_ptr_->SetPreferences(prefs);
85 } 87 }
86 88
87 void PrefObserverStore::OnPreferencesChanged( 89 void PrefObserverStore::OnPreferencesChanged(
88 const base::DictionaryValue& preferences) { 90 const base::DictionaryValue& preferences) {
89 for (base::DictionaryValue::Iterator it(preferences); !it.IsAtEnd(); 91 for (base::DictionaryValue::Iterator it(preferences); !it.IsAtEnd();
90 it.Advance()) { 92 it.Advance()) {
91 if (keys_.find(it.key()) == keys_.end()) 93 if (keys_.find(it.key()) == keys_.end())
92 continue; 94 continue;
93 // We deliberately call the parent to avoid notifying the server again. 95 // We deliberately call the parent to avoid notifying the server again.
94 ValueMapPrefStore::SetValue(it.key(), it.value().CreateDeepCopy(), 0); 96 if (!initialized_) {
97 ValueMapPrefStore::SetValueSilently(it.key(), it.value().CreateDeepCopy(),
98 0);
99 } else {
100 ValueMapPrefStore::SetValue(it.key(), it.value().CreateDeepCopy(), 0);
101 }
95 } 102 }
96 103
97 if (!initialized_) { 104 if (!initialized_) {
98 initialized_ = true; 105 initialized_ = true;
99 NotifyInitializationCompleted(); 106 NotifyInitializationCompleted();
100 } 107 }
101 } 108 }
OLDNEW
« ash/common/wm_shell.h ('K') | « components/prefs/value_map_pref_store.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698