Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
michael@0 | 3 | * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | "use strict"; |
michael@0 | 6 | |
michael@0 | 7 | const DEBUG = false; |
michael@0 | 8 | function debug(s) { dump("-*- NetworkStatsServiceProxy: " + s + "\n"); } |
michael@0 | 9 | |
michael@0 | 10 | const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components; |
michael@0 | 11 | |
michael@0 | 12 | this.EXPORTED_SYMBOLS = ["NetworkStatsServiceProxy"]; |
michael@0 | 13 | |
michael@0 | 14 | Cu.import("resource://gre/modules/XPCOMUtils.jsm"); |
michael@0 | 15 | Cu.import("resource://gre/modules/NetworkStatsService.jsm"); |
michael@0 | 16 | |
michael@0 | 17 | const NETWORKSTATSSERVICEPROXY_CONTRACTID = "@mozilla.org/networkstatsServiceProxy;1"; |
michael@0 | 18 | const NETWORKSTATSSERVICEPROXY_CID = Components.ID("705c01d6-8574-464c-8ec9-ac1522a45546"); |
michael@0 | 19 | const nsINetworkStatsServiceProxy = Ci.nsINetworkStatsServiceProxy; |
michael@0 | 20 | |
michael@0 | 21 | function NetworkStatsServiceProxy() { |
michael@0 | 22 | if (DEBUG) { |
michael@0 | 23 | debug("Proxy started"); |
michael@0 | 24 | } |
michael@0 | 25 | } |
michael@0 | 26 | |
michael@0 | 27 | NetworkStatsServiceProxy.prototype = { |
michael@0 | 28 | /* |
michael@0 | 29 | * Function called in the protocol layer (HTTP, FTP, WebSocket ...etc) |
michael@0 | 30 | * to pass the per-app stats to NetworkStatsService. |
michael@0 | 31 | */ |
michael@0 | 32 | saveAppStats: function saveAppStats(aAppId, aNetwork, aTimeStamp, |
michael@0 | 33 | aRxBytes, aTxBytes, aIsAccumulative, |
michael@0 | 34 | aCallback) { |
michael@0 | 35 | if (!aNetwork) { |
michael@0 | 36 | if (DEBUG) { |
michael@0 | 37 | debug("|aNetwork| is not specified. Failed to save stats. Returning."); |
michael@0 | 38 | } |
michael@0 | 39 | return; |
michael@0 | 40 | } |
michael@0 | 41 | |
michael@0 | 42 | if (DEBUG) { |
michael@0 | 43 | debug("saveAppStats: " + aAppId + " " + aNetwork.type + " " + aTimeStamp + |
michael@0 | 44 | " " + aRxBytes + " " + aTxBytes + " " + aIsAccumulative); |
michael@0 | 45 | } |
michael@0 | 46 | |
michael@0 | 47 | if (aCallback) { |
michael@0 | 48 | aCallback = aCallback.notify; |
michael@0 | 49 | } |
michael@0 | 50 | |
michael@0 | 51 | NetworkStatsService.saveStats(aAppId, "", aNetwork, aTimeStamp, |
michael@0 | 52 | aRxBytes, aTxBytes, aIsAccumulative, |
michael@0 | 53 | aCallback); |
michael@0 | 54 | }, |
michael@0 | 55 | |
michael@0 | 56 | /* |
michael@0 | 57 | * Function called in the points of different system services |
michael@0 | 58 | * to pass the per-serive stats to NetworkStatsService. |
michael@0 | 59 | */ |
michael@0 | 60 | saveServiceStats: function saveServiceStats(aServiceType, aNetwork, |
michael@0 | 61 | aTimeStamp, aRxBytes, aTxBytes, |
michael@0 | 62 | aIsAccumulative, aCallback) { |
michael@0 | 63 | if (!aNetwork) { |
michael@0 | 64 | if (DEBUG) { |
michael@0 | 65 | debug("|aNetwork| is not specified. Failed to save stats. Returning."); |
michael@0 | 66 | } |
michael@0 | 67 | return; |
michael@0 | 68 | } |
michael@0 | 69 | |
michael@0 | 70 | if (DEBUG) { |
michael@0 | 71 | debug("saveServiceStats: " + aServiceType + " " + aNetwork.type + " " + |
michael@0 | 72 | aTimeStamp + " " + aRxBytes + " " + aTxBytes + " " + |
michael@0 | 73 | aIsAccumulative); |
michael@0 | 74 | } |
michael@0 | 75 | |
michael@0 | 76 | if (aCallback) { |
michael@0 | 77 | aCallback = aCallback.notify; |
michael@0 | 78 | } |
michael@0 | 79 | |
michael@0 | 80 | NetworkStatsService.saveStats(0, aServiceType ,aNetwork, aTimeStamp, |
michael@0 | 81 | aRxBytes, aTxBytes, aIsAccumulative, |
michael@0 | 82 | aCallback); |
michael@0 | 83 | }, |
michael@0 | 84 | |
michael@0 | 85 | classID : NETWORKSTATSSERVICEPROXY_CID, |
michael@0 | 86 | QueryInterface : XPCOMUtils.generateQI([nsINetworkStatsServiceProxy]), |
michael@0 | 87 | } |
michael@0 | 88 | |
michael@0 | 89 | this.NSGetFactory = XPCOMUtils.generateNSGetFactory([NetworkStatsServiceProxy]); |