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 // Loop through the disabled extension list, find extensions to re-enable | |
1130 // automaticall automaticallyy. | |
Joao da Silva
2014/11/17 16:17:41
"automatically" (only once)
binjin
2014/11/18 13:25:55
Done.
| |
1131 for (scoped_refptr<const Extension> extension : | |
1132 registry_->disabled_extensions()) { | |
1133 // Find all disabled extensions disabled due to minimum version requirement, | |
1134 // but now satisfying it. | |
1135 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.
| |
1136 ->CheckMinimumVersion(extension.get(), nullptr) && | |
1137 extension_prefs_->HasDisableReason( | |
1138 extension->id(), Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY)) { | |
1139 if (extension_prefs_->GetDisableReasons(extension->id()) == | |
1140 Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY) { | |
1141 // We need to enable those disabled only due to minimum version | |
1142 // requirement. | |
1143 to_enable.push_back(extension->id()); | |
1144 extension_prefs_->ClearDisableReasons(extension->id()); | |
1145 } else { | |
1146 // otherwise, there are other disable reasons, just remove ours. | |
1147 extension_prefs_->RemoveDisableReason( | |
1148 extension->id(), Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY); | |
1149 } | |
1150 } | |
1151 } | |
1152 | |
1129 for (size_t i = 0; i < to_unload.size(); ++i) | 1153 for (size_t i = 0; i < to_unload.size(); ++i) |
1130 UnloadExtension(to_unload[i], UnloadedExtensionInfo::REASON_DISABLE); | 1154 UnloadExtension(to_unload[i], 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 (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
| |
1161 EnableExtension(to_enable[i]); | |
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_->HasDisableReason( | |
1171 extension->id(), 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 456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 | 1653 // If the extension was disabled because of unsupported requirements but |
1611 // now supports all requirements after an update and there are not other | 1654 // now supports all requirements after an update and there are no other |
1612 // disable reasons, enable it. | 1655 // disable reasons, enable it. |
1613 } else if (extension_prefs_->GetDisableReasons(id) == | 1656 } else if (extension_prefs_->GetDisableReasons(id) == |
1614 Extension::DISABLE_UNSUPPORTED_REQUIREMENT) { | 1657 Extension::DISABLE_UNSUPPORTED_REQUIREMENT) { |
1615 disable_reasons = Extension::DISABLE_NONE; | 1658 disable_reasons = Extension::DISABLE_NONE; |
1616 extension_prefs_->ClearDisableReasons(id); | 1659 extension_prefs_->ClearDisableReasons(id); |
1617 } | 1660 } |
1618 | 1661 |
1662 // If the extension was disabled because of the minimum version requirements | |
1663 // from enterprise policy, and satisfies it now and there are no other disable | |
1664 // reasons, enable it. | |
1665 if (extension_prefs_->GetDisableReasons(id) == | |
1666 Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY && | |
1667 extensions::ExtensionManagementFactory::GetForBrowserContext(profile()) | |
1668 ->CheckMinimumVersion(extension, nullptr)) { | |
1669 disable_reasons = Extension::DISABLE_NONE; | |
1670 extension_prefs_->ClearDisableReasons(id); | |
1671 } | |
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
| |
1672 | |
1619 if (install_flags & extensions::kInstallFlagIsBlacklistedForMalware) { | 1673 if (install_flags & extensions::kInstallFlagIsBlacklistedForMalware) { |
1620 // Installation of a blacklisted extension can happen from sync, policy, | 1674 // Installation of a blacklisted extension can happen from sync, policy, |
1621 // etc, where to maintain consistency we need to install it, just never | 1675 // 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 | 1676 // load it (see AddExtension). Usually it should be the job of callers to |
1623 // incercept blacklisted extension earlier (e.g. CrxInstaller, before even | 1677 // incercept blacklisted extension earlier (e.g. CrxInstaller, before even |
1624 // showing the install dialogue). | 1678 // showing the install dialogue). |
1625 extension_prefs_->AcknowledgeBlacklistedExtension(id); | 1679 extension_prefs_->AcknowledgeBlacklistedExtension(id); |
1626 UMA_HISTOGRAM_ENUMERATION("ExtensionBlacklist.SilentInstall", | 1680 UMA_HISTOGRAM_ENUMERATION("ExtensionBlacklist.SilentInstall", |
1627 extension->location(), | 1681 extension->location(), |
1628 Manifest::NUM_LOCATIONS); | 1682 Manifest::NUM_LOCATIONS); |
(...skipping 776 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2405 } | 2459 } |
2406 | 2460 |
2407 void ExtensionService::OnProfileDestructionStarted() { | 2461 void ExtensionService::OnProfileDestructionStarted() { |
2408 ExtensionIdSet ids_to_unload = registry_->enabled_extensions().GetIDs(); | 2462 ExtensionIdSet ids_to_unload = registry_->enabled_extensions().GetIDs(); |
2409 for (ExtensionIdSet::iterator it = ids_to_unload.begin(); | 2463 for (ExtensionIdSet::iterator it = ids_to_unload.begin(); |
2410 it != ids_to_unload.end(); | 2464 it != ids_to_unload.end(); |
2411 ++it) { | 2465 ++it) { |
2412 UnloadExtension(*it, UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN); | 2466 UnloadExtension(*it, UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN); |
2413 } | 2467 } |
2414 } | 2468 } |
OLD | NEW |