Backed out 7 changesets (bug 1942424) for causing frequent crashes. a=backout
[gecko.git] / toolkit / components / normandy / actions / BaseStudyAction.sys.mjs
blobcca66e65fa289d799864428487ee3d7217c9c8db
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 import { BaseAction } from "resource://normandy/actions/BaseAction.sys.mjs";
7 const OPT_OUT_STUDIES_ENABLED_PREF = "app.shield.optoutstudies.enabled";
9 /**
10  * Base class for local study actions.
11  *
12  * This should be subclassed. Subclasses must implement _run() for
13  * per-recipe behavior, and may implement _finalize for actions to be
14  * taken once after recipes are run.
15  *
16  * For actions that need to be taken once before recipes are run
17  * _preExecution may be overriden but the overridden method must
18  * call the parent method to ensure the appropriate checks occur.
19  *
20  * Other methods should be overridden with care, to maintain the life
21  * cycle events and error reporting implemented by this class.
22  */
23 export class BaseStudyAction extends BaseAction {
24   _preExecution() {
25     if (!Services.policies.isAllowed("Shield")) {
26       this.log.debug("Disabling Shield because it's blocked by policy.");
27       this.disable();
28     }
30     if (!Services.prefs.getBoolPref(OPT_OUT_STUDIES_ENABLED_PREF, true)) {
31       this.log.debug(
32         "User has opted-out of opt-out experiments, disabling action."
33       );
34       this.disable();
35     }
36   }