Chromium Code Reviews| 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 709 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 720 | 720 |
| 721 if (FindPreference(path)) { | 721 if (FindPreference(path)) { |
| 722 NOTREACHED() << "Tried to register duplicate pref " << path; | 722 NOTREACHED() << "Tried to register duplicate pref " << path; |
| 723 return; | 723 return; |
| 724 } | 724 } |
| 725 | 725 |
| 726 base::Value::Type orig_type = default_value->GetType(); | 726 base::Value::Type orig_type = default_value->GetType(); |
| 727 DCHECK(orig_type != Value::TYPE_NULL && orig_type != Value::TYPE_BINARY) << | 727 DCHECK(orig_type != Value::TYPE_NULL && orig_type != Value::TYPE_BINARY) << |
| 728 "invalid preference type: " << orig_type; | 728 "invalid preference type: " << orig_type; |
| 729 | 729 |
| 730 // For ListValue and DictionaryValue with non empty default, empty value | |
| 731 // for |path| needs to be persisted in |user_pref_store_|. So that | |
| 732 // non empty default is not used when user sets an empty ListValue or | |
| 733 // DictionaryValue. | |
| 734 bool needs_empty_value = false; | |
| 735 if (orig_type == base::Value::TYPE_LIST) { | |
| 736 base::ListValue * list = static_cast<base::ListValue*>(default_value); | |
|
battre
2012/04/11 21:55:51
nit: base::ListValue*
battre
2012/04/11 21:55:51
instead of the static_cast, I would recommend to u
xiyuan
2012/04/11 22:36:46
Done.
xiyuan
2012/04/11 22:36:46
Done.
| |
| 737 needs_empty_value = !list->empty(); | |
| 738 } else if (orig_type == base::Value::TYPE_DICTIONARY) { | |
| 739 base::DictionaryValue* dict = | |
| 740 static_cast<base::DictionaryValue*>(default_value); | |
| 741 needs_empty_value = !dict->empty(); | |
| 742 } | |
| 743 if (needs_empty_value) | |
| 744 user_pref_store_->MarkNeedsEmptyValue(path); | |
| 745 | |
| 730 // Hand off ownership. | 746 // Hand off ownership. |
| 731 default_store_->SetDefaultValue(path, scoped_value.release()); | 747 default_store_->SetDefaultValue(path, scoped_value.release()); |
| 732 | 748 |
| 733 // Register with sync if necessary. | 749 // Register with sync if necessary. |
| 734 if (sync_status == SYNCABLE_PREF && pref_sync_associator_.get()) | 750 if (sync_status == SYNCABLE_PREF && pref_sync_associator_.get()) |
| 735 pref_sync_associator_->RegisterPref(path); | 751 pref_sync_associator_->RegisterPref(path); |
| 736 } | 752 } |
| 737 | 753 |
| 738 void PrefService::UnregisterPreference(const char* path) { | 754 void PrefService::UnregisterPreference(const char* path) { |
| 739 DCHECK(CalledOnValidThread()); | 755 DCHECK(CalledOnValidThread()); |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 938 return pref_value_store()->PrefValueFromDefaultStore(name_.c_str()); | 954 return pref_value_store()->PrefValueFromDefaultStore(name_.c_str()); |
| 939 } | 955 } |
| 940 | 956 |
| 941 bool PrefService::Preference::IsUserModifiable() const { | 957 bool PrefService::Preference::IsUserModifiable() const { |
| 942 return pref_value_store()->PrefValueUserModifiable(name_.c_str()); | 958 return pref_value_store()->PrefValueUserModifiable(name_.c_str()); |
| 943 } | 959 } |
| 944 | 960 |
| 945 bool PrefService::Preference::IsExtensionModifiable() const { | 961 bool PrefService::Preference::IsExtensionModifiable() const { |
| 946 return pref_value_store()->PrefValueExtensionModifiable(name_.c_str()); | 962 return pref_value_store()->PrefValueExtensionModifiable(name_.c_str()); |
| 947 } | 963 } |
| OLD | NEW |