Bug 818565 - Replace test-ping with a function. r=vladan.

This commit is contained in:
Rafael Ávila de Espíndola 2012-12-07 01:06:33 -05:00
parent db21532283
commit 3e98a028ae
3 changed files with 19 additions and 17 deletions

View File

@ -964,13 +964,26 @@ TelemetryPing.prototype = {
this._addons = aAddOns;
},
sendIdlePing: function sendIdlePing(aTest, aServer) {
if (this._isIdleObserver) {
idleService.removeIdleObserver(this, IDLE_TIMEOUT_SECONDS);
this._isIdleObserver = false;
}
if (aTest) {
this.send("test-ping", aServer);
} else if (Telemetry.canSend) {
this.send("idle-daily", aServer);
}
},
testPing: function testPing(server) {
this.sendIdlePing(true, server);
},
/**
* This observer drives telemetry.
*/
observe: function (aSubject, aTopic, aData) {
// Allows to change the server for testing
var server = this._server;
switch (aTopic) {
case "profile-after-change":
this.setup();
@ -1027,20 +1040,8 @@ TelemetryPing.prototype = {
this._pingLoadsCompleted = 0;
this.loadHistograms(aSubject.QueryInterface(Ci.nsIFile), aData != "async");
break;
case "test-ping":
server = aData;
// fall through
case "idle":
if (this._isIdleObserver) {
idleService.removeIdleObserver(this, IDLE_TIMEOUT_SECONDS);
this._isIdleObserver = false;
}
if (aTopic == "test-ping") {
this.send("test-ping", server);
}
else if (Telemetry.canSend && aTopic == "idle") {
this.send("idle-daily", server);
}
this.sendIdlePing(false, this._server);
break;
case "quit-application-granted":
if (Telemetry.canSend) {

View File

@ -14,4 +14,5 @@ interface nsITelemetryPing : nsIObserver {
void gatherStartup();
void enableLoadSaveNotifications(); /* Used only for testing. */
void setAddOns(in AString aAddOns);
void testPing(in AString aServer);
};

View File

@ -47,7 +47,7 @@ function telemetry_ping () {
const TelemetryPing = Cc["@mozilla.org/base/telemetry-ping;1"].getService(Ci.nsITelemetryPing);
TelemetryPing.gatherStartup();
TelemetryPing.enableLoadSaveNotifications();
TelemetryPing.observe(null, "test-ping", SERVER);
TelemetryPing.testPing(SERVER);
}
// Mostly useful so that you can dump payloads from decodeRequestPayload.