| OLD | NEW |
| 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/pref_registry/pref_registry_syncable.h" | 5 #include "components/pref_registry/pref_registry_syncable.h" |
| 6 | 6 |
| 7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
| 8 #include "base/prefs/default_pref_store.h" | 8 #include "base/prefs/default_pref_store.h" |
| 9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 return new base::FundamentalValue(val); | 37 return new base::FundamentalValue(val); |
| 38 } | 38 } |
| 39 | 39 |
| 40 case base::Value::TYPE_DOUBLE: { | 40 case base::Value::TYPE_DOUBLE: { |
| 41 double val; | 41 double val; |
| 42 base::StringToDouble(resource_string, &val); | 42 base::StringToDouble(resource_string, &val); |
| 43 return base::Value::CreateDoubleValue(val); | 43 return base::Value::CreateDoubleValue(val); |
| 44 } | 44 } |
| 45 | 45 |
| 46 case base::Value::TYPE_STRING: { | 46 case base::Value::TYPE_STRING: { |
| 47 return base::Value::CreateStringValue(resource_string); | 47 return new base::StringValue(resource_string); |
| 48 } | 48 } |
| 49 | 49 |
| 50 default: { | 50 default: { |
| 51 NOTREACHED() << | 51 NOTREACHED() << |
| 52 "list and dictionary types cannot have default locale values"; | 52 "list and dictionary types cannot have default locale values"; |
| 53 } | 53 } |
| 54 } | 54 } |
| 55 NOTREACHED(); | 55 NOTREACHED(); |
| 56 return base::Value::CreateNullValue(); | 56 return base::Value::CreateNullValue(); |
| 57 } | 57 } |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 double default_value, | 92 double default_value, |
| 93 PrefSyncStatus sync_status) { | 93 PrefSyncStatus sync_status) { |
| 94 RegisterSyncablePreference(path, | 94 RegisterSyncablePreference(path, |
| 95 base::Value::CreateDoubleValue(default_value), | 95 base::Value::CreateDoubleValue(default_value), |
| 96 sync_status); | 96 sync_status); |
| 97 } | 97 } |
| 98 | 98 |
| 99 void PrefRegistrySyncable::RegisterStringPref(const char* path, | 99 void PrefRegistrySyncable::RegisterStringPref(const char* path, |
| 100 const std::string& default_value, | 100 const std::string& default_value, |
| 101 PrefSyncStatus sync_status) { | 101 PrefSyncStatus sync_status) { |
| 102 RegisterSyncablePreference(path, | 102 RegisterSyncablePreference( |
| 103 base::Value::CreateStringValue(default_value), | 103 path, new base::StringValue(default_value), sync_status); |
| 104 sync_status); | |
| 105 } | 104 } |
| 106 | 105 |
| 107 void PrefRegistrySyncable::RegisterFilePathPref( | 106 void PrefRegistrySyncable::RegisterFilePathPref( |
| 108 const char* path, | 107 const char* path, |
| 109 const base::FilePath& default_value, | 108 const base::FilePath& default_value, |
| 110 PrefSyncStatus sync_status) { | 109 PrefSyncStatus sync_status) { |
| 111 RegisterSyncablePreference(path, | 110 RegisterSyncablePreference( |
| 112 base::Value::CreateStringValue( | 111 path, new base::StringValue(default_value.value()), sync_status); |
| 113 default_value.value()), | |
| 114 sync_status); | |
| 115 } | 112 } |
| 116 | 113 |
| 117 void PrefRegistrySyncable::RegisterListPref(const char* path, | 114 void PrefRegistrySyncable::RegisterListPref(const char* path, |
| 118 PrefSyncStatus sync_status) { | 115 PrefSyncStatus sync_status) { |
| 119 RegisterSyncablePreference(path, new base::ListValue(), sync_status); | 116 RegisterSyncablePreference(path, new base::ListValue(), sync_status); |
| 120 } | 117 } |
| 121 | 118 |
| 122 void PrefRegistrySyncable::RegisterListPref(const char* path, | 119 void PrefRegistrySyncable::RegisterListPref(const char* path, |
| 123 base::ListValue* default_value, | 120 base::ListValue* default_value, |
| 124 PrefSyncStatus sync_status) { | 121 PrefSyncStatus sync_status) { |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 locale_default_message_id), | 177 locale_default_message_id), |
| 181 sync_status); | 178 sync_status); |
| 182 } | 179 } |
| 183 | 180 |
| 184 void PrefRegistrySyncable::RegisterInt64Pref( | 181 void PrefRegistrySyncable::RegisterInt64Pref( |
| 185 const char* path, | 182 const char* path, |
| 186 int64 default_value, | 183 int64 default_value, |
| 187 PrefSyncStatus sync_status) { | 184 PrefSyncStatus sync_status) { |
| 188 RegisterSyncablePreference( | 185 RegisterSyncablePreference( |
| 189 path, | 186 path, |
| 190 base::Value::CreateStringValue(base::Int64ToString(default_value)), | 187 new base::StringValue(base::Int64ToString(default_value)), |
| 191 sync_status); | 188 sync_status); |
| 192 } | 189 } |
| 193 | 190 |
| 194 void PrefRegistrySyncable::RegisterUint64Pref( | 191 void PrefRegistrySyncable::RegisterUint64Pref( |
| 195 const char* path, | 192 const char* path, |
| 196 uint64 default_value, | 193 uint64 default_value, |
| 197 PrefSyncStatus sync_status) { | 194 PrefSyncStatus sync_status) { |
| 198 RegisterSyncablePreference( | 195 RegisterSyncablePreference( |
| 199 path, | 196 path, |
| 200 base::Value::CreateStringValue(base::Uint64ToString(default_value)), | 197 new base::StringValue(base::Uint64ToString(default_value)), |
| 201 sync_status); | 198 sync_status); |
| 202 } | 199 } |
| 203 | 200 |
| 204 void PrefRegistrySyncable::RegisterSyncablePreference( | 201 void PrefRegistrySyncable::RegisterSyncablePreference( |
| 205 const char* path, | 202 const char* path, |
| 206 base::Value* default_value, | 203 base::Value* default_value, |
| 207 PrefSyncStatus sync_status) { | 204 PrefSyncStatus sync_status) { |
| 208 PrefRegistry::RegisterPreference(path, default_value); | 205 PrefRegistry::RegisterPreference(path, default_value); |
| 209 | 206 |
| 210 if (sync_status == PrefRegistrySyncable::SYNCABLE_PREF || | 207 if (sync_status == PrefRegistrySyncable::SYNCABLE_PREF || |
| 211 sync_status == PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF) { | 208 sync_status == PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF) { |
| 212 syncable_preferences_[path] = sync_status; | 209 syncable_preferences_[path] = sync_status; |
| 213 | 210 |
| 214 if (!callback_.is_null()) | 211 if (!callback_.is_null()) |
| 215 callback_.Run(path, sync_status); | 212 callback_.Run(path, sync_status); |
| 216 } | 213 } |
| 217 } | 214 } |
| 218 | 215 |
| 219 scoped_refptr<PrefRegistrySyncable> PrefRegistrySyncable::ForkForIncognito() { | 216 scoped_refptr<PrefRegistrySyncable> PrefRegistrySyncable::ForkForIncognito() { |
| 220 // TODO(joi): We can directly reuse the same PrefRegistry once | 217 // TODO(joi): We can directly reuse the same PrefRegistry once |
| 221 // PrefService no longer registers for callbacks on registration and | 218 // PrefService no longer registers for callbacks on registration and |
| 222 // unregistration. | 219 // unregistration. |
| 223 scoped_refptr<PrefRegistrySyncable> registry(new PrefRegistrySyncable()); | 220 scoped_refptr<PrefRegistrySyncable> registry(new PrefRegistrySyncable()); |
| 224 registry->defaults_ = defaults_; | 221 registry->defaults_ = defaults_; |
| 225 return registry; | 222 return registry; |
| 226 } | 223 } |
| 227 | 224 |
| 228 } // namespace user_prefs | 225 } // namespace user_prefs |
| OLD | NEW |