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 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 666 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
677 return NULL; | 677 return NULL; |
678 } | 678 } |
679 const Value* value = pref->GetValue(); | 679 const Value* value = pref->GetValue(); |
680 if (value->GetType() != Value::TYPE_DICTIONARY) { | 680 if (value->GetType() != Value::TYPE_DICTIONARY) { |
681 NOTREACHED(); | 681 NOTREACHED(); |
682 return NULL; | 682 return NULL; |
683 } | 683 } |
684 return static_cast<const DictionaryValue*>(value); | 684 return static_cast<const DictionaryValue*>(value); |
685 } | 685 } |
686 | 686 |
687 const base::Value* PrefService::GetUserPrefValue(const char* path) const { | |
688 DCHECK(CalledOnValidThread()); | |
689 | |
690 const Preference* pref = FindPreference(path); | |
691 if (!pref) { | |
692 NOTREACHED() << "Trying to get an unregistered pref: " << path; | |
693 return NULL; | |
694 } | |
695 | |
696 // Look for an existing preference in the user store. If it doesn't | |
697 // exist, return NULL. | |
698 base::Value* value = NULL; | |
699 if (user_pref_store_->GetMutableValue(path, &value) != | |
700 PersistentPrefStore::READ_OK) { | |
701 return NULL; | |
702 } | |
703 | |
704 if (!value->IsType(pref->GetType())) { | |
705 NOTREACHED() << "Pref value type doesn't match registered type."; | |
706 return NULL; | |
707 } | |
708 | |
709 return value; | |
710 } | |
711 | |
712 const ListValue* PrefService::GetList(const char* path) const { | 687 const ListValue* PrefService::GetList(const char* path) const { |
713 DCHECK(CalledOnValidThread()); | 688 DCHECK(CalledOnValidThread()); |
714 | 689 |
715 const Preference* pref = FindPreference(path); | 690 const Preference* pref = FindPreference(path); |
716 if (!pref) { | 691 if (!pref) { |
717 NOTREACHED() << "Trying to read an unregistered pref: " << path; | 692 NOTREACHED() << "Trying to read an unregistered pref: " << path; |
718 return NULL; | 693 return NULL; |
719 } | 694 } |
720 const Value* value = pref->GetValue(); | 695 const Value* value = pref->GetValue(); |
721 if (value->GetType() != Value::TYPE_LIST) { | 696 if (value->GetType() != Value::TYPE_LIST) { |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
980 return pref_value_store()->PrefValueFromDefaultStore(name_.c_str()); | 955 return pref_value_store()->PrefValueFromDefaultStore(name_.c_str()); |
981 } | 956 } |
982 | 957 |
983 bool PrefService::Preference::IsUserModifiable() const { | 958 bool PrefService::Preference::IsUserModifiable() const { |
984 return pref_value_store()->PrefValueUserModifiable(name_.c_str()); | 959 return pref_value_store()->PrefValueUserModifiable(name_.c_str()); |
985 } | 960 } |
986 | 961 |
987 bool PrefService::Preference::IsExtensionModifiable() const { | 962 bool PrefService::Preference::IsExtensionModifiable() const { |
988 return pref_value_store()->PrefValueExtensionModifiable(name_.c_str()); | 963 return pref_value_store()->PrefValueExtensionModifiable(name_.c_str()); |
989 } | 964 } |
OLD | NEW |