Publish Vulpes Preview 15 sources for desktop, Android and Tundra
Share Gaia assets and adapters, keep private profiles and development documents local, and update both public READMEs.
This commit is contained in:
parent
93e3a48004
commit
b38dea0597
25901 changed files with 9982925 additions and 369 deletions
52
gaia/shared/js/metrics_helper.js
Executable file
52
gaia/shared/js/metrics_helper.js
Executable file
|
|
@ -0,0 +1,52 @@
|
|||
/**
|
||||
* This module is a helper class for modules that want to report metrics for
|
||||
* transmission to the telemetry server for collection. This module handles the
|
||||
* details of creating an iac port for connection to the AppUsageMetrics
|
||||
* module and handles the details of reporting a message to AppUsageMetrics.
|
||||
*
|
||||
* Usage:
|
||||
* -To initialize the module: MetricsHelper.init();
|
||||
* -To report metrics:
|
||||
* MetricsHelper.report({action: 'your action', data: 'your data'});
|
||||
* Note that this needs to be hooked up on AppUsageMetrics to deliver anything
|
||||
* meaningful to the Telemetry Server.
|
||||
*
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
(function(exports) {
|
||||
|
||||
function MetricsHelper() {
|
||||
this._portMetrics = null;
|
||||
this._initialized = false;
|
||||
}
|
||||
|
||||
MetricsHelper.prototype = {
|
||||
init: function () {
|
||||
var self = this;
|
||||
// Initialize the port for connecting to the system app to report metrics.
|
||||
navigator.mozApps.getSelf().onsuccess = function () {
|
||||
var app = this.result;
|
||||
app.connect('app-metrics').then(function onConnAccepted(ports) {
|
||||
if (ports.length > 0) {
|
||||
self._portMetrics = ports[0];
|
||||
self._initialized = true;
|
||||
}
|
||||
}, function onConnectionRejected(reason) {
|
||||
console.log('Error connecting: ' + reason + '\n');
|
||||
});
|
||||
};
|
||||
},
|
||||
|
||||
report: function (action, data) {
|
||||
if (this._initialized) {
|
||||
this._portMetrics.postMessage({
|
||||
'action': action,
|
||||
'data': data
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
exports.MetricsHelper = MetricsHelper;
|
||||
})(window);
|
||||
Loading…
Reference in a new issue