Bug 818549 - Replace test-gather-startup with a function. r=vladan.
authorRafael Ávila de Espíndola <respindola@mozilla.org>
Fri, 07 Dec 2012 00:28:13 -0500
changeset 120855 390569a008e588ccae3b8f5b66e29f6e16a2417c
parent 120854 732f04efe8f52ba2b2cf3c7ce6cee8f06f2ac83a
child 120856 77ee9dec6b3aa378847471cc14833e426e87e3f8
push idunknown
push userunknown
push dateunknown
reviewersvladan
bugs818549
milestone20.0a1
Bug 818549 - Replace test-gather-startup with a function. r=vladan.
toolkit/components/telemetry/TelemetryPing.js
toolkit/components/telemetry/nsITelemetryPing.idl
toolkit/components/telemetry/tests/unit/test_TelemetryPing.js
--- a/toolkit/components/telemetry/TelemetryPing.js
+++ b/toolkit/components/telemetry/TelemetryPing.js
@@ -942,16 +942,25 @@ TelemetryPing.prototype = {
     // This function returns the current Telemetry payload to the caller.
     // We only gather startup info once.
     if (Object.keys(this._slowSQLStartup).length == 0)
       this.gatherStartupInformation();
     this.gatherMemory();
     return this.getCurrentSessionPayload("gather-payload");
   },
 
+  gatherStartup: function gatherStartup() {
+    let counters = processInfo.getCounters();
+    if (counters) {
+      [this._startupIO.startupSessionRestoreReadBytes,
+        this._startupIO.startupSessionRestoreWriteBytes] = counters;
+    }
+    this.gatherStartupInformation();
+  },
+
   /**
    * This observer drives telemetry.
    */
   observe: function (aSubject, aTopic, aData) {
     // Allows to change the server for testing
     var server = this._server;
 
     switch (aTopic) {
@@ -990,24 +999,17 @@ TelemetryPing.prototype = {
       }
       break;
     case "sessionstore-windows-restored":
       Services.obs.removeObserver(this, "sessionstore-windows-restored");
       this._hasWindowRestoredObserver = false;
       // Check whether debugger was attached during startup
       let debugService = Cc["@mozilla.org/xpcom/debug;1"].getService(Ci.nsIDebug2);
       gWasDebuggerAttached = debugService.isDebuggerAttached;
-      // fall through
-    case "test-gather-startup":
-      var counters = processInfo.getCounters();
-      if (counters) {  
-        [this._startupIO.startupSessionRestoreReadBytes, 
-          this._startupIO.startupSessionRestoreWriteBytes] = counters;
-      }
-      this.gatherStartupInformation();
+      this.gatherStartup();
       break;
     case "idle-daily":
       // Enqueue to main-thread, otherwise components may be inited by the
       // idle-daily category and miss the gather-telemetry notification.
       Services.tm.mainThread.dispatch((function() {
         // Notify that data should be gathered now, since ping will happen soon.
         Services.obs.notifyObservers(null, "gather-telemetry", null);
         // The ping happens at the first idle of length IDLE_TIMEOUT_SECONDS.
--- a/toolkit/components/telemetry/nsITelemetryPing.idl
+++ b/toolkit/components/telemetry/nsITelemetryPing.idl
@@ -6,9 +6,10 @@
 #include "nsIObserver.idl"
 
 interface nsIFile;
 
 [scriptable, uuid(077ee790-3a9d-11e2-81c1-0800200c9a66)]
 interface nsITelemetryPing : nsIObserver {
   jsval getPayload();
   void saveHistograms(in nsIFile aFile, in boolean aSync);
+  void gatherStartup();
 };
--- a/toolkit/components/telemetry/tests/unit/test_TelemetryPing.js
+++ b/toolkit/components/telemetry/tests/unit/test_TelemetryPing.js
@@ -40,17 +40,17 @@ const BinaryInputStream = Components.Con
   "setInputStream");
 const Telemetry = Cc["@mozilla.org/base/telemetry;1"].getService(Ci.nsITelemetry);
 
 var httpserver = new HttpServer();
 var gFinished = false;
 
 function telemetry_ping () {
   const TelemetryPing = Cc["@mozilla.org/base/telemetry-ping;1"].getService(Ci.nsITelemetryPing);
-  TelemetryPing.observe(null, "test-gather-startup", null);
+  TelemetryPing.gatherStartup();
   TelemetryPing.observe(null, "test-enable-load-save-notifications", null);
   TelemetryPing.observe(null, "test-ping", SERVER);
 }
 
 // Mostly useful so that you can dump payloads from decodeRequestPayload.
 function dummyHandler(request, response) {
   let p = decodeRequestPayload(request);
   return p;