Bug 1162538 - Add millisecondsToDays to TelemetryUtils.jsm. r=gfritzsche
☠☠ backed out by 8f69b7de3293 ☠ ☠
authorAlessio Placitelli <alessio.placitelli@gmail.com>
Tue, 26 May 2015 09:01:00 +0200
changeset 246265 96d6f014fda9dc55834d0e107a0c1f54466c0b41
parent 246264 f8b98f68de7666721255362e03b361a7f45b48b8
child 246266 0738be2ecfa703ce2e5ae9d7b359b30354dbd41e
push id28825
push userryanvm@gmail.com
push dateFri, 29 May 2015 20:56:27 +0000
treeherdermozilla-central@164a9a5ab7c9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgfritzsche
bugs1162538
milestone41.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 1162538 - Add millisecondsToDays to TelemetryUtils.jsm. r=gfritzsche
toolkit/components/telemetry/TelemetryEnvironment.jsm
toolkit/components/telemetry/TelemetryUtils.jsm
--- a/toolkit/components/telemetry/TelemetryEnvironment.jsm
+++ b/toolkit/components/telemetry/TelemetryEnvironment.jsm
@@ -12,18 +12,21 @@ const {classes: Cc, interfaces: Ci, util
 const myScope = this;
 
 Cu.import("resource://gre/modules/XPCOMUtils.jsm", this);
 Cu.import("resource://gre/modules/Task.jsm");
 Cu.import("resource://gre/modules/Log.jsm");
 Cu.import("resource://gre/modules/Preferences.jsm");
 Cu.import("resource://gre/modules/PromiseUtils.jsm");
 Cu.import("resource://gre/modules/Services.jsm");
+Cu.import("resource://gre/modules/TelemetryUtils.jsm", this);
 Cu.import("resource://gre/modules/ObjectUtils.jsm");
 
+const Utils = TelemetryUtils;
+
 XPCOMUtils.defineLazyModuleGetter(this, "ctypes",
                                   "resource://gre/modules/ctypes.jsm");
 #ifndef MOZ_WIDGET_GONK
 Cu.import("resource://gre/modules/AddonManager.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "LightweightThemeManager",
                                   "resource://gre/modules/LightweightThemeManager.jsm");
 #endif
 XPCOMUtils.defineLazyModuleGetter(this, "ProfileAge",
@@ -146,33 +149,21 @@ const PREF_DISTRIBUTOR_CHANNEL = "app.di
 const PREF_E10S_ENABLED = "browser.tabs.remote.autostart";
 const PREF_HOTFIX_LASTVERSION = "extensions.hotfix.lastVersion";
 const PREF_APP_PARTNER_BRANCH = "app.partner.";
 const PREF_PARTNER_ID = "mozilla.partner.id";
 const PREF_TELEMETRY_ENABLED = "toolkit.telemetry.enabled";
 const PREF_UPDATE_ENABLED = "app.update.enabled";
 const PREF_UPDATE_AUTODOWNLOAD = "app.update.auto";
 
-const MILLISECONDS_PER_DAY = 24 * 60 * 60 * 1000;
-
 const EXPERIMENTS_CHANGED_TOPIC = "experiments-changed";
 const SEARCH_ENGINE_MODIFIED_TOPIC = "browser-search-engine-modified";
 const SEARCH_SERVICE_TOPIC = "browser-search-service";
 
 /**
- * Turn a millisecond timestamp into a day timestamp.
- *
- * @param aMsec a number of milliseconds since epoch.
- * @return the number of whole days denoted by the input.
- */
-function truncateToDays(aMsec) {
-  return Math.floor(aMsec / MILLISECONDS_PER_DAY);
-}
-
-/**
  * Get the current browser.
  * @return a string with the locale or null on failure.
  */
 function getBrowserLocale() {
   try {
     return Cc["@mozilla.org/chrome/chrome-registry;1"].
              getService(Ci.nsIXULChromeRegistry).
              getSelectedLocale('global');
@@ -497,18 +488,18 @@ EnvironmentAddonBuilder.prototype = {
         name: addon.name,
         userDisabled: addon.userDisabled,
         appDisabled: addon.appDisabled,
         version: addon.version,
         scope: addon.scope,
         type: addon.type,
         foreignInstall: addon.foreignInstall,
         hasBinaryComponents: addon.hasBinaryComponents,
-        installDay: truncateToDays(installDate.getTime()),
-        updateDay: truncateToDays(updateDate.getTime()),
+        installDay: Utils.millisecondsToDays(installDate.getTime()),
+        updateDay: Utils.millisecondsToDays(updateDate.getTime()),
       };
     }
 
     return activeAddons;
   }),
 
   /**
    * Get the currently active theme data in object form.
@@ -532,18 +523,18 @@ EnvironmentAddonBuilder.prototype = {
         description: theme.description,
         name: theme.name,
         userDisabled: theme.userDisabled,
         appDisabled: theme.appDisabled,
         version: theme.version,
         scope: theme.scope,
         foreignInstall: theme.foreignInstall,
         hasBinaryComponents: theme.hasBinaryComponents,
-        installDay: truncateToDays(installDate.getTime()),
-        updateDay: truncateToDays(updateDate.getTime()),
+        installDay: Utils.millisecondsToDays(installDate.getTime()),
+        updateDay: Utils.millisecondsToDays(updateDate.getTime()),
       };
     }
 
     return activeTheme;
   }),
 
   /**
    * Get the plugins data in object form.
@@ -566,17 +557,17 @@ EnvironmentAddonBuilder.prototype = {
       activePlugins.push({
         name: tag.name,
         version: tag.version,
         description: tag.description,
         blocklisted: tag.blocklisted,
         disabled: tag.disabled,
         clicktoplay: tag.clicktoplay,
         mimeTypes: tag.getMimeTypes({}),
-        updateDay: truncateToDays(updateDate.getTime()),
+        updateDay: Utils.millisecondsToDays(updateDate.getTime()),
       });
     }
 
     return activePlugins;
   },
 
   /**
    * Get the GMPlugins data in object form.
@@ -996,19 +987,20 @@ EnvironmentCache.prototype = {
   _updateProfile: Task.async(function* () {
     const logger = Log.repository.getLoggerWithMessagePrefix(LOGGER_NAME, "ProfileAge - ");
     let profileAccessor = new ProfileAge(null, logger);
 
     let creationDate = yield profileAccessor.created;
     let resetDate = yield profileAccessor.reset;
 
     this._currentEnvironment.profile.creationDate =
-      truncateToDays(creationDate);
+      Utils.millisecondsToDays(creationDate);
     if (resetDate) {
-      this._currentEnvironment.profile.resetDate = truncateToDays(resetDate);
+      this._currentEnvironment.profile.resetDate =
+        Utils.millisecondsToDays(resetDate);
     }
   }),
 
   /**
    * Get the partner data in object form.
    * @return Object containing the partner data.
    */
   _getPartner: function () {
--- a/toolkit/components/telemetry/TelemetryUtils.jsm
+++ b/toolkit/components/telemetry/TelemetryUtils.jsm
@@ -5,18 +5,30 @@
 "use strict";
 
 this.EXPORTED_SYMBOLS = [
   "TelemetryUtils"
 ];
 
 const {classes: Cc, interfaces: Ci, results: Cr, utils: Cu} = Components;
 
+const MILLISECONDS_PER_DAY = 24 * 60 * 60 * 1000;
+
 this.TelemetryUtils = {
   /**
+   * Turn a millisecond timestamp into a day timestamp.
+   *
+   * @param aMsec A number of milliseconds since Unix epoch.
+   * @return The number of whole days since Unix epoch.
+   */
+  millisecondsToDays: function(aMsec) {
+    return Math.floor(aMsec / MILLISECONDS_PER_DAY);
+  },
+
+  /**
    * Takes a date and returns it trunctated to a date with daily precision.
    */
   truncateToDays: function(date) {
     return new Date(date.getFullYear(),
                     date.getMonth(),
                     date.getDate(),
                     0, 0, 0, 0);
   },