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

Unified Diff: chrome/browser/extensions/extension_util.cc

Issue 2054773002: Replace the WAS_INSTALLED_BY_CUSTODIAN creation flag with a pref (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixing the build Created 4 years, 6 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/extensions/extension_util.h ('k') | chrome/browser/extensions/pending_extension_info.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/extensions/extension_util.cc
diff --git a/chrome/browser/extensions/extension_util.cc b/chrome/browser/extensions/extension_util.cc
index 97796a6d4d3e7ad22c34607874c6c10287733b2e..4c019be7b86784d0c95a53a011f50a5fb73532be 100644
--- a/chrome/browser/extensions/extension_util.cc
+++ b/chrome/browser/extensions/extension_util.cc
@@ -54,6 +54,10 @@ const char kExtensionAllowedOnAllUrlsPrefName[] =
// allowed on all urls" pref.
const char kHasSetScriptOnAllUrlsPrefName[] = "has_set_script_all_urls";
+// The entry into the prefs used to flag an extension as installed by custodian.
+// It is relevant only for supervised users.
+const char kWasInstalledByCustodianPrefName[] = "was_installed_by_custodian";
+
// Returns true if |extension| should always be enabled in incognito mode.
bool IsWhitelistedForIncognito(const Extension* extension) {
const Feature* feature = FeatureProvider::GetBehaviorFeature(
@@ -222,6 +226,49 @@ void SetAllowFileAccess(const std::string& extension_id,
ReloadExtensionIfEnabled(extension_id, context);
}
+void SetWasInstalledByCustodian(const std::string& extension_id,
+ content::BrowserContext* context,
+ bool installed_by_custodian) {
+ if (installed_by_custodian == WasInstalledByCustodian(extension_id, context))
+ return;
+
+ ExtensionPrefs::Get(context)->UpdateExtensionPref(
+ extension_id, kWasInstalledByCustodianPrefName,
+ installed_by_custodian ? new base::FundamentalValue(true) : nullptr);
+ ExtensionRegistry* registry = ExtensionRegistry::Get(context);
+ const Extension* extension = registry->GetInstalledExtension(extension_id);
+ ExtensionService* service =
+ ExtensionSystem::Get(context)->extension_service();
+
+ // If the installed_by_custodian flag is reset, do nothing.
+ if (!installed_by_custodian) {
+ // If installed_by_custodian changes to false, the extension may need to
+ // be unloaded now.
+ service->ReloadExtension(extension_id);
+ return;
+ }
+
+ // If it is already enabled, do nothing.
+ if (registry->enabled_extensions().Contains(extension_id))
+ return;
+
+ // If the extension is not loaded, it may need to be reloaded.
+ // Example is a pre-installed extension that was unloaded when a
+ // supervised user flag has been received.
+ if (!extension) {
+ service->ReloadExtension(extension_id);
+ }
+}
+
+bool WasInstalledByCustodian(const std::string& extension_id,
+ content::BrowserContext* context) {
+ bool installed_by_custodian = false;
+ ExtensionPrefs* prefs = ExtensionPrefs::Get(context);
+ prefs->ReadPrefAsBoolean(extension_id, kWasInstalledByCustodianPrefName,
+ &installed_by_custodian);
+ return installed_by_custodian;
+}
+
bool AllowedScriptingOnAllUrls(const std::string& extension_id,
content::BrowserContext* context) {
bool allowed = false;
@@ -380,8 +427,9 @@ bool CanHostedAppsOpenInWindows() {
#endif
}
-bool IsExtensionSupervised(const Extension* extension, const Profile* profile) {
- return extension->was_installed_by_custodian() && profile->IsSupervised();
+bool IsExtensionSupervised(const Extension* extension, Profile* profile) {
+ return WasInstalledByCustodian(extension->id(), profile) &&
+ profile->IsSupervised();
}
bool NeedCustodianApprovalForPermissionIncrease(const Profile* profile) {
« no previous file with comments | « chrome/browser/extensions/extension_util.h ('k') | chrome/browser/extensions/pending_extension_info.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698