| 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 const base::ListValue* list = NULL; |
| 737 if (default_value->GetAsList(&list) && !list->empty()) |
| 738 needs_empty_value = true; |
| 739 } else if (orig_type == base::Value::TYPE_DICTIONARY) { |
| 740 const base::DictionaryValue* dict = NULL; |
| 741 if (default_value->GetAsDictionary(&dict) && !dict->empty()) |
| 742 needs_empty_value = true; |
| 743 } |
| 744 if (needs_empty_value) |
| 745 user_pref_store_->MarkNeedsEmptyValue(path); |
| 746 |
| 730 // Hand off ownership. | 747 // Hand off ownership. |
| 731 default_store_->SetDefaultValue(path, scoped_value.release()); | 748 default_store_->SetDefaultValue(path, scoped_value.release()); |
| 732 | 749 |
| 733 // Register with sync if necessary. | 750 // Register with sync if necessary. |
| 734 if (sync_status == SYNCABLE_PREF && pref_sync_associator_.get()) | 751 if (sync_status == SYNCABLE_PREF && pref_sync_associator_.get()) |
| 735 pref_sync_associator_->RegisterPref(path); | 752 pref_sync_associator_->RegisterPref(path); |
| 736 } | 753 } |
| 737 | 754 |
| 738 void PrefService::UnregisterPreference(const char* path) { | 755 void PrefService::UnregisterPreference(const char* path) { |
| 739 DCHECK(CalledOnValidThread()); | 756 DCHECK(CalledOnValidThread()); |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 938 return pref_value_store()->PrefValueFromDefaultStore(name_.c_str()); | 955 return pref_value_store()->PrefValueFromDefaultStore(name_.c_str()); |
| 939 } | 956 } |
| 940 | 957 |
| 941 bool PrefService::Preference::IsUserModifiable() const { | 958 bool PrefService::Preference::IsUserModifiable() const { |
| 942 return pref_value_store()->PrefValueUserModifiable(name_.c_str()); | 959 return pref_value_store()->PrefValueUserModifiable(name_.c_str()); |
| 943 } | 960 } |
| 944 | 961 |
| 945 bool PrefService::Preference::IsExtensionModifiable() const { | 962 bool PrefService::Preference::IsExtensionModifiable() const { |
| 946 return pref_value_store()->PrefValueExtensionModifiable(name_.c_str()); | 963 return pref_value_store()->PrefValueExtensionModifiable(name_.c_str()); |
| 947 } | 964 } |
| OLD | NEW |