forked from mirrors/gecko-dev
MozReview-Commit-ID: 4uQBq3Qvj0M --HG-- extra : rebase_source : a875fd98c0e22250de47baa0c5947485d72b9c9c
98 lines
3.4 KiB
JavaScript
98 lines
3.4 KiB
JavaScript
"use strict";
|
|
|
|
ChromeUtils.defineModuleGetter(this, "TelemetryController",
|
|
"resource://gre/modules/TelemetryController.jsm");
|
|
ChromeUtils.defineModuleGetter(this, "TelemetryUtils",
|
|
"resource://gre/modules/TelemetryUtils.jsm");
|
|
ChromeUtils.defineModuleGetter(this, "Services",
|
|
"resource://gre/modules/Services.jsm");
|
|
ChromeUtils.defineModuleGetter(this, "ExtensionUtils",
|
|
"resource://gre/modules/ExtensionUtils.jsm");
|
|
|
|
const SCALAR_TYPES = {
|
|
count: Ci.nsITelemetry.SCALAR_TYPE_COUNT,
|
|
string: Ci.nsITelemetry.SCALAR_TYPE_STRING,
|
|
boolean: Ci.nsITelemetry.SCALAR_TYPE_BOOLEAN,
|
|
};
|
|
|
|
this.telemetry = class extends ExtensionAPI {
|
|
getAPI(context) {
|
|
return {
|
|
telemetry: {
|
|
submitPing(type, payload, options) {
|
|
try {
|
|
TelemetryController.submitExternalPing(type, payload, options);
|
|
} catch (ex) {
|
|
throw new ExtensionUtils.ExtensionError(ex);
|
|
}
|
|
},
|
|
canUpload() {
|
|
// Note: remove the ternary and direct pref check when
|
|
// TelemetryController.canUpload() is implemented (bug 1440089).
|
|
try {
|
|
const result = ("canUpload" in TelemetryController) ?
|
|
TelemetryController.canUpload() :
|
|
Services.prefs.getBoolPref(TelemetryUtils.Preferences.FhrUploadEnabled, false);
|
|
return result;
|
|
} catch (ex) {
|
|
throw new ExtensionUtils.ExtensionError(ex);
|
|
}
|
|
},
|
|
scalarAdd(name, value) {
|
|
try {
|
|
Services.telemetry.scalarAdd(name, value);
|
|
} catch (ex) {
|
|
throw new ExtensionUtils.ExtensionError(ex);
|
|
}
|
|
},
|
|
scalarSet(name, value) {
|
|
try {
|
|
Services.telemetry.scalarSet(name, value);
|
|
} catch (ex) {
|
|
throw new ExtensionUtils.ExtensionError(ex);
|
|
}
|
|
},
|
|
scalarSetMaximum(name, value) {
|
|
try {
|
|
Services.telemetry.scalarSetMaximum(name, value);
|
|
} catch (ex) {
|
|
throw new ExtensionUtils.ExtensionError(ex);
|
|
}
|
|
},
|
|
recordEvent(category, method, object, value, extra) {
|
|
try {
|
|
Services.telemetry.recordEvent(category, method, object, value, extra);
|
|
} catch (ex) {
|
|
throw new ExtensionUtils.ExtensionError(ex);
|
|
}
|
|
},
|
|
registerScalars(category, data) {
|
|
try {
|
|
// For each scalar in `data`, replace scalar.kind with
|
|
// the appropriate nsITelemetry constant.
|
|
Object.keys(data).forEach(scalar => {
|
|
data[scalar].kind = SCALAR_TYPES[data[scalar].kind];
|
|
});
|
|
Services.telemetry.registerScalars(category, data);
|
|
} catch (ex) {
|
|
throw new ExtensionUtils.ExtensionError(ex);
|
|
}
|
|
},
|
|
setEventRecordingEnabled(category, enabled) {
|
|
try {
|
|
Services.telemetry.setEventRecordingEnabled(category, enabled);
|
|
} catch (ex) {
|
|
throw new ExtensionUtils.ExtensionError(ex);
|
|
}
|
|
},
|
|
registerEvents(category, data) {
|
|
try {
|
|
Services.telemetry.registerEvents(category, data);
|
|
} catch (ex) {
|
|
throw new ExtensionUtils.ExtensionError(ex);
|
|
}
|
|
},
|
|
},
|
|
};
|
|
}
|
|
};
|