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

Side by Side Diff: chrome/browser/extensions/extension_service.cc

Issue 706623004: Add minimum version to extension management (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ext-update-url
Patch Set: fix comment Created 6 years, 1 month 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 unified diff | Download patch
OLDNEW
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
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 &&
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.
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
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;
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
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->CheckMinimumVersion(extension.get(), nullptr) &&
1139 extension_prefs_->HasDisableReason(
1140 extension->id(), Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY)) {
1141 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.
1142 Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY) {
1143 // 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.
1144 // requirement.
1145 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
1146 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.
1147 } else {
1148 // otherwise, there are other disable reasons, just remove ours.
1149 extension_prefs_->RemoveDisableReason(
1150 extension->id(), Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY);
1151 }
1152 }
1153 }
1154
1155 for (const std::string& id : to_unload)
1156 UnloadExtension(id, UnloadedExtensionInfo::REASON_DISABLE);
1131 1157
1132 for (std::map<std::string, Extension::DisableReason>::const_iterator i = 1158 for (std::map<std::string, Extension::DisableReason>::const_iterator i =
1133 to_disable.begin(); i != to_disable.end(); ++i) 1159 to_disable.begin(); i != to_disable.end(); ++i)
1134 DisableExtension(i->first, i->second); 1160 DisableExtension(i->first, i->second);
1161
1162 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.
1163 EnableExtension(id);
1164
1165 if (updater_.get()) {
1166 // Find all extensions (including the ones that got disabled just now)
1167 // disabled due to minimum version requirement from policy, and check for
1168 // 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.
1169 extensions::ExtensionUpdater::CheckParams params;
1170 for (scoped_refptr<const Extension> extension :
1171 registry_->disabled_extensions()) {
1172 if (extension_prefs_->HasDisableReason(
1173 extension->id(), Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY)) {
1174 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.
1175 }
1176 }
1177 if (!params.ids.empty())
1178 updater_->CheckNow(params);
1179 }
1135 } 1180 }
1136 1181
1137 void ExtensionService::CheckForUpdatesSoon() { 1182 void ExtensionService::CheckForUpdatesSoon() {
1138 // This can legitimately happen in unit tests. 1183 // This can legitimately happen in unit tests.
1139 if (!updater_.get()) 1184 if (!updater_.get())
1140 return; 1185 return;
1141 1186
1142 if (AreAllExternalProvidersReady()) { 1187 if (AreAllExternalProvidersReady()) {
1143 updater_->CheckSoon(); 1188 updater_->CheckSoon();
1144 } else { 1189 } else {
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after
1600 // extension; if we're here, that means the user is manually 1645 // extension; if we're here, that means the user is manually
1601 // installing the extension. 1646 // installing the extension.
1602 if (extension_prefs_->IsExternalExtensionUninstalled(id)) { 1647 if (extension_prefs_->IsExternalExtensionUninstalled(id)) {
1603 disable_reasons = Extension::DISABLE_NONE; 1648 disable_reasons = Extension::DISABLE_NONE;
1604 } 1649 }
1605 } 1650 }
1606 1651
1607 // Unsupported requirements overrides the management policy. 1652 // Unsupported requirements overrides the management policy.
1608 if (install_flags & extensions::kInstallFlagHasRequirementErrors) { 1653 if (install_flags & extensions::kInstallFlagHasRequirementErrors) {
1609 disable_reasons |= Extension::DISABLE_UNSUPPORTED_REQUIREMENT; 1654 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) == 1655 } else if (extension_prefs_->GetDisableReasons(id) ==
1614 Extension::DISABLE_UNSUPPORTED_REQUIREMENT) { 1656 Extension::DISABLE_UNSUPPORTED_REQUIREMENT) {
1657 // The extension was disabled because of unsupported requirements but
1658 // now supports all requirements after an update.
1659 // If there are no other disable reasons, enable it.
1615 disable_reasons = Extension::DISABLE_NONE; 1660 disable_reasons = Extension::DISABLE_NONE;
1616 extension_prefs_->ClearDisableReasons(id); 1661 extension_prefs_->ClearDisableReasons(id);
1662 } else {
1663 // Otherwise just remove the corresponding disable reason.
1664 extension_prefs_->RemoveDisableReason(
1665 id, Extension::DISABLE_UNSUPPORTED_REQUIREMENT);
1666 disable_reasons &= ~Extension::DISABLE_UNSUPPORTED_REQUIREMENT;
1667 }
Finnur 2014/11/19 10:16:26 Both RemoveDisableReason and the bitmask removal o
binjin 2014/11/19 13:36:11 Done.
1668
1669 // Check if the extension was disabled because of the minimum version
1670 // requirements from enterprise policy, and satisfies it now.
1671 if (extensions::ExtensionManagementFactory::GetForBrowserContext(profile())
1672 ->CheckMinimumVersion(extension, nullptr)) {
1673 if (extension_prefs_->GetDisableReasons(id) ==
1674 Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY) {
1675 // There are no other disable reasons, re-enable the extension.
1676 disable_reasons = Extension::DISABLE_NONE;
1677 extension_prefs_->ClearDisableReasons(id);
1678 } else {
1679 // Otherwise just clear the corresponding disable reason.
1680 extension_prefs_->RemoveDisableReason(
1681 id, Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY);
1682 disable_reasons &= ~Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY;
1683 }
1617 } 1684 }
1618 1685
1619 if (install_flags & extensions::kInstallFlagIsBlacklistedForMalware) { 1686 if (install_flags & extensions::kInstallFlagIsBlacklistedForMalware) {
1620 // Installation of a blacklisted extension can happen from sync, policy, 1687 // Installation of a blacklisted extension can happen from sync, policy,
1621 // etc, where to maintain consistency we need to install it, just never 1688 // 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 1689 // load it (see AddExtension). Usually it should be the job of callers to
1623 // incercept blacklisted extension earlier (e.g. CrxInstaller, before even 1690 // incercept blacklisted extension earlier (e.g. CrxInstaller, before even
1624 // showing the install dialogue). 1691 // showing the install dialogue).
1625 extension_prefs_->AcknowledgeBlacklistedExtension(id); 1692 extension_prefs_->AcknowledgeBlacklistedExtension(id);
1626 UMA_HISTOGRAM_ENUMERATION("ExtensionBlacklist.SilentInstall", 1693 UMA_HISTOGRAM_ENUMERATION("ExtensionBlacklist.SilentInstall",
(...skipping 778 matching lines...) Expand 10 before | Expand all | Expand 10 after
2405 } 2472 }
2406 2473
2407 void ExtensionService::OnProfileDestructionStarted() { 2474 void ExtensionService::OnProfileDestructionStarted() {
2408 ExtensionIdSet ids_to_unload = registry_->enabled_extensions().GetIDs(); 2475 ExtensionIdSet ids_to_unload = registry_->enabled_extensions().GetIDs();
2409 for (ExtensionIdSet::iterator it = ids_to_unload.begin(); 2476 for (ExtensionIdSet::iterator it = ids_to_unload.begin();
2410 it != ids_to_unload.end(); 2477 it != ids_to_unload.end();
2411 ++it) { 2478 ++it) {
2412 UnloadExtension(*it, UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN); 2479 UnloadExtension(*it, UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN);
2413 } 2480 }
2414 } 2481 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698