Bug 1458308 - Change telemetry to use the new auto update lookup mechanism draft
authorKirk Steuber <ksteuber@mozilla.com>
Mon, 09 Jul 2018 13:49:13 -0700
changeset 829193 c1445cf55db73e6fc916cc4a639168ede1197d13
parent 829192 dde7f7c1dd4d09f3c306e0d2220af37a22b621e1
child 829194 7911d7f492a9bb487d3010f277762dc994afbe41
push id118747
push userbmo:ksteuber@mozilla.com
push dateTue, 14 Aug 2018 21:08:44 +0000
bugs1458308
milestone63.0a1
Bug 1458308 - Change telemetry to use the new auto update lookup mechanism This change makes TelemetryEnvironment.settings.update.autoDownload load asynchronously. Now, a file needs to be read before that value can be written. This has the potential to delay the initialization of TelemetryEnvironment, but since it should be pretty quick and it runs in parallel with the other asynchronously loading values of TelemetryEnvironment, it should not delay initialization significantly. MozReview-Commit-ID: 1UUAi4sDopX
toolkit/components/telemetry/TelemetryEnvironment.jsm
toolkit/mozapps/update/nsUpdateService.js
--- a/toolkit/components/telemetry/TelemetryEnvironment.jsm
+++ b/toolkit/components/telemetry/TelemetryEnvironment.jsm
@@ -179,17 +179,16 @@ const RECORD_PREF_VALUE = TelemetryEnvir
 const RECORD_DEFAULTPREF_VALUE = TelemetryEnvironment.RECORD_DEFAULTPREF_VALUE;
 const RECORD_DEFAULTPREF_STATE = TelemetryEnvironment.RECORD_DEFAULTPREF_STATE;
 const DEFAULT_ENVIRONMENT_PREFS = new Map([
   ["app.feedback.baseURL", {what: RECORD_PREF_VALUE}],
   ["app.support.baseURL", {what: RECORD_PREF_VALUE}],
   ["accessibility.browsewithcaret", {what: RECORD_PREF_VALUE}],
   ["accessibility.force_disabled", {what:  RECORD_PREF_VALUE}],
   ["app.shield.optoutstudies.enabled", {what: RECORD_PREF_VALUE}],
-  ["app.update.auto", {what: RECORD_PREF_VALUE}],
   ["app.update.interval", {what: RECORD_PREF_VALUE}],
   ["app.update.service.enabled", {what: RECORD_PREF_VALUE}],
   ["app.update.silent", {what: RECORD_PREF_VALUE}],
   ["app.update.url", {what: RECORD_PREF_VALUE}],
   ["browser.cache.disk.enable", {what: RECORD_PREF_VALUE}],
   ["browser.cache.disk.capacity", {what: RECORD_PREF_VALUE}],
   ["browser.cache.memory.enable", {what: RECORD_PREF_VALUE}],
   ["browser.cache.offline.enable", {what: RECORD_PREF_VALUE}],
@@ -260,28 +259,28 @@ const LOGGER_NAME = "Toolkit.Telemetry";
 
 const PREF_BLOCKLIST_ENABLED = "extensions.blocklist.enabled";
 const PREF_DISTRIBUTION_ID = "distribution.id";
 const PREF_DISTRIBUTION_VERSION = "distribution.version";
 const PREF_DISTRIBUTOR = "app.distributor";
 const PREF_DISTRIBUTOR_CHANNEL = "app.distributor.channel";
 const PREF_APP_PARTNER_BRANCH = "app.partner.";
 const PREF_PARTNER_ID = "mozilla.partner.id";
-const PREF_UPDATE_AUTODOWNLOAD = "app.update.auto";
 const PREF_SEARCH_COHORT = "browser.search.cohort";
 
 const COMPOSITOR_CREATED_TOPIC = "compositor:created";
 const COMPOSITOR_PROCESS_ABORTED_TOPIC = "compositor:process-aborted";
 const DISTRIBUTION_CUSTOMIZATION_COMPLETE_TOPIC = "distribution-customization-complete";
 const GFX_FEATURES_READY_TOPIC = "gfx-features-ready";
 const SEARCH_ENGINE_MODIFIED_TOPIC = "browser-search-engine-modified";
 const SEARCH_SERVICE_TOPIC = "browser-search-service";
 const SESSIONSTORE_WINDOWS_RESTORED_TOPIC = "sessionstore-windows-restored";
 const PREF_CHANGED_TOPIC = "nsPref:changed";
 const BLOCKLIST_LOADED_TOPIC = "blocklist-loaded";
+const AUTO_UPDATE_PREF_CHANGE_TOPIC = "auto-update-pref-change";
 
 /**
  * Enforces the parameter to a boolean value.
  * @param aValue The input value.
  * @return {Boolean|Object} If aValue is a boolean or a number, returns its truthfulness
  *         value. Otherwise, return null.
  */
 function enforceBoolean(aValue) {
@@ -895,16 +894,17 @@ function EnvironmentCache() {
   this._addonBuilder = new EnvironmentAddonBuilder(this);
   p = [ this._addonBuilder.init() ];
 
   this._currentEnvironment.profile = {};
   p.push(this._updateProfile());
   if (AppConstants.MOZ_BUILD_APP == "browser") {
     p.push(this._loadAttributionAsync());
   }
+  p.push(this._loadAutoUpdateAsync());
 
   for (const [id, {branch, options}] of gActiveExperimentStartupBuffer.entries()) {
     this.setExperimentActive(id, branch, options);
   }
   gActiveExperimentStartupBuffer = null;
 
   let setup = () => {
     this._initTask = null;
@@ -1145,28 +1145,30 @@ EnvironmentCache.prototype = {
     // Watch the search engine change and service topics.
     Services.obs.addObserver(this, SESSIONSTORE_WINDOWS_RESTORED_TOPIC);
     Services.obs.addObserver(this, COMPOSITOR_CREATED_TOPIC);
     Services.obs.addObserver(this, COMPOSITOR_PROCESS_ABORTED_TOPIC);
     Services.obs.addObserver(this, DISTRIBUTION_CUSTOMIZATION_COMPLETE_TOPIC);
     Services.obs.addObserver(this, GFX_FEATURES_READY_TOPIC);
     Services.obs.addObserver(this, SEARCH_ENGINE_MODIFIED_TOPIC);
     Services.obs.addObserver(this, SEARCH_SERVICE_TOPIC);
+    Services.obs.addObserver(this, AUTO_UPDATE_PREF_CHANGE_TOPIC);
   },
 
   _removeObservers() {
     Services.obs.removeObserver(this, SESSIONSTORE_WINDOWS_RESTORED_TOPIC);
     Services.obs.removeObserver(this, COMPOSITOR_CREATED_TOPIC);
     Services.obs.removeObserver(this, COMPOSITOR_PROCESS_ABORTED_TOPIC);
     try {
       Services.obs.removeObserver(this, DISTRIBUTION_CUSTOMIZATION_COMPLETE_TOPIC);
     } catch (ex) {}
     Services.obs.removeObserver(this, GFX_FEATURES_READY_TOPIC);
     Services.obs.removeObserver(this, SEARCH_ENGINE_MODIFIED_TOPIC);
     Services.obs.removeObserver(this, SEARCH_SERVICE_TOPIC);
+    Services.obs.removeObserver(this, AUTO_UPDATE_PREF_CHANGE_TOPIC);
   },
 
   observe(aSubject, aTopic, aData) {
     this._log.trace("observe - aTopic: " + aTopic + ", aData: " + aData);
     switch (aTopic) {
       case SEARCH_ENGINE_MODIFIED_TOPIC:
         if (aData != "engine-current") {
           return;
@@ -1210,16 +1212,19 @@ EnvironmentCache.prototype = {
         this._updateDefaultBrowser();
         break;
       case PREF_CHANGED_TOPIC:
         let options = this._watchedPrefs.get(aData);
         if (options && !options.requiresRestart) {
           this._onPrefChanged(aData);
         }
         break;
+      case AUTO_UPDATE_PREF_CHANGE_TOPIC:
+        this._currentEnvironment.settings.update.autoDownload = (aData == "true");
+        break;
     }
   },
 
   /**
    * Get the default search engine.
    * @return {String} Returns the search engine identifier, "NONE" if no default search
    *         engine is defined or "UNDEFINED" if no engine identifier or name can be found.
    */
@@ -1405,28 +1410,28 @@ EnvironmentCache.prototype = {
       blocklistEnabled: Services.prefs.getBoolPref(PREF_BLOCKLIST_ENABLED, true),
       e10sEnabled: Services.appinfo.browserTabsRemoteAutostart,
       e10sMultiProcesses: Services.appinfo.maxWebProcessCount,
       telemetryEnabled: Utils.isTelemetryEnabled,
       locale: getBrowserLocale(),
       update: {
         channel: updateChannel,
         enabled: !Services.policies || Services.policies.isAllowed("appUpdate"),
-        autoDownload: Services.prefs.getBoolPref(PREF_UPDATE_AUTODOWNLOAD, true),
       },
       userPrefs: this._getPrefData(),
       sandbox: this._getSandboxData(),
     };
 
     this._currentEnvironment.settings.addonCompatibilityCheckEnabled =
       AddonManager.checkCompatibility;
 
     this._updateAttribution();
     this._updateDefaultBrowser();
     this._updateSearchEngine();
+    this._updateAutoDownload();
   },
 
   _getSandboxData() {
     let effectiveContentProcessLevel = null;
     try {
       let sandboxSettings = Cc["@mozilla.org/sandbox/sandbox-settings;1"].
                             getService(Ci.mozISandboxSettings);
       effectiveContentProcessLevel =
@@ -1491,16 +1496,37 @@ EnvironmentCache.prototype = {
     for (let key in data) {
       attributionData[key] =
         limitStringToLength(data[key], MAX_ATTRIBUTION_STRING_LENGTH);
     }
     this._currentEnvironment.settings.attribution = attributionData;
   },
 
   /**
+   * Load the auto update pref and adds it to the environment
+   */
+  async _loadAutoUpdateAsync() {
+    let aus = Cc["@mozilla.org/updates/update-service;1"]
+              .getService(Ci.nsIApplicationUpdateService);
+    this._updateAutoDownloadCache = await aus.autoUpdateIsEnabled();
+    this._updateAutoDownload();
+  },
+
+  /**
+   * Update the environment with the cached value for whether updates can auto-
+   * download.
+   */
+  _updateAutoDownload() {
+    if (this._updateAutoDownloadCache === undefined) {
+      return;
+    }
+    this._currentEnvironment.settings.update.autoDownload = this._updateAutoDownloadCache;
+  },
+
+  /**
    * Get the partner data in object form.
    * @return Object containing the partner data.
    */
   _getPartner() {
     let partnerData = {
       distributionId: Services.prefs.getStringPref(PREF_DISTRIBUTION_ID, null),
       distributionVersion: Services.prefs.getStringPref(PREF_DISTRIBUTION_VERSION, null),
       partnerId: Services.prefs.getStringPref(PREF_PARTNER_ID, null),
--- a/toolkit/mozapps/update/nsUpdateService.js
+++ b/toolkit/mozapps/update/nsUpdateService.js
@@ -1991,18 +1991,20 @@ UpdateService.prototype = {
     // UPDATE_INVALID_LASTUPDATETIME_EXTERNAL
     // UPDATE_INVALID_LASTUPDATETIME_NOTIFY
     // UPDATE_LAST_NOTIFY_INTERVAL_DAYS_EXTERNAL
     // UPDATE_LAST_NOTIFY_INTERVAL_DAYS_NOTIFY
     AUSTLMY.pingLastUpdateTime(this._pingSuffix);
     // Histogram IDs:
     // UPDATE_NOT_PREF_UPDATE_AUTO_EXTERNAL
     // UPDATE_NOT_PREF_UPDATE_AUTO_NOTIFY
-    AUSTLMY.pingBoolPref("UPDATE_NOT_PREF_UPDATE_AUTO_" + this._pingSuffix,
-                         PREF_APP_UPDATE_AUTO, true, true);
+    this.autoUpdateIsEnabled().then(enabled => {
+      AUSTLMY.pingGeneric("UPDATE_NOT_PREF_UPDATE_AUTO_" + this._pingSuffix,
+                          enabled, DEFAULT_VALUE_APP_UPDATE_AUTO);
+    });
     // Histogram IDs:
     // UPDATE_NOT_PREF_UPDATE_STAGING_ENABLED_EXTERNAL
     // UPDATE_NOT_PREF_UPDATE_STAGING_ENABLED_NOTIFY
     AUSTLMY.pingBoolPref("UPDATE_NOT_PREF_UPDATE_STAGING_ENABLED_" +
                          this._pingSuffix,
                          PREF_APP_UPDATE_STAGING_ENABLED, true, true);
     if (AppConstants.platform == "win" || AppConstants.platform == "macosx") {
       // Histogram IDs: