summaryrefslogtreecommitdiffstats
path: root/toolkit/components/normandy/actions/PreferenceRollbackAction.jsm
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
commit43a97878ce14b72f0981164f87f2e35e14151312 (patch)
tree620249daf56c0258faa40cbdcf9cfba06de2a846 /toolkit/components/normandy/actions/PreferenceRollbackAction.jsm
parentInitial commit. (diff)
downloadfirefox-43a97878ce14b72f0981164f87f2e35e14151312.tar.xz
firefox-43a97878ce14b72f0981164f87f2e35e14151312.zip
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/components/normandy/actions/PreferenceRollbackAction.jsm')
-rw-r--r--toolkit/components/normandy/actions/PreferenceRollbackAction.jsm125
1 files changed, 125 insertions, 0 deletions
diff --git a/toolkit/components/normandy/actions/PreferenceRollbackAction.jsm b/toolkit/components/normandy/actions/PreferenceRollbackAction.jsm
new file mode 100644
index 0000000000..19200ee4be
--- /dev/null
+++ b/toolkit/components/normandy/actions/PreferenceRollbackAction.jsm
@@ -0,0 +1,125 @@
+/* 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/. */
+
+"use strict";
+
+const { BaseAction } = ChromeUtils.import(
+ "resource://normandy/actions/BaseAction.jsm"
+);
+const lazy = {};
+ChromeUtils.defineESModuleGetters(lazy, {
+ TelemetryEnvironment: "resource://gre/modules/TelemetryEnvironment.sys.mjs",
+});
+ChromeUtils.defineModuleGetter(
+ lazy,
+ "PreferenceRollouts",
+ "resource://normandy/lib/PreferenceRollouts.jsm"
+);
+ChromeUtils.defineModuleGetter(
+ lazy,
+ "PrefUtils",
+ "resource://normandy/lib/PrefUtils.jsm"
+);
+ChromeUtils.defineModuleGetter(
+ lazy,
+ "ActionSchemas",
+ "resource://normandy/actions/schemas/index.js"
+);
+ChromeUtils.defineModuleGetter(
+ lazy,
+ "TelemetryEvents",
+ "resource://normandy/lib/TelemetryEvents.jsm"
+);
+
+var EXPORTED_SYMBOLS = ["PreferenceRollbackAction"];
+
+class PreferenceRollbackAction extends BaseAction {
+ get schema() {
+ return lazy.ActionSchemas["preference-rollback"];
+ }
+
+ async _run(recipe) {
+ const { rolloutSlug } = recipe.arguments;
+ const rollout = await lazy.PreferenceRollouts.get(rolloutSlug);
+
+ if (lazy.PreferenceRollouts.GRADUATION_SET.has(rolloutSlug)) {
+ // graduated rollouts can't be rolled back
+ lazy.TelemetryEvents.sendEvent(
+ "unenrollFailed",
+ "preference_rollback",
+ rolloutSlug,
+ {
+ reason: "in-graduation-set",
+ enrollmentId:
+ rollout?.enrollmentId ??
+ lazy.TelemetryEvents.NO_ENROLLMENT_ID_MARKER,
+ }
+ );
+ throw new Error(
+ `Cannot rollback rollout in graduation set "${rolloutSlug}".`
+ );
+ }
+
+ if (!rollout) {
+ this.log.debug(`Rollback ${rolloutSlug} not applicable, skipping`);
+ return;
+ }
+
+ switch (rollout.state) {
+ case lazy.PreferenceRollouts.STATE_ACTIVE: {
+ this.log.info(`Rolling back ${rolloutSlug}`);
+ rollout.state = lazy.PreferenceRollouts.STATE_ROLLED_BACK;
+ for (const { preferenceName, previousValue } of rollout.preferences) {
+ lazy.PrefUtils.setPref(preferenceName, previousValue, {
+ branch: "default",
+ });
+ }
+ await lazy.PreferenceRollouts.update(rollout);
+ lazy.TelemetryEvents.sendEvent(
+ "unenroll",
+ "preference_rollback",
+ rolloutSlug,
+ {
+ reason: "rollback",
+ enrollmentId:
+ rollout.enrollmentId ||
+ lazy.TelemetryEvents.NO_ENROLLMENT_ID_MARKER,
+ }
+ );
+ lazy.TelemetryEnvironment.setExperimentInactive(rolloutSlug);
+ break;
+ }
+ case lazy.PreferenceRollouts.STATE_ROLLED_BACK: {
+ // The rollout has already been rolled back, so nothing to do here.
+ break;
+ }
+ case lazy.PreferenceRollouts.STATE_GRADUATED: {
+ // graduated rollouts can't be rolled back
+ lazy.TelemetryEvents.sendEvent(
+ "unenrollFailed",
+ "preference_rollback",
+ rolloutSlug,
+ {
+ reason: "graduated",
+ enrollmentId:
+ rollout.enrollmentId ||
+ lazy.TelemetryEvents.NO_ENROLLMENT_ID_MARKER,
+ }
+ );
+ throw new Error(
+ `Cannot rollback already graduated rollout ${rolloutSlug}`
+ );
+ }
+ default: {
+ throw new Error(
+ `Unexpected state when rolling back ${rolloutSlug}: ${rollout.state}`
+ );
+ }
+ }
+ }
+
+ async _finalize() {
+ await lazy.PreferenceRollouts.saveStartupPrefs();
+ }
+}