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

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: 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 if (extension_prefs_->IsExtensionGreylisted((*it)->id()))
582 greylist_.Insert(*it);
583 }
584 }
585
574 void ExtensionService::VerifyAllExtensions() { 586 void ExtensionService::VerifyAllExtensions() {
575 ExtensionIdSet to_add; 587 ExtensionIdSet to_add;
576 scoped_ptr<ExtensionSet> all_extensions = GenerateInstalledExtensionsSet(); 588 scoped_ptr<ExtensionSet> all_extensions = GenerateInstalledExtensionsSet();
577 589
578 for (ExtensionSet::const_iterator i = all_extensions->begin(); 590 for (ExtensionSet::const_iterator i = all_extensions->begin();
579 i != all_extensions->end(); ++i) { 591 i != all_extensions->end(); ++i) {
580 const Extension& extension = **i; 592 const Extension& extension = **i;
581 593
582 if (InstallVerifier::NeedsVerification(extension)) 594 if (InstallVerifier::NeedsVerification(extension))
583 to_add.insert(extension.id()); 595 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()); 2764 to_be_installed.push_back((*it)->id());
2753 } 2765 }
2754 for (std::vector<std::string>::const_iterator it = to_be_installed.begin(); 2766 for (std::vector<std::string>::const_iterator it = to_be_installed.begin();
2755 it != to_be_installed.end(); 2767 it != to_be_installed.end();
2756 ++it) { 2768 ++it) {
2757 MaybeFinishDelayedInstallation(*it); 2769 MaybeFinishDelayedInstallation(*it);
2758 } 2770 }
2759 } 2771 }
2760 2772
2761 void ExtensionService::OnBlacklistUpdated() { 2773 void ExtensionService::OnBlacklistUpdated() {
2762 blacklist_->GetMalwareIDs( 2774 blacklist_->GetBlacklistedIDs(
2763 GenerateInstalledExtensionsSet()->GetIDs(), 2775 GenerateInstalledExtensionsSet()->GetIDs(),
2764 base::Bind(&ExtensionService::ManageBlacklist, AsWeakPtr())); 2776 base::Bind(&ExtensionService::ManageBlacklist, AsWeakPtr()));
2765 } 2777 }
2766 2778
2767 void ExtensionService::ManageBlacklist(const std::set<std::string>& updated) { 2779 void ExtensionService::ManageBlacklist(
2780 const extensions::Blacklist::BlacklistStateMap& state_map) {
2768 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 2781 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2769 2782
2770 std::set<std::string> before = registry_->blacklisted_extensions().GetIDs(); 2783 std::set<std::string> blocked;
not at google - send to devlin 2014/01/22 00:33:14 (following on from comment in header file) persona
Oleg Eterevsky 2014/01/22 21:25:04 I think we should fix the terminology everywhere,
not at google - send to devlin 2014/01/22 22:24:38 I think this is actually the thing that needs to c
Oleg Eterevsky 2014/01/23 14:48:54 Ok, let's commit it like this and then discuss the
2771 std::set<std::string> no_longer_blacklisted = 2784 std::set<std::string> greylist;
2772 base::STLSetDifference<std::set<std::string> >(before, updated); 2785 std::set<std::string> unknown;
not at google - send to devlin 2014/01/22 00:33:14 nit: could you call this "ignore" or "skip" everyw
Oleg Eterevsky 2014/01/22 21:25:04 Changed to 'unchanged'.
2773 std::set<std::string> not_yet_blacklisted = 2786 for (extensions::Blacklist::BlacklistStateMap::const_iterator it =
2774 base::STLSetDifference<std::set<std::string> >(updated, before); 2787 state_map.begin();
2788 it != state_map.end();
2789 ++it) {
2790 switch (it->second) {
2791 case extensions::NOT_BLACKLISTED:
2792 break;
2775 2793
2776 for (std::set<std::string>::iterator it = no_longer_blacklisted.begin(); 2794 case extensions::BLACKLISTED_MALWARE:
2777 it != no_longer_blacklisted.end(); ++it) { 2795 blocked.insert(it->first);
2796 break;
2797
2798 case extensions::BLACKLISTED_SECURITY_VULNERABILITY:
2799 case extensions::BLACKLISTED_CWS_POLICY_VIOLATION:
2800 case extensions::BLACKLISTED_POTENTIALLY_UNWANTED:
2801 greylist.insert(it->first);
2802 break;
2803
2804 case extensions::BLACKLISTED_UNKNOWN:
2805 unknown.insert(it->first);
2806 break;
2807 }
2808 }
2809
2810 UpdateBlockedExtensions(blocked, unknown);
2811 UpdateGreylistedExtensions(greylist, unknown);
2812
2813 IdentifyAlertableExtensions();
2814 }
2815
2816 void ExtensionService::UpdateBlockedExtensions(
2817 const std::set<std::string>& blocked,
2818 const std::set<std::string>& unknown) {
2819 std::set<std::string> blocked_and_unknown;
2820 std::set_union(
2821 blocked.begin(), blocked.end(), unknown.begin(), unknown.end(),
2822 std::inserter(blocked_and_unknown, blocked_and_unknown.end()));
2823
2824 // Extensions with unknown blacklist state will remain blocked or unblocked as
2825 // before this update.
2826 std::set<std::string> blocked_before =
2827 registry_->blacklisted_extensions().GetIDs();
2828 std::set<std::string> no_longer_blocked =
2829 base::STLSetDifference<std::set<std::string> >(
2830 blocked_before, blocked_and_unknown);
2831 std::set<std::string> not_yet_blocked =
2832 base::STLSetDifference<std::set<std::string> >(blocked, blocked_before);
2833
2834 for (std::set<std::string>::iterator it = no_longer_blocked.begin();
2835 it != no_longer_blocked.end(); ++it) {
2778 scoped_refptr<const Extension> extension = 2836 scoped_refptr<const Extension> extension =
2779 registry_->blacklisted_extensions().GetByID(*it); 2837 registry_->blacklisted_extensions().GetByID(*it);
2780 if (!extension.get()) { 2838 if (!extension.get()) {
2781 NOTREACHED() << "Extension " << *it << " no longer blacklisted, " 2839 NOTREACHED() << "Extension " << *it << " no longer blocked, "
2782 << "but it was never blacklisted."; 2840 << "but it was never blocked.";
2783 continue; 2841 continue;
2784 } 2842 }
2785 registry_->RemoveBlacklisted(*it); 2843 registry_->RemoveBlacklisted(*it);
2786 extension_prefs_->SetExtensionBlacklisted(extension->id(), false); 2844 extension_prefs_->SetExtensionBlacklisted(extension->id(), false);
2787 AddExtension(extension.get()); 2845 AddExtension(extension.get());
2788 UMA_HISTOGRAM_ENUMERATION("ExtensionBlacklist.UnblacklistInstalled", 2846 UMA_HISTOGRAM_ENUMERATION("ExtensionBlacklist.UnblacklistInstalled",
2789 extension->location(), 2847 extension->location(),
2790 Manifest::NUM_LOCATIONS); 2848 Manifest::NUM_LOCATIONS);
2791 } 2849 }
2792 2850
2793 for (std::set<std::string>::iterator it = not_yet_blacklisted.begin(); 2851 for (std::set<std::string>::iterator it = not_yet_blocked.begin();
2794 it != not_yet_blacklisted.end(); ++it) { 2852 it != not_yet_blocked.end(); ++it) {
2795 scoped_refptr<const Extension> extension = GetInstalledExtension(*it); 2853 scoped_refptr<const Extension> extension = GetInstalledExtension(*it);
2796 if (!extension.get()) { 2854 if (!extension.get()) {
2797 NOTREACHED() << "Extension " << *it << " needs to be " 2855 NOTREACHED() << "Extension " << *it << " needs to be "
2798 << "blacklisted, but it's not installed."; 2856 << "blacklisted, but it's not installed.";
2799 continue; 2857 continue;
2800 } 2858 }
2801 registry_->AddBlacklisted(extension); 2859 registry_->AddBlacklisted(extension);
2802 extension_prefs_->SetExtensionBlacklisted(extension->id(), true); 2860 extension_prefs_->SetExtensionBlacklisted(extension->id(), true);
2803 UnloadExtension(*it, UnloadedExtensionInfo::REASON_BLACKLIST); 2861 UnloadExtension(*it, UnloadedExtensionInfo::REASON_BLACKLIST);
2804 UMA_HISTOGRAM_ENUMERATION("ExtensionBlacklist.BlacklistInstalled", 2862 UMA_HISTOGRAM_ENUMERATION("ExtensionBlacklist.BlacklistInstalled",
2805 extension->location(), Manifest::NUM_LOCATIONS); 2863 extension->location(), Manifest::NUM_LOCATIONS);
2806 } 2864 }
2807 2865
2808 IdentifyAlertableExtensions(); 2866 }
2867
2868 void ExtensionService::UpdateGreylistedExtensions(
not at google - send to devlin 2014/01/22 00:33:14 seems like this method is basically the same as Up
Oleg Eterevsky 2014/01/22 21:25:04 I'm not sure what exactly to log. Is it ok if I ad
not at google - send to devlin 2014/01/22 22:24:38 I suppose you might as well do it in a follow up.
Oleg Eterevsky 2014/01/23 14:48:54 Done. It actually did make the code simpler.
2869 const std::set<std::string>& greylist,
2870 const std::set<std::string>& unknown) {
2871 std::set<std::string> greylist_and_unknown;
2872 std::set_union(
2873 greylist.begin(), greylist.end(), unknown.begin(), unknown.end(),
2874 std::inserter(greylist_and_unknown, greylist_and_unknown.end()));
2875
2876 std::set<std::string> greylisted_before = greylist_.GetIDs();
2877 std::set<std::string> no_longer_greylisted =
2878 base::STLSetDifference<std::set<std::string> >(
2879 greylisted_before, greylist_and_unknown);
2880 std::set<std::string> not_yet_greylisted =
2881 base::STLSetDifference<std::set<std::string> >(
2882 greylist, greylisted_before);
2883
2884 for (std::set<std::string>::iterator it = no_longer_greylisted.begin();
2885 it != no_longer_greylisted.end(); ++it) {
2886 scoped_refptr<const Extension> extension = greylist_.GetByID(*it);
2887 if (!extension.get()) {
2888 NOTREACHED() << "Extension " << *it << " no longer greylisted, "
2889 << "but it was not marked as greylisted.";
2890 continue;
2891 }
2892
2893 greylist_.Remove(*it);
2894 extension_prefs_->SetExtensionGreylisted(extension->id(), false);
2895 EnableExtension(*it);
2896 }
2897
2898 for (std::set<std::string>::iterator it = not_yet_greylisted.begin();
2899 it != not_yet_greylisted.end(); ++it) {
2900 scoped_refptr<const Extension> extension = GetInstalledExtension(*it);
2901 if (!extension.get()) {
2902 NOTREACHED() << "Extension " << *it << " needs to be "
2903 << "disabled, but it's not installed.";
2904 continue;
2905 }
2906 greylist_.Insert(extension);
2907 extension_prefs_->SetExtensionGreylisted(extension->id(), true);
2908 DisableExtension(*it, extensions::Extension::DISABLE_GREYLISTED);
2909 }
2809 } 2910 }
2810 2911
2811 void ExtensionService::AddUpdateObserver(extensions::UpdateObserver* observer) { 2912 void ExtensionService::AddUpdateObserver(extensions::UpdateObserver* observer) {
2812 update_observers_.AddObserver(observer); 2913 update_observers_.AddObserver(observer);
2813 } 2914 }
2814 2915
2815 void ExtensionService::RemoveUpdateObserver( 2916 void ExtensionService::RemoveUpdateObserver(
2816 extensions::UpdateObserver* observer) { 2917 extensions::UpdateObserver* observer) {
2817 update_observers_.RemoveObserver(observer); 2918 update_observers_.RemoveObserver(observer);
2818 } 2919 }
2819 2920
2820 // Used only by test code. 2921 // Used only by test code.
2821 void ExtensionService::UnloadAllExtensionsInternal() { 2922 void ExtensionService::UnloadAllExtensionsInternal() {
2822 profile_->GetExtensionSpecialStoragePolicy()->RevokeRightsForAllExtensions(); 2923 profile_->GetExtensionSpecialStoragePolicy()->RevokeRightsForAllExtensions();
2823 2924
2824 registry_->ClearAll(); 2925 registry_->ClearAll();
2825 extension_runtime_data_.clear(); 2926 extension_runtime_data_.clear();
2826 2927
2827 // TODO(erikkay) should there be a notification for this? We can't use 2928 // 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 2929 // EXTENSION_UNLOADED since that implies that the extension has been disabled
2829 // or uninstalled. 2930 // or uninstalled.
2830 } 2931 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698