| 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/extensions/extension_prefs.h" | 5 #include "chrome/browser/extensions/extension_prefs.h" |
| 6 | 6 |
| 7 #include <iterator> | 7 #include <iterator> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/prefs/pref_notifier.h" | 10 #include "base/prefs/pref_notifier.h" |
| (...skipping 1182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1193 const std::string& id) const { | 1193 const std::string& id) const { |
| 1194 return DoesExtensionHaveState(id, Extension::EXTERNAL_EXTENSION_UNINSTALLED); | 1194 return DoesExtensionHaveState(id, Extension::EXTERNAL_EXTENSION_UNINSTALLED); |
| 1195 } | 1195 } |
| 1196 | 1196 |
| 1197 bool ExtensionPrefs::IsExtensionDisabled( | 1197 bool ExtensionPrefs::IsExtensionDisabled( |
| 1198 const std::string& id) const { | 1198 const std::string& id) const { |
| 1199 return DoesExtensionHaveState(id, Extension::DISABLED); | 1199 return DoesExtensionHaveState(id, Extension::DISABLED); |
| 1200 } | 1200 } |
| 1201 | 1201 |
| 1202 ExtensionIdList ExtensionPrefs::GetToolbarOrder() { | 1202 ExtensionIdList ExtensionPrefs::GetToolbarOrder() { |
| 1203 return GetExtensionPrefAsContainer<ExtensionIdList>(prefs::kExtensionToolbar); | 1203 ExtensionIdList id_list_out; |
| 1204 GetUserExtensionPrefIntoContainer(prefs::kExtensionToolbar, &id_list_out); |
| 1205 return id_list_out; |
| 1204 } | 1206 } |
| 1205 | 1207 |
| 1206 void ExtensionPrefs::SetToolbarOrder(const ExtensionIdList& extension_ids) { | 1208 void ExtensionPrefs::SetToolbarOrder(const ExtensionIdList& extension_ids) { |
| 1207 SetExtensionPrefFromContainer(prefs::kExtensionToolbar, extension_ids); | 1209 SetExtensionPrefFromContainer(prefs::kExtensionToolbar, extension_ids); |
| 1208 } | 1210 } |
| 1209 | 1211 |
| 1210 ExtensionIdSet ExtensionPrefs::GetKnownDisabled() { | 1212 bool ExtensionPrefs::GetKnownDisabled(ExtensionIdSet* id_set_out) { |
| 1211 return GetExtensionPrefAsContainer<ExtensionIdSet>( | 1213 return GetUserExtensionPrefIntoContainer(prefs::kExtensionKnownDisabled, |
| 1212 prefs::kExtensionKnownDisabled); | 1214 id_set_out); |
| 1213 } | 1215 } |
| 1214 | 1216 |
| 1215 void ExtensionPrefs::SetKnownDisabled(const ExtensionIdSet& extension_ids) { | 1217 void ExtensionPrefs::SetKnownDisabled(const ExtensionIdSet& extension_ids) { |
| 1216 SetExtensionPrefFromContainer(prefs::kExtensionKnownDisabled, extension_ids); | 1218 SetExtensionPrefFromContainer(prefs::kExtensionKnownDisabled, extension_ids); |
| 1217 } | 1219 } |
| 1218 | 1220 |
| 1219 void ExtensionPrefs::OnExtensionInstalled( | 1221 void ExtensionPrefs::OnExtensionInstalled( |
| 1220 const Extension* extension, | 1222 const Extension* extension, |
| 1221 Extension::State initial_state, | 1223 Extension::State initial_state, |
| 1222 bool blacklisted_for_malware, | 1224 bool blacklisted_for_malware, |
| (...skipping 639 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1862 0, | 1864 0, |
| 1863 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 1865 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 1864 #endif | 1866 #endif |
| 1865 registry->RegisterDictionaryPref( | 1867 registry->RegisterDictionaryPref( |
| 1866 kInstallSignature, | 1868 kInstallSignature, |
| 1867 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 1869 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 1868 | 1870 |
| 1869 } | 1871 } |
| 1870 | 1872 |
| 1871 template <class ExtensionIdContainer> | 1873 template <class ExtensionIdContainer> |
| 1872 ExtensionIdContainer ExtensionPrefs::GetExtensionPrefAsContainer( | 1874 bool ExtensionPrefs::GetUserExtensionPrefIntoContainer( |
| 1873 const char* pref) { | 1875 const char* pref, |
| 1874 ExtensionIdContainer extension_ids; | 1876 ExtensionIdContainer* id_container_out) { |
| 1875 const ListValue* list_of_values = prefs_->GetList(pref); | 1877 DCHECK(id_container_out->empty()); |
| 1876 if (!list_of_values) | 1878 |
| 1877 return extension_ids; | 1879 const Value* user_pref_value = prefs_->GetUserPrefValue(pref); |
| 1880 const ListValue* user_pref_as_list; |
| 1881 if (!user_pref_value || !user_pref_value->GetAsList(&user_pref_as_list)) |
| 1882 return false; |
| 1878 | 1883 |
| 1879 std::insert_iterator<ExtensionIdContainer> insert_iterator( | 1884 std::insert_iterator<ExtensionIdContainer> insert_iterator( |
| 1880 extension_ids, extension_ids.end()); | 1885 *id_container_out, id_container_out->end()); |
| 1881 std::string extension_id; | 1886 std::string extension_id; |
| 1882 for (size_t i = 0; i < list_of_values->GetSize(); ++i) { | 1887 for (base::ListValue::const_iterator value_it = user_pref_as_list->begin(); |
| 1883 if (list_of_values->GetString(i, &extension_id)) | 1888 value_it != user_pref_as_list->end(); ++value_it) { |
| 1884 insert_iterator = extension_id; | 1889 if (!(*value_it)->GetAsString(&extension_id)) { |
| 1890 NOTREACHED(); |
| 1891 continue; |
| 1892 } |
| 1893 insert_iterator = extension_id; |
| 1885 } | 1894 } |
| 1886 return extension_ids; | 1895 return true; |
| 1887 } | 1896 } |
| 1888 | 1897 |
| 1889 template <class ExtensionIdContainer> | 1898 template <class ExtensionIdContainer> |
| 1890 void ExtensionPrefs::SetExtensionPrefFromContainer( | 1899 void ExtensionPrefs::SetExtensionPrefFromContainer( |
| 1891 const char* pref, | 1900 const char* pref, |
| 1892 const ExtensionIdContainer& strings) { | 1901 const ExtensionIdContainer& strings) { |
| 1893 ListPrefUpdate update(prefs_, pref); | 1902 ListPrefUpdate update(prefs_, pref); |
| 1894 ListValue* list_of_values = update.Get(); | 1903 ListValue* list_of_values = update.Get(); |
| 1895 list_of_values->Clear(); | 1904 list_of_values->Clear(); |
| 1896 for (typename ExtensionIdContainer::const_iterator iter = strings.begin(); | 1905 for (typename ExtensionIdContainer::const_iterator iter = strings.begin(); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1987 is_enabled = initial_state == Extension::ENABLED; | 1996 is_enabled = initial_state == Extension::ENABLED; |
| 1988 } | 1997 } |
| 1989 | 1998 |
| 1990 extension_pref_value_map_->RegisterExtension(extension_id, install_time, | 1999 extension_pref_value_map_->RegisterExtension(extension_id, install_time, |
| 1991 is_enabled); | 2000 is_enabled); |
| 1992 content_settings_store_->RegisterExtension(extension_id, install_time, | 2001 content_settings_store_->RegisterExtension(extension_id, install_time, |
| 1993 is_enabled); | 2002 is_enabled); |
| 1994 } | 2003 } |
| 1995 | 2004 |
| 1996 } // namespace extensions | 2005 } // namespace extensions |
| OLD | NEW |