2013-08-14 10:05:35 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const DEBUG = false;
|
|
|
|
function debug(s) { dump("-*- NetworkStatsServiceProxy: " + s + "\n"); }
|
|
|
|
|
|
|
|
const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
|
|
|
|
|
|
|
|
this.EXPORTED_SYMBOLS = ["NetworkStatsServiceProxy"];
|
|
|
|
|
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
|
|
|
Cu.import("resource://gre/modules/NetworkStatsService.jsm");
|
|
|
|
|
|
|
|
const NETWORKSTATSSERVICEPROXY_CONTRACTID = "@mozilla.org/networkstatsServiceProxy;1";
|
2015-01-27 09:15:44 +00:00
|
|
|
const NETWORKSTATSSERVICEPROXY_CID = Components.ID("98fd8f69-784e-4626-aa59-56d6436a3c24");
|
2013-08-14 10:05:35 +00:00
|
|
|
const nsINetworkStatsServiceProxy = Ci.nsINetworkStatsServiceProxy;
|
|
|
|
|
|
|
|
function NetworkStatsServiceProxy() {
|
|
|
|
if (DEBUG) {
|
|
|
|
debug("Proxy started");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NetworkStatsServiceProxy.prototype = {
|
|
|
|
/*
|
|
|
|
* Function called in the protocol layer (HTTP, FTP, WebSocket ...etc)
|
|
|
|
* to pass the per-app stats to NetworkStatsService.
|
|
|
|
*/
|
2016-02-18 02:55:57 +00:00
|
|
|
saveAppStats: function saveAppStats(aAppId, aIsInIsolatedMozBrowser, aNetworkInfo, aTimeStamp,
|
2013-11-15 03:29:54 +00:00
|
|
|
aRxBytes, aTxBytes, aIsAccumulative,
|
|
|
|
aCallback) {
|
2015-07-29 06:15:00 +00:00
|
|
|
if (!aNetworkInfo) {
|
2013-10-30 06:55:28 +00:00
|
|
|
if (DEBUG) {
|
2015-07-29 06:15:00 +00:00
|
|
|
debug("|aNetworkInfo| is not specified. Failed to save stats. Returning.");
|
2013-10-30 06:55:28 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-08-14 10:05:35 +00:00
|
|
|
if (DEBUG) {
|
2016-02-18 02:55:57 +00:00
|
|
|
debug("saveAppStats: " + aAppId + " " + aIsInIsolatedMozBrowser + " " +
|
2015-07-29 06:15:00 +00:00
|
|
|
aNetworkInfo.type + " " + aTimeStamp + " " +
|
2015-01-27 09:15:44 +00:00
|
|
|
aRxBytes + " " + aTxBytes + " " + aIsAccumulative);
|
2013-08-14 10:05:35 +00:00
|
|
|
}
|
|
|
|
|
2014-03-04 07:58:08 +00:00
|
|
|
if (aCallback) {
|
|
|
|
aCallback = aCallback.notify;
|
|
|
|
}
|
|
|
|
|
2016-02-18 02:55:57 +00:00
|
|
|
NetworkStatsService.saveStats(aAppId, aIsInIsolatedMozBrowser, "", aNetworkInfo,
|
2015-01-27 09:15:44 +00:00
|
|
|
aTimeStamp, aRxBytes, aTxBytes,
|
|
|
|
aIsAccumulative, aCallback);
|
2013-11-15 03:29:54 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Function called in the points of different system services
|
2015-01-27 09:15:44 +00:00
|
|
|
* to pass the per-service stats to NetworkStatsService.
|
2013-11-15 03:29:54 +00:00
|
|
|
*/
|
2015-07-29 06:15:00 +00:00
|
|
|
saveServiceStats: function saveServiceStats(aServiceType, aNetworkInfo,
|
2013-11-15 03:29:54 +00:00
|
|
|
aTimeStamp, aRxBytes, aTxBytes,
|
|
|
|
aIsAccumulative, aCallback) {
|
2015-07-29 06:15:00 +00:00
|
|
|
if (!aNetworkInfo) {
|
2013-11-15 03:29:54 +00:00
|
|
|
if (DEBUG) {
|
2015-07-29 06:15:00 +00:00
|
|
|
debug("|aNetworkInfo| is not specified. Failed to save stats. Returning.");
|
2013-11-15 03:29:54 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (DEBUG) {
|
2015-07-29 06:15:00 +00:00
|
|
|
debug("saveServiceStats: " + aServiceType + " " + aNetworkInfo.type + " " +
|
2013-11-15 03:29:54 +00:00
|
|
|
aTimeStamp + " " + aRxBytes + " " + aTxBytes + " " +
|
|
|
|
aIsAccumulative);
|
|
|
|
}
|
|
|
|
|
2014-03-04 07:58:08 +00:00
|
|
|
if (aCallback) {
|
|
|
|
aCallback = aCallback.notify;
|
|
|
|
}
|
|
|
|
|
2015-07-29 06:15:00 +00:00
|
|
|
NetworkStatsService.saveStats(0, false, aServiceType , aNetworkInfo, aTimeStamp,
|
2013-11-15 03:29:54 +00:00
|
|
|
aRxBytes, aTxBytes, aIsAccumulative,
|
|
|
|
aCallback);
|
2013-08-14 10:05:35 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
classID : NETWORKSTATSSERVICEPROXY_CID,
|
|
|
|
QueryInterface : XPCOMUtils.generateQI([nsINetworkStatsServiceProxy]),
|
|
|
|
}
|
|
|
|
|
|
|
|
this.NSGetFactory = XPCOMUtils.generateNSGetFactory([NetworkStatsServiceProxy]);
|