diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
commit | 6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /toolkit/components/normandy/actions/AddonRollbackAction.sys.mjs | |
parent | Initial commit. (diff) | |
download | thunderbird-upstream.tar.xz thunderbird-upstream.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | toolkit/components/normandy/actions/AddonRollbackAction.sys.mjs | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/toolkit/components/normandy/actions/AddonRollbackAction.sys.mjs b/toolkit/components/normandy/actions/AddonRollbackAction.sys.mjs new file mode 100644 index 0000000000..d4b2d4c423 --- /dev/null +++ b/toolkit/components/normandy/actions/AddonRollbackAction.sys.mjs @@ -0,0 +1,88 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +import { BaseAction } from "resource://normandy/actions/BaseAction.sys.mjs"; + +const lazy = {}; + +ChromeUtils.defineESModuleGetters(lazy, { + ActionSchemas: "resource://normandy/actions/schemas/index.sys.mjs", + AddonManager: "resource://gre/modules/AddonManager.sys.mjs", + AddonRollouts: "resource://normandy/lib/AddonRollouts.sys.mjs", + TelemetryEnvironment: "resource://gre/modules/TelemetryEnvironment.sys.mjs", + TelemetryEvents: "resource://normandy/lib/TelemetryEvents.sys.mjs", +}); + +export class AddonRollbackAction extends BaseAction { + get schema() { + return lazy.ActionSchemas["addon-rollback"]; + } + + async _run(recipe) { + const { rolloutSlug } = recipe.arguments; + const rollout = await lazy.AddonRollouts.get(rolloutSlug); + + if (!rollout) { + this.log.debug(`Rollback ${rolloutSlug} not applicable, skipping`); + return; + } + + switch (rollout.state) { + case lazy.AddonRollouts.STATE_ACTIVE: { + await lazy.AddonRollouts.update({ + ...rollout, + state: lazy.AddonRollouts.STATE_ROLLED_BACK, + }); + + const addon = await lazy.AddonManager.getAddonByID(rollout.addonId); + if (addon) { + try { + await addon.uninstall(); + } catch (err) { + lazy.TelemetryEvents.sendEvent( + "unenrollFailed", + "addon_rollback", + rolloutSlug, + { + reason: "uninstall-failed", + enrollmentId: + rollout.enrollmentId || + lazy.TelemetryEvents.NO_ENROLLMENT_ID_MARKER, + } + ); + throw err; + } + } else { + this.log.warn( + `Could not uninstall addon ${rollout.addonId} for rollback ${rolloutSlug}: it is not installed.` + ); + } + + lazy.TelemetryEvents.sendEvent( + "unenroll", + "addon_rollback", + rolloutSlug, + { + reason: "rollback", + enrollmentId: + rollout.enrollmentId || + lazy.TelemetryEvents.NO_ENROLLMENT_ID_MARKER, + } + ); + lazy.TelemetryEnvironment.setExperimentInactive(rolloutSlug); + break; + } + + case lazy.AddonRollouts.STATE_ROLLED_BACK: { + return; // Do nothing + } + + default: { + throw new Error( + `Unexpected state when rolling back ${rolloutSlug}: ${rollout.state}` + ); + } + } + } +} |