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

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

Issue 2577563002: Add struct traits for base::Value. (Closed)
Patch Set: rebase 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 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/public/cpp/bindings/array.h" 8 #include "mojo/public/cpp/bindings/array.h"
9 #include "services/service_manager/public/cpp/connector.h" 9 #include "services/service_manager/public/cpp/connector.h"
10 10
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 ValueMapPrefStore::SetValueSilently(key, std::move(value), flags); 71 ValueMapPrefStore::SetValueSilently(key, std::move(value), flags);
72 } 72 }
73 73
74 PrefObserverStore::~PrefObserverStore() {} 74 PrefObserverStore::~PrefObserverStore() {}
75 75
76 void PrefObserverStore::SetValueOnPreferenceManager(const std::string& key, 76 void PrefObserverStore::SetValueOnPreferenceManager(const std::string& key,
77 const base::Value& value) { 77 const base::Value& value) {
78 if (keys_.find(key) == keys_.end()) 78 if (keys_.find(key) == keys_.end())
79 return; 79 return;
80 80
81 base::DictionaryValue prefs; 81 auto prefs = base::MakeUnique<base::DictionaryValue>();
82 prefs.Set(key, value.CreateDeepCopy()); 82 prefs->Set(key, value.CreateDeepCopy());
83 prefs_manager_ptr_->SetPreferences(prefs); 83 prefs_manager_ptr_->SetPreferences(std::move(prefs));
84 } 84 }
85 85
86 void PrefObserverStore::OnPreferencesChanged( 86 void PrefObserverStore::OnPreferencesChanged(
87 const base::DictionaryValue& preferences) { 87 std::unique_ptr<base::DictionaryValue> preferences) {
88 for (base::DictionaryValue::Iterator it(preferences); !it.IsAtEnd(); 88 for (base::DictionaryValue::Iterator it(*preferences); !it.IsAtEnd();
89 it.Advance()) { 89 it.Advance()) {
90 if (keys_.find(it.key()) == keys_.end()) 90 if (keys_.find(it.key()) == keys_.end())
91 continue; 91 continue;
92 // We deliberately call the parent to avoid notifying the server again. 92 // We deliberately call the parent to avoid notifying the server again.
93 ValueMapPrefStore::SetValue(it.key(), it.value().CreateDeepCopy(), 0); 93 ValueMapPrefStore::SetValue(it.key(), it.value().CreateDeepCopy(), 0);
94 } 94 }
95 95
96 if (!initialized_) { 96 if (!initialized_) {
97 initialized_ = true; 97 initialized_ = true;
98 NotifyInitializationCompleted(); 98 NotifyInitializationCompleted();
99 } 99 }
100 } 100 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698