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

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

Issue 98463005: Enable/disable extensions upon changes in blacklist. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added UI, store blacklist state in prefs, +2 unittests. Created 6 years, 11 months 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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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_service.h" 5 #include "chrome/browser/extensions/extension_service.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <iterator> 8 #include <iterator>
9 #include <set> 9 #include <set>
10 10
(...skipping 547 matching lines...) Expand 10 before | Expand all | Expand 10 after
558 FROM_HERE, 558 FROM_HERE,
559 base::Bind(&ExtensionService::GarbageCollectExtensions, AsWeakPtr()), 559 base::Bind(&ExtensionService::GarbageCollectExtensions, AsWeakPtr()),
560 base::TimeDelta::FromSeconds(kGarbageCollectStartupDelay)); 560 base::TimeDelta::FromSeconds(kGarbageCollectStartupDelay));
561 561
562 if (extension_prefs_->NeedsStorageGarbageCollection()) { 562 if (extension_prefs_->NeedsStorageGarbageCollection()) {
563 GarbageCollectIsolatedStorage(); 563 GarbageCollectIsolatedStorage();
564 extension_prefs_->SetNeedsStorageGarbageCollection(false); 564 extension_prefs_->SetNeedsStorageGarbageCollection(false);
565 } 565 }
566 system_->management_policy()->RegisterProvider( 566 system_->management_policy()->RegisterProvider(
567 shared_module_policy_provider_.get()); 567 shared_module_policy_provider_.get());
568
569 LoadGreylistFromPrefs();
568 } 570 }
569 571
570 UMA_HISTOGRAM_TIMES("Extensions.ExtensionServiceInitTime", 572 UMA_HISTOGRAM_TIMES("Extensions.ExtensionServiceInitTime",
571 base::Time::Now() - begin_time); 573 base::Time::Now() - begin_time);
572 } 574 }
573 575
576 void ExtensionService::LoadGreylistFromPrefs() {
577 scoped_ptr<ExtensionSet> all_extensions = GenerateInstalledExtensionsSet();
578
579 for (ExtensionSet::const_iterator it = all_extensions->begin();
580 it != all_extensions->end(); ++it) {
581 extensions::BlacklistState state =
582 extension_prefs_->GetExtensionBlacklistState((*it)->id());
583 if (state == extensions::BLACKLISTED_SECURITY_VULNERABILITY ||
584 state == extensions::BLACKLISTED_POTENTIALLY_UNWANTED ||
585 state == extensions::BLACKLISTED_CWS_POLICY_VIOLATION)
586 greylist_.Insert(*it);
587 }
588 }
589
574 void ExtensionService::VerifyAllExtensions() { 590 void ExtensionService::VerifyAllExtensions() {
575 ExtensionIdSet to_add; 591 ExtensionIdSet to_add;
576 scoped_ptr<ExtensionSet> all_extensions = GenerateInstalledExtensionsSet(); 592 scoped_ptr<ExtensionSet> all_extensions = GenerateInstalledExtensionsSet();
577 593
578 for (ExtensionSet::const_iterator i = all_extensions->begin(); 594 for (ExtensionSet::const_iterator i = all_extensions->begin();
579 i != all_extensions->end(); ++i) { 595 i != all_extensions->end(); ++i) {
580 const Extension& extension = **i; 596 const Extension& extension = **i;
581 597
582 if (InstallVerifier::NeedsVerification(extension)) 598 if (InstallVerifier::NeedsVerification(extension))
583 to_add.insert(extension.id()); 599 to_add.insert(extension.id());
(...skipping 2168 matching lines...) Expand 10 before | Expand all | Expand 10 after
2752 to_be_installed.push_back((*it)->id()); 2768 to_be_installed.push_back((*it)->id());
2753 } 2769 }
2754 for (std::vector<std::string>::const_iterator it = to_be_installed.begin(); 2770 for (std::vector<std::string>::const_iterator it = to_be_installed.begin();
2755 it != to_be_installed.end(); 2771 it != to_be_installed.end();
2756 ++it) { 2772 ++it) {
2757 MaybeFinishDelayedInstallation(*it); 2773 MaybeFinishDelayedInstallation(*it);
2758 } 2774 }
2759 } 2775 }
2760 2776
2761 void ExtensionService::OnBlacklistUpdated() { 2777 void ExtensionService::OnBlacklistUpdated() {
2762 blacklist_->GetMalwareIDs( 2778 blacklist_->GetBlacklistedIDs(
2763 GenerateInstalledExtensionsSet()->GetIDs(), 2779 GenerateInstalledExtensionsSet()->GetIDs(),
2764 base::Bind(&ExtensionService::ManageBlacklist, AsWeakPtr())); 2780 base::Bind(&ExtensionService::ManageBlacklist, AsWeakPtr()));
2765 } 2781 }
2766 2782
2767 void ExtensionService::ManageBlacklist(const std::set<std::string>& updated) { 2783 void ExtensionService::ManageBlacklist(
2784 const extensions::Blacklist::BlacklistStateMap& state_map) {
2768 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 2785 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2769 2786
2770 std::set<std::string> before = registry_->blacklisted_extensions().GetIDs(); 2787 std::set<std::string> blocked;
2771 std::set<std::string> no_longer_blacklisted = 2788 std::set<std::string> greylist;
2772 base::STLSetDifference<std::set<std::string> >(before, updated); 2789 std::set<std::string> unchanged;
2773 std::set<std::string> not_yet_blacklisted = 2790 for (extensions::Blacklist::BlacklistStateMap::const_iterator it =
2774 base::STLSetDifference<std::set<std::string> >(updated, before); 2791 state_map.begin();
2792 it != state_map.end();
2793 ++it) {
2794 switch (it->second) {
2795 case extensions::NOT_BLACKLISTED:
2796 break;
2775 2797
2776 for (std::set<std::string>::iterator it = no_longer_blacklisted.begin(); 2798 case extensions::BLACKLISTED_MALWARE:
2777 it != no_longer_blacklisted.end(); ++it) { 2799 blocked.insert(it->first);
2800 break;
2801
2802 case extensions::BLACKLISTED_SECURITY_VULNERABILITY:
2803 case extensions::BLACKLISTED_CWS_POLICY_VIOLATION:
2804 case extensions::BLACKLISTED_POTENTIALLY_UNWANTED:
2805 greylist.insert(it->first);
2806 break;
2807
2808 case extensions::BLACKLISTED_UNKNOWN:
2809 unchanged.insert(it->first);
2810 break;
2811 }
2812 }
2813
2814 UpdateBlockedExtensions(blocked, unchanged);
2815 UpdateGreylistedExtensions(greylist, unchanged, state_map);
2816
2817 IdentifyAlertableExtensions();
2818 }
2819
2820 void ExtensionService::UpdateBlockedExtensions(
2821 const std::set<std::string>& blocked,
2822 const std::set<std::string>& unchanged) {
2823 std::set<std::string> blocked_and_unchanged;
2824 std::set_union(
2825 blocked.begin(), blocked.end(), unchanged.begin(), unchanged.end(),
2826 std::inserter(blocked_and_unchanged, blocked_and_unchanged.end()));
2827
2828 // Extensions with unchanged blacklist state will remain blocked or unblocked
2829 // as before this update.
2830 std::set<std::string> blocked_before =
2831 registry_->blacklisted_extensions().GetIDs();
2832 std::set<std::string> no_longer_blocked =
2833 base::STLSetDifference<std::set<std::string> >(
2834 blocked_before, blocked_and_unchanged);
2835 std::set<std::string> not_yet_blocked =
2836 base::STLSetDifference<std::set<std::string> >(blocked, blocked_before);
2837
2838 for (std::set<std::string>::iterator it = no_longer_blocked.begin();
2839 it != no_longer_blocked.end(); ++it) {
2778 scoped_refptr<const Extension> extension = 2840 scoped_refptr<const Extension> extension =
2779 registry_->blacklisted_extensions().GetByID(*it); 2841 registry_->blacklisted_extensions().GetByID(*it);
2780 if (!extension.get()) { 2842 if (!extension.get()) {
2781 NOTREACHED() << "Extension " << *it << " no longer blacklisted, " 2843 NOTREACHED() << "Extension " << *it << " no longer blocked, "
2782 << "but it was never blacklisted."; 2844 << "but it was never blocked.";
2783 continue; 2845 continue;
2784 } 2846 }
2785 registry_->RemoveBlacklisted(*it); 2847 registry_->RemoveBlacklisted(*it);
2786 extension_prefs_->SetExtensionBlacklisted(extension->id(), false); 2848 extension_prefs_->SetExtensionBlacklisted(extension->id(), false);
2787 AddExtension(extension.get()); 2849 AddExtension(extension.get());
2788 UMA_HISTOGRAM_ENUMERATION("ExtensionBlacklist.UnblacklistInstalled", 2850 UMA_HISTOGRAM_ENUMERATION("ExtensionBlacklist.UnblacklistInstalled",
2789 extension->location(), 2851 extension->location(),
2790 Manifest::NUM_LOCATIONS); 2852 Manifest::NUM_LOCATIONS);
2791 } 2853 }
2792 2854
2793 for (std::set<std::string>::iterator it = not_yet_blacklisted.begin(); 2855 for (std::set<std::string>::iterator it = not_yet_blocked.begin();
2794 it != not_yet_blacklisted.end(); ++it) { 2856 it != not_yet_blocked.end(); ++it) {
2795 scoped_refptr<const Extension> extension = GetInstalledExtension(*it); 2857 scoped_refptr<const Extension> extension = GetInstalledExtension(*it);
2796 if (!extension.get()) { 2858 if (!extension.get()) {
2797 NOTREACHED() << "Extension " << *it << " needs to be " 2859 NOTREACHED() << "Extension " << *it << " needs to be "
2798 << "blacklisted, but it's not installed."; 2860 << "blacklisted, but it's not installed.";
2799 continue; 2861 continue;
2800 } 2862 }
2801 registry_->AddBlacklisted(extension); 2863 registry_->AddBlacklisted(extension);
2802 extension_prefs_->SetExtensionBlacklisted(extension->id(), true); 2864 extension_prefs_->SetExtensionBlacklistState(
2865 extension->id(), extensions::BLACKLISTED_MALWARE);
2803 UnloadExtension(*it, UnloadedExtensionInfo::REASON_BLACKLIST); 2866 UnloadExtension(*it, UnloadedExtensionInfo::REASON_BLACKLIST);
2804 UMA_HISTOGRAM_ENUMERATION("ExtensionBlacklist.BlacklistInstalled", 2867 UMA_HISTOGRAM_ENUMERATION("ExtensionBlacklist.BlacklistInstalled",
2805 extension->location(), Manifest::NUM_LOCATIONS); 2868 extension->location(), Manifest::NUM_LOCATIONS);
2806 } 2869 }
2870 }
2807 2871
2808 IdentifyAlertableExtensions(); 2872 // TODO(oleg): UMA logging
2873 void ExtensionService::UpdateGreylistedExtensions(
2874 const std::set<std::string>& greylist,
2875 const std::set<std::string>& unchanged,
2876 const extensions::Blacklist::BlacklistStateMap& state_map) {
2877 std::set<std::string> greylist_and_unchanged;
2878 std::set_union(
2879 greylist.begin(), greylist.end(), unchanged.begin(), unchanged.end(),
2880 std::inserter(greylist_and_unchanged, greylist_and_unchanged.end()));
2881
2882 std::set<std::string> greylisted_before = greylist_.GetIDs();
2883 std::set<std::string> no_longer_greylisted =
2884 base::STLSetDifference<std::set<std::string> >(
2885 greylisted_before, greylist_and_unchanged);
2886 std::set<std::string> not_yet_greylisted =
2887 base::STLSetDifference<std::set<std::string> >(
2888 greylist, greylisted_before);
2889
2890 for (std::set<std::string>::iterator it = no_longer_greylisted.begin();
2891 it != no_longer_greylisted.end(); ++it) {
2892 scoped_refptr<const Extension> extension = greylist_.GetByID(*it);
2893 if (!extension.get()) {
2894 NOTREACHED() << "Extension " << *it << " no longer greylisted, "
2895 << "but it was not marked as greylisted.";
2896 continue;
2897 }
2898
2899 greylist_.Remove(*it);
2900 extension_prefs_->SetExtensionBlacklistState(extension->id(),
2901 extensions::NOT_BLACKLISTED);
2902 if (extension_prefs_->GetDisableReasons(extension->id()) &
2903 extensions::Extension::DISABLE_GREYLIST)
2904 EnableExtension(*it);
2905 }
2906
2907 for (std::set<std::string>::iterator it = not_yet_greylisted.begin();
2908 it != not_yet_greylisted.end(); ++it) {
2909 scoped_refptr<const Extension> extension = GetInstalledExtension(*it);
2910 if (!extension.get()) {
2911 NOTREACHED() << "Extension " << *it << " needs to be "
2912 << "disabled, but it's not installed.";
2913 continue;
2914 }
2915 greylist_.Insert(extension);
2916 extension_prefs_->SetExtensionBlacklistState(extension->id(),
2917 state_map.find(*it)->second);
2918 if (registry_->enabled_extensions().Contains(extension->id()))
2919 DisableExtension(*it, extensions::Extension::DISABLE_GREYLIST);
2920 }
2809 } 2921 }
2810 2922
2811 void ExtensionService::AddUpdateObserver(extensions::UpdateObserver* observer) { 2923 void ExtensionService::AddUpdateObserver(extensions::UpdateObserver* observer) {
2812 update_observers_.AddObserver(observer); 2924 update_observers_.AddObserver(observer);
2813 } 2925 }
2814 2926
2815 void ExtensionService::RemoveUpdateObserver( 2927 void ExtensionService::RemoveUpdateObserver(
2816 extensions::UpdateObserver* observer) { 2928 extensions::UpdateObserver* observer) {
2817 update_observers_.RemoveObserver(observer); 2929 update_observers_.RemoveObserver(observer);
2818 } 2930 }
2819 2931
2820 // Used only by test code. 2932 // Used only by test code.
2821 void ExtensionService::UnloadAllExtensionsInternal() { 2933 void ExtensionService::UnloadAllExtensionsInternal() {
2822 profile_->GetExtensionSpecialStoragePolicy()->RevokeRightsForAllExtensions(); 2934 profile_->GetExtensionSpecialStoragePolicy()->RevokeRightsForAllExtensions();
2823 2935
2824 registry_->ClearAll(); 2936 registry_->ClearAll();
2825 extension_runtime_data_.clear(); 2937 extension_runtime_data_.clear();
2826 2938
2827 // TODO(erikkay) should there be a notification for this? We can't use 2939 // TODO(erikkay) should there be a notification for this? We can't use
2828 // EXTENSION_UNLOADED since that implies that the extension has been disabled 2940 // EXTENSION_UNLOADED since that implies that the extension has been disabled
2829 // or uninstalled. 2941 // or uninstalled.
2830 } 2942 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698