Bug 1462725 - Init Savant module at Firefox startup with study pref; r=rhelmer
This module observes the study pref to enable/disable the study.
MozReview-Commit-ID: Ht7M1gT05wG
--- a/browser/app/profile/firefox.js
+++ b/browser/app/profile/firefox.js
@@ -1718,8 +1718,12 @@ pref("app.normandy.first_run", true);
pref("app.normandy.logging.level", 50); // Warn
pref("app.normandy.run_interval_seconds", 21600); // 6 hours
pref("app.normandy.shieldLearnMoreUrl", "https://support.mozilla.org/1/firefox/%VERSION%/%OS%/%LOCALE%/shield");
#ifdef MOZ_DATA_REPORTING
pref("app.shield.optoutstudies.enabled", true);
#else
pref("app.shield.optoutstudies.enabled", false);
#endif
+
+// Savant Shield study preferences
+pref("shield.savant.enabled", false);
+pref("shield.savant.loglevel", "debug");
--- a/browser/components/nsBrowserGlue.js
+++ b/browser/components/nsBrowserGlue.js
@@ -132,16 +132,17 @@ XPCOMUtils.defineLazyModuleGetters(this,
PrivateBrowsingUtils: "resource://gre/modules/PrivateBrowsingUtils.jsm",
ProcessHangMonitor: "resource:///modules/ProcessHangMonitor.jsm",
ReaderParent: "resource:///modules/ReaderParent.jsm",
RemotePrompt: "resource:///modules/RemotePrompt.jsm",
SafeBrowsing: "resource://gre/modules/SafeBrowsing.jsm",
Sanitizer: "resource:///modules/Sanitizer.jsm",
SessionStore: "resource:///modules/sessionstore/SessionStore.jsm",
ShellService: "resource:///modules/ShellService.jsm",
+ ShieldStudySavant: "resource:///modules/ShieldStudySavant.jsm",
TabCrashHandler: "resource:///modules/ContentCrashHandlers.jsm",
UIState: "resource://services-sync/UIState.jsm",
UITour: "resource:///modules/UITour.jsm",
WebChannel: "resource://gre/modules/WebChannel.jsm",
WindowsRegistry: "resource://gre/modules/WindowsRegistry.jsm",
});
/* global ContentPrefServiceParent:false, ContentSearch:false,
@@ -1054,16 +1055,18 @@ BrowserGlue.prototype = {
PageActions.init();
this._firstWindowTelemetry(aWindow);
this._firstWindowLoaded();
// Set the default favicon size for UI views that use the page-icon protocol.
PlacesUtils.favicons.setDefaultIconURIPreferredSize(16 * aWindow.devicePixelRatio);
+
+ ShieldStudySavant.init();
},
_sendMediaTelemetry() {
let win = Services.appShell.hiddenDOMWindow;
let v = win.document.createElementNS("http://www.w3.org/1999/xhtml", "video");
v.reportCanPlayTelemetry();
},
new file mode 100644
--- /dev/null
+++ b/browser/modules/ShieldStudySavant.jsm
@@ -0,0 +1,59 @@
+/* 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";
+
+var EXPORTED_SYMBOLS = ["ShieldStudySavant"];
+
+ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
+ChromeUtils.import("resource://gre/modules/Services.jsm");
+
+class ShieldStudySavantClass {
+ constructor() {
+ this.SHIELD_STUDY_SAVANT_PREF = "shield.savant.enabled";
+ }
+
+ init() {
+ // check the pref in case Normandy flipped it on before we could add the pref listener
+ this.shouldCollect = Services.prefs.getBoolPref(this.SHIELD_STUDY_SAVANT_PREF);
+ if (this.shouldCollect) {
+ this.enableCollection();
+ }
+ Services.prefs.addObserver(this.SHIELD_STUDY_SAVANT_PREF, this);
+ }
+
+ observe(subject, topic, data) {
+ if (topic === "nsPref:changed" && data === this.SHIELD_STUDY_SAVANT_PREF) {
+ // toggle state of the pref
+ this.shouldCollect = !this.shouldCollect;
+ if (this.shouldCollect) {
+ this.enableCollection();
+ } else {
+ // Normandy has flipped off the pref
+ this.endStudy("expired");
+ }
+ }
+ }
+
+ enableCollection() {
+ // TODO: enable data collection
+ }
+
+ endStudy(reason) {
+ this.disableCollection();
+ // TODO: send endStudy ping with reason code
+ this.uninit();
+ }
+
+ disableCollection() {
+ // TODO: disable data collection
+ }
+
+ uninit() {
+ Services.prefs.removeObserver(this.SHIELD_STUDY_SAVANT_PREF, this);
+ Services.prefs.clearUserPref(this.SHIELD_STUDY_SAVANT_PREF);
+ }
+};
+
+const ShieldStudySavant = new ShieldStudySavantClass();
--- a/browser/modules/moz.build
+++ b/browser/modules/moz.build
@@ -163,16 +163,17 @@ EXTRA_JS_MODULES += [
'PermissionUI.jsm',
'PingCentre.jsm',
'PluginContent.jsm',
'ProcessHangMonitor.jsm',
'ReaderParent.jsm',
'RemotePrompt.jsm',
'Sanitizer.jsm',
'SchedulePressure.jsm',
+ 'ShieldStudySavant.jsm',
'SiteDataManager.jsm',
'SitePermissions.jsm',
'TabsPopup.jsm',
'ThemeVariableMap.jsm',
'TransientPrefs.jsm',
'webrtcUI.jsm',
'ZoomUI.jsm',
]