Bug 763526 - move telemetry-test-xhr-complete notification; r=taras

This commit is contained in:
Nathan Froyd 2012-06-12 14:20:42 -04:00
parent 8ab246e877
commit 51e27947ea

View File

@ -462,14 +462,13 @@ TelemetryPing.prototype = {
let slug = (isTestPing ? reason : this._uuid);
payloadObj.info = this.getMetadata(reason);
return { previous: false, slug: slug, payload: JSON.stringify(payloadObj) };
return { slug: slug, payload: JSON.stringify(payloadObj) };
},
getPayloads: function getPayloads(reason) {
function payloadIter() {
if (this._pendingPings.length > 0) {
let data = this._pendingPings.pop();
data.previous = true;
// Send persisted pings to the test URL too.
if (reason == "test-ping") {
data.slug = reason;
@ -490,7 +489,8 @@ TelemetryPing.prototype = {
send: function send(reason, server) {
// populate histograms one last time
this.gatherMemory();
this.sendPingsFromIterator(server, Iterator(this.getPayloads(reason)));
this.sendPingsFromIterator(server, reason,
Iterator(this.getPayloads(reason)));
},
/**
@ -505,25 +505,32 @@ TelemetryPing.prototype = {
* and provide callbacks for XMLHttpRequest when a request has
* finished.
*/
sendPingsFromIterator: function sendPingsFromIterator(server, i) {
sendPingsFromIterator: function sendPingsFromIterator(server, reason, i) {
function finishPings(reason) {
if (reason == "test-ping") {
Services.obs.notifyObservers(null, "telemetry-test-xhr-complete", null);
}
}
let data = null;
try {
data = i.next();
} catch (e if e instanceof StopIteration) {
finishPings(reason);
return;
}
function onSuccess() {
this.sendPingsFromIterator(server, i);
this.sendPingsFromIterator(server, reason, i);
}
function onError() {
/* nothing */
// Notify that testing is complete, even if we didn't send everything.
finishPings(reason);
}
this.doPing(server, data.slug, data.payload, !data.previous,
this.doPing(server, data.slug, data.payload,
onSuccess.bind(this), onError.bind(this));
},
doPing: function doPing(server, slug, payload, recordSuccess,
onSuccess, onError) {
doPing: function doPing(server, slug, payload, onSuccess, onError) {
let submitPath = "/submit/telemetry/" + slug;
let url = server + submitPath;
let request = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"]
@ -552,8 +559,6 @@ TelemetryPing.prototype = {
if (success && file.exists()) {
file.remove(true);
}
if (slug == "test-ping" && recordSuccess)
Services.obs.notifyObservers(null, "telemetry-test-xhr-complete", null);
}
function handler(callback) {