26 Components.utils.import(
"resource://gre/modules/XPCOMUtils.jsm");
39 this.
prefs = Components.classes[
"@mozilla.org/preferences-service;1"]
40 .getService(Components.interfaces.nsIPrefBranch);
49 Components.interfaces.nsIWebProgressListener,
50 Components.interfaces.nsISupportsWeakReference
57 [
new RegExp(/^firstrun\.mediaimport\.(.+)$/g),
58 "install",
"first run media import"],
59 [
new RegExp(/^app\.appstart$/g),
61 [
new RegExp(/^mediacore\.play\.attempt\.(.+)$/g),
62 "usage",
"media playback"],
66 var consoleService = Components.classes[
'@mozilla.org/consoleservice;1']
67 .getService(Components.interfaces.nsIConsoleService);
68 consoleService.logStringMessage(
str);
75 checkUploadMetrics:
function()
77 if (!this._isEnabled())
return;
79 var timeUp = this._isWaitPeriodUp();
92 uploadMetrics:
function()
94 var user_install_uuid = this._getPlayerUUID();
96 var xulRuntime = Components.classes[
"@mozilla.org/xre/runtime;1"].getService(Components.interfaces.nsIXULRuntime);
97 var user_os = xulRuntime.OS;
100 var metrics = this._getTable();
102 var appInfo = Components.classes[
"@mozilla.org/xre/app-info;1"].getService(Components.interfaces.nsIXULAppInfo);
108 abi = appInfo.XPCOMABI;
114 var macutils = Components.classes[
"@mozilla.org/xpcom/mac-utils;1"]
115 .getService(Components.interfaces.nsIMacUtils);
116 if (macutils.isUniversalBinary) abi =
"Universal-gcc3";
120 var platform = appInfo.OS +
"_" + abi;
125 var tzh = Math.floor(tzo / 60);
126 var tzm = tzo - (tzh*60);
131 var tz = (neg ?
"+" :
"-") + this.formatDigits(tzh,2) +
":" + this.formatDigits(tzm,2);
135 for (var
i = 0;
i < metrics.length;
i++)
137 var
key = metrics[
i][0];
138 var
val = metrics[
i][1];
141 var dot = key.indexOf(
".");
143 var timestamp = key.substr(0, dot);
144 var cleanKey = key.substr(dot + 1);
153 handleEvent:
function(
event ) { this._that.onGetLoad(); }
155 ongetload._that =
this;
159 handleEvent:
function(
event ) { this._that.onGetError(); }
161 ongeterror._that =
this;
163 var getURL =
"http://www.google-analytics.com/__ga.gif?";
173 formatDigits:
function(
str, n) {
179 onGetLoad:
function() {
180 this.
LOG(
"GET metrics done: " + this._getreq.status +
" - " +
this._getreq.responseText);
183 if (this._getreq.status == 200 &&
this._getreq.responseText ==
"OK")
186 var
pref = Components.classes[
"@mozilla.org/preferences-service;1"]
187 .getService(Components.interfaces.nsIPrefBranch);
188 var timenow =
new Date();
189 var
now = timenow.getTime();
191 pref.setCharPref(
"app.metrics.last_upload", now);
192 pref.setCharPref(
"app.metrics.last_version", this._getCurrentVersion());
193 pref.setIntPref(
"app.metrics.last_update_count", this._getUpdateCount());
195 this.
LOG(
"metrics reset");
199 this.
LOG(
"GET metrics failed: " + this._getreq.responseText);
203 onGetError:
function() {
204 this.
LOG(
"GET metrics error");
213 _isEnabled:
function() {
218 enabled = parseInt(this.
prefs.getCharPref(
"app.metrics.enabled"));
231 _isWaitPeriodUp:
function() {
233 var timenow =
new Date();
234 var now = timenow.getTime();
238 last = parseInt(this.
prefs.getCharPref(
"app.metrics.last_upload"));
243 this.
prefs.setCharPref(
"app.metrics.last_upload", now);
247 var diff = now - last;
256 _hasVersionChanged:
function() {
258 var upgraded =
false;
260 var currentVersion = this._getCurrentVersion();
261 var lastVersion =
null;
265 lastVersion = this.
prefs.getCharPref(
"app.metrics.last_version");
269 if (currentVersion != lastVersion)
280 _getCurrentVersion:
function() {
282 var appInfo = Components.classes[
"@mozilla.org/xre/app-info;1"].getService(Components.interfaces.nsIXULAppInfo);
283 return appInfo.name +
" " + appInfo.version +
" - " + appInfo.appBuildID;
290 _getUpdateCount:
function() {
291 var updateManager = Components.classes[
"@mozilla.org/updates/update-manager;1"].getService(Components.interfaces.nsIUpdateManager);
292 return updateManager.updateCount;
299 _getPlayerUUID:
function() {
305 uuid = this.
prefs.getCharPref(
"app.player_uuid");
314 var aUUIDGenerator = Components.classes[
"@mozilla.org/uuid-generator;1"].createInstance(Components.interfaces.nsIUUIDGenerator);
315 uuid = aUUIDGenerator.generateUUID();
316 this.
prefs.setCharPref(
"app.player_uuid", uuid);
317 uuid = this.
prefs.getCharPref(
"app.player_uuid");
323 metricsInc:
function( aCategory, aUniqueID, aExtraString ) {
324 this.metricsAdd( aCategory, aUniqueID, aExtraString, 1 );
327 metricsAdd:
function( aCategory, aUniqueID, aExtraString, aIntValue ) {
328 var
gPrompt = Components.classes[
"@mozilla.org/embedcomp/prompt-service;1"]
329 .getService(Components.interfaces.nsIPromptService);
332 var key = aCategory +
"." + aUniqueID;
333 if (aExtraString !=
null && aExtraString !=
"") key = key +
"." + aExtraString;
335 var eventCode =
null;
336 for(var iPattern = 0; iPattern < this._eventMatchArray.length; iPattern++ ) {
337 var
match = this._eventMatchArray[iPattern][0].exec(key);
338 if(match && (match.length > 0) && (match[0] == key)) {
339 eventCode =
"5({0}*{1}*{2})(1)";
340 eventCode = eventCode.replace(
"{0}", this._eventMatchArray[iPattern][1]);
341 eventCode = eventCode.replace(
"{1}", this._eventMatchArray[iPattern][2]);
342 eventCode = eventCode.replace(
"{2}", (match.length > 1) ? match[1] :
"");
355 var timestamp = (Math.floor(d.getTime() / 3600000) * 3600) + (d.getTimezoneOffset() * 60);
357 var gaCompliantUUID = this._getPlayerUUID().replace(/[{}-]/g,
"");
360 this._gaHash(
"songbirdnest.com"),
361 this._gaHash(gaCompliantUUID),
362 timestamp,timestamp,timestamp,
365 var rand = Math.floor(Math.random()*1000000000);
370 "utmac=" + gaPropKey,
371 "utmcc=__utma%3D" + cookie,
380 var getURL =
"http://www.google-analytics.com/__utm.gif?"
383 this._getreq = Components.classes[
"@mozilla.org/xmlextras/xmlhttprequest;1"]
384 .createInstance(Components.interfaces.nsIXMLHttpRequest);
385 this._getreq.open(
'GET', getURL,
false);
386 this._getreq.send(
null);
389 _initDB:
function() {
390 if (!this._dbquery) {
391 this._dbquery = Components.classes[
"@songbirdnest.com/Songbird/DatabaseQuery;1"].
393 this._dbquery.setAsyncQuery(
false);
394 this._dbquery.setDatabaseGUID(
"metrics");
395 this._dbquery.resetQuery();
396 this._dbquery.addQuery(
"CREATE TABLE IF NOT EXISTS metrics (keyname TEXT UNIQUE NOT NULL, keyvalue BIGINT DEFAULT 0)");
397 this._dbquery.execute();
401 _getValue:
function(
key) {
405 this._dbquery.resetQuery();
407 this._dbquery.addQuery(
"SELECT * FROM metrics WHERE keyname = \"" + key +
"\"");
408 this._dbquery.execute();
410 var dbresult = this._dbquery.getResultObject();
411 if (dbresult.getRowCount() > 0) {
412 retval = parseInt(dbresult.getRowCell(0, 1));
418 _setValue:
function(
key, n) {
420 this._dbquery.resetQuery();
421 this._dbquery.addQuery(
"INSERT OR REPLACE INTO metrics VALUES (\"" + key +
"\", " + n +
")");
422 this._dbquery.execute();
425 _getTable:
function() {
426 var table =
new Array();
428 this._dbquery.resetQuery();
429 this._dbquery.addQuery(
"SELECT * FROM metrics");
430 this._dbquery.execute();
432 var dbresult = this._dbquery.getResultObject();
433 var
count = dbresult.getRowCount();
436 var key = dbresult.getRowCell(
i, 0);
437 var val = parseInt(dbresult.getRowCell(
i, 1));
438 table.push([key, val]);
444 _emptyTable:
function() {
446 this._dbquery.resetQuery();
447 this._dbquery.addQuery(
"DELETE FROM metrics");
448 this._dbquery.execute();
451 _gaHash :
function(aString) {
458 for( charIndex = aString[
"length"]-1; charIndex>=0; charIndex--) {
459 charCode = aString.charCodeAt(charIndex);
460 result = (result<<6&268435455)+charCode+(charCode<<14);
461 partial = result&266338304;
462 result = (partial!=0) ? result^partial>>21 : result;
470 return XPCOMUtils.generateModule([
Metrics]);
const SONGBIRD_METRICS_CID
sbDeviceFirmwareAutoCheckForUpdate prototype contractID
const SONGBIRD_METRICS_GA_PROPERTYKEY
const SONGBIRD_METRICS_CONTRACTID
sbOSDControlService prototype QueryInterface
sbDeviceFirmwareAutoCheckForUpdate prototype classDescription
iso8601Week date date date getTimezoneOffset()/-60))
const SONGBIRD_METRICS_IID
const SONGBIRD_METRICS_GA_PROPERTYDEF
this _dialogInput val(dateText)
ExtensionSchemeMatcher prototype match
const SONGBIRD_METRICS_CLASSNAME
sbDeviceFirmwareAutoCheckForUpdate prototype classID
const SONGBIRD_UPLOAD_METRICS_EVERY_NDAYS
_getSelectedPageStyle s i