Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(646)

Side by Side Diff: chrome/browser/prefs/pref_service.cc

Issue 7661009: base: Add Is* functions to Value class. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: tony review Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 780 matching lines...) Expand 10 before | Expand all | Expand 10 after
791 if (pref->GetType() != type) { 791 if (pref->GetType() != type) {
792 NOTREACHED() << "Wrong type for GetMutableValue: " << path; 792 NOTREACHED() << "Wrong type for GetMutableValue: " << path;
793 return NULL; 793 return NULL;
794 } 794 }
795 795
796 // Look for an existing preference in the user store. If it doesn't 796 // Look for an existing preference in the user store. If it doesn't
797 // exist or isn't the correct type, create a new user preference. 797 // exist or isn't the correct type, create a new user preference.
798 Value* value = NULL; 798 Value* value = NULL;
799 if (user_pref_store_->GetMutableValue(path, &value) 799 if (user_pref_store_->GetMutableValue(path, &value)
800 != PersistentPrefStore::READ_OK || 800 != PersistentPrefStore::READ_OK ||
801 !value->IsType(type)) { 801 value->GetType() != type) {
802 if (type == Value::TYPE_DICTIONARY) { 802 if (type == Value::TYPE_DICTIONARY) {
803 value = new DictionaryValue; 803 value = new DictionaryValue;
804 } else if (type == Value::TYPE_LIST) { 804 } else if (type == Value::TYPE_LIST) {
805 value = new ListValue; 805 value = new ListValue;
806 } else { 806 } else {
807 NOTREACHED(); 807 NOTREACHED();
808 } 808 }
809 user_pref_store_->SetValueSilently(path, value); 809 user_pref_store_->SetValueSilently(path, value);
810 } 810 }
811 return value; 811 return value;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
854 base::Value::Type PrefService::Preference::GetType() const { 854 base::Value::Type PrefService::Preference::GetType() const {
855 return type_; 855 return type_;
856 } 856 }
857 857
858 const Value* PrefService::Preference::GetValue() const { 858 const Value* PrefService::Preference::GetValue() const {
859 DCHECK(pref_service_->FindPreference(name_.c_str())) << 859 DCHECK(pref_service_->FindPreference(name_.c_str())) <<
860 "Must register pref before getting its value"; 860 "Must register pref before getting its value";
861 861
862 const Value* found_value = NULL; 862 const Value* found_value = NULL;
863 if (pref_value_store()->GetValue(name_, type_, &found_value)) { 863 if (pref_value_store()->GetValue(name_, type_, &found_value)) {
864 DCHECK(found_value->IsType(type_)); 864 DCHECK(found_value->GetType() == type_);
865 return found_value; 865 return found_value;
866 } 866 }
867 867
868 // Every registered preference has at least a default value. 868 // Every registered preference has at least a default value.
869 NOTREACHED() << "no valid value found for registered pref " << name_; 869 NOTREACHED() << "no valid value found for registered pref " << name_;
870 return NULL; 870 return NULL;
871 } 871 }
872 872
873 bool PrefService::Preference::IsManaged() const { 873 bool PrefService::Preference::IsManaged() const {
874 return pref_value_store()->PrefValueInManagedStore(name_.c_str()); 874 return pref_value_store()->PrefValueInManagedStore(name_.c_str());
(...skipping 19 matching lines...) Expand all
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 }
OLDNEW
« no previous file with comments | « chrome/browser/prefs/pref_model_associator.cc ('k') | chrome/browser/prefs/pref_service_uitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698