IPPNimbusHelper.sys.mjs (1465B)
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/. */ 4 5 /** 6 * Note: If you add or modify the list of helpers, make sure to update the 7 * corresponding documentation in the `docs` folder as well. 8 */ 9 10 const lazy = {}; 11 12 ChromeUtils.defineESModuleGetters(lazy, { 13 IPProtectionService: 14 "moz-src:///browser/components/ipprotection/IPProtectionService.sys.mjs", 15 NimbusFeatures: "resource://nimbus/ExperimentAPI.sys.mjs", 16 }); 17 /** 18 * This class monitors the eligibility flag from Nimbus 19 */ 20 class IPPNimbusHelperSingleton { 21 init() {} 22 23 initOnStartupCompleted() { 24 lazy.NimbusFeatures.ipProtection.onUpdate( 25 lazy.IPProtectionService.updateState 26 ); 27 } 28 29 uninit() { 30 lazy.NimbusFeatures.ipProtection.offUpdate( 31 lazy.IPProtectionService.updateState 32 ); 33 } 34 35 /** 36 * Check if this device is in the experiment with a variant branch. 37 * 38 * @returns {boolean} 39 */ 40 get isEligible() { 41 let inExperiment = lazy.NimbusFeatures.ipProtection.getEnrollmentMetadata(); 42 let isEligible = inExperiment?.branch && inExperiment.branch !== "control"; 43 44 if (inExperiment) { 45 lazy.NimbusFeatures.ipProtection.recordExposureEvent({ 46 once: true, 47 }); 48 } 49 50 return isEligible; 51 } 52 } 53 54 const IPPNimbusHelper = new IPPNimbusHelperSingleton(); 55 56 export { IPPNimbusHelper };