Bug 1462725 - Init Savant module at Firefox startup with study pref; r=rhelmer, a=RyanVM
authorBianca Danforth <bdanforth@mozilla.com>
Mon, 04 Jun 2018 16:18:13 -0700
changeset 473699 acf128a41e11d4f85e076f2286be475bb4bbe014
parent 473698 bd79850d10f8da83f0af64408418dd0dbb9a7bca
child 473700 6d9e80629c215964674d5d7ee39ccf531334fdb5
push id1728
push userjlund@mozilla.com
push dateMon, 18 Jun 2018 21:12:27 +0000
treeherdermozilla-release@c296fde26f5f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrhelmer, RyanVM
bugs1462725
milestone61.0
Bug 1462725 - Init Savant module at Firefox startup with study pref; r=rhelmer, a=RyanVM 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
@@ -1731,8 +1731,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
@@ -129,16 +129,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 AboutHome:false, ContentPrefServiceParent:false, ContentSearch:false,
@@ -1018,16 +1019,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
@@ -149,16 +149,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',
     'ThemeVariableMap.jsm',
     'TransientPrefs.jsm',
     'webrtcUI.jsm',
     'ZoomUI.jsm',
 ]