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

Side by Side Diff: components/prefs/pref_service.cc

Issue 1910323002: Allow whitelisted prefs to be displayed in ChromeOS in chrome://local-state. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "components/prefs/pref_service.h" 5 #include "components/prefs/pref_service.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 uint32_t write_flags = WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS; 45 uint32_t write_flags = WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS;
46 46
47 if (!pref) 47 if (!pref)
48 return write_flags; 48 return write_flags;
49 49
50 if (pref->registration_flags() & PrefRegistry::LOSSY_PREF) 50 if (pref->registration_flags() & PrefRegistry::LOSSY_PREF)
51 write_flags |= WriteablePrefStore::LOSSY_PREF_WRITE_FLAG; 51 write_flags |= WriteablePrefStore::LOSSY_PREF_WRITE_FLAG;
52 return write_flags; 52 return write_flags;
53 } 53 }
54 54
55 bool HasValidPrefix(const std::string& pref_name,
56 const std::vector<std::string> valid_prefixes) {
57 for (const std::string& prefix : valid_prefixes) {
58 if (pref_name.compare(0, prefix.size(), prefix) == 0)
59 return true;
60 }
61 return false;
62 }
63
55 } // namespace 64 } // namespace
56 65
57 PrefService::PrefService( 66 PrefService::PrefService(
58 PrefNotifierImpl* pref_notifier, 67 PrefNotifierImpl* pref_notifier,
59 PrefValueStore* pref_value_store, 68 PrefValueStore* pref_value_store,
60 PersistentPrefStore* user_prefs, 69 PersistentPrefStore* user_prefs,
61 PrefRegistry* pref_registry, 70 PrefRegistry* pref_registry,
62 base::Callback<void(PersistentPrefStore::PrefReadError)> 71 base::Callback<void(PersistentPrefStore::PrefReadError)>
63 read_error_callback, 72 read_error_callback,
64 bool async) 73 bool async)
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 203
195 scoped_ptr<base::DictionaryValue> PrefService::GetPreferenceValues() const { 204 scoped_ptr<base::DictionaryValue> PrefService::GetPreferenceValues() const {
196 DCHECK(CalledOnValidThread()); 205 DCHECK(CalledOnValidThread());
197 scoped_ptr<base::DictionaryValue> out(new base::DictionaryValue); 206 scoped_ptr<base::DictionaryValue> out(new base::DictionaryValue);
198 for (const auto& it : *pref_registry_) { 207 for (const auto& it : *pref_registry_) {
199 out->Set(it.first, GetPreferenceValue(it.first)->CreateDeepCopy()); 208 out->Set(it.first, GetPreferenceValue(it.first)->CreateDeepCopy());
200 } 209 }
201 return out; 210 return out;
202 } 211 }
203 212
213 void PrefService::SetPreferenceOmitdefault(const std::string& pref_name,
214 base::DictionaryValue* out) const {
215 const Preference* pref = FindPreference(pref_name);
216 if (pref->IsDefaultValue())
217 return;
218 out->Set(pref_name, pref->GetValue()->CreateDeepCopy());
219 }
220
204 scoped_ptr<base::DictionaryValue> PrefService::GetPreferenceValuesOmitDefaults() 221 scoped_ptr<base::DictionaryValue> PrefService::GetPreferenceValuesOmitDefaults()
205 const { 222 const {
206 DCHECK(CalledOnValidThread()); 223 DCHECK(CalledOnValidThread());
207 scoped_ptr<base::DictionaryValue> out(new base::DictionaryValue); 224 scoped_ptr<base::DictionaryValue> out(new base::DictionaryValue);
208 for (const auto& it : *pref_registry_) { 225 for (const auto& it : *pref_registry_) {
209 const Preference* pref = FindPreference(it.first); 226 SetPreferenceOmitdefault(it.first, out.get());
210 if (pref->IsDefaultValue())
211 continue;
212 out->Set(it.first, pref->GetValue()->CreateDeepCopy());
213 } 227 }
214 return out; 228 return out;
215 } 229 }
230
231 scoped_ptr<base::DictionaryValue>
232 PrefService::GetWhitelistedPreferenceValuesOmitDefaults(
233 const std::vector<std::string>& whitelisted_prefixes) const {
234 DCHECK(CalledOnValidThread());
235 scoped_ptr<base::DictionaryValue> out(new base::DictionaryValue);
236 for (const auto& it : *pref_registry_) {
237 if (HasValidPrefix(it.first, whitelisted_prefixes))
238 SetPreferenceOmitdefault(it.first, out.get());
239 }
240 return out;
241 }
216 242
217 scoped_ptr<base::DictionaryValue> 243 scoped_ptr<base::DictionaryValue>
218 PrefService::GetPreferenceValuesWithoutPathExpansion() const { 244 PrefService::GetPreferenceValuesWithoutPathExpansion() const {
219 DCHECK(CalledOnValidThread()); 245 DCHECK(CalledOnValidThread());
220 scoped_ptr<base::DictionaryValue> out(new base::DictionaryValue); 246 scoped_ptr<base::DictionaryValue> out(new base::DictionaryValue);
221 for (const auto& it : *pref_registry_) { 247 for (const auto& it : *pref_registry_) {
222 const base::Value* value = GetPreferenceValue(it.first); 248 const base::Value* value = GetPreferenceValue(it.first);
223 DCHECK(value); 249 DCHECK(value);
224 out->SetWithoutPathExpansion(it.first, value->CreateDeepCopy()); 250 out->SetWithoutPathExpansion(it.first, value->CreateDeepCopy());
225 } 251 }
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after
611 DCHECK(found_value->IsType(default_type)); 637 DCHECK(found_value->IsType(default_type));
612 return found_value; 638 return found_value;
613 } else { 639 } else {
614 // Every registered preference has at least a default value. 640 // Every registered preference has at least a default value.
615 NOTREACHED() << "no valid value found for registered pref " << path; 641 NOTREACHED() << "no valid value found for registered pref " << path;
616 } 642 }
617 } 643 }
618 644
619 return NULL; 645 return NULL;
620 } 646 }
OLDNEW
« chrome/browser/ui/webui/local_state/local_state_ui.cc ('K') | « components/prefs/pref_service.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698