| Index: components/prefs/pref_service.cc
|
| diff --git a/components/prefs/pref_service.cc b/components/prefs/pref_service.cc
|
| index 1ef2313b3fa45576e6784ed373609f23725984ef..d9b99ed9456c6e08d444466f6ec8282676528771 100644
|
| --- a/components/prefs/pref_service.cc
|
| +++ b/components/prefs/pref_service.cc
|
| @@ -52,6 +52,15 @@ uint32_t GetWriteFlags(const PrefService::Preference* pref) {
|
| return write_flags;
|
| }
|
|
|
| +bool HasValidPrefix(const std::string& pref_name,
|
| + const std::vector<std::string> valid_prefixes) {
|
| + for (const std::string& prefix : valid_prefixes) {
|
| + if (pref_name.compare(0, prefix.size(), prefix) == 0)
|
| + return true;
|
| + }
|
| + return false;
|
| +}
|
| +
|
| } // namespace
|
|
|
| PrefService::PrefService(
|
| @@ -201,15 +210,32 @@ scoped_ptr<base::DictionaryValue> PrefService::GetPreferenceValues() const {
|
| return out;
|
| }
|
|
|
| +void PrefService::SetPreferenceOmitdefault(const std::string& pref_name,
|
| + base::DictionaryValue* out) const {
|
| + const Preference* pref = FindPreference(pref_name);
|
| + if (pref->IsDefaultValue())
|
| + return;
|
| + out->Set(pref_name, pref->GetValue()->CreateDeepCopy());
|
| +}
|
| +
|
| scoped_ptr<base::DictionaryValue> PrefService::GetPreferenceValuesOmitDefaults()
|
| const {
|
| DCHECK(CalledOnValidThread());
|
| scoped_ptr<base::DictionaryValue> out(new base::DictionaryValue);
|
| for (const auto& it : *pref_registry_) {
|
| - const Preference* pref = FindPreference(it.first);
|
| - if (pref->IsDefaultValue())
|
| - continue;
|
| - out->Set(it.first, pref->GetValue()->CreateDeepCopy());
|
| + SetPreferenceOmitdefault(it.first, out.get());
|
| + }
|
| + return out;
|
| +}
|
| +
|
| +scoped_ptr<base::DictionaryValue>
|
| +PrefService::GetWhitelistedPreferenceValuesOmitDefaults(
|
| + const std::vector<std::string>& whitelisted_prefixes) const {
|
| + DCHECK(CalledOnValidThread());
|
| + scoped_ptr<base::DictionaryValue> out(new base::DictionaryValue);
|
| + for (const auto& it : *pref_registry_) {
|
| + if (HasValidPrefix(it.first, whitelisted_prefixes))
|
| + SetPreferenceOmitdefault(it.first, out.get());
|
| }
|
| return out;
|
| }
|
|
|