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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/extension_service.cc
diff --git a/chrome/browser/extensions/extension_service.cc b/chrome/browser/extensions/extension_service.cc
index b9c734071674fc1a52e7e0df6d7d737803cc8c26..ffd03d062a5c2658ac3a3d299b2dbe121ba70ad8 100644
--- a/chrome/browser/extensions/extension_service.cc
+++ b/chrome/browser/extensions/extension_service.cc
@@ -565,12 +565,24 @@ void ExtensionService::Init() {
}
system_->management_policy()->RegisterProvider(
shared_module_policy_provider_.get());
+
+ LoadGreylistFromPrefs();
}
UMA_HISTOGRAM_TIMES("Extensions.ExtensionServiceInitTime",
base::Time::Now() - begin_time);
}
+void ExtensionService::LoadGreylistFromPrefs() {
+ scoped_ptr<ExtensionSet> all_extensions = GenerateInstalledExtensionsSet();
+
+ for (ExtensionSet::const_iterator it = all_extensions->begin();
+ it != all_extensions->end(); ++it) {
+ if (extension_prefs_->IsExtensionGreylisted((*it)->id()))
+ greylist_.Insert(*it);
+ }
+}
+
void ExtensionService::VerifyAllExtensions() {
ExtensionIdSet to_add;
scoped_ptr<ExtensionSet> all_extensions = GenerateInstalledExtensionsSet();
@@ -2759,27 +2771,73 @@ void ExtensionService::MaybeFinishDelayedInstallations() {
}
void ExtensionService::OnBlacklistUpdated() {
- blacklist_->GetMalwareIDs(
+ blacklist_->GetBlacklistedIDs(
GenerateInstalledExtensionsSet()->GetIDs(),
base::Bind(&ExtensionService::ManageBlacklist, AsWeakPtr()));
}
-void ExtensionService::ManageBlacklist(const std::set<std::string>& updated) {
+void ExtensionService::ManageBlacklist(
+ const extensions::Blacklist::BlacklistStateMap& state_map) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- std::set<std::string> before = registry_->blacklisted_extensions().GetIDs();
- std::set<std::string> no_longer_blacklisted =
- base::STLSetDifference<std::set<std::string> >(before, updated);
- std::set<std::string> not_yet_blacklisted =
- base::STLSetDifference<std::set<std::string> >(updated, before);
+ 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
+ std::set<std::string> greylist;
+ 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'.
+ for (extensions::Blacklist::BlacklistStateMap::const_iterator it =
+ state_map.begin();
+ it != state_map.end();
+ ++it) {
+ switch (it->second) {
+ case extensions::NOT_BLACKLISTED:
+ break;
+
+ case extensions::BLACKLISTED_MALWARE:
+ blocked.insert(it->first);
+ break;
- for (std::set<std::string>::iterator it = no_longer_blacklisted.begin();
- it != no_longer_blacklisted.end(); ++it) {
+ case extensions::BLACKLISTED_SECURITY_VULNERABILITY:
+ case extensions::BLACKLISTED_CWS_POLICY_VIOLATION:
+ case extensions::BLACKLISTED_POTENTIALLY_UNWANTED:
+ greylist.insert(it->first);
+ break;
+
+ case extensions::BLACKLISTED_UNKNOWN:
+ unknown.insert(it->first);
+ break;
+ }
+ }
+
+ UpdateBlockedExtensions(blocked, unknown);
+ UpdateGreylistedExtensions(greylist, unknown);
+
+ IdentifyAlertableExtensions();
+}
+
+void ExtensionService::UpdateBlockedExtensions(
+ const std::set<std::string>& blocked,
+ const std::set<std::string>& unknown) {
+ std::set<std::string> blocked_and_unknown;
+ std::set_union(
+ blocked.begin(), blocked.end(), unknown.begin(), unknown.end(),
+ std::inserter(blocked_and_unknown, blocked_and_unknown.end()));
+
+ // Extensions with unknown blacklist state will remain blocked or unblocked as
+ // before this update.
+ std::set<std::string> blocked_before =
+ registry_->blacklisted_extensions().GetIDs();
+ std::set<std::string> no_longer_blocked =
+ base::STLSetDifference<std::set<std::string> >(
+ blocked_before, blocked_and_unknown);
+ std::set<std::string> not_yet_blocked =
+ base::STLSetDifference<std::set<std::string> >(blocked, blocked_before);
+
+ for (std::set<std::string>::iterator it = no_longer_blocked.begin();
+ it != no_longer_blocked.end(); ++it) {
scoped_refptr<const Extension> extension =
registry_->blacklisted_extensions().GetByID(*it);
if (!extension.get()) {
- NOTREACHED() << "Extension " << *it << " no longer blacklisted, "
- << "but it was never blacklisted.";
+ NOTREACHED() << "Extension " << *it << " no longer blocked, "
+ << "but it was never blocked.";
continue;
}
registry_->RemoveBlacklisted(*it);
@@ -2790,8 +2848,8 @@ void ExtensionService::ManageBlacklist(const std::set<std::string>& updated) {
Manifest::NUM_LOCATIONS);
}
- for (std::set<std::string>::iterator it = not_yet_blacklisted.begin();
- it != not_yet_blacklisted.end(); ++it) {
+ for (std::set<std::string>::iterator it = not_yet_blocked.begin();
+ it != not_yet_blocked.end(); ++it) {
scoped_refptr<const Extension> extension = GetInstalledExtension(*it);
if (!extension.get()) {
NOTREACHED() << "Extension " << *it << " needs to be "
@@ -2805,7 +2863,50 @@ void ExtensionService::ManageBlacklist(const std::set<std::string>& updated) {
extension->location(), Manifest::NUM_LOCATIONS);
}
- IdentifyAlertableExtensions();
+}
+
+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.
+ const std::set<std::string>& greylist,
+ const std::set<std::string>& unknown) {
+ std::set<std::string> greylist_and_unknown;
+ std::set_union(
+ greylist.begin(), greylist.end(), unknown.begin(), unknown.end(),
+ std::inserter(greylist_and_unknown, greylist_and_unknown.end()));
+
+ std::set<std::string> greylisted_before = greylist_.GetIDs();
+ std::set<std::string> no_longer_greylisted =
+ base::STLSetDifference<std::set<std::string> >(
+ greylisted_before, greylist_and_unknown);
+ std::set<std::string> not_yet_greylisted =
+ base::STLSetDifference<std::set<std::string> >(
+ greylist, greylisted_before);
+
+ for (std::set<std::string>::iterator it = no_longer_greylisted.begin();
+ it != no_longer_greylisted.end(); ++it) {
+ scoped_refptr<const Extension> extension = greylist_.GetByID(*it);
+ if (!extension.get()) {
+ NOTREACHED() << "Extension " << *it << " no longer greylisted, "
+ << "but it was not marked as greylisted.";
+ continue;
+ }
+
+ greylist_.Remove(*it);
+ extension_prefs_->SetExtensionGreylisted(extension->id(), false);
+ EnableExtension(*it);
+ }
+
+ for (std::set<std::string>::iterator it = not_yet_greylisted.begin();
+ it != not_yet_greylisted.end(); ++it) {
+ scoped_refptr<const Extension> extension = GetInstalledExtension(*it);
+ if (!extension.get()) {
+ NOTREACHED() << "Extension " << *it << " needs to be "
+ << "disabled, but it's not installed.";
+ continue;
+ }
+ greylist_.Insert(extension);
+ extension_prefs_->SetExtensionGreylisted(extension->id(), true);
+ DisableExtension(*it, extensions::Extension::DISABLE_GREYLISTED);
+ }
}
void ExtensionService::AddUpdateObserver(extensions::UpdateObserver* observer) {

Powered by Google App Engine
This is Rietveld 408576698