Bug 1612979 - Fix "auto-update-config-change" notification bugs r=mhowell

Includes fixes for the following bugs:
 - "auto-update-config-change" notification is never sent because it never updates its cached value so it always thinks the value is uninitialized, at state in which it does not send the notification.
 - maybeUpdateAutoConfigChanged doesn't send the first notification because the value hasn't changed yet, just been set. But this is only true on Windows. On other OS's, the function is only called when the value changes.
 - If a non-Windows user changes the app.update.auto pref value, it effectively changes the value of the auto update setting but doesn't generate a "auto-update-config-change" notification.
 - Minor cleanup of an unnecessary bind call.

Differential Revision: https://phabricator.services.mozilla.com/D63983

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Kirk Steuber 2020-03-03 18:13:07 +00:00
Родитель f55e67e699
Коммит a392fbda66
1 изменённых файлов: 19 добавлений и 8 удалений

Просмотреть файл

@ -240,7 +240,7 @@ var UpdateUtils = {
// Fallthrough for if the value could not be read or migrated.
return DEFAULT_APP_UPDATE_AUTO;
})
.then(maybeUpdateAutoConfigChanged.bind(this));
.then(maybeUpdateAutoConfigChanged);
updateAutoIOPromise = readPromise;
return readPromise;
},
@ -281,7 +281,10 @@ var UpdateUtils = {
// Only in Windows do we store the update config in the update directory
let prefValue = !!enabledValue;
Services.prefs.setBoolPref(PREF_APP_UPDATE_AUTO, prefValue);
maybeUpdateAutoConfigChanged(prefValue);
// Rather than call maybeUpdateAutoConfigChanged, a pref observer has
// been connected to PREF_APP_UPDATE_AUTO. This allows us to catch direct
// changes to the pref (which Firefox shouldn't be doing, but the user
// might do in about:config).
return Promise.resolve(prefValue);
}
// Justification for the empty catch statement below:
@ -309,7 +312,7 @@ var UpdateUtils = {
throw e;
}
})
.then(maybeUpdateAutoConfigChanged.bind(this));
.then(maybeUpdateAutoConfigChanged);
updateAutoIOPromise = writePromise;
return writePromise;
},
@ -357,11 +360,7 @@ async function writeUpdateAutoConfig(enabledValue) {
// Notifies observers if the value of app.update.auto has changed and returns
// the value for app.update.auto.
function maybeUpdateAutoConfigChanged(newValue) {
// Don't notify on the first read when updateAutoSettingCachedVal is null.
if (
updateAutoSettingCachedVal !== null &&
newValue != updateAutoSettingCachedVal
) {
if (newValue !== updateAutoSettingCachedVal) {
updateAutoSettingCachedVal = newValue;
Services.obs.notifyObservers(
null,
@ -371,6 +370,18 @@ function maybeUpdateAutoConfigChanged(newValue) {
}
return newValue;
}
// On non-Windows platforms, the Update Auto Config is still stored as a pref.
// On those platforms, the best way to notify observers of this setting is
// just to propagate it from a pref observer
if (AppConstants.platform != "win") {
Services.prefs.addObserver(
PREF_APP_UPDATE_AUTO,
async (subject, topic, data) => {
let value = await UpdateUtils.getAppUpdateAutoEnabled();
maybeUpdateAutoConfigChanged(value);
}
);
}
/* Get the distribution pref values, from defaults only */
function getDistributionPrefValue(aPrefName) {