Bug 1420514 - Remove pref app.update.enabled from the update mechanism
Getting rid of this pref allowed some other code to be removed:
- Changed nsIUpdateService::stopChecking(duration) to nsIUpdateService::stopCurrentCheck() and got rid of the constants representing durations. The available durations were CURRENT_CHECK, CURRENT_SESSION, and ANY_CHECKS, but only CURRENT_CHECK was ever used.
- nsIUpdateChecker::stopChecking(CURRENT_SESSION) and nsIUpdateChecker::stopChecking(ANY_CHECKS) were the only mechanisms for setting Checker::_enabled to false, so Checker::_enabled and Checker::enabled were removed. References to Checker::enabled were replaced with checks for nsUpdateService::canCheckForUpdates.
- In browser/base/content/aboutDialog-appUpdater.js, the updateDisabledAndLocked() function was renamed to updateDisabledByPolicy, since the old name is no longer accurate and the new function name is a better description of the function's actual use.
MozReview-Commit-ID: 4wwqo4ROr1V
--- a/browser/base/content/aboutDialog-appUpdater.js
+++ b/browser/base/content/aboutDialog-appUpdater.js
@@ -15,17 +15,17 @@ ChromeUtils.defineModuleGetter(this, "Up
const PREF_APP_UPDATE_CANCELATIONS_OSX = "app.update.cancelations.osx";
const PREF_APP_UPDATE_ELEVATE_NEVER = "app.update.elevate.never";
var gAppUpdater;
function onUnload(aEvent) {
if (gAppUpdater.isChecking)
- gAppUpdater.checker.stopChecking(Ci.nsIUpdateChecker.CURRENT_CHECK);
+ gAppUpdater.checker.stopCurrentCheck();
// Safe to call even when there isn't a download in progress.
gAppUpdater.removeDownloadListener();
gAppUpdater = null;
}
function appUpdater(options = {}) {
XPCOMUtils.defineLazyServiceGetter(this, "aus",
@@ -55,18 +55,18 @@ function appUpdater(options = {}) {
createBundle("chrome://browser/locale/browser.properties");
let manualURL = Services.urlFormatter.formatURLPref("app.update.url.manual");
let manualLink = document.getElementById("manualLink");
manualLink.textContent = manualURL;
manualLink.href = manualURL;
document.getElementById("failedLink").href = manualURL;
- if (this.updateDisabledAndLocked) {
- this.selectPanel("adminDisabled");
+ if (this.updateDisabledByPolicy) {
+ this.selectPanel("policyDisabled");
return;
}
if (this.isPending || this.isApplied) {
this.selectPanel("apply");
return;
}
@@ -76,26 +76,16 @@ function appUpdater(options = {}) {
}
if (this.isDownloading) {
this.startDownload();
// selectPanel("downloading") is called from setupDownloadingUI().
return;
}
- // Honor the "Never check for updates" option by not only disabling background
- // update checks, but also in the About dialog, by presenting a
- // "Check for updates" button.
- // If updates are found, the user is then asked if he wants to "Update to <version>".
- if (!this.updateEnabled ||
- Services.prefs.prefHasUserValue(PREF_APP_UPDATE_ELEVATE_NEVER)) {
- this.selectPanel("checkForUpdates");
- return;
- }
-
// That leaves the options
// "Check for updates, but let me choose whether to install them", and
// "Automatically install updates".
// In both cases, we check for updates without asking.
// In the "let me choose" case, we ask before downloading though, in onCheckComplete.
this.checkForUpdates();
}
@@ -130,35 +120,24 @@ appUpdater.prototype =
// true when there is an update download in progress.
get isDownloading() {
if (this.update)
return this.update.state == "downloading";
return this.um.activeUpdate &&
this.um.activeUpdate.state == "downloading";
},
- // true when updating is disabled by an administrator.
- get updateDisabledAndLocked() {
- return (!this.updateEnabled &&
- Services.prefs.prefIsLocked("app.update.enabled")) ||
- (Services.policies &&
- !Services.policies.isAllowed("appUpdate"));
- },
-
- // true when updating is enabled.
- get updateEnabled() {
- try {
- return Services.prefs.getBoolPref("app.update.enabled");
- } catch (e) { }
- return true; // Firefox default is true
+ // true when updating has been disabled by enterprise policy
+ get updateDisabledByPolicy() {
+ return Services.policies && !Services.policies.isAllowed("appUpdate");
},
// true when updating in background is enabled.
get backgroundUpdateEnabled() {
- return this.updateEnabled &&
+ return !this.updateDisabledByPolicy &&
gAppUpdater.aus.canStageUpdates;
},
// true when updating is automatic.
get updateAuto() {
try {
return Services.prefs.getBoolPref("app.update.auto");
} catch (e) { }
--- a/browser/base/content/aboutDialog.xul
+++ b/browser/base/content/aboutDialog.xul
@@ -88,17 +88,17 @@
<image class="update-throbber"/><label>&update.downloading.start;</label><label id="downloadStatus"/><label>&update.downloading.end;</label>
</hbox>
<hbox id="applying" align="center">
<image class="update-throbber"/><label>&update.applying;</label>
</hbox>
<hbox id="downloadFailed" align="center">
<label>&update.failed.start;</label><label id="failedLink" class="text-link">&update.failed.linkText;</label><label>&update.failed.end;</label>
</hbox>
- <hbox id="adminDisabled" align="center">
+ <hbox id="policyDisabled" align="center">
<label>&update.adminDisabled;</label>
</hbox>
<hbox id="noUpdatesFound" align="center">
<label>&update.noUpdatesFound;</label>
</hbox>
<hbox id="otherInstanceHandlingUpdates" align="center">
<label>&update.otherInstanceHandlingUpdates;</label>
</hbox>
--- a/browser/components/nsBrowserGlue.js
+++ b/browser/components/nsBrowserGlue.js
@@ -763,17 +763,16 @@ BrowserGlue.prototype = {
L10nRegistry.registerSource(appSource);
Services.obs.notifyObservers(null, "browser-ui-startup-complete");
},
_checkForOldBuildUpdates() {
// check for update if our build is old
if (AppConstants.MOZ_UPDATER &&
- Services.prefs.getBoolPref("app.update.enabled") &&
Services.prefs.getBoolPref("app.update.checkInstallTime")) {
let buildID = Services.appinfo.appBuildID;
let today = new Date().getTime();
/* eslint-disable no-multi-spaces */
let buildDate = new Date(buildID.slice(0, 4), // year
buildID.slice(4, 6) - 1, // months are zero-based.
buildID.slice(6, 8), // day
--- a/browser/components/preferences/in-content/main.xul
+++ b/browser/components/preferences/in-content/main.xul
@@ -479,17 +479,17 @@
</hbox>
<hbox id="downloadFailed" align="start">
<label>&update.failed.start;</label><label id="failedLink" class="text-link">&update.failed.linkText;</label><label>&update.failed.end;</label>
<spacer flex="1"/>
<button label="&update.checkForUpdatesButton.label;"
accesskey="&update.checkForUpdatesButton.accesskey;"
oncommand="gAppUpdater.checkForUpdates();"/>
</hbox>
- <hbox id="adminDisabled" align="start">
+ <hbox id="policyDisabled" align="start">
<label>&update.adminDisabled;</label>
<spacer flex="1"/>
<button label="&update.checkForUpdatesButton.label;"
accesskey="&update.checkForUpdatesButton.accesskey;"
disabled="true"/>
</hbox>
<hbox id="noUpdatesFound" align="start">
<image class="face-smile"/>
--- a/toolkit/mozapps/update/content/updates.js
+++ b/toolkit/mozapps/update/content/updates.js
@@ -9,20 +9,20 @@
/* globals DownloadUtils, Services, AUSTLMY */
ChromeUtils.import("resource://gre/modules/DownloadUtils.jsm", this);
ChromeUtils.import("resource://gre/modules/Services.jsm", this);
ChromeUtils.import("resource://gre/modules/UpdateTelemetry.jsm", this);
const XMLNS_XUL = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
+const PREF_APP_UPDATE_AUTO = "app.update.auto";
const PREF_APP_UPDATE_BACKGROUNDERRORS = "app.update.backgroundErrors";
const PREF_APP_UPDATE_CERT_ERRORS = "app.update.cert.errors";
const PREF_APP_UPDATE_ELEVATE_NEVER = "app.update.elevate.never";
-const PREF_APP_UPDATE_ENABLED = "app.update.enabled";
const PREF_APP_UPDATE_LOG = "app.update.log";
const PREF_APP_UPDATE_NOTIFIEDUNSUPPORTED = "app.update.notifiedUnsupported";
const PREF_APP_UPDATE_URL_MANUAL = "app.update.url.manual";
const URI_UPDATES_PROPERTIES = "chrome://mozapps/locale/update/updates.properties";
const STATE_DOWNLOADING = "downloading";
const STATE_PENDING = "pending";
@@ -487,17 +487,17 @@ var gCheckingPage = {
this._checker.checkForUpdates(this.updateListener, true);
},
/**
* The user has closed the window, either by pressing cancel or using a Window
* Manager control, so stop checking for updates.
*/
onWizardCancel() {
- this._checker.stopChecking(Ci.nsIUpdateChecker.CURRENT_CHECK);
+ this._checker.stopCurrentCheck();
},
/**
* An object implementing nsIUpdateCheckListener that is notified as the
* update check commences.
*/
updateListener: {
/**
@@ -556,18 +556,17 @@ var gCheckingPage = {
*/
var gNoUpdatesPage = {
/**
* Initialize
*/
onPageShow() {
LOG("gNoUpdatesPage", "onPageShow - could not select an appropriate " +
"update. Either there were no updates or |selectUpdate| failed");
-
- if (Services.prefs.getBoolPref(PREF_APP_UPDATE_ENABLED, true))
+ if (Services.prefs.getBoolPref(PREF_APP_UPDATE_AUTO, true))
document.getElementById("noUpdatesAutoEnabled").hidden = false;
else
document.getElementById("noUpdatesAutoDisabled").hidden = false;
gUpdates.setButtons(null, null, "okButton", true);
gUpdates.wiz.getButton("finish").focus();
}
};
--- a/toolkit/mozapps/update/nsIUpdateService.idl
+++ b/toolkit/mozapps/update/nsIUpdateService.idl
@@ -270,40 +270,25 @@ interface nsIUpdateChecker : nsISupports
* @param listener
* An object implementing nsIUpdateCheckListener which is notified
* of the results of an update check.
* @param force
* Forces the checker to check for updates, regardless of the
* current value of the user's update settings. This is used by
* any piece of UI that offers the user the imperative option to
* check for updates now, regardless of their update settings.
- * force will not work if the system administrator has locked
- * the app.update.enabled preference.
+ * However, if updates are disabled by policy, setting force to true
+ * will not override the the policy.
*/
void checkForUpdates(in nsIUpdateCheckListener listener, in boolean force);
/**
- * Constants for the |stopChecking| function that tell the Checker how long
- * to stop checking:
- *
- * CURRENT_CHECK: Stops the current (active) check only
- * CURRENT_SESSION: Stops all checking for the current session
- * ANY_CHECKS: Stops all checking, any session from now on
- * (disables update checking preferences)
+ * Ends any pending update check.
*/
- const unsigned short CURRENT_CHECK = 1;
- const unsigned short CURRENT_SESSION = 2;
- const unsigned short ANY_CHECKS = 3;
-
- /**
- * Ends any pending update check.
- * @param duration
- * A value representing the set of checks to stop doing.
- */
- void stopChecking(in unsigned short duration);
+ void stopCurrentCheck();
};
/**
* An interface describing a global application service that handles performing
* background update checks and provides utilities for selecting and
* downloading update patches.
*/
[scriptable, uuid(1107d207-a263-403a-b268-05772ec10757)]
--- a/toolkit/mozapps/update/nsUpdateService.js
+++ b/toolkit/mozapps/update/nsUpdateService.js
@@ -27,17 +27,17 @@ const PREF_APP_UPDATE_CANCELATIONS_OSX
const PREF_APP_UPDATE_CANCELATIONS_OSX_MAX = "app.update.cancelations.osx.max";
const PREF_APP_UPDATE_DOORHANGER = "app.update.doorhanger";
const PREF_APP_UPDATE_DOWNLOAD_ATTEMPTS = "app.update.download.attempts";
const PREF_APP_UPDATE_DOWNLOAD_MAXATTEMPTS = "app.update.download.maxAttempts";
const PREF_APP_UPDATE_ELEVATE_NEVER = "app.update.elevate.never";
const PREF_APP_UPDATE_ELEVATE_VERSION = "app.update.elevate.version";
const PREF_APP_UPDATE_ELEVATE_ATTEMPTS = "app.update.elevate.attempts";
const PREF_APP_UPDATE_ELEVATE_MAXATTEMPTS = "app.update.elevate.maxAttempts";
-const PREF_APP_UPDATE_ENABLED = "app.update.enabled";
+const PREF_APP_UPDATE_DISABLEDFORTESTING = "app.update.disabledForTesting";
const PREF_APP_UPDATE_IDLETIME = "app.update.idletime";
const PREF_APP_UPDATE_LOG = "app.update.log";
const PREF_APP_UPDATE_NOTIFIEDUNSUPPORTED = "app.update.notifiedUnsupported";
const PREF_APP_UPDATE_POSTUPDATE = "app.update.postupdate";
const PREF_APP_UPDATE_PROMPTWAITTIME = "app.update.promptWaitTime";
const PREF_APP_UPDATE_SERVICE_ENABLED = "app.update.service.enabled";
const PREF_APP_UPDATE_SERVICE_ERRORS = "app.update.service.errors";
const PREF_APP_UPDATE_SERVICE_MAXERRORS = "app.update.service.maxErrors";
@@ -514,50 +514,16 @@ function getCanStageUpdates() {
"instance of the application is already handling updates for this " +
"installation.");
return false;
}
return gCanStageUpdatesSession;
}
-XPCOMUtils.defineLazyGetter(this, "gCanCheckForUpdates", function aus_gCanCheckForUpdates() {
- // If the administrator has disabled app update and locked the preference so
- // users can't check for updates. This preference check is ok in this lazy
- // getter since locked prefs don't change until the application is restarted.
- var enabled = Services.prefs.getBoolPref(PREF_APP_UPDATE_ENABLED, true);
- if (!enabled && Services.prefs.prefIsLocked(PREF_APP_UPDATE_ENABLED)) {
- LOG("gCanCheckForUpdates - unable to automatically check for updates, " +
- "the preference is disabled and admistratively locked.");
- return false;
- }
-
- if (Services.policies && !Services.policies.isAllowed("appUpdate")) {
- LOG("gCanCheckForUpdates - unable to automatically check for updates. " +
- "Functionality disabled by enterprise policy.");
- return false;
- }
-
- // If we don't know the binary platform we're updating, we can't update.
- if (!UpdateUtils.ABI) {
- LOG("gCanCheckForUpdates - unable to check for updates, unknown ABI");
- return false;
- }
-
- // If we don't know the OS version we're updating, we can't update.
- if (!UpdateUtils.OSVersion) {
- LOG("gCanCheckForUpdates - unable to check for updates, unknown OS " +
- "version");
- return false;
- }
-
- LOG("gCanCheckForUpdates - able to check for updates");
- return true;
-});
-
/**
* Logs a string to the error console.
* @param string
* The string to write to the error console.
*/
function LOG(string) {
if (gLogEnabled) {
dump("*** AUS:SVC " + string + "\n");
@@ -2011,21 +1977,16 @@ UpdateService.prototype = {
getCanStageUpdates(), true);
// Histogram IDs:
// UPDATE_INVALID_LASTUPDATETIME_EXTERNAL
// UPDATE_INVALID_LASTUPDATETIME_NOTIFY
// UPDATE_LAST_NOTIFY_INTERVAL_DAYS_EXTERNAL
// UPDATE_LAST_NOTIFY_INTERVAL_DAYS_NOTIFY
AUSTLMY.pingLastUpdateTime(this._pingSuffix);
// Histogram IDs:
- // UPDATE_NOT_PREF_UPDATE_ENABLED_EXTERNAL
- // UPDATE_NOT_PREF_UPDATE_ENABLED_NOTIFY
- AUSTLMY.pingBoolPref("UPDATE_NOT_PREF_UPDATE_ENABLED_" + this._pingSuffix,
- PREF_APP_UPDATE_ENABLED, true, true);
- // Histogram IDs:
// UPDATE_NOT_PREF_UPDATE_AUTO_EXTERNAL
// UPDATE_NOT_PREF_UPDATE_AUTO_NOTIFY
AUSTLMY.pingBoolPref("UPDATE_NOT_PREF_UPDATE_AUTO_" + this._pingSuffix,
PREF_APP_UPDATE_AUTO, true, true);
// Histogram IDs:
// UPDATE_NOT_PREF_UPDATE_STAGING_ENABLED_EXTERNAL
// UPDATE_NOT_PREF_UPDATE_STAGING_ENABLED_NOTIFY
AUSTLMY.pingBoolPref("UPDATE_NOT_PREF_UPDATE_STAGING_ENABLED_" +
@@ -2093,24 +2054,22 @@ UpdateService.prototype = {
// foreground checks.
if (!UpdateUtils.OSVersion) {
AUSTLMY.pingCheckCode(this._pingSuffix, AUSTLMY.CHK_NO_OS_VERSION);
} else if (!UpdateUtils.ABI) {
AUSTLMY.pingCheckCode(this._pingSuffix, AUSTLMY.CHK_NO_OS_ABI);
} else if (!validUpdateURL) {
AUSTLMY.pingCheckCode(this._pingSuffix,
AUSTLMY.CHK_INVALID_DEFAULT_URL);
- } else if (!Services.prefs.getBoolPref(PREF_APP_UPDATE_ENABLED, true)) {
+ } else if (this.disabledByPolicy) {
AUSTLMY.pingCheckCode(this._pingSuffix, AUSTLMY.CHK_PREF_DISABLED);
} else if (!hasUpdateMutex()) {
AUSTLMY.pingCheckCode(this._pingSuffix, AUSTLMY.CHK_NO_MUTEX);
- } else if (!gCanCheckForUpdates) {
+ } else if (!this.canCheckForUpdates) {
AUSTLMY.pingCheckCode(this._pingSuffix, AUSTLMY.CHK_UNABLE_TO_CHECK);
- } else if (!this.backgroundChecker._enabled) {
- AUSTLMY.pingCheckCode(this._pingSuffix, AUSTLMY.CHK_DISABLED_FOR_SESSION);
}
this.backgroundChecker.checkForUpdates(this, false);
});
},
/**
* Determine the update from the specified updates that should be offered.
@@ -2246,18 +2205,17 @@ UpdateService.prototype = {
// is downloading or performed some user action to prevent notification.
var um = Cc["@mozilla.org/updates/update-manager;1"].
getService(Ci.nsIUpdateManager);
if (um.activeUpdate) {
AUSTLMY.pingCheckCode(this._pingSuffix, AUSTLMY.CHK_HAS_ACTIVEUPDATE);
return;
}
- var updateEnabled = Services.prefs.getBoolPref(PREF_APP_UPDATE_ENABLED, true);
- if (!updateEnabled) {
+ if (this.disabledByPolicy) {
AUSTLMY.pingCheckCode(this._pingSuffix, AUSTLMY.CHK_PREF_DISABLED);
LOG("UpdateService:_selectAndInstallUpdate - not prompting because " +
"update is disabled");
return;
}
var update = this.selectUpdate(updates, updates.length);
if (!update || update.elevationFailure) {
@@ -2339,21 +2297,58 @@ UpdateService.prototype = {
* See nsIUpdateService.idl
*/
get backgroundChecker() {
if (!this._backgroundChecker)
this._backgroundChecker = new Checker();
return this._backgroundChecker;
},
+ get disabledForTesting() {
+ return Cu.isInAutomation &&
+ Services.prefs.getBoolPref(PREF_APP_UPDATE_DISABLEDFORTESTING, false);
+ },
+
+ get disabledByPolicy() {
+ return (Services.policies && !Services.policies.isAllowed("appUpdate")) ||
+ this.disabledForTesting;
+ },
+
/**
* See nsIUpdateService.idl
*/
get canCheckForUpdates() {
- return gCanCheckForUpdates && hasUpdateMutex();
+ if (this.disabledByPolicy) {
+ LOG("UpdateService.canCheckForUpdates - unable to automatically check " +
+ "for updates, the option has been disabled by the administrator.");
+ return false;
+ }
+
+ // If we don't know the binary platform we're updating, we can't update.
+ if (!UpdateUtils.ABI) {
+ LOG("UpdateService.canCheckForUpdates - unable to check for updates, " +
+ "unknown ABI");
+ return false;
+ }
+
+ // If we don't know the OS version we're updating, we can't update.
+ if (!UpdateUtils.OSVersion) {
+ LOG("UpdateService.canCheckForUpdates - unable to check for updates, " +
+ "unknown OS version");
+ return false;
+ }
+
+ if (!hasUpdateMutex()) {
+ LOG("UpdateService.canCheckForUpdates - unable to check for updates, " +
+ "unable to acquire update mutex");
+ return false;
+ }
+
+ LOG("UpdateService.canCheckForUpdates - able to check for updates");
+ return true;
},
/**
* See nsIUpdateService.idl
*/
get elevationRequired() {
return getElevationRequired();
},
@@ -2959,17 +2954,23 @@ Checker.prototype = {
* See nsIUpdateService.idl
*/
checkForUpdates: function UC_checkForUpdates(listener, force) {
LOG("Checker: checkForUpdates, force: " + force);
if (!listener) {
throw Cr.NS_ERROR_NULL_POINTER;
}
- if (!this.enabled && !force) {
+ let UpdateServiceInstance = UpdateServiceFactory.createInstance();
+ // |force| can override |canCheckForUpdates| since |force| indicates a
+ // manual update check. But nothing should override enterprise policies.
+ if (UpdateServiceInstance.disabledByPolicy) {
+ return;
+ }
+ if (!UpdateServiceInstance.canCheckForUpdates && !force) {
return;
}
this.getUpdateURL(force).then(url => {
if (!url) {
return;
}
@@ -3139,42 +3140,22 @@ Checker.prototype = {
update.errorCode = HTTP_ERROR_OFFSET + status;
}
this._callback.onError(request, update);
this._request = null;
},
/**
- * Whether or not we are allowed to do update checking.
- */
- _enabled: true,
- get enabled() {
- return Services.prefs.getBoolPref(PREF_APP_UPDATE_ENABLED, true) &&
- gCanCheckForUpdates && hasUpdateMutex() && this._enabled;
- },
-
- /**
* See nsIUpdateService.idl
*/
- stopChecking: function UC_stopChecking(duration) {
+ stopCurrentCheck: function UC_stopCurrentCheck() {
// Always stop the current check
if (this._request)
this._request.abort();
-
- switch (duration) {
- case Ci.nsIUpdateChecker.CURRENT_SESSION:
- this._enabled = false;
- break;
- case Ci.nsIUpdateChecker.ANY_CHECKS:
- this._enabled = false;
- Services.prefs.setBoolPref(PREF_APP_UPDATE_ENABLED, this._enabled);
- break;
- }
-
this._callback = null;
},
classID: Components.ID("{898CDC9B-E43F-422F-9CC4-2F6291B415A3}"),
QueryInterface: ChromeUtils.generateQI([Ci.nsIUpdateChecker])
};
/**