| 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 "chrome/browser/prefs/pref_service.h" | 5 #include "chrome/browser/prefs/pref_service.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 713 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 724 | 724 |
| 725 const Preference* pref = FindPreference(path); | 725 const Preference* pref = FindPreference(path); |
| 726 if (!pref) { | 726 if (!pref) { |
| 727 NOTREACHED() << "Trying to get an unregistered pref: " << path; | 727 NOTREACHED() << "Trying to get an unregistered pref: " << path; |
| 728 return NULL; | 728 return NULL; |
| 729 } | 729 } |
| 730 | 730 |
| 731 // Look for an existing preference in the user store. If it doesn't | 731 // Look for an existing preference in the user store. If it doesn't |
| 732 // exist, return NULL. | 732 // exist, return NULL. |
| 733 base::Value* value = NULL; | 733 base::Value* value = NULL; |
| 734 if (user_pref_store_->GetMutableValue(path, &value) != PrefStore::READ_OK) | 734 if (!user_pref_store_->GetMutableValue(path, &value)) |
| 735 return NULL; | 735 return NULL; |
| 736 | 736 |
| 737 if (!value->IsType(pref->GetType())) { | 737 if (!value->IsType(pref->GetType())) { |
| 738 NOTREACHED() << "Pref value type doesn't match registered type."; | 738 NOTREACHED() << "Pref value type doesn't match registered type."; |
| 739 return NULL; | 739 return NULL; |
| 740 } | 740 } |
| 741 | 741 |
| 742 return value; | 742 return value; |
| 743 } | 743 } |
| 744 | 744 |
| 745 const base::Value* PrefService::GetDefaultPrefValue(const char* path) const { | 745 const base::Value* PrefService::GetDefaultPrefValue(const char* path) const { |
| 746 DCHECK(CalledOnValidThread()); | 746 DCHECK(CalledOnValidThread()); |
| 747 // Lookup the preference in the default store. | 747 // Lookup the preference in the default store. |
| 748 const base::Value* value = NULL; | 748 const base::Value* value = NULL; |
| 749 if (default_store_->GetValue(path, &value) != PrefStore::READ_OK) { | 749 if (!default_store_->GetValue(path, &value)) { |
| 750 NOTREACHED() << "Default value missing for pref: " << path; | 750 NOTREACHED() << "Default value missing for pref: " << path; |
| 751 return NULL; | 751 return NULL; |
| 752 } | 752 } |
| 753 return value; | 753 return value; |
| 754 } | 754 } |
| 755 | 755 |
| 756 const ListValue* PrefService::GetList(const char* path) const { | 756 const ListValue* PrefService::GetList(const char* path) const { |
| 757 DCHECK(CalledOnValidThread()); | 757 DCHECK(CalledOnValidThread()); |
| 758 | 758 |
| 759 const Preference* pref = FindPreference(path); | 759 const Preference* pref = FindPreference(path); |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 925 return NULL; | 925 return NULL; |
| 926 } | 926 } |
| 927 if (pref->GetType() != type) { | 927 if (pref->GetType() != type) { |
| 928 NOTREACHED() << "Wrong type for GetMutableValue: " << path; | 928 NOTREACHED() << "Wrong type for GetMutableValue: " << path; |
| 929 return NULL; | 929 return NULL; |
| 930 } | 930 } |
| 931 | 931 |
| 932 // Look for an existing preference in the user store. If it doesn't | 932 // Look for an existing preference in the user store. If it doesn't |
| 933 // exist or isn't the correct type, create a new user preference. | 933 // exist or isn't the correct type, create a new user preference. |
| 934 Value* value = NULL; | 934 Value* value = NULL; |
| 935 if (user_pref_store_->GetMutableValue(path, &value) != PrefStore::READ_OK || | 935 if (!user_pref_store_->GetMutableValue(path, &value) || |
| 936 !value->IsType(type)) { | 936 !value->IsType(type)) { |
| 937 if (type == Value::TYPE_DICTIONARY) { | 937 if (type == Value::TYPE_DICTIONARY) { |
| 938 value = new DictionaryValue; | 938 value = new DictionaryValue; |
| 939 } else if (type == Value::TYPE_LIST) { | 939 } else if (type == Value::TYPE_LIST) { |
| 940 value = new ListValue; | 940 value = new ListValue; |
| 941 } else { | 941 } else { |
| 942 NOTREACHED(); | 942 NOTREACHED(); |
| 943 } | 943 } |
| 944 user_pref_store_->SetValueSilently(path, value); | 944 user_pref_store_->SetValueSilently(path, value); |
| 945 } | 945 } |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1059 return pref_value_store()->PrefValueFromDefaultStore(name_.c_str()); | 1059 return pref_value_store()->PrefValueFromDefaultStore(name_.c_str()); |
| 1060 } | 1060 } |
| 1061 | 1061 |
| 1062 bool PrefService::Preference::IsUserModifiable() const { | 1062 bool PrefService::Preference::IsUserModifiable() const { |
| 1063 return pref_value_store()->PrefValueUserModifiable(name_.c_str()); | 1063 return pref_value_store()->PrefValueUserModifiable(name_.c_str()); |
| 1064 } | 1064 } |
| 1065 | 1065 |
| 1066 bool PrefService::Preference::IsExtensionModifiable() const { | 1066 bool PrefService::Preference::IsExtensionModifiable() const { |
| 1067 return pref_value_store()->PrefValueExtensionModifiable(name_.c_str()); | 1067 return pref_value_store()->PrefValueExtensionModifiable(name_.c_str()); |
| 1068 } | 1068 } |
| OLD | NEW |