Bug 1462725 - Init Savant module at Firefox startup with study pref; r=rhelmer
authorBianca Danforth <bdanforth@mozilla.com>
Mon, 04 Jun 2018 16:18:13 -0700
changeset 421465 ac7e4d209fb44e1c4bafbe749385195bfda6e449
parent 421464 b7ddd726b2f93b6d2da560aab18d9ce147125580
child 421466 227bfae843a7fd7385a3fe243b1b3d7408e44e05
push id34095
push usernbeleuzu@mozilla.com
push dateWed, 06 Jun 2018 09:35:33 +0000
treeherdermozilla-central@d51b920aef69 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrhelmer
bugs1462725
milestone62.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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: 1dcHfk5tc3Q
browser/app/profile/firefox.js
browser/components/nsBrowserGlue.js
browser/modules/ShieldStudySavant.jsm
browser/modules/moz.build
--- 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,
@@ -1055,16 +1056,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',
 ]