1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
8 function debug(s) { dump("-*- NetworkStatsServiceProxy: " + s + "\n"); }
10 const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
12 this.EXPORTED_SYMBOLS = ["NetworkStatsServiceProxy"];
14 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
15 Cu.import("resource://gre/modules/NetworkStatsService.jsm");
17 const NETWORKSTATSSERVICEPROXY_CONTRACTID = "@mozilla.org/networkstatsServiceProxy;1";
18 const NETWORKSTATSSERVICEPROXY_CID = Components.ID("98fd8f69-784e-4626-aa59-56d6436a3c24");
19 const nsINetworkStatsServiceProxy = Ci.nsINetworkStatsServiceProxy;
21 function NetworkStatsServiceProxy() {
23 debug("Proxy started");
27 NetworkStatsServiceProxy.prototype = {
29 * Function called in the protocol layer (HTTP, FTP, WebSocket ...etc)
30 * to pass the per-app stats to NetworkStatsService.
32 saveAppStats: function saveAppStats(aAppId, aIsInBrowser, aNetwork, aTimeStamp,
33 aRxBytes, aTxBytes, aIsAccumulative,
37 debug("|aNetwork| is not specified. Failed to save stats. Returning.");
43 debug("saveAppStats: " + aAppId + " " + aIsInBrowser + " " +
44 aNetwork.type + " " + aTimeStamp + " " +
45 aRxBytes + " " + aTxBytes + " " + aIsAccumulative);
49 aCallback = aCallback.notify;
52 NetworkStatsService.saveStats(aAppId, aIsInBrowser, "", aNetwork,
53 aTimeStamp, aRxBytes, aTxBytes,
54 aIsAccumulative, aCallback);
58 * Function called in the points of different system services
59 * to pass the per-service stats to NetworkStatsService.
61 saveServiceStats: function saveServiceStats(aServiceType, aNetwork,
62 aTimeStamp, aRxBytes, aTxBytes,
63 aIsAccumulative, aCallback) {
66 debug("|aNetwork| is not specified. Failed to save stats. Returning.");
72 debug("saveServiceStats: " + aServiceType + " " + aNetwork.type + " " +
73 aTimeStamp + " " + aRxBytes + " " + aTxBytes + " " +
78 aCallback = aCallback.notify;
81 NetworkStatsService.saveStats(0, false, aServiceType ,aNetwork, aTimeStamp,
82 aRxBytes, aTxBytes, aIsAccumulative,
86 classID : NETWORKSTATSSERVICEPROXY_CID,
87 QueryInterface : XPCOMUtils.generateQI([nsINetworkStatsServiceProxy]),
90 this.NSGetFactory = XPCOMUtils.generateNSGetFactory([NetworkStatsServiceProxy]);