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

Side by Side Diff: chrome/browser/extensions/extension_prefs.cc

Issue 11415216: Make Blacklist::IsBlacklist asynchronous (it will need to be for safe (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase past conflict #2 Created 8 years 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) 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 "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/prefs/pref_notifier.h" 8 #include "base/prefs/pref_notifier.h"
9 #include "base/string_number_conversions.h" 9 #include "base/string_number_conversions.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
(...skipping 730 matching lines...) Expand 10 before | Expand all | Expand 10 after
741 } else { 741 } else {
742 UpdateExtensionPref(extension_id, kPrefDisableReasons, 742 UpdateExtensionPref(extension_id, kPrefDisableReasons,
743 Value::CreateIntegerValue(new_value)); 743 Value::CreateIntegerValue(new_value));
744 } 744 }
745 } 745 }
746 746
747 void ExtensionPrefs::ClearDisableReasons(const std::string& extension_id) { 747 void ExtensionPrefs::ClearDisableReasons(const std::string& extension_id) {
748 UpdateExtensionPref(extension_id, kPrefDisableReasons, NULL); 748 UpdateExtensionPref(extension_id, kPrefDisableReasons, NULL);
749 } 749 }
750 750
751 void ExtensionPrefs::UpdateBlacklist( 751 std::set<std::string> ExtensionPrefs::GetBlacklistedExtensions() {
752 const std::set<std::string>& blacklist_set) { 752 std::set<std::string> ids;
753 ExtensionIdList remove_pref_ids; 753
754 std::set<std::string> used_id_set;
755 const DictionaryValue* extensions = prefs_->GetDictionary(kExtensionsPref); 754 const DictionaryValue* extensions = prefs_->GetDictionary(kExtensionsPref);
755 if (!extensions)
756 return ids;
756 757
757 if (extensions) { 758 for (DictionaryValue::Iterator it(*extensions); it.HasNext(); it.Advance()) {
758 for (DictionaryValue::key_iterator extension_id = extensions->begin_keys(); 759 if (!it.value().IsType(Value::TYPE_DICTIONARY)) {
759 extension_id != extensions->end_keys(); ++extension_id) { 760 NOTREACHED() << "Invalid pref for extension " << it.key();
760 const DictionaryValue* ext; 761 continue;
761 if (!extensions->GetDictionaryWithoutPathExpansion(*extension_id, &ext)) {
762 NOTREACHED() << "Invalid pref for extension " << *extension_id;
763 continue;
764 }
765 const std::string& id(*extension_id);
766 if (blacklist_set.find(id) == blacklist_set.end()) {
767 if (!IsBlacklistBitSet(ext)) {
768 // This extension is not in blacklist. And it was not blacklisted
769 // before.
770 continue;
771 } else {
772 if (ext->size() == 1) {
773 // We should remove the entry if the only flag here is blacklist.
774 remove_pref_ids.push_back(id);
775 } else {
776 // Remove the blacklist bit.
777 UpdateExtensionPref(id, kPrefBlacklist, NULL);
778 }
779 }
780 } else {
781 if (!IsBlacklistBitSet(ext)) {
782 // Only set the blacklist if it was not set.
783 UpdateExtensionPref(id, kPrefBlacklist,
784 Value::CreateBooleanValue(true));
785 }
786 // Keep the record if this extension is already processed.
787 used_id_set.insert(id);
788 }
789 } 762 }
763 if (IsBlacklistBitSet(static_cast<const DictionaryValue*>(&it.value())))
764 ids.insert(it.key());
790 } 765 }
791 766
792 // Iterate the leftovers to set blacklist in pref 767 return ids;
793 std::set<std::string>::const_iterator set_itr = blacklist_set.begin(); 768 }
794 for (; set_itr != blacklist_set.end(); ++set_itr) { 769
795 if (used_id_set.find(*set_itr) == used_id_set.end()) { 770 void ExtensionPrefs::SetExtensionBlacklisted(const std::string& extension_id,
796 UpdateExtensionPref(*set_itr, kPrefBlacklist, 771 bool is_blacklisted) {
797 Value::CreateBooleanValue(true)); 772 if (is_blacklisted) {
798 } 773 UpdateExtensionPref(extension_id,
774 kPrefBlacklist,
775 new base::FundamentalValue(true));
776 UpdateExtensionPref(extension_id,
777 kPrefBlacklistAcknowledged,
778 new base::FundamentalValue(true));
779 return;
799 } 780 }
800 for (size_t i = 0; i < remove_pref_ids.size(); ++i) { 781
801 DeleteExtensionPrefs(remove_pref_ids[i]); 782 // If we're clearing the blacklist bit, we also want to delete the entry for
802 } 783 // the extension in prefs altogether if the resulting entry is empty.
784 UpdateExtensionPref(extension_id, kPrefBlacklist, NULL);
785 UpdateExtensionPref(extension_id, kPrefBlacklistAcknowledged, NULL);
786 const DictionaryValue* dict = GetExtensionPref(extension_id);
787 if (dict && dict->empty())
788 DeleteExtensionPrefs(extension_id);
803 } 789 }
804 790
805 bool ExtensionPrefs::IsExtensionBlacklisted(const std::string& id) const { 791 bool ExtensionPrefs::IsExtensionBlacklisted(const std::string& id) const {
806 const DictionaryValue* ext_prefs = GetExtensionPref(id); 792 const DictionaryValue* ext_prefs = GetExtensionPref(id);
807 return ext_prefs && IsBlacklistBitSet(ext_prefs); 793 return ext_prefs && IsBlacklistBitSet(ext_prefs);
808 } 794 }
809 795
810 namespace { 796 namespace {
811 797
812 // Serializes |time| as a string value mapped to |key| in |dictionary|. 798 // Serializes |time| as a string value mapped to |key| in |dictionary|.
(...skipping 836 matching lines...) Expand 10 before | Expand all | Expand 10 after
1649 return extension; 1635 return extension;
1650 } 1636 }
1651 1637
1652 scoped_ptr<ExtensionInfo> ExtensionPrefs::GetInstalledExtensionInfo( 1638 scoped_ptr<ExtensionInfo> ExtensionPrefs::GetInstalledExtensionInfo(
1653 const std::string& extension_id) const { 1639 const std::string& extension_id) const {
1654 const DictionaryValue* ext; 1640 const DictionaryValue* ext;
1655 const DictionaryValue* extensions = prefs_->GetDictionary(kExtensionsPref); 1641 const DictionaryValue* extensions = prefs_->GetDictionary(kExtensionsPref);
1656 if (!extensions || 1642 if (!extensions ||
1657 !extensions->GetDictionaryWithoutPathExpansion(extension_id, &ext)) 1643 !extensions->GetDictionaryWithoutPathExpansion(extension_id, &ext))
1658 return scoped_ptr<ExtensionInfo>(); 1644 return scoped_ptr<ExtensionInfo>();
1659 if (IsBlacklistBitSet(ext))
1660 return scoped_ptr<ExtensionInfo>();
1661 int state_value; 1645 int state_value;
1662 if (!ext->GetInteger(kPrefState, &state_value) || 1646 if (!ext->GetInteger(kPrefState, &state_value) ||
1663 state_value == Extension::ENABLED_COMPONENT) { 1647 state_value == Extension::ENABLED_COMPONENT) {
1664 // Old preferences files may not have kPrefState for component extensions. 1648 // Old preferences files may not have kPrefState for component extensions.
1665 return scoped_ptr<ExtensionInfo>(); 1649 return scoped_ptr<ExtensionInfo>();
1666 } 1650 }
1667 1651
1668 if (state_value == Extension::EXTERNAL_EXTENSION_UNINSTALLED) { 1652 if (state_value == Extension::EXTERNAL_EXTENSION_UNINSTALLED) {
1669 LOG(WARNING) << "External extension with id " << extension_id 1653 LOG(WARNING) << "External extension with id " << extension_id
1670 << " has been uninstalled by the user"; 1654 << " has been uninstalled by the user";
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
2010 return result; // Empty set 1994 return result; // Empty set
2011 } 1995 }
2012 1996
2013 for (base::DictionaryValue::key_iterator it = extension_prefs->begin_keys(); 1997 for (base::DictionaryValue::key_iterator it = extension_prefs->begin_keys();
2014 it != extension_prefs->end_keys(); ++it) { 1998 it != extension_prefs->end_keys(); ++it) {
2015 const DictionaryValue* ext; 1999 const DictionaryValue* ext;
2016 if (!extension_prefs->GetDictionaryWithoutPathExpansion(*it, &ext)) { 2000 if (!extension_prefs->GetDictionaryWithoutPathExpansion(*it, &ext)) {
2017 NOTREACHED() << "Invalid pref for extension " << *it; 2001 NOTREACHED() << "Invalid pref for extension " << *it;
2018 continue; 2002 continue;
2019 } 2003 }
2020 if (!IsBlacklistBitSet(ext))
2021 result.push_back(*it);
2022 } 2004 }
2023 return result; 2005 return result;
2024 } 2006 }
2025 2007
2026 void ExtensionPrefs::FixMissingPrefs(const ExtensionIdList& extension_ids) { 2008 void ExtensionPrefs::FixMissingPrefs(const ExtensionIdList& extension_ids) {
2027 // Fix old entries that did not get an installation time entry when they 2009 // Fix old entries that did not get an installation time entry when they
2028 // were installed or don't have a preferences field. 2010 // were installed or don't have a preferences field.
2029 for (ExtensionIdList::const_iterator ext_id = extension_ids.begin(); 2011 for (ExtensionIdList::const_iterator ext_id = extension_ids.begin();
2030 ext_id != extension_ids.end(); ++ext_id) { 2012 ext_id != extension_ids.end(); ++ext_id) {
2031 if (GetInstallTime(*ext_id) == base::Time()) { 2013 if (GetInstallTime(*ext_id) == base::Time()) {
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
2320 const ExtensionIdList& strings) { 2302 const ExtensionIdList& strings) {
2321 ListPrefUpdate update(prefs_, pref); 2303 ListPrefUpdate update(prefs_, pref);
2322 ListValue* list_of_values = update.Get(); 2304 ListValue* list_of_values = update.Get();
2323 list_of_values->Clear(); 2305 list_of_values->Clear();
2324 for (ExtensionIdList::const_iterator iter = strings.begin(); 2306 for (ExtensionIdList::const_iterator iter = strings.begin();
2325 iter != strings.end(); ++iter) 2307 iter != strings.end(); ++iter)
2326 list_of_values->Append(new StringValue(*iter)); 2308 list_of_values->Append(new StringValue(*iter));
2327 } 2309 }
2328 2310
2329 } // namespace extensions 2311 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698