Bug 1103101 - Use DeferredTask in TelemetryPing; r=vladan
authorJim Chen <nchen@mozilla.com>
Tue, 06 Jan 2015 16:48:02 -0500
changeset 248118 f2c3615385149c731ee8e20ad1cbc50bbca51db4
parent 248117 6299801edf7c57c4e9885dd8bea16a343f5f314b
child 248119 ffb52826fcfa255157571356b510a74a2a53b570
push id4489
push userraliiev@mozilla.com
push dateMon, 23 Feb 2015 15:17:55 +0000
treeherdermozilla-beta@fd7c3dc24146 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvladan
bugs1103101
milestone37.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 1103101 - Use DeferredTask in TelemetryPing; r=vladan
toolkit/components/telemetry/TelemetryPing.jsm
--- a/toolkit/components/telemetry/TelemetryPing.jsm
+++ b/toolkit/components/telemetry/TelemetryPing.jsm
@@ -13,18 +13,18 @@ const Cu = Components.utils;
 Cu.import("resource://gre/modules/debug.js", this);
 Cu.import("resource://gre/modules/Services.jsm", this);
 Cu.import("resource://gre/modules/XPCOMUtils.jsm", this);
 #ifndef MOZ_WIDGET_GONK
 Cu.import("resource://gre/modules/LightweightThemeManager.jsm", this);
 #endif
 Cu.import("resource://gre/modules/ThirdPartyCookieProbe.jsm", this);
 Cu.import("resource://gre/modules/Promise.jsm", this);
-Cu.import("resource://gre/modules/Task.jsm", this);
 Cu.import("resource://gre/modules/AsyncShutdown.jsm", this);
+Cu.import("resource://gre/modules/DeferredTask.jsm", this);
 Cu.import("resource://gre/modules/Preferences.jsm");
 
 // When modifying the payload in incompatible ways, please bump this version number
 const PAYLOAD_VERSION = 1;
 
 // This is the HG changeset of the Histogram.json file, used to associate
 // submitted ping data with its histogram definition (bug 832007)
 #expand const HISTOGRAMS_FILE_VERSION = "__HISTOGRAMS_FILE_VERSION__";
@@ -963,57 +963,51 @@ let Impl = {
 #endif
     Services.obs.addObserver(this, "xul-window-visible", false);
     this._hasWindowRestoredObserver = true;
     this._hasXulWindowVisibleObserver = true;
 
     // Delay full telemetry initialization to give the browser time to
     // run various late initializers. Otherwise our gathered memory
     // footprint and other numbers would be too optimistic.
-    this._timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
     let deferred = Promise.defer();
-
-    function timerCallback() {
-      Task.spawn(function*(){
-        this._initialized = true;
+    let delayedTask = new DeferredTask(function* () {
+      this._initialized = true;
 
-        yield TelemetryFile.loadSavedPings();
-        // If we have any TelemetryPings lying around, we'll be aggressive
-        // and try to send them all off ASAP.
-        if (TelemetryFile.pingsOverdue > 0) {
-          // It doesn't really matter what we pass to this.send as a reason,
-          // since it's never sent to the server. All that this.send does with
-          // the reason is check to make sure it's not a test-ping.
-          yield this.send("overdue-flush", this._server);
-        }
+      yield TelemetryFile.loadSavedPings();
+      // If we have any TelemetryPings lying around, we'll be aggressive
+      // and try to send them all off ASAP.
+      if (TelemetryFile.pingsOverdue > 0) {
+        // It doesn't really matter what we pass to this.send as a reason,
+        // since it's never sent to the server. All that this.send does with
+        // the reason is check to make sure it's not a test-ping.
+        yield this.send("overdue-flush", this._server);
+      }
 
-        if ("@mozilla.org/datareporting/service;1" in Cc) {
-          let drs = Cc["@mozilla.org/datareporting/service;1"]
-                      .getService(Ci.nsISupports)
-                      .wrappedJSObject;
-          this._clientID = yield drs.getClientID();
-          // Update cached client id.
-          Preferences.set(PREF_CACHED_CLIENTID, this._clientID);
-        } else {
-          // Nuke potentially cached client id.
-          Preferences.reset(PREF_CACHED_CLIENTID);
-        }
+      if ("@mozilla.org/datareporting/service;1" in Cc) {
+        let drs = Cc["@mozilla.org/datareporting/service;1"]
+                    .getService(Ci.nsISupports)
+                    .wrappedJSObject;
+        this._clientID = yield drs.getClientID();
+        // Update cached client id.
+        Preferences.set(PREF_CACHED_CLIENTID, this._clientID);
+      } else {
+        // Nuke potentially cached client id.
+        Preferences.reset(PREF_CACHED_CLIENTID);
+      }
 
-        this.attachObservers();
-        this.gatherMemory();
+      this.attachObservers();
+      this.gatherMemory();
 
-        Telemetry.asyncFetchTelemetryData(function () {});
-        delete this._timer;
-        deferred.resolve();
-      }.bind(this));
-    }
+      Telemetry.asyncFetchTelemetryData(function () {});
+      deferred.resolve();
 
-    this._timer.initWithCallback(timerCallback.bind(this),
-                                 aTesting ? TELEMETRY_TEST_DELAY : TELEMETRY_DELAY,
-                                 Ci.nsITimer.TYPE_ONE_SHOT);
+    }.bind(this), aTesting ? TELEMETRY_TEST_DELAY : TELEMETRY_DELAY);
+
+    delayedTask.arm();
     return deferred.promise;
   },
 
   testLoadHistograms: function testLoadHistograms(file) {
     return TelemetryFile.testLoadHistograms(file);
   },
 
   getFlashVersion: function getFlashVersion() {