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

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: fix another test 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 bool currently_blacklisted = IsExtensionBlacklisted(extension_id);
798 } 773 if (is_blacklisted == currently_blacklisted) {
774 NOTREACHED() << extension_id << " is " <<
775 (currently_blacklisted ? "already" : "not") <<
776 " blacklisted";
777 return;
799 } 778 }
800 for (size_t i = 0; i < remove_pref_ids.size(); ++i) { 779
801 DeleteExtensionPrefs(remove_pref_ids[i]); 780 // Always make sure the "acknowledged" bit is cleared since the blacklist bit
781 // is changing.
782 UpdateExtensionPref(extension_id, kPrefBlacklistAcknowledged, NULL);
783
784 if (is_blacklisted) {
785 UpdateExtensionPref(extension_id,
786 kPrefBlacklist,
787 new base::FundamentalValue(true));
788 } else {
789 UpdateExtensionPref(extension_id, kPrefBlacklist, NULL);
790 const DictionaryValue* dict = GetExtensionPref(extension_id);
791 if (dict && dict->empty())
792 DeleteExtensionPrefs(extension_id);
802 } 793 }
803 } 794 }
804 795
805 bool ExtensionPrefs::IsExtensionBlacklisted(const std::string& id) const { 796 bool ExtensionPrefs::IsExtensionBlacklisted(const std::string& id) const {
806 const DictionaryValue* ext_prefs = GetExtensionPref(id); 797 const DictionaryValue* ext_prefs = GetExtensionPref(id);
807 return ext_prefs && IsBlacklistBitSet(ext_prefs); 798 return ext_prefs && IsBlacklistBitSet(ext_prefs);
808 } 799 }
809 800
810 namespace { 801 namespace {
811 802
(...skipping 837 matching lines...) Expand 10 before | Expand all | Expand 10 after
1649 return extension; 1640 return extension;
1650 } 1641 }
1651 1642
1652 scoped_ptr<ExtensionInfo> ExtensionPrefs::GetInstalledExtensionInfo( 1643 scoped_ptr<ExtensionInfo> ExtensionPrefs::GetInstalledExtensionInfo(
1653 const std::string& extension_id) const { 1644 const std::string& extension_id) const {
1654 const DictionaryValue* ext; 1645 const DictionaryValue* ext;
1655 const DictionaryValue* extensions = prefs_->GetDictionary(kExtensionsPref); 1646 const DictionaryValue* extensions = prefs_->GetDictionary(kExtensionsPref);
1656 if (!extensions || 1647 if (!extensions ||
1657 !extensions->GetDictionaryWithoutPathExpansion(extension_id, &ext)) 1648 !extensions->GetDictionaryWithoutPathExpansion(extension_id, &ext))
1658 return scoped_ptr<ExtensionInfo>(); 1649 return scoped_ptr<ExtensionInfo>();
1659 if (IsBlacklistBitSet(ext))
1660 return scoped_ptr<ExtensionInfo>();
1661 int state_value; 1650 int state_value;
1662 if (!ext->GetInteger(kPrefState, &state_value) || 1651 if (!ext->GetInteger(kPrefState, &state_value) ||
1663 state_value == Extension::ENABLED_COMPONENT) { 1652 state_value == Extension::ENABLED_COMPONENT) {
1664 // Old preferences files may not have kPrefState for component extensions. 1653 // Old preferences files may not have kPrefState for component extensions.
1665 return scoped_ptr<ExtensionInfo>(); 1654 return scoped_ptr<ExtensionInfo>();
1666 } 1655 }
1667 1656
1668 if (state_value == Extension::EXTERNAL_EXTENSION_UNINSTALLED) { 1657 if (state_value == Extension::EXTERNAL_EXTENSION_UNINSTALLED) {
1669 LOG(WARNING) << "External extension with id " << extension_id 1658 LOG(WARNING) << "External extension with id " << extension_id
1670 << " has been uninstalled by the user"; 1659 << " has been uninstalled by the user";
(...skipping 649 matching lines...) Expand 10 before | Expand all | Expand 10 after
2320 const ExtensionIdList& strings) { 2309 const ExtensionIdList& strings) {
2321 ListPrefUpdate update(prefs_, pref); 2310 ListPrefUpdate update(prefs_, pref);
2322 ListValue* list_of_values = update.Get(); 2311 ListValue* list_of_values = update.Get();
2323 list_of_values->Clear(); 2312 list_of_values->Clear();
2324 for (ExtensionIdList::const_iterator iter = strings.begin(); 2313 for (ExtensionIdList::const_iterator iter = strings.begin();
2325 iter != strings.end(); ++iter) 2314 iter != strings.end(); ++iter)
2326 list_of_values->Append(new StringValue(*iter)); 2315 list_of_values->Append(new StringValue(*iter));
2327 } 2316 }
2328 2317
2329 } // namespace extensions 2318 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_prefs.h ('k') | chrome/browser/extensions/extension_prefs_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698