Index: chrome/browser/extensions/extension_service.cc |
diff --git a/chrome/browser/extensions/extension_service.cc b/chrome/browser/extensions/extension_service.cc |
index 283f42a1fc3059b09f965b156b5455ac1dbfa62c..008a62a149de09ccfc9607a3923e7d0cb37b118d 100644 |
--- a/chrome/browser/extensions/extension_service.cc |
+++ b/chrome/browser/extensions/extension_service.cc |
@@ -853,6 +853,7 @@ void ExtensionService::DisableExtension( |
// preferences. |
if (extension && |
disable_reason != Extension::DISABLE_RELOAD && |
+ disable_reason != Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY && |
!system_->management_policy()->UserMayModifySettings(extension, NULL) && |
extension->location() != Manifest::EXTERNAL_COMPONENT) { |
return; |
@@ -1111,27 +1112,69 @@ base::SequencedTaskRunner* ExtensionService::GetFileTaskRunner() { |
void ExtensionService::CheckManagementPolicy() { |
std::vector<std::string> to_unload; |
std::map<std::string, Extension::DisableReason> to_disable; |
+ std::vector<std::string> to_enable; |
// Loop through the extensions list, finding extensions we need to unload or |
// disable. |
- const ExtensionSet& extensions = registry_->enabled_extensions(); |
- for (ExtensionSet::const_iterator iter = extensions.begin(); |
- iter != extensions.end(); ++iter) { |
- const Extension* extension = (iter->get()); |
- if (!system_->management_policy()->UserMayLoad(extension, NULL)) |
+ for (scoped_refptr<const Extension> extension : |
+ registry_->enabled_extensions()) { |
+ if (!system_->management_policy()->UserMayLoad(extension.get(), nullptr)) |
to_unload.push_back(extension->id()); |
Extension::DisableReason disable_reason = Extension::DISABLE_NONE; |
if (system_->management_policy()->MustRemainDisabled( |
- extension, &disable_reason, NULL)) |
+ extension.get(), &disable_reason, nullptr)) |
to_disable[extension->id()] = disable_reason; |
} |
+ // Loop through the disabled extension list, find extensions to re-enable |
+ // automaticall automaticallyy. |
Joao da Silva
2014/11/17 16:17:41
"automatically" (only once)
binjin
2014/11/18 13:25:55
Done.
|
+ for (scoped_refptr<const Extension> extension : |
+ registry_->disabled_extensions()) { |
+ // Find all disabled extensions disabled due to minimum version requirement, |
+ // but now satisfying it. |
+ if (extensions::ExtensionManagementFactory::GetForBrowserContext(profile()) |
Joao da Silva
2014/11/17 16:17:41
Get this outside of the loop and put in a local va
binjin
2014/11/18 13:25:55
Done.
|
+ ->CheckMinimumVersion(extension.get(), nullptr) && |
+ extension_prefs_->HasDisableReason( |
+ extension->id(), Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY)) { |
+ if (extension_prefs_->GetDisableReasons(extension->id()) == |
+ Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY) { |
+ // We need to enable those disabled only due to minimum version |
+ // requirement. |
+ to_enable.push_back(extension->id()); |
+ extension_prefs_->ClearDisableReasons(extension->id()); |
+ } else { |
+ // otherwise, there are other disable reasons, just remove ours. |
+ extension_prefs_->RemoveDisableReason( |
+ extension->id(), Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY); |
+ } |
+ } |
+ } |
+ |
for (size_t i = 0; i < to_unload.size(); ++i) |
UnloadExtension(to_unload[i], UnloadedExtensionInfo::REASON_DISABLE); |
for (std::map<std::string, Extension::DisableReason>::const_iterator i = |
to_disable.begin(); i != to_disable.end(); ++i) |
DisableExtension(i->first, i->second); |
+ |
+ for (size_t i = 0; i < to_enable.size(); ++i) |
Joao da Silva
2014/11/17 16:17:41
for (const std::string& id : to_enable) { ... }
D
binjin
2014/11/18 13:25:55
Done. Actually I intended to keep consistent with
|
+ EnableExtension(to_enable[i]); |
+ |
+ if (updater_.get()) { |
+ // Find all extensions (including the ones that got disabled just now) |
+ // disabled due to minimum version requirement from policy, and check for |
+ // update. |
+ extensions::ExtensionUpdater::CheckParams params; |
+ for (scoped_refptr<const Extension> extension : |
+ registry_->disabled_extensions()) { |
+ if (extension_prefs_->HasDisableReason( |
+ extension->id(), Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY)) { |
+ params.ids.push_back(extension->id()); |
+ } |
+ } |
+ if (!params.ids.empty()) |
+ updater_->CheckNow(params); |
+ } |
} |
void ExtensionService::CheckForUpdatesSoon() { |
@@ -1608,7 +1651,7 @@ void ExtensionService::OnExtensionInstalled( |
if (install_flags & extensions::kInstallFlagHasRequirementErrors) { |
disable_reasons |= Extension::DISABLE_UNSUPPORTED_REQUIREMENT; |
// If the extension was disabled because of unsupported requirements but |
- // now supports all requirements after an update and there are not other |
+ // now supports all requirements after an update and there are no other |
// disable reasons, enable it. |
} else if (extension_prefs_->GetDisableReasons(id) == |
Extension::DISABLE_UNSUPPORTED_REQUIREMENT) { |
@@ -1616,6 +1659,17 @@ void ExtensionService::OnExtensionInstalled( |
extension_prefs_->ClearDisableReasons(id); |
} |
+ // If the extension was disabled because of the minimum version requirements |
+ // from enterprise policy, and satisfies it now and there are no other disable |
+ // reasons, enable it. |
+ if (extension_prefs_->GetDisableReasons(id) == |
+ Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY && |
+ extensions::ExtensionManagementFactory::GetForBrowserContext(profile()) |
+ ->CheckMinimumVersion(extension, nullptr)) { |
+ disable_reasons = Extension::DISABLE_NONE; |
+ extension_prefs_->ClearDisableReasons(id); |
+ } |
Joao da Silva
2014/11/17 16:17:41
What if the extension had more than one disable_re
binjin
2014/11/18 13:25:55
Done. Also made similar change to code above(unsup
|
+ |
if (install_flags & extensions::kInstallFlagIsBlacklistedForMalware) { |
// Installation of a blacklisted extension can happen from sync, policy, |
// etc, where to maintain consistency we need to install it, just never |