Bug 1875502 - Add UpdateManager.updateInstalledAtStartup r=nalexander,application-update-reviewers,firefox-desktop-core-reviewers

Differential Revision: https://phabricator.services.mozilla.com/D209127
This commit is contained in:
Robin Steuber
2024-05-15 17:06:18 +00:00
parent 2b97ef7e76
commit 058a179fc5
5 changed files with 59 additions and 23 deletions

View File

@@ -739,7 +739,7 @@ nsBrowserContentHandler.prototype = {
overridePage = Services.urlFormatter.formatURLPref(
"startup.homepage_override_url"
);
let update = lazy.UpdateManager.readyUpdate;
let update = lazy.UpdateManager.updateInstalledAtStartup;
/** If the override URL is provided by an experiment, is a valid
* Firefox What's New Page URL, and the update version is less than

View File

@@ -46,23 +46,6 @@ export var UpdatePing = {
Services.obs.addObserver(this, UPDATE_STAGED_TOPIC);
},
/**
* Get the information about the update we're going to apply/was just applied
* from the update manager.
*
* @return {nsIUpdate} The information about the update, if available, or null.
*/
_getActiveUpdate() {
let updateManager = Cc["@mozilla.org/updates/update-manager;1"].getService(
Ci.nsIUpdateManager
);
if (!updateManager || !updateManager.readyUpdate) {
return null;
}
return updateManager.readyUpdate;
},
/**
* Generate an "update" ping with reason "success" and dispatch it
* to the Telemetry system.
@@ -84,7 +67,10 @@ export var UpdatePing = {
// update manager should still have information about the active update: given the
// previous assumptions, we can simply get the channel from the update and assume
// it matches with the state previous to the update.
let update = this._getActiveUpdate();
let updateManager = Cc["@mozilla.org/updates/update-manager;1"].getService(
Ci.nsIUpdateManager
);
let update = updateManager ? updateManager.updateInstalledAtStartup : null;
const payload = {
reason: "success",
@@ -115,7 +101,7 @@ export var UpdatePing = {
* @param {String} aUpdateState The state of the downloaded patch. See
* nsIUpdateService.idl for a list of possible values.
*/
_handleUpdateReady(aUpdateState) {
async _handleUpdateReady(aUpdateState) {
const ALLOWED_STATES = [
"applied",
"applied-service",
@@ -130,7 +116,10 @@ export var UpdatePing = {
// Get the information about the update we're going to apply from the
// update manager.
let update = this._getActiveUpdate();
let updateManager = Cc["@mozilla.org/updates/update-manager;1"].getService(
Ci.nsIUpdateManager
);
let update = updateManager ? await updateManager.getReadyUpdate() : null;
if (!update) {
this._log.trace(
"Cannot get the update manager or no update is currently active."
@@ -164,10 +153,10 @@ export var UpdatePing = {
/**
* The notifications handler.
*/
observe(aSubject, aTopic, aData) {
async observe(aSubject, aTopic, aData) {
this._log.trace("observe - aTopic: " + aTopic);
if (aTopic == UPDATE_DOWNLOADED_TOPIC || aTopic == UPDATE_STAGED_TOPIC) {
this._handleUpdateReady(aData);
await this._handleUpdateReady(aData);
}
},

View File

@@ -4335,6 +4335,11 @@ export class UpdateManager {
*/
_updatesDirty = false;
/**
* The backing for `nsIUpdateManager.updateInstalledAtStartup`.
*/
#updateInstalledAtStartup = null;
/**
* A service to manage active and past updates.
* @constructor
@@ -4365,6 +4370,8 @@ export class UpdateManager {
}
this._downloadingUpdate = this._readyUpdate;
this._readyUpdate = null;
} else if (status == STATE_SUCCEEDED && this._readyUpdate) {
this.#updateInstalledAtStartup = this._readyUpdate;
}
}
@@ -4388,6 +4395,10 @@ export class UpdateManager {
this._readyUpdate.state
);
}
LOG(
"UpdateManager:UpdateManager - Initialized updateInstalledAtStartup to " +
this.#updateInstalledAtStartup
);
this.internal = {
reload: skipFiles => this.#reload(skipFiles),
@@ -4428,6 +4439,7 @@ export class UpdateManager {
this._updatesDirty = true;
this._readyUpdate = null;
this._downloadingUpdate = null;
this.#updateInstalledAtStartup = null;
transitionState(Ci.nsIApplicationUpdateService.STATE_IDLE);
if (!skipFiles) {
let activeUpdates = this._loadXMLFileIntoArray(FILE_ACTIVE_UPDATE_XML);
@@ -4453,6 +4465,9 @@ export class UpdateManager {
) {
transitionState(Ci.nsIApplicationUpdateService.STATE_PENDING);
}
if (status == STATE_SUCCEEDED && this._readyUpdate) {
this.#updateInstalledAtStartup = this._readyUpdate;
}
}
updates = this._loadXMLFileIntoArray(FILE_UPDATES_XML);
}
@@ -4475,6 +4490,10 @@ export class UpdateManager {
this._readyUpdate.state
);
}
LOG(
"UpdateManager:UpdateManager - Reloaded updateInstalledAtStartup as " +
this.#updateInstalledAtStartup
);
}
/**
@@ -4613,6 +4632,13 @@ export class UpdateManager {
return this._downloadingUpdate;
}
/**
* See nsIUpdateService.idl
*/
get updateInstalledAtStartup() {
return this.#updateInstalledAtStartup;
}
#addUpdateToHistory(aUpdate) {
this._updatesDirty = true;
let updates = this._getUpdates();

View File

@@ -888,6 +888,12 @@ interface nsIUpdateManager : nsISupports
*/
Promise getDownloadingUpdate();
/**
* If Firefox installed an update at the launch of the current session, this
* will contain that update. If not, this will be `null`.
*/
readonly attribute nsIUpdate updateInstalledAtStartup;
/**
* Adds the specified update to the update history. The update history is
* limited to 10 items, so this may also remove the last item from the

View File

@@ -37,6 +37,11 @@ async function run_test() {
1,
"the update manager update count" + MSG_SHOULD_EQUAL
);
Assert.equal(
gUpdateManager.updateInstalledAtStartup,
history[0],
"the update installed at startup should be the update from the history"
);
await waitForUpdateXMLFiles();
let cancelations = Services.prefs.getIntPref(PREF_APP_UPDATE_CANCELATIONS, 0);
@@ -77,5 +82,15 @@ async function run_test() {
let dir = getUpdateDirFile(DIR_PATCH);
Assert.ok(dir.exists(), MSG_SHOULD_EXIST);
// Simulate the browser restarting by rerunning update initialization.
reloadUpdateManagerData();
await testPostUpdateProcessing();
Assert.equal(
gUpdateManager.updateInstalledAtStartup,
null,
"updateInstalledAtStartup should be cleared on next browser start"
);
doTestFinish();
}