OLD | NEW |
---|---|
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 835 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
846 } | 846 } |
847 | 847 |
848 const Extension* extension = GetInstalledExtension(extension_id); | 848 const Extension* extension = GetInstalledExtension(extension_id); |
849 // |extension| can be NULL if sync disables an extension that is not | 849 // |extension| can be NULL if sync disables an extension that is not |
850 // installed yet. | 850 // installed yet. |
851 // EXTERNAL_COMPONENT extensions are not generally modifiable by users, but | 851 // EXTERNAL_COMPONENT extensions are not generally modifiable by users, but |
852 // can be uninstalled by the browser if the user sets extension-specific | 852 // can be uninstalled by the browser if the user sets extension-specific |
853 // preferences. | 853 // preferences. |
854 if (extension && | 854 if (extension && |
855 disable_reason != Extension::DISABLE_RELOAD && | 855 disable_reason != Extension::DISABLE_RELOAD && |
856 disable_reason != Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY && | |
856 !system_->management_policy()->UserMayModifySettings(extension, NULL) && | 857 !system_->management_policy()->UserMayModifySettings(extension, NULL) && |
857 extension->location() != Manifest::EXTERNAL_COMPONENT) { | 858 extension->location() != Manifest::EXTERNAL_COMPONENT) { |
858 return; | 859 return; |
859 } | 860 } |
860 | 861 |
861 extension_prefs_->SetExtensionState(extension_id, Extension::DISABLED); | 862 extension_prefs_->SetExtensionState(extension_id, Extension::DISABLED); |
862 extension_prefs_->AddDisableReason(extension_id, disable_reason); | 863 extension_prefs_->AddDisableReason(extension_id, disable_reason); |
863 | 864 |
864 int include_mask = | 865 int include_mask = |
865 ExtensionRegistry::EVERYTHING & ~ExtensionRegistry::DISABLED; | 866 ExtensionRegistry::EVERYTHING & ~ExtensionRegistry::DISABLED; |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1104 file_task_runner_ = BrowserThread::GetBlockingPool()-> | 1105 file_task_runner_ = BrowserThread::GetBlockingPool()-> |
1105 GetSequencedTaskRunnerWithShutdownBehavior( | 1106 GetSequencedTaskRunnerWithShutdownBehavior( |
1106 BrowserThread::GetBlockingPool()->GetNamedSequenceToken(token), | 1107 BrowserThread::GetBlockingPool()->GetNamedSequenceToken(token), |
1107 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); | 1108 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); |
1108 return file_task_runner_.get(); | 1109 return file_task_runner_.get(); |
1109 } | 1110 } |
1110 | 1111 |
1111 void ExtensionService::CheckManagementPolicy() { | 1112 void ExtensionService::CheckManagementPolicy() { |
1112 std::vector<std::string> to_unload; | 1113 std::vector<std::string> to_unload; |
1113 std::map<std::string, Extension::DisableReason> to_disable; | 1114 std::map<std::string, Extension::DisableReason> to_disable; |
1115 std::vector<std::string> to_enable; | |
1114 | 1116 |
1115 // Loop through the extensions list, finding extensions we need to unload or | 1117 // Loop through the extensions list, finding extensions we need to unload or |
1116 // disable. | 1118 // disable. |
1117 const ExtensionSet& extensions = registry_->enabled_extensions(); | 1119 for (scoped_refptr<const Extension> extension : |
1118 for (ExtensionSet::const_iterator iter = extensions.begin(); | 1120 registry_->enabled_extensions()) { |
1119 iter != extensions.end(); ++iter) { | 1121 if (!system_->management_policy()->UserMayLoad(extension.get(), nullptr)) |
1120 const Extension* extension = (iter->get()); | |
1121 if (!system_->management_policy()->UserMayLoad(extension, NULL)) | |
1122 to_unload.push_back(extension->id()); | 1122 to_unload.push_back(extension->id()); |
1123 Extension::DisableReason disable_reason = Extension::DISABLE_NONE; | 1123 Extension::DisableReason disable_reason = Extension::DISABLE_NONE; |
1124 if (system_->management_policy()->MustRemainDisabled( | 1124 if (system_->management_policy()->MustRemainDisabled( |
1125 extension, &disable_reason, NULL)) | 1125 extension.get(), &disable_reason, nullptr)) |
1126 to_disable[extension->id()] = disable_reason; | 1126 to_disable[extension->id()] = disable_reason; |
1127 } | 1127 } |
1128 | 1128 |
1129 for (size_t i = 0; i < to_unload.size(); ++i) | 1129 extensions::ExtensionManagement* management = |
1130 UnloadExtension(to_unload[i], UnloadedExtensionInfo::REASON_DISABLE); | 1130 extensions::ExtensionManagementFactory::GetForBrowserContext(profile()); |
1131 | |
1132 // Loop through the disabled extension list, find extensions to re-enable | |
1133 // automatically. | |
1134 for (scoped_refptr<const Extension> extension : | |
1135 registry_->disabled_extensions()) { | |
1136 // Find all disabled extensions disabled due to minimum version requirement, | |
1137 // but now satisfying it. | |
1138 if (management->CheckMinimumVersionRequirement(extension.get(), nullptr) && | |
1139 extension_prefs_->HasDisableReason( | |
1140 extension->id(), Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY)) { | |
1141 // Is DISABLE_UPDATE_REQUIRED_BY_POLICY the *only* reason? | |
1142 if (extension_prefs_->GetDisableReasons(extension->id()) == | |
1143 Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY) { | |
1144 // We need to enable those disabled *only* due to minimum version | |
1145 // requirement. | |
1146 to_enable.push_back(extension->id()); | |
1147 } | |
1148 extension_prefs_->RemoveDisableReason( | |
1149 extension->id(), Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY); | |
1150 } | |
1151 } | |
1152 | |
1153 for (const std::string& id : to_unload) | |
1154 UnloadExtension(id, UnloadedExtensionInfo::REASON_DISABLE); | |
1131 | 1155 |
1132 for (std::map<std::string, Extension::DisableReason>::const_iterator i = | 1156 for (std::map<std::string, Extension::DisableReason>::const_iterator i = |
1133 to_disable.begin(); i != to_disable.end(); ++i) | 1157 to_disable.begin(); i != to_disable.end(); ++i) |
1134 DisableExtension(i->first, i->second); | 1158 DisableExtension(i->first, i->second); |
1159 | |
1160 for (const std::string& id : to_enable) | |
1161 EnableExtension(id); | |
1162 | |
1163 if (updater_.get()) { | |
1164 // Find all extensions (including the ones that got disabled just now) | |
1165 // disabled due to minimum version requirement from policy, and check for | |
1166 // update. | |
1167 extensions::ExtensionUpdater::CheckParams params; | |
1168 for (scoped_refptr<const Extension> extension : | |
1169 registry_->disabled_extensions()) { | |
1170 if (extension_prefs_->GetDisableReasons(extension->id()) == | |
1171 Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY) { | |
1172 params.ids.push_back(extension->id()); | |
1173 } | |
1174 } | |
1175 if (!params.ids.empty()) | |
1176 updater_->CheckNow(params); | |
1177 } | |
1135 } | 1178 } |
1136 | 1179 |
1137 void ExtensionService::CheckForUpdatesSoon() { | 1180 void ExtensionService::CheckForUpdatesSoon() { |
1138 // This can legitimately happen in unit tests. | 1181 // This can legitimately happen in unit tests. |
1139 if (!updater_.get()) | 1182 if (!updater_.get()) |
1140 return; | 1183 return; |
1141 | 1184 |
1142 if (AreAllExternalProvidersReady()) { | 1185 if (AreAllExternalProvidersReady()) { |
1143 updater_->CheckSoon(); | 1186 updater_->CheckSoon(); |
1144 } else { | 1187 } else { |
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1600 // extension; if we're here, that means the user is manually | 1643 // extension; if we're here, that means the user is manually |
1601 // installing the extension. | 1644 // installing the extension. |
1602 if (extension_prefs_->IsExternalExtensionUninstalled(id)) { | 1645 if (extension_prefs_->IsExternalExtensionUninstalled(id)) { |
1603 disable_reasons = Extension::DISABLE_NONE; | 1646 disable_reasons = Extension::DISABLE_NONE; |
1604 } | 1647 } |
1605 } | 1648 } |
1606 | 1649 |
1607 // Unsupported requirements overrides the management policy. | 1650 // Unsupported requirements overrides the management policy. |
1608 if (install_flags & extensions::kInstallFlagHasRequirementErrors) { | 1651 if (install_flags & extensions::kInstallFlagHasRequirementErrors) { |
1609 disable_reasons |= Extension::DISABLE_UNSUPPORTED_REQUIREMENT; | 1652 disable_reasons |= Extension::DISABLE_UNSUPPORTED_REQUIREMENT; |
1610 // If the extension was disabled because of unsupported requirements but | |
1611 // now supports all requirements after an update and there are not other | |
1612 // disable reasons, enable it. | |
1613 } else if (extension_prefs_->GetDisableReasons(id) == | 1653 } else if (extension_prefs_->GetDisableReasons(id) == |
1614 Extension::DISABLE_UNSUPPORTED_REQUIREMENT) { | 1654 Extension::DISABLE_UNSUPPORTED_REQUIREMENT) { |
1615 disable_reasons = Extension::DISABLE_NONE; | 1655 // Satisfies now, remove the corresponding disable reason instead. |
Finnur
2014/11/19 15:47:39
"Satisfies now" is weird.
But more importantly, I
binjin
2014/11/19 17:21:42
Ooops, yes.
Finnur
2014/11/19 20:50:18
I'm sorry, but I'm totally lost now.
How did we g
binjin
2014/11/19 21:31:40
I'm confused as well at this point. I think my sol
Finnur
2014/11/20 12:25:34
Again, I think the confusion is probably my fault.
| |
1616 extension_prefs_->ClearDisableReasons(id); | 1656 extension_prefs_->RemoveDisableReason( |
1657 id, Extension::DISABLE_UNSUPPORTED_REQUIREMENT); | |
1658 disable_reasons &= ~Extension::DISABLE_UNSUPPORTED_REQUIREMENT; | |
1659 } | |
1660 | |
1661 // Check if the extension was disabled because of the minimum version | |
1662 // requirements from enterprise policy, and satisfies it now. | |
1663 if (extensions::ExtensionManagementFactory::GetForBrowserContext(profile()) | |
1664 ->CheckMinimumVersionRequirement(extension, nullptr)) { | |
1665 // And remove the corresponding disable reason. | |
1666 extension_prefs_->RemoveDisableReason( | |
1667 id, Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY); | |
1668 disable_reasons &= ~Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY; | |
1617 } | 1669 } |
1618 | 1670 |
1619 if (install_flags & extensions::kInstallFlagIsBlacklistedForMalware) { | 1671 if (install_flags & extensions::kInstallFlagIsBlacklistedForMalware) { |
1620 // Installation of a blacklisted extension can happen from sync, policy, | 1672 // Installation of a blacklisted extension can happen from sync, policy, |
1621 // etc, where to maintain consistency we need to install it, just never | 1673 // etc, where to maintain consistency we need to install it, just never |
1622 // load it (see AddExtension). Usually it should be the job of callers to | 1674 // load it (see AddExtension). Usually it should be the job of callers to |
1623 // incercept blacklisted extension earlier (e.g. CrxInstaller, before even | 1675 // incercept blacklisted extension earlier (e.g. CrxInstaller, before even |
1624 // showing the install dialogue). | 1676 // showing the install dialogue). |
1625 extension_prefs_->AcknowledgeBlacklistedExtension(id); | 1677 extension_prefs_->AcknowledgeBlacklistedExtension(id); |
1626 UMA_HISTOGRAM_ENUMERATION("ExtensionBlacklist.SilentInstall", | 1678 UMA_HISTOGRAM_ENUMERATION("ExtensionBlacklist.SilentInstall", |
(...skipping 778 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2405 } | 2457 } |
2406 | 2458 |
2407 void ExtensionService::OnProfileDestructionStarted() { | 2459 void ExtensionService::OnProfileDestructionStarted() { |
2408 ExtensionIdSet ids_to_unload = registry_->enabled_extensions().GetIDs(); | 2460 ExtensionIdSet ids_to_unload = registry_->enabled_extensions().GetIDs(); |
2409 for (ExtensionIdSet::iterator it = ids_to_unload.begin(); | 2461 for (ExtensionIdSet::iterator it = ids_to_unload.begin(); |
2410 it != ids_to_unload.end(); | 2462 it != ids_to_unload.end(); |
2411 ++it) { | 2463 ++it) { |
2412 UnloadExtension(*it, UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN); | 2464 UnloadExtension(*it, UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN); |
2413 } | 2465 } |
2414 } | 2466 } |
OLD | NEW |