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("705c01d6-8574-464c-8ec9-ac1522a45546");
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, aNetwork, aTimeStamp,
33 aRxBytes, aTxBytes, aIsAccumulative,
37 debug("|aNetwork| is not specified. Failed to save stats. Returning.");
43 debug("saveAppStats: " + aAppId + " " + aNetwork.type + " " + aTimeStamp +
44 " " + aRxBytes + " " + aTxBytes + " " + aIsAccumulative);
48 aCallback = aCallback.notify;
51 NetworkStatsService.saveStats(aAppId, "", aNetwork, aTimeStamp,
52 aRxBytes, aTxBytes, aIsAccumulative,
57 * Function called in the points of different system services
58 * to pass the per-serive stats to NetworkStatsService.
60 saveServiceStats: function saveServiceStats(aServiceType, aNetwork,
61 aTimeStamp, aRxBytes, aTxBytes,
62 aIsAccumulative, aCallback) {
65 debug("|aNetwork| is not specified. Failed to save stats. Returning.");
71 debug("saveServiceStats: " + aServiceType + " " + aNetwork.type + " " +
72 aTimeStamp + " " + aRxBytes + " " + aTxBytes + " " +
77 aCallback = aCallback.notify;
80 NetworkStatsService.saveStats(0, aServiceType ,aNetwork, aTimeStamp,
81 aRxBytes, aTxBytes, aIsAccumulative,
85 classID : NETWORKSTATSSERVICEPROXY_CID,
86 QueryInterface : XPCOMUtils.generateQI([nsINetworkStatsServiceProxy]),
89 this.NSGetFactory = XPCOMUtils.generateNSGetFactory([NetworkStatsServiceProxy]);