Chromium Code Reviews| Index: components/pref_registry/pref_registry_syncable.cc |
| diff --git a/components/pref_registry/pref_registry_syncable.cc b/components/pref_registry/pref_registry_syncable.cc |
| index 49d0020a39f103a4713da81afaa8ffb82b1e8900..8a3dcd36c6d24aecba6c08ba52e65b4aaf04249b 100644 |
| --- a/components/pref_registry/pref_registry_syncable.cc |
| +++ b/components/pref_registry/pref_registry_syncable.cc |
| @@ -11,15 +11,34 @@ |
| namespace user_prefs { |
| -PrefRegistrySyncable::PrefRegistrySyncable() { |
| +namespace { |
| + |
| +// Tests that |flags| contains a single sync flag since all sync flags are |
| +// mutually exclusive. |
| +bool HasSyncFlag(uint32 flags) { |
| + size_t flag_count = 0; |
| + |
| + const uint32 kSyncFlags[] = { |
| + PrefRegistrySyncable::UNSYNCABLE_PREF, |
| + PrefRegistrySyncable::SYNCABLE_PREF, |
| + PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF |
| + }; |
| + |
| + for (uint32 i = 0; 0 < arraysize(kSyncFlags); ++i) { |
| + if (flags && kSyncFlags[i]) |
| + flag_count++; |
| + } |
| + |
| + return flag_count == 1; |
| } |
| -PrefRegistrySyncable::~PrefRegistrySyncable() { |
| +} // namespace |
| + |
|
Mattias Nissler (ping if slow)
2015/04/20 09:33:34
nit: remove extra blank line
raymes
2015/04/21 07:58:54
Done.
|
| + |
| +PrefRegistrySyncable::PrefRegistrySyncable() { |
| } |
| -const PrefRegistrySyncable::PrefToStatus& |
| -PrefRegistrySyncable::syncable_preferences() const { |
| - return syncable_preferences_; |
| +PrefRegistrySyncable::~PrefRegistrySyncable() { |
| } |
| void PrefRegistrySyncable::SetSyncableRegistrationCallback( |
| @@ -29,95 +48,93 @@ void PrefRegistrySyncable::SetSyncableRegistrationCallback( |
| void PrefRegistrySyncable::RegisterBooleanPref(const char* path, |
| bool default_value, |
| - PrefSyncStatus sync_status) { |
| + uint32 flags) { |
| RegisterSyncablePreference( |
| - path, new base::FundamentalValue(default_value), sync_status); |
| + path, new base::FundamentalValue(default_value), flags); |
| } |
| void PrefRegistrySyncable::RegisterIntegerPref(const char* path, |
| int default_value, |
| - PrefSyncStatus sync_status) { |
| + uint32 flags) { |
| RegisterSyncablePreference( |
| - path, new base::FundamentalValue(default_value), sync_status); |
| + path, new base::FundamentalValue(default_value), flags); |
| } |
| void PrefRegistrySyncable::RegisterDoublePref(const char* path, |
| double default_value, |
| - PrefSyncStatus sync_status) { |
| + uint32 flags) { |
| RegisterSyncablePreference( |
| - path, new base::FundamentalValue(default_value), sync_status); |
| + path, new base::FundamentalValue(default_value), flags); |
| } |
| void PrefRegistrySyncable::RegisterStringPref(const char* path, |
| const std::string& default_value, |
| - PrefSyncStatus sync_status) { |
| + uint32 flags) { |
| RegisterSyncablePreference( |
| - path, new base::StringValue(default_value), sync_status); |
| + path, new base::StringValue(default_value), flags); |
| } |
| void PrefRegistrySyncable::RegisterFilePathPref( |
| const char* path, |
| const base::FilePath& default_value, |
| - PrefSyncStatus sync_status) { |
| + uint32 flags) { |
| RegisterSyncablePreference( |
| - path, new base::StringValue(default_value.value()), sync_status); |
| + path, new base::StringValue(default_value.value()), flags); |
| } |
| -void PrefRegistrySyncable::RegisterListPref(const char* path, |
| - PrefSyncStatus sync_status) { |
| - RegisterSyncablePreference(path, new base::ListValue(), sync_status); |
| +void PrefRegistrySyncable::RegisterListPref(const char* path, uint32 flags) { |
| + RegisterSyncablePreference(path, new base::ListValue(), flags); |
| } |
| void PrefRegistrySyncable::RegisterListPref(const char* path, |
| base::ListValue* default_value, |
| - PrefSyncStatus sync_status) { |
| - RegisterSyncablePreference(path, default_value, sync_status); |
| + uint32 flags) { |
| + RegisterSyncablePreference(path, default_value, flags); |
| } |
| void PrefRegistrySyncable::RegisterDictionaryPref(const char* path, |
| - PrefSyncStatus sync_status) { |
| - RegisterSyncablePreference(path, new base::DictionaryValue(), sync_status); |
| + uint32 flags) { |
| + RegisterSyncablePreference(path, new base::DictionaryValue(), flags); |
| } |
| void PrefRegistrySyncable::RegisterDictionaryPref( |
| const char* path, |
| base::DictionaryValue* default_value, |
| - PrefSyncStatus sync_status) { |
| - RegisterSyncablePreference(path, default_value, sync_status); |
| + uint32 flags) { |
| + RegisterSyncablePreference(path, default_value, flags); |
| } |
| void PrefRegistrySyncable::RegisterInt64Pref( |
| const char* path, |
| int64 default_value, |
| - PrefSyncStatus sync_status) { |
| + uint32 flags) { |
| RegisterSyncablePreference( |
| path, |
| new base::StringValue(base::Int64ToString(default_value)), |
| - sync_status); |
| + flags); |
| } |
| void PrefRegistrySyncable::RegisterUint64Pref( |
| const char* path, |
| uint64 default_value, |
| - PrefSyncStatus sync_status) { |
| + uint32 flags) { |
| RegisterSyncablePreference( |
| path, |
| new base::StringValue(base::Uint64ToString(default_value)), |
| - sync_status); |
| + flags); |
| } |
| void PrefRegistrySyncable::RegisterSyncablePreference( |
| const char* path, |
| base::Value* default_value, |
| - PrefSyncStatus sync_status) { |
| - PrefRegistry::RegisterPreference(path, default_value); |
| - |
| - if (sync_status == PrefRegistrySyncable::SYNCABLE_PREF || |
| - sync_status == PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF) { |
| - syncable_preferences_[path] = sync_status; |
| + uint32 flags) { |
| + DCHECK(HasSyncFlag(flags)); |
| + PrefRegistry::RegisterPreference(path, default_value, flags); |
| + if (flags & PrefRegistrySyncable::SYNCABLE_PREF || |
| + flags & PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF) { |
| if (!callback_.is_null()) |
| - callback_.Run(path, sync_status); |
| + callback_.Run(path, flags); |
| } |
| } |