| 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 28 matching lines...) Expand all Loading... |
| 39 | 39 |
| 40 // A helper function for RegisterLocalized*Pref that creates a Value* based on | 40 // A helper function for RegisterLocalized*Pref that creates a Value* based on |
| 41 // the string value in the locale dll. Because we control the values in a | 41 // the string value in the locale dll. Because we control the values in a |
| 42 // locale dll, this should always return a Value of the appropriate type. | 42 // locale dll, this should always return a Value of the appropriate type. |
| 43 Value* CreateLocaleDefaultValue(base::Value::Type type, int message_id) { | 43 Value* CreateLocaleDefaultValue(base::Value::Type type, int message_id) { |
| 44 std::string resource_string = l10n_util::GetStringUTF8(message_id); | 44 std::string resource_string = l10n_util::GetStringUTF8(message_id); |
| 45 DCHECK(!resource_string.empty()); | 45 DCHECK(!resource_string.empty()); |
| 46 switch (type) { | 46 switch (type) { |
| 47 case Value::TYPE_BOOLEAN: { | 47 case Value::TYPE_BOOLEAN: { |
| 48 if ("true" == resource_string) | 48 if ("true" == resource_string) |
| 49 return Value::CreateBooleanValue(true); | 49 return base::TrueValue(); |
| 50 if ("false" == resource_string) | 50 if ("false" == resource_string) |
| 51 return Value::CreateBooleanValue(false); | 51 return base::FalseValue(); |
| 52 break; | 52 break; |
| 53 } | 53 } |
| 54 | 54 |
| 55 case Value::TYPE_INTEGER: { | 55 case Value::TYPE_INTEGER: { |
| 56 int val; | 56 int val; |
| 57 base::StringToInt(resource_string, &val); | 57 base::StringToInt(resource_string, &val); |
| 58 return Value::CreateIntegerValue(val); | 58 return base::NumberValue::New(val); |
| 59 } | 59 } |
| 60 | 60 |
| 61 case Value::TYPE_DOUBLE: { | 61 case Value::TYPE_DOUBLE: { |
| 62 double val; | 62 double val; |
| 63 base::StringToDouble(resource_string, &val); | 63 base::StringToDouble(resource_string, &val); |
| 64 return Value::CreateDoubleValue(val); | 64 return base::NumberValue::New(val); |
| 65 } | 65 } |
| 66 | 66 |
| 67 case Value::TYPE_STRING: { | 67 case Value::TYPE_STRING: { |
| 68 return Value::CreateStringValue(resource_string); | 68 return base::StringValue::New(resource_string); |
| 69 } | 69 } |
| 70 | 70 |
| 71 default: { | 71 default: { |
| 72 NOTREACHED() << | 72 NOTREACHED() << |
| 73 "list and dictionary types cannot have default locale values"; | 73 "list and dictionary types cannot have default locale values"; |
| 74 } | 74 } |
| 75 } | 75 } |
| 76 NOTREACHED(); | 76 NOTREACHED(); |
| 77 return Value::CreateNullValue(); | 77 return base::NullValue(); |
| 78 } | 78 } |
| 79 | 79 |
| 80 // Forwards a notification after a PostMessage so that we can wait for the | 80 // Forwards a notification after a PostMessage so that we can wait for the |
| 81 // MessageLoop to run. | 81 // MessageLoop to run. |
| 82 void NotifyReadError(int message_id) { | 82 void NotifyReadError(int message_id) { |
| 83 ShowProfileErrorDialog(message_id); | 83 ShowProfileErrorDialog(message_id); |
| 84 } | 84 } |
| 85 | 85 |
| 86 // Shows notifications which correspond to PersistentPrefStore's reading errors. | 86 // Shows notifications which correspond to PersistentPrefStore's reading errors. |
| 87 class ReadErrorHandler : public PersistentPrefStore::ReadErrorDelegate { | 87 class ReadErrorHandler : public PersistentPrefStore::ReadErrorDelegate { |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 } // namespace | 275 } // namespace |
| 276 | 276 |
| 277 | 277 |
| 278 // Local State prefs. | 278 // Local State prefs. |
| 279 void PrefService::RegisterBooleanPref(const char* path, | 279 void PrefService::RegisterBooleanPref(const char* path, |
| 280 bool default_value) { | 280 bool default_value) { |
| 281 // If this fails, the pref service in use is a profile pref service, so the | 281 // If this fails, the pref service in use is a profile pref service, so the |
| 282 // sync status must be provided (see profile pref registration calls below). | 282 // sync status must be provided (see profile pref registration calls below). |
| 283 DCHECK(IsLocalStatePrefService(this)); | 283 DCHECK(IsLocalStatePrefService(this)); |
| 284 RegisterPreference(path, | 284 RegisterPreference(path, |
| 285 Value::CreateBooleanValue(default_value), | 285 base::BooleanValue::New(default_value), |
| 286 UNSYNCABLE_PREF); | 286 UNSYNCABLE_PREF); |
| 287 } | 287 } |
| 288 | 288 |
| 289 void PrefService::RegisterIntegerPref(const char* path, int default_value) { | 289 void PrefService::RegisterIntegerPref(const char* path, int default_value) { |
| 290 // If this fails, the pref service in use is a profile pref service, so the | 290 // If this fails, the pref service in use is a profile pref service, so the |
| 291 // sync status must be provided (see profile pref registration calls below). | 291 // sync status must be provided (see profile pref registration calls below). |
| 292 DCHECK(IsLocalStatePrefService(this)); | 292 DCHECK(IsLocalStatePrefService(this)); |
| 293 RegisterPreference(path, | 293 RegisterPreference(path, |
| 294 Value::CreateIntegerValue(default_value), | 294 base::NumberValue::New(default_value), |
| 295 UNSYNCABLE_PREF); | 295 UNSYNCABLE_PREF); |
| 296 } | 296 } |
| 297 | 297 |
| 298 void PrefService::RegisterDoublePref(const char* path, double default_value) { | 298 void PrefService::RegisterDoublePref(const char* path, double default_value) { |
| 299 // If this fails, the pref service in use is a profile pref service, so the | 299 // If this fails, the pref service in use is a profile pref service, so the |
| 300 // sync status must be provided (see profile pref registration calls below). | 300 // sync status must be provided (see profile pref registration calls below). |
| 301 DCHECK(IsLocalStatePrefService(this)); | 301 DCHECK(IsLocalStatePrefService(this)); |
| 302 RegisterPreference(path, | 302 RegisterPreference(path, |
| 303 Value::CreateDoubleValue(default_value), | 303 base::NumberValue::New(default_value), |
| 304 UNSYNCABLE_PREF); | 304 UNSYNCABLE_PREF); |
| 305 } | 305 } |
| 306 | 306 |
| 307 void PrefService::RegisterStringPref(const char* path, | 307 void PrefService::RegisterStringPref(const char* path, |
| 308 const std::string& default_value) { | 308 const std::string& default_value) { |
| 309 // If this fails, the pref service in use is a profile pref service, so the | 309 // If this fails, the pref service in use is a profile pref service, so the |
| 310 // sync status must be provided (see profile pref registration calls below). | 310 // sync status must be provided (see profile pref registration calls below). |
| 311 DCHECK(IsLocalStatePrefService(this)); | 311 DCHECK(IsLocalStatePrefService(this)); |
| 312 RegisterPreference(path, | 312 RegisterPreference(path, |
| 313 Value::CreateStringValue(default_value), | 313 base::StringValue::New(default_value), |
| 314 UNSYNCABLE_PREF); | 314 UNSYNCABLE_PREF); |
| 315 } | 315 } |
| 316 | 316 |
| 317 void PrefService::RegisterFilePathPref(const char* path, | 317 void PrefService::RegisterFilePathPref(const char* path, |
| 318 const FilePath& default_value) { | 318 const FilePath& default_value) { |
| 319 // If this fails, the pref service in use is a profile pref service, so the | 319 // If this fails, the pref service in use is a profile pref service, so the |
| 320 // sync status must be provided (see profile pref registration calls below). | 320 // sync status must be provided (see profile pref registration calls below). |
| 321 DCHECK(IsLocalStatePrefService(this)); | 321 DCHECK(IsLocalStatePrefService(this)); |
| 322 RegisterPreference(path, | 322 RegisterPreference(path, |
| 323 Value::CreateStringValue(default_value.value()), | 323 base::StringValue::New(default_value.value()), |
| 324 UNSYNCABLE_PREF); | 324 UNSYNCABLE_PREF); |
| 325 } | 325 } |
| 326 | 326 |
| 327 void PrefService::RegisterListPref(const char* path) { | 327 void PrefService::RegisterListPref(const char* path) { |
| 328 // If this fails, the pref service in use is a profile pref service, so the | 328 // If this fails, the pref service in use is a profile pref service, so the |
| 329 // sync status must be provided (see profile pref registration calls below). | 329 // sync status must be provided (see profile pref registration calls below). |
| 330 DCHECK(IsLocalStatePrefService(this)); | 330 DCHECK(IsLocalStatePrefService(this)); |
| 331 RegisterPreference(path, | 331 RegisterPreference(path, |
| 332 new ListValue(), | 332 new ListValue(), |
| 333 UNSYNCABLE_PREF); | 333 UNSYNCABLE_PREF); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 404 CreateLocaleDefaultValue(Value::TYPE_STRING, locale_default_message_id), | 404 CreateLocaleDefaultValue(Value::TYPE_STRING, locale_default_message_id), |
| 405 UNSYNCABLE_PREF); | 405 UNSYNCABLE_PREF); |
| 406 } | 406 } |
| 407 | 407 |
| 408 void PrefService::RegisterInt64Pref(const char* path, int64 default_value) { | 408 void PrefService::RegisterInt64Pref(const char* path, int64 default_value) { |
| 409 // If this fails, the pref service in use is a profile pref service, so the | 409 // If this fails, the pref service in use is a profile pref service, so the |
| 410 // sync status must be provided (see profile pref registration calls below). | 410 // sync status must be provided (see profile pref registration calls below). |
| 411 DCHECK(IsLocalStatePrefService(this)); | 411 DCHECK(IsLocalStatePrefService(this)); |
| 412 RegisterPreference( | 412 RegisterPreference( |
| 413 path, | 413 path, |
| 414 Value::CreateStringValue(base::Int64ToString(default_value)), | 414 base::StringValue::New(base::Int64ToString(default_value)), |
| 415 UNSYNCABLE_PREF); | 415 UNSYNCABLE_PREF); |
| 416 } | 416 } |
| 417 | 417 |
| 418 // Profile prefs (must use the sync_status variable). | 418 // Profile prefs (must use the sync_status variable). |
| 419 void PrefService::RegisterBooleanPref(const char* path, | 419 void PrefService::RegisterBooleanPref(const char* path, |
| 420 bool default_value, | 420 bool default_value, |
| 421 PrefSyncStatus sync_status) { | 421 PrefSyncStatus sync_status) { |
| 422 DCHECK(IsProfilePrefService(this)); | 422 DCHECK(IsProfilePrefService(this)); |
| 423 RegisterPreference(path, | 423 RegisterPreference(path, |
| 424 Value::CreateBooleanValue(default_value), | 424 base::BooleanValue::New(default_value), |
| 425 sync_status); | 425 sync_status); |
| 426 } | 426 } |
| 427 | 427 |
| 428 void PrefService::RegisterIntegerPref(const char* path, | 428 void PrefService::RegisterIntegerPref(const char* path, |
| 429 int default_value, | 429 int default_value, |
| 430 PrefSyncStatus sync_status) { | 430 PrefSyncStatus sync_status) { |
| 431 DCHECK(IsProfilePrefService(this)); | 431 DCHECK(IsProfilePrefService(this)); |
| 432 RegisterPreference(path, | 432 RegisterPreference(path, |
| 433 Value::CreateIntegerValue(default_value), | 433 base::NumberValue::New(default_value), |
| 434 sync_status); | 434 sync_status); |
| 435 } | 435 } |
| 436 | 436 |
| 437 void PrefService::RegisterDoublePref(const char* path, | 437 void PrefService::RegisterDoublePref(const char* path, |
| 438 double default_value, | 438 double default_value, |
| 439 PrefSyncStatus sync_status) { | 439 PrefSyncStatus sync_status) { |
| 440 DCHECK(IsProfilePrefService(this)); | 440 DCHECK(IsProfilePrefService(this)); |
| 441 RegisterPreference(path, | 441 RegisterPreference(path, |
| 442 Value::CreateDoubleValue(default_value), | 442 base::NumberValue::New(default_value), |
| 443 sync_status); | 443 sync_status); |
| 444 } | 444 } |
| 445 | 445 |
| 446 void PrefService::RegisterStringPref(const char* path, | 446 void PrefService::RegisterStringPref(const char* path, |
| 447 const std::string& default_value, | 447 const std::string& default_value, |
| 448 PrefSyncStatus sync_status) { | 448 PrefSyncStatus sync_status) { |
| 449 DCHECK(IsProfilePrefService(this)); | 449 DCHECK(IsProfilePrefService(this)); |
| 450 RegisterPreference(path, | 450 RegisterPreference(path, |
| 451 Value::CreateStringValue(default_value), | 451 base::StringValue::New(default_value), |
| 452 sync_status); | 452 sync_status); |
| 453 } | 453 } |
| 454 | 454 |
| 455 void PrefService::RegisterFilePathPref(const char* path, | 455 void PrefService::RegisterFilePathPref(const char* path, |
| 456 const FilePath& default_value, | 456 const FilePath& default_value, |
| 457 PrefSyncStatus sync_status) { | 457 PrefSyncStatus sync_status) { |
| 458 DCHECK(IsProfilePrefService(this)); | 458 DCHECK(IsProfilePrefService(this)); |
| 459 RegisterPreference(path, | 459 RegisterPreference(path, |
| 460 Value::CreateStringValue(default_value.value()), | 460 base::StringValue::New(default_value.value()), |
| 461 sync_status); | 461 sync_status); |
| 462 } | 462 } |
| 463 | 463 |
| 464 void PrefService::RegisterListPref(const char* path, | 464 void PrefService::RegisterListPref(const char* path, |
| 465 PrefSyncStatus sync_status) { | 465 PrefSyncStatus sync_status) { |
| 466 DCHECK(IsProfilePrefService(this)); | 466 DCHECK(IsProfilePrefService(this)); |
| 467 RegisterPreference(path, new ListValue(), sync_status); | 467 RegisterPreference(path, new ListValue(), sync_status); |
| 468 } | 468 } |
| 469 | 469 |
| 470 void PrefService::RegisterListPref(const char* path, | 470 void PrefService::RegisterListPref(const char* path, |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 526 CreateLocaleDefaultValue(Value::TYPE_STRING, locale_default_message_id), | 526 CreateLocaleDefaultValue(Value::TYPE_STRING, locale_default_message_id), |
| 527 sync_status); | 527 sync_status); |
| 528 } | 528 } |
| 529 | 529 |
| 530 void PrefService::RegisterInt64Pref(const char* path, | 530 void PrefService::RegisterInt64Pref(const char* path, |
| 531 int64 default_value, | 531 int64 default_value, |
| 532 PrefSyncStatus sync_status) { | 532 PrefSyncStatus sync_status) { |
| 533 DCHECK(IsProfilePrefService(this)); | 533 DCHECK(IsProfilePrefService(this)); |
| 534 RegisterPreference( | 534 RegisterPreference( |
| 535 path, | 535 path, |
| 536 Value::CreateStringValue(base::Int64ToString(default_value)), | 536 base::StringValue::New(base::Int64ToString(default_value)), |
| 537 sync_status); | 537 sync_status); |
| 538 } | 538 } |
| 539 | 539 |
| 540 bool PrefService::GetBoolean(const char* path) const { | 540 bool PrefService::GetBoolean(const char* path) const { |
| 541 DCHECK(CalledOnValidThread()); | 541 DCHECK(CalledOnValidThread()); |
| 542 | 542 |
| 543 bool result = false; | 543 bool result = false; |
| 544 | 544 |
| 545 const Preference* pref = FindPreference(path); | 545 const Preference* pref = FindPreference(path); |
| 546 if (!pref) { | 546 if (!pref) { |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 731 return; | 731 return; |
| 732 } | 732 } |
| 733 user_pref_store_->RemoveValue(path); | 733 user_pref_store_->RemoveValue(path); |
| 734 } | 734 } |
| 735 | 735 |
| 736 void PrefService::Set(const char* path, const Value& value) { | 736 void PrefService::Set(const char* path, const Value& value) { |
| 737 SetUserPrefValue(path, value.DeepCopy()); | 737 SetUserPrefValue(path, value.DeepCopy()); |
| 738 } | 738 } |
| 739 | 739 |
| 740 void PrefService::SetBoolean(const char* path, bool value) { | 740 void PrefService::SetBoolean(const char* path, bool value) { |
| 741 SetUserPrefValue(path, Value::CreateBooleanValue(value)); | 741 SetUserPrefValue(path, base::BooleanValue::New(value)); |
| 742 } | 742 } |
| 743 | 743 |
| 744 void PrefService::SetInteger(const char* path, int value) { | 744 void PrefService::SetInteger(const char* path, int value) { |
| 745 SetUserPrefValue(path, Value::CreateIntegerValue(value)); | 745 SetUserPrefValue(path, base::NumberValue::New(value)); |
| 746 } | 746 } |
| 747 | 747 |
| 748 void PrefService::SetDouble(const char* path, double value) { | 748 void PrefService::SetDouble(const char* path, double value) { |
| 749 SetUserPrefValue(path, Value::CreateDoubleValue(value)); | 749 SetUserPrefValue(path, base::NumberValue::New(value)); |
| 750 } | 750 } |
| 751 | 751 |
| 752 void PrefService::SetString(const char* path, const std::string& value) { | 752 void PrefService::SetString(const char* path, const std::string& value) { |
| 753 SetUserPrefValue(path, Value::CreateStringValue(value)); | 753 SetUserPrefValue(path, base::StringValue::New(value)); |
| 754 } | 754 } |
| 755 | 755 |
| 756 void PrefService::SetFilePath(const char* path, const FilePath& value) { | 756 void PrefService::SetFilePath(const char* path, const FilePath& value) { |
| 757 SetUserPrefValue(path, base::CreateFilePathValue(value)); | 757 SetUserPrefValue(path, base::CreateFilePathValue(value)); |
| 758 } | 758 } |
| 759 | 759 |
| 760 void PrefService::SetInt64(const char* path, int64 value) { | 760 void PrefService::SetInt64(const char* path, int64 value) { |
| 761 SetUserPrefValue(path, Value::CreateStringValue(base::Int64ToString(value))); | 761 SetUserPrefValue(path, base::StringValue::New(base::Int64ToString(value))); |
| 762 } | 762 } |
| 763 | 763 |
| 764 int64 PrefService::GetInt64(const char* path) const { | 764 int64 PrefService::GetInt64(const char* path) const { |
| 765 DCHECK(CalledOnValidThread()); | 765 DCHECK(CalledOnValidThread()); |
| 766 | 766 |
| 767 const Preference* pref = FindPreference(path); | 767 const Preference* pref = FindPreference(path); |
| 768 if (!pref) { | 768 if (!pref) { |
| 769 NOTREACHED() << "Trying to read an unregistered pref: " << path; | 769 NOTREACHED() << "Trying to read an unregistered pref: " << path; |
| 770 return 0; | 770 return 0; |
| 771 } | 771 } |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 894 return pref_value_store()->PrefValueFromDefaultStore(name_.c_str()); | 894 return pref_value_store()->PrefValueFromDefaultStore(name_.c_str()); |
| 895 } | 895 } |
| 896 | 896 |
| 897 bool PrefService::Preference::IsUserModifiable() const { | 897 bool PrefService::Preference::IsUserModifiable() const { |
| 898 return pref_value_store()->PrefValueUserModifiable(name_.c_str()); | 898 return pref_value_store()->PrefValueUserModifiable(name_.c_str()); |
| 899 } | 899 } |
| 900 | 900 |
| 901 bool PrefService::Preference::IsExtensionModifiable() const { | 901 bool PrefService::Preference::IsExtensionModifiable() const { |
| 902 return pref_value_store()->PrefValueExtensionModifiable(name_.c_str()); | 902 return pref_value_store()->PrefValueExtensionModifiable(name_.c_str()); |
| 903 } | 903 } |
| OLD | NEW |