OLD | NEW |
1 // Copyright (c) 2010 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/extensions/extension_prefs.h" | 5 #include "chrome/browser/extensions/extension_prefs.h" |
6 | 6 |
7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
8 #include "base/string_number_conversions.h" | 8 #include "base/string_number_conversions.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "chrome/browser/extensions/extension_pref_store.h" | 10 #include "chrome/browser/extensions/extension_pref_store.h" |
11 #include "chrome/browser/prefs/pref_notifier.h" | 11 #include "chrome/browser/prefs/pref_notifier.h" |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 std::set<std::string>* result) { | 134 std::set<std::string>* result) { |
135 ExtensionExtent::PatternList patterns = host_extent.patterns(); | 135 ExtensionExtent::PatternList patterns = host_extent.patterns(); |
136 ExtensionExtent::PatternList::const_iterator i; | 136 ExtensionExtent::PatternList::const_iterator i; |
137 | 137 |
138 for (i = patterns.begin(); i != patterns.end(); ++i) | 138 for (i = patterns.begin(); i != patterns.end(); ++i) |
139 result->insert(i->GetAsString()); | 139 result->insert(i->GetAsString()); |
140 } | 140 } |
141 | 141 |
142 } // namespace | 142 } // namespace |
143 | 143 |
144 ExtensionPrefs::ExtensionPrefs(PrefService* prefs, | 144 ExtensionPrefs::ExtensionPrefs( |
145 const FilePath& root_dir, | 145 PrefService* prefs, |
146 ExtensionPrefStore* pref_store) | 146 const FilePath& root_dir, |
| 147 ExtensionPrefValueMap* extension_pref_value_map) |
147 : prefs_(prefs), | 148 : prefs_(prefs), |
148 install_directory_(root_dir), | 149 install_directory_(root_dir), |
149 pref_store_(pref_store) { | 150 extension_pref_value_map_(extension_pref_value_map) { |
150 // TODO(asargent) - Remove this in a couple of months. (See comment above | 151 // TODO(asargent) - Remove this in a couple of months. (See comment above |
151 // CleanupBadExtensionKeys). | 152 // CleanupBadExtensionKeys). |
152 CleanupBadExtensionKeys(prefs_); | 153 CleanupBadExtensionKeys(prefs_); |
153 | 154 |
154 MakePathsRelative(); | 155 MakePathsRelative(); |
155 | 156 |
156 InitPrefStore(); | 157 InitPrefStore(); |
157 } | 158 } |
158 | 159 |
159 ExtensionPrefs::~ExtensionPrefs() {} | 160 ExtensionPrefs::~ExtensionPrefs() {} |
(...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
689 extension->path(), NULL); | 690 extension->path(), NULL); |
690 UpdateExtensionPref(id, kPrefPath, Value::CreateStringValue(path)); | 691 UpdateExtensionPref(id, kPrefPath, Value::CreateStringValue(path)); |
691 // We store prefs about LOAD extensions, but don't cache their manifest | 692 // We store prefs about LOAD extensions, but don't cache their manifest |
692 // since it may change on disk. | 693 // since it may change on disk. |
693 if (extension->location() != Extension::LOAD) { | 694 if (extension->location() != Extension::LOAD) { |
694 UpdateExtensionPref(id, kPrefManifest, | 695 UpdateExtensionPref(id, kPrefManifest, |
695 extension->manifest_value()->DeepCopy()); | 696 extension->manifest_value()->DeepCopy()); |
696 } | 697 } |
697 UpdateExtensionPref(id, kPrefAppLaunchIndex, | 698 UpdateExtensionPref(id, kPrefAppLaunchIndex, |
698 Value::CreateIntegerValue(GetNextAppLaunchIndex())); | 699 Value::CreateIntegerValue(GetNextAppLaunchIndex())); |
| 700 extension_pref_value_map_->RegisterExtension( |
| 701 id, install_time, initial_state == Extension::ENABLED); |
699 SavePrefsAndNotify(); | 702 SavePrefsAndNotify(); |
700 } | 703 } |
701 | 704 |
702 void ExtensionPrefs::OnExtensionUninstalled(const std::string& extension_id, | 705 void ExtensionPrefs::OnExtensionUninstalled(const std::string& extension_id, |
703 const Extension::Location& location, | 706 const Extension::Location& location, |
704 bool external_uninstall) { | 707 bool external_uninstall) { |
705 PrefKeySet pref_keys; | |
706 GetExtensionControlledPrefKeys(extension_id, &pref_keys); | |
707 | |
708 // For external extensions, we save a preference reminding ourself not to try | 708 // For external extensions, we save a preference reminding ourself not to try |
709 // and install the extension anymore (except when |external_uninstall| is | 709 // and install the extension anymore (except when |external_uninstall| is |
710 // true, which signifies that the registry key was deleted or the pref file | 710 // true, which signifies that the registry key was deleted or the pref file |
711 // no longer lists the extension). | 711 // no longer lists the extension). |
712 if (!external_uninstall && Extension::IsExternalLocation(location)) { | 712 if (!external_uninstall && Extension::IsExternalLocation(location)) { |
713 UpdateExtensionPref(extension_id, kPrefState, | 713 UpdateExtensionPref(extension_id, kPrefState, |
714 Value::CreateIntegerValue(Extension::KILLBIT)); | 714 Value::CreateIntegerValue(Extension::KILLBIT)); |
715 SavePrefsAndNotify(); | 715 SavePrefsAndNotify(); |
| 716 extension_pref_value_map_->SetExtensionState(extension_id, false); |
716 } else { | 717 } else { |
717 DeleteExtensionPrefs(extension_id); | 718 DeleteExtensionPrefs(extension_id); |
718 } | 719 } |
719 | |
720 UpdatePrefStore(pref_keys); | |
721 } | 720 } |
722 | 721 |
723 Extension::State ExtensionPrefs::GetExtensionState( | 722 Extension::State ExtensionPrefs::GetExtensionState( |
724 const std::string& extension_id) const { | 723 const std::string& extension_id) const { |
725 DictionaryValue* extension = GetExtensionPref(extension_id); | 724 DictionaryValue* extension = GetExtensionPref(extension_id); |
726 | 725 |
727 // If the extension doesn't have a pref, it's a --load-extension. | 726 // If the extension doesn't have a pref, it's a --load-extension. |
728 if (!extension) | 727 if (!extension) |
729 return Extension::ENABLED; | 728 return Extension::ENABLED; |
730 | 729 |
731 int state = -1; | 730 int state = -1; |
732 if (!extension->GetInteger(kPrefState, &state) || | 731 if (!extension->GetInteger(kPrefState, &state) || |
733 state < 0 || state >= Extension::NUM_STATES) { | 732 state < 0 || state >= Extension::NUM_STATES) { |
734 LOG(ERROR) << "Bad or missing pref 'state' for extension '" | 733 LOG(ERROR) << "Bad or missing pref 'state' for extension '" |
735 << extension_id << "'"; | 734 << extension_id << "'"; |
736 return Extension::ENABLED; | 735 return Extension::ENABLED; |
737 } | 736 } |
738 return static_cast<Extension::State>(state); | 737 return static_cast<Extension::State>(state); |
739 } | 738 } |
740 | 739 |
741 void ExtensionPrefs::SetExtensionState(const Extension* extension, | 740 void ExtensionPrefs::SetExtensionState(const Extension* extension, |
742 Extension::State state) { | 741 Extension::State state) { |
743 UpdateExtensionPref(extension->id(), kPrefState, | 742 UpdateExtensionPref(extension->id(), kPrefState, |
744 Value::CreateIntegerValue(state)); | 743 Value::CreateIntegerValue(state)); |
| 744 SavePrefsAndNotify(); |
745 | 745 |
746 PrefKeySet pref_keys; | 746 bool enabled = (state == Extension::ENABLED); |
747 GetExtensionControlledPrefKeys(extension->id(), &pref_keys); | 747 extension_pref_value_map_->SetExtensionState(extension->id(), enabled); |
748 UpdatePrefStore(pref_keys); | |
749 | |
750 SavePrefsAndNotify(); | |
751 } | 748 } |
752 | 749 |
753 bool ExtensionPrefs::GetBrowserActionVisibility(const Extension* extension) { | 750 bool ExtensionPrefs::GetBrowserActionVisibility(const Extension* extension) { |
754 DictionaryValue* extension_prefs = GetExtensionPref(extension->id()); | 751 DictionaryValue* extension_prefs = GetExtensionPref(extension->id()); |
755 if (!extension_prefs) | 752 if (!extension_prefs) |
756 return true; | 753 return true; |
757 bool visible = false; | 754 bool visible = false; |
758 if (!extension_prefs->GetBoolean(kBrowserActionVisible, &visible) || visible) | 755 if (!extension_prefs->GetBoolean(kBrowserActionVisible, &visible) || visible) |
759 return true; | 756 return true; |
760 | 757 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
820 DictionaryValue* extension = GetOrCreateExtensionPref(extension_id); | 817 DictionaryValue* extension = GetOrCreateExtensionPref(extension_id); |
821 extension->Set(key, data_value); | 818 extension->Set(key, data_value); |
822 } | 819 } |
823 | 820 |
824 void ExtensionPrefs::DeleteExtensionPrefs(const std::string& extension_id) { | 821 void ExtensionPrefs::DeleteExtensionPrefs(const std::string& extension_id) { |
825 DictionaryValue* dict = prefs_->GetMutableDictionary(kExtensionsPref); | 822 DictionaryValue* dict = prefs_->GetMutableDictionary(kExtensionsPref); |
826 if (dict->HasKey(extension_id)) { | 823 if (dict->HasKey(extension_id)) { |
827 dict->Remove(extension_id, NULL); | 824 dict->Remove(extension_id, NULL); |
828 SavePrefsAndNotify(); | 825 SavePrefsAndNotify(); |
829 } | 826 } |
| 827 extension_pref_value_map_->UnregisterExtension(extension_id); |
830 } | 828 } |
831 | 829 |
832 DictionaryValue* ExtensionPrefs::GetOrCreateExtensionPref( | 830 DictionaryValue* ExtensionPrefs::GetOrCreateExtensionPref( |
833 const std::string& extension_id) { | 831 const std::string& extension_id) { |
834 DCHECK(Extension::IdIsValid(extension_id)); | 832 DCHECK(Extension::IdIsValid(extension_id)); |
835 DictionaryValue* dict = prefs_->GetMutableDictionary(kExtensionsPref); | 833 DictionaryValue* dict = prefs_->GetMutableDictionary(kExtensionsPref); |
836 DictionaryValue* extension = NULL; | 834 DictionaryValue* extension = NULL; |
837 if (!dict->GetDictionary(extension_id, &extension)) { | 835 if (!dict->GetDictionary(extension_id, &extension)) { |
838 // Extension pref does not exist, create it. | 836 // Extension pref does not exist, create it. |
839 extension = new DictionaryValue(); | 837 extension = new DictionaryValue(); |
840 dict->Set(extension_id, extension); | 838 dict->Set(extension_id, extension); |
841 } | 839 } |
842 return extension; | 840 return extension; |
843 } | 841 } |
844 | 842 |
845 DictionaryValue* ExtensionPrefs::GetExtensionPref( | 843 DictionaryValue* ExtensionPrefs::GetExtensionPref( |
846 const std::string& extension_id) const { | 844 const std::string& extension_id) const { |
847 const DictionaryValue* dict = prefs_->GetDictionary(kExtensionsPref); | 845 const DictionaryValue* dict = prefs_->GetDictionary(kExtensionsPref); |
848 if (!dict) | 846 if (!dict) |
849 return NULL; | 847 return NULL; |
850 DictionaryValue* extension = NULL; | 848 DictionaryValue* extension = NULL; |
851 dict->GetDictionary(extension_id, &extension); | 849 dict->GetDictionary(extension_id, &extension); |
852 return extension; | 850 return extension; |
853 } | 851 } |
854 | 852 |
855 DictionaryValue* ExtensionPrefs::GetExtensionControlledPrefs( | |
856 const std::string& extension_id) const { | |
857 DictionaryValue* extension = GetExtensionPref(extension_id); | |
858 if (!extension) { | |
859 NOTREACHED(); | |
860 return NULL; | |
861 } | |
862 DictionaryValue* preferences = NULL; | |
863 extension->GetDictionary(kPrefPreferences, &preferences); | |
864 return preferences; | |
865 } | |
866 | |
867 // Helper function for GetInstalledExtensionsInfo. | 853 // Helper function for GetInstalledExtensionsInfo. |
868 static ExtensionInfo* GetInstalledExtensionInfoImpl( | 854 static ExtensionInfo* GetInstalledExtensionInfoImpl( |
869 DictionaryValue* extension_data, | 855 DictionaryValue* extension_data, |
870 DictionaryValue::key_iterator extension_id) { | 856 DictionaryValue::key_iterator extension_id) { |
871 DictionaryValue* ext; | 857 DictionaryValue* ext; |
872 if (!extension_data->GetDictionaryWithoutPathExpansion(*extension_id, &ext)) { | 858 if (!extension_data->GetDictionaryWithoutPathExpansion(*extension_id, &ext)) { |
873 LOG(WARNING) << "Invalid pref for extension " << *extension_id; | 859 LOG(WARNING) << "Invalid pref for extension " << *extension_id; |
874 NOTREACHED(); | 860 NOTREACHED(); |
875 return NULL; | 861 return NULL; |
876 } | 862 } |
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1147 } | 1133 } |
1148 std::string install_time_str; | 1134 std::string install_time_str; |
1149 if (!extension->GetString(kPrefInstallTime, &install_time_str)) | 1135 if (!extension->GetString(kPrefInstallTime, &install_time_str)) |
1150 return base::Time(); | 1136 return base::Time(); |
1151 int64 install_time_i64 = 0; | 1137 int64 install_time_i64 = 0; |
1152 if (!base::StringToInt64(install_time_str, &install_time_i64)) | 1138 if (!base::StringToInt64(install_time_str, &install_time_i64)) |
1153 return base::Time(); | 1139 return base::Time(); |
1154 return base::Time::FromInternalValue(install_time_i64); | 1140 return base::Time::FromInternalValue(install_time_i64); |
1155 } | 1141 } |
1156 | 1142 |
1157 void ExtensionPrefs::GetEnabledExtensions(ExtensionIdSet* out) const { | 1143 void ExtensionPrefs::GetExtensions(ExtensionIdSet* out) const { |
1158 CHECK(out); | 1144 CHECK(out); |
1159 const DictionaryValue* extensions = | 1145 const DictionaryValue* extensions = |
1160 pref_service()->GetDictionary(kExtensionsPref); | 1146 pref_service()->GetDictionary(kExtensionsPref); |
1161 | 1147 |
1162 for (DictionaryValue::key_iterator ext_id = extensions->begin_keys(); | 1148 for (DictionaryValue::key_iterator ext_id = extensions->begin_keys(); |
1163 ext_id != extensions->end_keys(); ++ext_id) { | 1149 ext_id != extensions->end_keys(); ++ext_id) { |
1164 if (GetExtensionState(*ext_id) != Extension::ENABLED) | |
1165 continue; | |
1166 out->push_back(*ext_id); | 1150 out->push_back(*ext_id); |
1167 } | 1151 } |
1168 } | 1152 } |
1169 | 1153 |
1170 void ExtensionPrefs::FixMissingPrefs(const ExtensionIdSet& extension_ids) { | 1154 void ExtensionPrefs::FixMissingPrefs(const ExtensionIdSet& extension_ids) { |
1171 // Fix old entries that did not get an installation time entry when they | 1155 // Fix old entries that did not get an installation time entry when they |
1172 // were installed or don't have a preferences field. | 1156 // were installed or don't have a preferences field. |
1173 bool persist_required = false; | 1157 bool persist_required = false; |
1174 for (ExtensionIdSet::const_iterator ext_id = extension_ids.begin(); | 1158 for (ExtensionIdSet::const_iterator ext_id = extension_ids.begin(); |
1175 ext_id != extension_ids.end(); ++ext_id) { | 1159 ext_id != extension_ids.end(); ++ext_id) { |
1176 DictionaryValue* extension = GetExtensionPref(*ext_id); | 1160 DictionaryValue* extension = GetExtensionPref(*ext_id); |
1177 CHECK(extension); | 1161 CHECK(extension); |
1178 | 1162 |
1179 if (GetInstallTime(*ext_id) == base::Time()) { | 1163 if (GetInstallTime(*ext_id) == base::Time()) { |
1180 LOG(INFO) << "Could not parse installation time of extension " | 1164 LOG(INFO) << "Could not parse installation time of extension " |
1181 << *ext_id << ". It was probably installed before setting " | 1165 << *ext_id << ". It was probably installed before setting " |
1182 << kPrefInstallTime << " was introduced. Updating " | 1166 << kPrefInstallTime << " was introduced. Updating " |
1183 << kPrefInstallTime << " to the current time."; | 1167 << kPrefInstallTime << " to the current time."; |
1184 const base::Time install_time = GetCurrentTime(); | 1168 const base::Time install_time = GetCurrentTime(); |
1185 extension->Set(kPrefInstallTime, | 1169 extension->Set(kPrefInstallTime, |
1186 Value::CreateStringValue( | 1170 Value::CreateStringValue( |
1187 base::Int64ToString(install_time.ToInternalValue()))); | 1171 base::Int64ToString(install_time.ToInternalValue()))); |
1188 persist_required = true; | 1172 persist_required = true; |
1189 } | 1173 } |
1190 } | 1174 } |
1191 if (persist_required) | 1175 if (persist_required) |
1192 SavePrefsAndNotify(); | 1176 SavePrefsAndNotify(); |
1193 } | 1177 } |
1194 | 1178 |
| 1179 DictionaryValue* ExtensionPrefs::GetExtensionControlledPrefs( |
| 1180 const std::string& extension_id) const { |
| 1181 DictionaryValue* source_dict = prefs_->GetMutableDictionary(kExtensionsPref); |
| 1182 DictionaryValue* preferences = NULL; |
| 1183 std::string key = extension_id + std::string(".") + kPrefPreferences; |
| 1184 if (!source_dict->GetDictionary(key, &preferences)) { |
| 1185 source_dict->Set(key, new DictionaryValue); |
| 1186 bool success = source_dict->GetDictionary(key, &preferences); |
| 1187 DCHECK(success); |
| 1188 } |
| 1189 return preferences; |
| 1190 } |
| 1191 |
1195 void ExtensionPrefs::InitPrefStore() { | 1192 void ExtensionPrefs::InitPrefStore() { |
1196 // When this is called, the PrefService is initialized and provides access | 1193 // When this is called, the PrefService is initialized and provides access |
1197 // to the user preferences stored in a JSON file. | 1194 // to the user preferences stored in a JSON file. |
1198 ExtensionIdSet extension_ids; | 1195 ExtensionIdSet extension_ids; |
1199 GetEnabledExtensions(&extension_ids); | 1196 GetExtensions(&extension_ids); |
1200 FixMissingPrefs(extension_ids); | 1197 FixMissingPrefs(extension_ids); |
1201 | 1198 |
1202 // Collect the unique extension controlled preference keys of all extensions. | 1199 // Store extension controlled preference values in the |
1203 PrefKeySet ext_controlled_prefs; | 1200 // |extension_pref_value_map_|, which then informs the subscribers |
| 1201 // (ExtensionPrefStores) about the winning values. |
1204 for (ExtensionIdSet::iterator ext_id = extension_ids.begin(); | 1202 for (ExtensionIdSet::iterator ext_id = extension_ids.begin(); |
1205 ext_id != extension_ids.end(); ++ext_id) { | 1203 ext_id != extension_ids.end(); ++ext_id) { |
1206 GetExtensionControlledPrefKeys(*ext_id, &ext_controlled_prefs); | 1204 extension_pref_value_map_->RegisterExtension( |
1207 } | 1205 *ext_id, |
| 1206 GetInstallTime(*ext_id), |
| 1207 GetExtensionState(*ext_id) == Extension::ENABLED); |
1208 | 1208 |
1209 // Store winning preference for each extension controlled preference. | 1209 DictionaryValue* prefs = GetExtensionControlledPrefs(*ext_id); |
1210 UpdatePrefStore(ext_controlled_prefs); | 1210 for (DictionaryValue::key_iterator i = prefs->begin_keys(); |
1211 pref_store_->OnInitializationCompleted(); | 1211 i != prefs->end_keys(); ++i) { |
1212 } | 1212 Value* value; |
1213 | 1213 if (!prefs->GetWithoutPathExpansion(*i, &value)) |
1214 const Value* ExtensionPrefs::GetWinningExtensionControlledPrefValue( | 1214 continue; |
1215 const std::string& key) const { | 1215 extension_pref_value_map_->SetExtensionPref( |
1216 Value *winner = NULL; | 1216 *ext_id, *i, false, value->DeepCopy()); |
1217 base::Time winners_install_time = base::Time(); | |
1218 | |
1219 ExtensionIdSet extension_ids; | |
1220 GetEnabledExtensions(&extension_ids); | |
1221 for (ExtensionIdSet::iterator ext_id = extension_ids.begin(); | |
1222 ext_id != extension_ids.end(); ++ext_id) { | |
1223 base::Time extension_install_time = GetInstallTime(*ext_id); | |
1224 | |
1225 // We do not need to consider extensions that were installed before the | |
1226 // most recent extension found that provides the requested preference. | |
1227 if (extension_install_time < winners_install_time) | |
1228 continue; | |
1229 | |
1230 DictionaryValue* preferences = GetExtensionControlledPrefs(*ext_id); | |
1231 Value *value = NULL; | |
1232 if (preferences && preferences->GetWithoutPathExpansion(key, &value)) { | |
1233 // This extension is more recent than the last one providing this pref. | |
1234 winner = value; | |
1235 winners_install_time = extension_install_time; | |
1236 } | 1217 } |
1237 } | 1218 } |
1238 | 1219 |
1239 return winner; | 1220 extension_pref_value_map_->NotifyInitializationCompleted(); |
1240 } | 1221 } |
1241 | 1222 |
1242 void ExtensionPrefs::UpdatePrefStore( | |
1243 const ExtensionPrefs::PrefKeySet& pref_keys) { | |
1244 for (PrefKeySet::const_iterator i = pref_keys.begin(); | |
1245 i != pref_keys.end(); ++i) { | |
1246 UpdatePrefStore(*i); | |
1247 } | |
1248 } | |
1249 | |
1250 void ExtensionPrefs::UpdatePrefStore(const std::string& pref_key) { | |
1251 if (pref_store_ == NULL) | |
1252 return; | |
1253 const Value* winning_pref_value = | |
1254 GetWinningExtensionControlledPrefValue(pref_key); | |
1255 | |
1256 if (winning_pref_value) | |
1257 pref_store_->SetExtensionPref(pref_key, winning_pref_value->DeepCopy()); | |
1258 else | |
1259 pref_store_->RemoveExtensionPref(pref_key); | |
1260 } | |
1261 | 1223 |
1262 void ExtensionPrefs::SetExtensionControlledPref(const std::string& extension_id, | 1224 void ExtensionPrefs::SetExtensionControlledPref(const std::string& extension_id, |
1263 const std::string& pref_key, | 1225 const std::string& pref_key, |
| 1226 bool incognito, |
1264 Value* value) { | 1227 Value* value) { |
1265 scoped_ptr<Value> scoped_value(value); | |
1266 DCHECK(pref_service()->FindPreference(pref_key.c_str())) | 1228 DCHECK(pref_service()->FindPreference(pref_key.c_str())) |
1267 << "Extension controlled preference key " << pref_key | 1229 << "Extension controlled preference key " << pref_key |
1268 << " not registered."; | 1230 << " not registered."; |
1269 DictionaryValue* extension_preferences = | |
1270 GetExtensionControlledPrefs(extension_id); | |
1271 | 1231 |
1272 if (extension_preferences == NULL) { // May be pruned when writing to disk. | 1232 if (!incognito) { |
1273 DictionaryValue* extension = GetExtensionPref(extension_id); | 1233 // Also store in persisted Preferences file to recover after a |
1274 if (extension == NULL) { | 1234 // browser restart. |
1275 LOG(ERROR) << "Extension preference for " << extension_id << " undefined"; | 1235 DictionaryValue* dict = GetExtensionControlledPrefs(extension_id); |
1276 return; | 1236 dict->SetWithoutPathExpansion(pref_key, value->DeepCopy()); |
1277 } | 1237 pref_service()->ScheduleSavePersistentPrefs(); |
1278 extension_preferences = new DictionaryValue; | |
1279 extension->Set(kPrefPreferences, extension_preferences); | |
1280 } | 1238 } |
1281 | 1239 |
1282 Value* oldValue = NULL; | 1240 extension_pref_value_map_->SetExtensionPref( |
1283 extension_preferences->GetWithoutPathExpansion(pref_key, &oldValue); | 1241 extension_id, pref_key, incognito, value); |
1284 bool modified = !Value::Equals(oldValue, scoped_value.get()); | |
1285 if (!modified) | |
1286 return; | |
1287 | |
1288 if (scoped_value.get() == NULL) | |
1289 extension_preferences->RemoveWithoutPathExpansion(pref_key, NULL); | |
1290 else | |
1291 extension_preferences->SetWithoutPathExpansion(pref_key, | |
1292 scoped_value.release()); | |
1293 pref_service()->ScheduleSavePersistentPrefs(); | |
1294 | |
1295 UpdatePrefStore(pref_key); | |
1296 } | |
1297 | |
1298 void ExtensionPrefs::GetExtensionControlledPrefKeys( | |
1299 const std::string& extension_id, PrefKeySet *out) const { | |
1300 DCHECK(out != NULL); | |
1301 DictionaryValue* ext_prefs = GetExtensionControlledPrefs(extension_id); | |
1302 if (ext_prefs) { | |
1303 for (DictionaryValue::key_iterator i = ext_prefs->begin_keys(); | |
1304 i != ext_prefs->end_keys(); ++i) { | |
1305 out->insert(*i); | |
1306 } | |
1307 } | |
1308 } | 1242 } |
1309 | 1243 |
1310 // static | 1244 // static |
1311 void ExtensionPrefs::RegisterUserPrefs(PrefService* prefs) { | 1245 void ExtensionPrefs::RegisterUserPrefs(PrefService* prefs) { |
1312 prefs->RegisterDictionaryPref(kExtensionsPref); | 1246 prefs->RegisterDictionaryPref(kExtensionsPref); |
1313 prefs->RegisterListPref(kExtensionToolbar); | 1247 prefs->RegisterListPref(kExtensionToolbar); |
1314 prefs->RegisterIntegerPref(prefs::kExtensionToolbarSize, -1); | 1248 prefs->RegisterIntegerPref(prefs::kExtensionToolbarSize, -1); |
1315 prefs->RegisterDictionaryPref(kExtensionsBlacklistUpdate); | 1249 prefs->RegisterDictionaryPref(kExtensionsBlacklistUpdate); |
1316 prefs->RegisterListPref(prefs::kExtensionInstallAllowList); | 1250 prefs->RegisterListPref(prefs::kExtensionInstallAllowList); |
1317 prefs->RegisterListPref(prefs::kExtensionInstallDenyList); | 1251 prefs->RegisterListPref(prefs::kExtensionInstallDenyList); |
1318 prefs->RegisterListPref(prefs::kExtensionInstallForceList); | 1252 prefs->RegisterListPref(prefs::kExtensionInstallForceList); |
1319 prefs->RegisterStringPref(kWebStoreLogin, std::string() /* default_value */); | 1253 prefs->RegisterStringPref(kWebStoreLogin, std::string() /* default_value */); |
1320 } | 1254 } |
OLD | NEW |