| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/prefs/pref_service.h" | 5 #include "chrome/browser/prefs/pref_service.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 return Value::CreateBooleanValue(false); | 49 return Value::CreateBooleanValue(false); |
| 50 break; | 50 break; |
| 51 } | 51 } |
| 52 | 52 |
| 53 case Value::TYPE_INTEGER: { | 53 case Value::TYPE_INTEGER: { |
| 54 int val; | 54 int val; |
| 55 base::StringToInt(resource_string, &val); | 55 base::StringToInt(resource_string, &val); |
| 56 return Value::CreateIntegerValue(val); | 56 return Value::CreateIntegerValue(val); |
| 57 } | 57 } |
| 58 | 58 |
| 59 case Value::TYPE_REAL: { | 59 case Value::TYPE_DOUBLE: { |
| 60 double val; | 60 double val; |
| 61 base::StringToDouble(resource_string, &val); | 61 base::StringToDouble(resource_string, &val); |
| 62 return Value::CreateRealValue(val); | 62 return Value::CreateDoubleValue(val); |
| 63 } | 63 } |
| 64 | 64 |
| 65 case Value::TYPE_STRING: { | 65 case Value::TYPE_STRING: { |
| 66 return Value::CreateStringValue(resource_string); | 66 return Value::CreateStringValue(resource_string); |
| 67 } | 67 } |
| 68 | 68 |
| 69 default: { | 69 default: { |
| 70 NOTREACHED() << | 70 NOTREACHED() << |
| 71 "list and dictionary types cannot have default locale values"; | 71 "list and dictionary types cannot have default locale values"; |
| 72 } | 72 } |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 | 220 |
| 221 void PrefService::RegisterBooleanPref(const char* path, | 221 void PrefService::RegisterBooleanPref(const char* path, |
| 222 bool default_value) { | 222 bool default_value) { |
| 223 RegisterPreference(path, Value::CreateBooleanValue(default_value)); | 223 RegisterPreference(path, Value::CreateBooleanValue(default_value)); |
| 224 } | 224 } |
| 225 | 225 |
| 226 void PrefService::RegisterIntegerPref(const char* path, int default_value) { | 226 void PrefService::RegisterIntegerPref(const char* path, int default_value) { |
| 227 RegisterPreference(path, Value::CreateIntegerValue(default_value)); | 227 RegisterPreference(path, Value::CreateIntegerValue(default_value)); |
| 228 } | 228 } |
| 229 | 229 |
| 230 void PrefService::RegisterRealPref(const char* path, double default_value) { | 230 void PrefService::RegisterDoublePref(const char* path, double default_value) { |
| 231 RegisterPreference(path, Value::CreateRealValue(default_value)); | 231 RegisterPreference(path, Value::CreateDoubleValue(default_value)); |
| 232 } | 232 } |
| 233 | 233 |
| 234 void PrefService::RegisterStringPref(const char* path, | 234 void PrefService::RegisterStringPref(const char* path, |
| 235 const std::string& default_value) { | 235 const std::string& default_value) { |
| 236 RegisterPreference(path, Value::CreateStringValue(default_value)); | 236 RegisterPreference(path, Value::CreateStringValue(default_value)); |
| 237 } | 237 } |
| 238 | 238 |
| 239 void PrefService::RegisterFilePathPref(const char* path, | 239 void PrefService::RegisterFilePathPref(const char* path, |
| 240 const FilePath& default_value) { | 240 const FilePath& default_value) { |
| 241 RegisterPreference(path, Value::CreateStringValue(default_value.value())); | 241 RegisterPreference(path, Value::CreateStringValue(default_value.value())); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 256 CreateLocaleDefaultValue(Value::TYPE_BOOLEAN, locale_default_message_id)); | 256 CreateLocaleDefaultValue(Value::TYPE_BOOLEAN, locale_default_message_id)); |
| 257 } | 257 } |
| 258 | 258 |
| 259 void PrefService::RegisterLocalizedIntegerPref(const char* path, | 259 void PrefService::RegisterLocalizedIntegerPref(const char* path, |
| 260 int locale_default_message_id) { | 260 int locale_default_message_id) { |
| 261 RegisterPreference( | 261 RegisterPreference( |
| 262 path, | 262 path, |
| 263 CreateLocaleDefaultValue(Value::TYPE_INTEGER, locale_default_message_id)); | 263 CreateLocaleDefaultValue(Value::TYPE_INTEGER, locale_default_message_id)); |
| 264 } | 264 } |
| 265 | 265 |
| 266 void PrefService::RegisterLocalizedRealPref(const char* path, | 266 void PrefService::RegisterLocalizedDoublePref(const char* path, |
| 267 int locale_default_message_id) { | 267 int locale_default_message_id) { |
| 268 RegisterPreference( | 268 RegisterPreference( |
| 269 path, | 269 path, |
| 270 CreateLocaleDefaultValue(Value::TYPE_REAL, locale_default_message_id)); | 270 CreateLocaleDefaultValue(Value::TYPE_DOUBLE, locale_default_message_id)); |
| 271 } | 271 } |
| 272 | 272 |
| 273 void PrefService::RegisterLocalizedStringPref(const char* path, | 273 void PrefService::RegisterLocalizedStringPref(const char* path, |
| 274 int locale_default_message_id) { | 274 int locale_default_message_id) { |
| 275 RegisterPreference( | 275 RegisterPreference( |
| 276 path, | 276 path, |
| 277 CreateLocaleDefaultValue(Value::TYPE_STRING, locale_default_message_id)); | 277 CreateLocaleDefaultValue(Value::TYPE_STRING, locale_default_message_id)); |
| 278 } | 278 } |
| 279 | 279 |
| 280 bool PrefService::GetBoolean(const char* path) const { | 280 bool PrefService::GetBoolean(const char* path) const { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 300 const Preference* pref = FindPreference(path); | 300 const Preference* pref = FindPreference(path); |
| 301 if (!pref) { | 301 if (!pref) { |
| 302 NOTREACHED() << "Trying to read an unregistered pref: " << path; | 302 NOTREACHED() << "Trying to read an unregistered pref: " << path; |
| 303 return result; | 303 return result; |
| 304 } | 304 } |
| 305 bool rv = pref->GetValue()->GetAsInteger(&result); | 305 bool rv = pref->GetValue()->GetAsInteger(&result); |
| 306 DCHECK(rv); | 306 DCHECK(rv); |
| 307 return result; | 307 return result; |
| 308 } | 308 } |
| 309 | 309 |
| 310 double PrefService::GetReal(const char* path) const { | 310 double PrefService::GetDouble(const char* path) const { |
| 311 DCHECK(CalledOnValidThread()); | 311 DCHECK(CalledOnValidThread()); |
| 312 | 312 |
| 313 double result = 0.0; | 313 double result = 0.0; |
| 314 | 314 |
| 315 const Preference* pref = FindPreference(path); | 315 const Preference* pref = FindPreference(path); |
| 316 if (!pref) { | 316 if (!pref) { |
| 317 NOTREACHED() << "Trying to read an unregistered pref: " << path; | 317 NOTREACHED() << "Trying to read an unregistered pref: " << path; |
| 318 return result; | 318 return result; |
| 319 } | 319 } |
| 320 bool rv = pref->GetValue()->GetAsReal(&result); | 320 bool rv = pref->GetValue()->GetAsDouble(&result); |
| 321 DCHECK(rv); | 321 DCHECK(rv); |
| 322 return result; | 322 return result; |
| 323 } | 323 } |
| 324 | 324 |
| 325 std::string PrefService::GetString(const char* path) const { | 325 std::string PrefService::GetString(const char* path) const { |
| 326 DCHECK(CalledOnValidThread()); | 326 DCHECK(CalledOnValidThread()); |
| 327 | 327 |
| 328 std::string result; | 328 std::string result; |
| 329 | 329 |
| 330 const Preference* pref = FindPreference(path); | 330 const Preference* pref = FindPreference(path); |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 487 } | 487 } |
| 488 | 488 |
| 489 void PrefService::SetBoolean(const char* path, bool value) { | 489 void PrefService::SetBoolean(const char* path, bool value) { |
| 490 SetUserPrefValue(path, Value::CreateBooleanValue(value)); | 490 SetUserPrefValue(path, Value::CreateBooleanValue(value)); |
| 491 } | 491 } |
| 492 | 492 |
| 493 void PrefService::SetInteger(const char* path, int value) { | 493 void PrefService::SetInteger(const char* path, int value) { |
| 494 SetUserPrefValue(path, Value::CreateIntegerValue(value)); | 494 SetUserPrefValue(path, Value::CreateIntegerValue(value)); |
| 495 } | 495 } |
| 496 | 496 |
| 497 void PrefService::SetReal(const char* path, double value) { | 497 void PrefService::SetDouble(const char* path, double value) { |
| 498 SetUserPrefValue(path, Value::CreateRealValue(value)); | 498 SetUserPrefValue(path, Value::CreateDoubleValue(value)); |
| 499 } | 499 } |
| 500 | 500 |
| 501 void PrefService::SetString(const char* path, const std::string& value) { | 501 void PrefService::SetString(const char* path, const std::string& value) { |
| 502 SetUserPrefValue(path, Value::CreateStringValue(value)); | 502 SetUserPrefValue(path, Value::CreateStringValue(value)); |
| 503 } | 503 } |
| 504 | 504 |
| 505 void PrefService::SetFilePath(const char* path, const FilePath& value) { | 505 void PrefService::SetFilePath(const char* path, const FilePath& value) { |
| 506 #if defined(OS_POSIX) | 506 #if defined(OS_POSIX) |
| 507 // Value::SetString only knows about UTF8 strings, so convert the path from | 507 // Value::SetString only knows about UTF8 strings, so convert the path from |
| 508 // the system native value to UTF8. | 508 // the system native value to UTF8. |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 675 | 675 |
| 676 bool PrefService::Preference::IsDefaultValue() const { | 676 bool PrefService::Preference::IsDefaultValue() const { |
| 677 return pref_service_->pref_value_store_-> | 677 return pref_service_->pref_value_store_-> |
| 678 PrefValueFromDefaultStore(name_.c_str()); | 678 PrefValueFromDefaultStore(name_.c_str()); |
| 679 } | 679 } |
| 680 | 680 |
| 681 bool PrefService::Preference::IsUserModifiable() const { | 681 bool PrefService::Preference::IsUserModifiable() const { |
| 682 return pref_service_->pref_value_store_-> | 682 return pref_service_->pref_value_store_-> |
| 683 PrefValueUserModifiable(name_.c_str()); | 683 PrefValueUserModifiable(name_.c_str()); |
| 684 } | 684 } |
| OLD | NEW |