Bug 668392 - Include enabled addons + persona in telemetry r=Mossop

This commit is contained in:
Taras Glek 2011-08-11 14:19:40 -07:00
parent b4b66fce43
commit 7ddd54326f
3 changed files with 92 additions and 17 deletions

View File

@ -42,6 +42,7 @@ const Cu = Components.utils;
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/LightweightThemeManager.jsm");
// When modifying the payload in incompatible ways, please bump this version number
const PAYLOAD_VERSION = 1;
@ -220,6 +221,54 @@ TelemetryPing.prototype = {
h.add(val);
},
/**
* Descriptive metadata
*
* @param reason
* The reason for the telemetry ping, this will be included in the
* returned metadata,
* @return The metadata as a JS object
*/
getMetadata: function getMetadata(reason) {
let ai = Services.appinfo;
let ret = {
reason: reason,
OS: ai.OS,
appID: ai.ID,
appVersion: ai.version,
appName: ai.name,
appBuildID: ai.appBuildID,
platformBuildID: ai.platformBuildID,
};
// sysinfo fields are not always available, get what we can.
let sysInfo = Cc["@mozilla.org/system-info;1"].getService(Ci.nsIPropertyBag2);
let fields = ["cpucount", "memsize", "arch", "version", "device", "manufacturer", "hardware"];
for each (let field in fields) {
let value;
try {
value = sysInfo.getProperty(field);
} catch (e) {
continue
}
if (field == "memsize") {
// Send RAM size in megabytes. Rounding because sysinfo doesn't
// always provide RAM in multiples of 1024.
value = Math.round(value / 1024 / 1024)
}
ret[field] = value
}
let theme = LightweightThemeManager.currentTheme;
if (theme)
ret.persona = theme.id;
if (this._addons)
ret.addons = this._addons;
return ret;
},
/**
* Pull values from about:memory into corresponding histograms
*/
@ -286,10 +335,11 @@ TelemetryPing.prototype = {
this.gatherMemory();
let payload = {
ver: PAYLOAD_VERSION,
info: getMetadata(reason),
info: this.getMetadata(reason),
simpleMeasurements: getSimpleMeasurements(),
histograms: getHistograms()
};
let isTestPing = (reason == "test-ping");
// Generate a unique id once per session so the server can cope with duplicate submissions.
// Use a deterministic url for testing.
@ -395,6 +445,9 @@ TelemetryPing.prototype = {
var server = this._server;
switch (aTopic) {
case "Add-ons":
this._addons = aData;
break;
case "profile-after-change":
this.setup();
break;

View File

@ -10,6 +10,7 @@
do_load_httpd_js();
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/LightweightThemeManager.jsm");
const PATH = "/submit/telemetry/test-ping";
const SERVER = "http://localhost:4444";
@ -21,6 +22,7 @@ const BinaryInputStream = Components.Constructor(
"setInputStream");
var httpserver = new nsHttpServer();
var gFinished = false;
function telemetry_ping () {
const TelemetryPing = Cc["@mozilla.org/base/telemetry-ping;1"].getService(Ci.nsIObserver);
@ -46,27 +48,12 @@ function telemetryObserver(aSubject, aTopic, aData) {
telemetry_ping();
}
function run_test() {
createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
Services.obs.addObserver(nonexistentServerObserver, "telemetry-test-xhr-complete", false);
telemetry_ping();
// spin the event loop
do_test_pending();
}
function readBytesFromInputStream(inputStream, count) {
if (!count) {
count = inputStream.available();
}
return new BinaryInputStream(inputStream).readBytes(count);
}
function checkHistograms(request, response) {
// do not need the http server anymore
httpserver.stop(do_test_finished);
let s = request.bodyInputStream
let payload = Cc["@mozilla.org/dom/json;1"].createInstance(Ci.nsIJSON)
.decode(readBytesFromInputStream(s))
.decodeFromStream(s, s.available())
do_check_eq(request.getHeader("content-type"), "application/json; charset=UTF-8");
do_check_true(payload.simpleMeasurements.uptime >= 0)
@ -102,6 +89,7 @@ function checkHistograms(request, response) {
let tc = payload.histograms[TELEMETRY_SUCCESS]
do_check_eq(uneval(tc),
uneval(expected_tc));
gFinished = true;
}
// copied from toolkit/mozapps/extensions/test/xpcshell/head_addons.js
@ -152,3 +140,34 @@ function createAppInfo(id, name, version, platformVersion) {
registrar.registerFactory(XULAPPINFO_CID, "XULAppInfo",
XULAPPINFO_CONTRACTID, XULAppInfoFactory);
}
function dummyTheme(id) {
return {
id: id,
name: Math.random().toString(),
headerURL: "http://lwttest.invalid/a.png",
footerURL: "http://lwttest.invalid/b.png",
textcolor: Math.random().toString(),
accentcolor: Math.random().toString()
};
}
function run_test() {
// Addon manager needs a profile directory
do_get_profile();
createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
// try to make LightweightThemeManager do stuff
let gInternalManager = Cc["@mozilla.org/addons/integration;1"]
.getService(Ci.nsIObserver)
.QueryInterface(Ci.nsITimerCallback);
gInternalManager.observe(null, "addons-startup", null);
LightweightThemeManager.currentTheme = dummyTheme("1234");
Services.obs.addObserver(nonexistentServerObserver, "telemetry-test-xhr-complete", false);
telemetry_ping();
// spin the event loop
do_test_pending();
// ensure that test runs to completion
do_register_cleanup(function () do_check_true(gFinished))
}

View File

@ -1738,6 +1738,9 @@ var XPIProvider = {
Services.appinfo.annotateCrashReport("Add-ons", data);
}
catch (e) { }
const TelemetryPing = Cc["@mozilla.org/base/telemetry-ping;1"].getService(Ci.nsIObserver);
TelemetryPing.observe(null, "Add-ons", data);
},
/**