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

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: WIP 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 839 matching lines...) Expand 10 before | Expand all | Expand 10 after
850 } 850 }
851 851
852 const Extension* extension = GetInstalledExtension(extension_id); 852 const Extension* extension = GetInstalledExtension(extension_id);
853 // |extension| can be NULL if sync disables an extension that is not 853 // |extension| can be NULL if sync disables an extension that is not
854 // installed yet. 854 // installed yet.
855 // EXTERNAL_COMPONENT extensions are not generally modifiable by users, but 855 // EXTERNAL_COMPONENT extensions are not generally modifiable by users, but
856 // can be uninstalled by the browser if the user sets extension-specific 856 // can be uninstalled by the browser if the user sets extension-specific
857 // preferences. 857 // preferences.
858 if (extension && 858 if (extension &&
859 disable_reason != Extension::DISABLE_RELOAD && 859 disable_reason != Extension::DISABLE_RELOAD &&
860 disable_reason != Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY &&
860 !system_->management_policy()->UserMayModifySettings(extension, NULL) && 861 !system_->management_policy()->UserMayModifySettings(extension, NULL) &&
861 extension->location() != Manifest::EXTERNAL_COMPONENT) { 862 extension->location() != Manifest::EXTERNAL_COMPONENT) {
862 return; 863 return;
863 } 864 }
864 865
865 extension_prefs_->SetExtensionState(extension_id, Extension::DISABLED); 866 extension_prefs_->SetExtensionState(extension_id, Extension::DISABLED);
866 extension_prefs_->AddDisableReason(extension_id, disable_reason); 867 extension_prefs_->AddDisableReason(extension_id, disable_reason);
867 868
868 int include_mask = 869 int include_mask =
869 ExtensionRegistry::EVERYTHING & ~ExtensionRegistry::DISABLED; 870 ExtensionRegistry::EVERYTHING & ~ExtensionRegistry::DISABLED;
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
1111 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); 1112 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN);
1112 return file_task_runner_.get(); 1113 return file_task_runner_.get();
1113 } 1114 }
1114 1115
1115 void ExtensionService::CheckManagementPolicy() { 1116 void ExtensionService::CheckManagementPolicy() {
1116 std::vector<std::string> to_unload; 1117 std::vector<std::string> to_unload;
1117 std::map<std::string, Extension::DisableReason> to_disable; 1118 std::map<std::string, Extension::DisableReason> to_disable;
1118 1119
1119 // Loop through the extensions list, finding extensions we need to unload or 1120 // Loop through the extensions list, finding extensions we need to unload or
1120 // disable. 1121 // disable.
1121 const ExtensionSet& extensions = registry_->enabled_extensions(); 1122 for (scoped_refptr<const Extension> extension :
1122 for (ExtensionSet::const_iterator iter = extensions.begin(); 1123 registry_->enabled_extensions()) {
1123 iter != extensions.end(); ++iter) { 1124 if (!system_->management_policy()->UserMayLoad(extension.get(), nullptr))
1124 const Extension* extension = (iter->get());
1125 if (!system_->management_policy()->UserMayLoad(extension, NULL))
1126 to_unload.push_back(extension->id()); 1125 to_unload.push_back(extension->id());
1127 Extension::DisableReason disable_reason = Extension::DISABLE_NONE; 1126 Extension::DisableReason disable_reason = Extension::DISABLE_NONE;
1128 if (system_->management_policy()->MustRemainDisabled( 1127 if (system_->management_policy()->MustRemainDisabled(
1129 extension, &disable_reason, NULL)) 1128 extension.get(), &disable_reason, nullptr))
1130 to_disable[extension->id()] = disable_reason; 1129 to_disable[extension->id()] = disable_reason;
1131 } 1130 }
1132 1131
1133 for (size_t i = 0; i < to_unload.size(); ++i) 1132 for (size_t i = 0; i < to_unload.size(); ++i)
1134 UnloadExtension(to_unload[i], UnloadedExtensionInfo::REASON_DISABLE); 1133 UnloadExtension(to_unload[i], UnloadedExtensionInfo::REASON_DISABLE);
1135 1134
1136 for (std::map<std::string, Extension::DisableReason>::const_iterator i = 1135 for (std::map<std::string, Extension::DisableReason>::const_iterator i =
1137 to_disable.begin(); i != to_disable.end(); ++i) 1136 to_disable.begin(); i != to_disable.end(); ++i)
1138 DisableExtension(i->first, i->second); 1137 DisableExtension(i->first, i->second);
1138
1139 if (updater_.get()) {
1140 // Find all extensions (including the ones got disabled just now) disabled
pastarmovj 2014/11/11 12:50:55 nit: ...ones _that_ got...
binjin 2014/11/11 19:10:37 Done.
1141 // due to minimum version requirement from policy, and check for update.
1142 extensions::ExtensionUpdater::CheckParams params;
1143 for (scoped_refptr<const Extension> extension :
1144 registry_->disabled_extensions()) {
1145 if (extension_prefs_->HasDisableReason(
1146 extension->id(), Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY)) {
1147 params.ids.push_back(extension->id());
1148 }
1149 }
1150 if (!params.ids.empty())
1151 updater_->CheckNow(params);
1152 }
1139 } 1153 }
1140 1154
1141 void ExtensionService::CheckForUpdatesSoon() { 1155 void ExtensionService::CheckForUpdatesSoon() {
1142 // This can legitimately happen in unit tests. 1156 // This can legitimately happen in unit tests.
1143 if (!updater_.get()) 1157 if (!updater_.get())
1144 return; 1158 return;
1145 1159
1146 if (AreAllExternalProvidersReady()) { 1160 if (AreAllExternalProvidersReady()) {
1147 updater_->CheckSoon(); 1161 updater_->CheckSoon();
1148 } else { 1162 } else {
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after
1615 id, Extension::DISABLE_UNSUPPORTED_REQUIREMENT); 1629 id, Extension::DISABLE_UNSUPPORTED_REQUIREMENT);
1616 // If the extension was disabled because of unsupported requirements but 1630 // If the extension was disabled because of unsupported requirements but
1617 // now supports all requirements after an update and there are not other 1631 // now supports all requirements after an update and there are not other
1618 // disable reasons, enable it. 1632 // disable reasons, enable it.
1619 } else if (extension_prefs_->GetDisableReasons(id) == 1633 } else if (extension_prefs_->GetDisableReasons(id) ==
1620 Extension::DISABLE_UNSUPPORTED_REQUIREMENT) { 1634 Extension::DISABLE_UNSUPPORTED_REQUIREMENT) {
1621 initial_enable = true; 1635 initial_enable = true;
1622 extension_prefs_->ClearDisableReasons(id); 1636 extension_prefs_->ClearDisableReasons(id);
1623 } 1637 }
1624 1638
1639 // If the extension was disabled because of the minimum version requirements
1640 // from enterprise policy, and now satisfies it now and there are not other
pastarmovj 2014/11/11 12:50:55 nit: remove the first "now". Also s/not/no/
binjin 2014/11/11 19:10:37 Done.
1641 // disable reasons, enable it.
1642 if (extension_prefs_->GetDisableReasons(id) ==
1643 Extension::DISABLE_UPDATE_REQUIRED_BY_POLICY &&
1644 extensions::ExtensionManagementFactory::GetForBrowserContext(profile())
1645 ->CheckMinimumVersion(extension, nullptr)) {
1646 initial_enable = true;
1647 extension_prefs_->ClearDisableReasons(id);
1648 }
1649
1625 if (install_flags & extensions::kInstallFlagIsBlacklistedForMalware) { 1650 if (install_flags & extensions::kInstallFlagIsBlacklistedForMalware) {
1626 // Installation of a blacklisted extension can happen from sync, policy, 1651 // Installation of a blacklisted extension can happen from sync, policy,
1627 // etc, where to maintain consistency we need to install it, just never 1652 // etc, where to maintain consistency we need to install it, just never
1628 // load it (see AddExtension). Usually it should be the job of callers to 1653 // load it (see AddExtension). Usually it should be the job of callers to
1629 // incercept blacklisted extension earlier (e.g. CrxInstaller, before even 1654 // incercept blacklisted extension earlier (e.g. CrxInstaller, before even
1630 // showing the install dialogue). 1655 // showing the install dialogue).
1631 extension_prefs_->AcknowledgeBlacklistedExtension(id); 1656 extension_prefs_->AcknowledgeBlacklistedExtension(id);
1632 UMA_HISTOGRAM_ENUMERATION("ExtensionBlacklist.SilentInstall", 1657 UMA_HISTOGRAM_ENUMERATION("ExtensionBlacklist.SilentInstall",
1633 extension->location(), 1658 extension->location(),
1634 Manifest::NUM_LOCATIONS); 1659 Manifest::NUM_LOCATIONS);
(...skipping 12 matching lines...) Expand all
1647 UMA_HISTOGRAM_ENUMERATION("Extensions.UpdateSource", 1672 UMA_HISTOGRAM_ENUMERATION("Extensions.UpdateSource",
1648 extension->location(), Manifest::NUM_LOCATIONS); 1673 extension->location(), Manifest::NUM_LOCATIONS);
1649 1674
1650 // A fully installed app cannot be demoted to an ephemeral app. 1675 // A fully installed app cannot be demoted to an ephemeral app.
1651 if ((install_flags & extensions::kInstallFlagIsEphemeral) && 1676 if ((install_flags & extensions::kInstallFlagIsEphemeral) &&
1652 !extension_prefs_->IsEphemeralApp(id)) { 1677 !extension_prefs_->IsEphemeralApp(id)) {
1653 install_flags &= ~static_cast<int>(extensions::kInstallFlagIsEphemeral); 1678 install_flags &= ~static_cast<int>(extensions::kInstallFlagIsEphemeral);
1654 } 1679 }
1655 } 1680 }
1656 1681
1682 // WIP(binjin): need to figure out a way to check MustRemainDisabled here and
pastarmovj 2014/11/11 12:50:55 nit: AFAIK WIP is not officially used in Chromium
binjin 2014/11/11 19:10:37 It's a mark for myself, reminding that there are u
1683 // pass reasons to extension prefs.
1657 const Extension::State initial_state = 1684 const Extension::State initial_state =
1658 initial_enable ? Extension::ENABLED : Extension::DISABLED; 1685 initial_enable ? Extension::ENABLED : Extension::DISABLED;
1659 if (ShouldDelayExtensionUpdate( 1686 if (ShouldDelayExtensionUpdate(
1660 id, 1687 id,
1661 !!(install_flags & extensions::kInstallFlagInstallImmediately))) { 1688 !!(install_flags & extensions::kInstallFlagInstallImmediately))) {
1662 extension_prefs_->SetDelayedInstallInfo( 1689 extension_prefs_->SetDelayedInstallInfo(
1663 extension, 1690 extension,
1664 initial_state, 1691 initial_state,
1665 install_flags, 1692 install_flags,
1666 extensions::ExtensionPrefs::DELAY_REASON_WAIT_FOR_IDLE, 1693 extensions::ExtensionPrefs::DELAY_REASON_WAIT_FOR_IDLE,
(...skipping 721 matching lines...) Expand 10 before | Expand all | Expand 10 after
2388 } 2415 }
2389 2416
2390 void ExtensionService::OnProfileDestructionStarted() { 2417 void ExtensionService::OnProfileDestructionStarted() {
2391 ExtensionIdSet ids_to_unload = registry_->enabled_extensions().GetIDs(); 2418 ExtensionIdSet ids_to_unload = registry_->enabled_extensions().GetIDs();
2392 for (ExtensionIdSet::iterator it = ids_to_unload.begin(); 2419 for (ExtensionIdSet::iterator it = ids_to_unload.begin();
2393 it != ids_to_unload.end(); 2420 it != ids_to_unload.end();
2394 ++it) { 2421 ++it) {
2395 UnloadExtension(*it, UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN); 2422 UnloadExtension(*it, UnloadedExtensionInfo::REASON_PROFILE_SHUTDOWN);
2396 } 2423 }
2397 } 2424 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698