Chromium Code Reviews| 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..28117deb664fe9fede11d5d37d2dee4d544ef4d8 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 && |
|
Finnur
2014/11/19 10:16:26
This doesn't look quite right. Disable reasons use
binjin
2014/11/19 13:36:11
I think it's desired, the Extension::DisableReason
Finnur
2014/11/19 15:47:38
Ah, right! Sorry.
|
| !system_->management_policy()->UserMayModifySettings(extension, NULL) && |
| extension->location() != Manifest::EXTERNAL_COMPONENT) { |
| return; |
| @@ -1111,27 +1112,71 @@ 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; |
|
Finnur
2014/11/19 10:16:26
It seems a bit weird to let the system disable ext
binjin
2014/11/19 13:36:11
|to_enable| and |to_disable| are mutually exclusiv
Finnur
2014/11/19 15:47:38
Hmmm, that's totally non-obvious due to the MustRe
binjin
2014/11/19 17:21:41
Yes, we use MustRemainDisabled() for that purpose.
Finnur
2014/11/19 20:50:18
But... that's my point. Isn't it a bug that MustRe
binjin
2014/11/19 21:31:40
I'm confused. MustRemainDisaabled() will add an ex
Finnur
2014/11/20 12:25:34
Sorry, this confusion is, I think, on my part and
|
| // 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; |
| } |
| - for (size_t i = 0; i < to_unload.size(); ++i) |
| - UnloadExtension(to_unload[i], UnloadedExtensionInfo::REASON_DISABLE); |
| + extensions::ExtensionManagement* management = |
| + extensions::ExtensionManagementFactory::GetForBrowserContext(profile()); |
| + |
| + // Loop through the disabled extension list, find extensions to re-enable |
| + // automatically. |
| + for (scoped_refptr<const Extension> extension : |
| + registry_->disabled_extensions()) { |
| + // Find all disabled extensions disabled due to minimum version requirement, |
| + // but now satisfying it. |
| + if (management->CheckMinimumVersion(extension.get(), nullptr) && |
| + extension_prefs_->HasDisableReason( |
| + extension->id(), Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY)) { |
| + if (extension_prefs_->GetDisableReasons(extension->id()) == |
|
Finnur
2014/11/19 10:16:26
I would comment this line with:
// Is DISABLE_UPDA
binjin
2014/11/19 13:36:11
Done.
|
| + Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY) { |
| + // We need to enable those disabled only due to minimum version |
|
Finnur
2014/11/19 10:16:26
nit: Indentation is wrong here.
binjin
2014/11/19 13:36:11
Oops, Done.
|
| + // requirement. |
| + to_enable.push_back(extension->id()); |
|
Finnur
2014/11/19 10:16:26
You've already established here that this is an ex
binjin
2014/11/19 13:36:11
|to_enable| and |to_disable| are mutually exclusiv
|
| + extension_prefs_->ClearDisableReasons(extension->id()); |
|
Finnur
2014/11/19 10:16:26
Delete line 1146, remove the else clause and just
binjin
2014/11/19 13:36:11
Done.
|
| + } else { |
| + // otherwise, there are other disable reasons, just remove ours. |
| + extension_prefs_->RemoveDisableReason( |
| + extension->id(), Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY); |
| + } |
| + } |
| + } |
| + |
| + for (const std::string& id : to_unload) |
| + UnloadExtension(id, 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 (const std::string& id : to_enable) |
|
Finnur
2014/11/20 12:25:34
I would comment this |for| loop with something lik
binjin
2014/11/20 13:11:54
Done.
|
| + EnableExtension(id); |
| + |
| + 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. |
|
Finnur
2014/11/19 10:16:26
nit: This comment will probably need to be updated
binjin
2014/11/19 13:36:11
Acknowledged.
Finnur
2014/11/20 12:25:34
Suggest for easier reading:
// Find all extensions
binjin
2014/11/20 13:11:54
Done.
|
| + 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()); |
|
Finnur
2014/11/19 10:16:25
Is this code *required* to get a disabled extensio
binjin
2014/11/19 13:36:11
Done.
|
| + } |
| + } |
| + if (!params.ids.empty()) |
| + updater_->CheckNow(params); |
| + } |
| } |
| void ExtensionService::CheckForUpdatesSoon() { |
| @@ -1607,13 +1652,35 @@ void ExtensionService::OnExtensionInstalled( |
| // Unsupported requirements overrides the management policy. |
| 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 |
| - // disable reasons, enable it. |
| } else if (extension_prefs_->GetDisableReasons(id) == |
| Extension::DISABLE_UNSUPPORTED_REQUIREMENT) { |
| + // The extension was disabled because of unsupported requirements but |
| + // now supports all requirements after an update. |
| + // If there are no other disable reasons, enable it. |
| disable_reasons = Extension::DISABLE_NONE; |
| extension_prefs_->ClearDisableReasons(id); |
| + } else { |
| + // Otherwise just remove the corresponding disable reason. |
| + extension_prefs_->RemoveDisableReason( |
| + id, Extension::DISABLE_UNSUPPORTED_REQUIREMENT); |
| + disable_reasons &= ~Extension::DISABLE_UNSUPPORTED_REQUIREMENT; |
| + } |
|
Finnur
2014/11/19 10:16:26
Both RemoveDisableReason and the bitmask removal o
binjin
2014/11/19 13:36:11
Done.
|
| + |
| + // Check if the extension was disabled because of the minimum version |
| + // requirements from enterprise policy, and satisfies it now. |
| + if (extensions::ExtensionManagementFactory::GetForBrowserContext(profile()) |
| + ->CheckMinimumVersion(extension, nullptr)) { |
| + if (extension_prefs_->GetDisableReasons(id) == |
| + Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY) { |
| + // There are no other disable reasons, re-enable the extension. |
| + disable_reasons = Extension::DISABLE_NONE; |
| + extension_prefs_->ClearDisableReasons(id); |
| + } else { |
| + // Otherwise just clear the corresponding disable reason. |
| + extension_prefs_->RemoveDisableReason( |
| + id, Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY); |
| + disable_reasons &= ~Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY; |
| + } |
| } |
| if (install_flags & extensions::kInstallFlagIsBlacklistedForMalware) { |