michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: "use strict"; michael@0: michael@0: const DEBUG = false; michael@0: function debug(s) { dump("-*- NetworkStatsServiceProxy: " + s + "\n"); } michael@0: michael@0: const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components; michael@0: michael@0: this.EXPORTED_SYMBOLS = ["NetworkStatsServiceProxy"]; michael@0: michael@0: Cu.import("resource://gre/modules/XPCOMUtils.jsm"); michael@0: Cu.import("resource://gre/modules/NetworkStatsService.jsm"); michael@0: michael@0: const NETWORKSTATSSERVICEPROXY_CONTRACTID = "@mozilla.org/networkstatsServiceProxy;1"; michael@0: const NETWORKSTATSSERVICEPROXY_CID = Components.ID("705c01d6-8574-464c-8ec9-ac1522a45546"); michael@0: const nsINetworkStatsServiceProxy = Ci.nsINetworkStatsServiceProxy; michael@0: michael@0: function NetworkStatsServiceProxy() { michael@0: if (DEBUG) { michael@0: debug("Proxy started"); michael@0: } michael@0: } michael@0: michael@0: NetworkStatsServiceProxy.prototype = { michael@0: /* michael@0: * Function called in the protocol layer (HTTP, FTP, WebSocket ...etc) michael@0: * to pass the per-app stats to NetworkStatsService. michael@0: */ michael@0: saveAppStats: function saveAppStats(aAppId, aNetwork, aTimeStamp, michael@0: aRxBytes, aTxBytes, aIsAccumulative, michael@0: aCallback) { michael@0: if (!aNetwork) { michael@0: if (DEBUG) { michael@0: debug("|aNetwork| is not specified. Failed to save stats. Returning."); michael@0: } michael@0: return; michael@0: } michael@0: michael@0: if (DEBUG) { michael@0: debug("saveAppStats: " + aAppId + " " + aNetwork.type + " " + aTimeStamp + michael@0: " " + aRxBytes + " " + aTxBytes + " " + aIsAccumulative); michael@0: } michael@0: michael@0: if (aCallback) { michael@0: aCallback = aCallback.notify; michael@0: } michael@0: michael@0: NetworkStatsService.saveStats(aAppId, "", aNetwork, aTimeStamp, michael@0: aRxBytes, aTxBytes, aIsAccumulative, michael@0: aCallback); michael@0: }, michael@0: michael@0: /* michael@0: * Function called in the points of different system services michael@0: * to pass the per-serive stats to NetworkStatsService. michael@0: */ michael@0: saveServiceStats: function saveServiceStats(aServiceType, aNetwork, michael@0: aTimeStamp, aRxBytes, aTxBytes, michael@0: aIsAccumulative, aCallback) { michael@0: if (!aNetwork) { michael@0: if (DEBUG) { michael@0: debug("|aNetwork| is not specified. Failed to save stats. Returning."); michael@0: } michael@0: return; michael@0: } michael@0: michael@0: if (DEBUG) { michael@0: debug("saveServiceStats: " + aServiceType + " " + aNetwork.type + " " + michael@0: aTimeStamp + " " + aRxBytes + " " + aTxBytes + " " + michael@0: aIsAccumulative); michael@0: } michael@0: michael@0: if (aCallback) { michael@0: aCallback = aCallback.notify; michael@0: } michael@0: michael@0: NetworkStatsService.saveStats(0, aServiceType ,aNetwork, aTimeStamp, michael@0: aRxBytes, aTxBytes, aIsAccumulative, michael@0: aCallback); michael@0: }, michael@0: michael@0: classID : NETWORKSTATSSERVICEPROXY_CID, michael@0: QueryInterface : XPCOMUtils.generateQI([nsINetworkStatsServiceProxy]), michael@0: } michael@0: michael@0: this.NSGetFactory = XPCOMUtils.generateNSGetFactory([NetworkStatsServiceProxy]);