Bumping manifests a=b2g-bump
[gecko.git] / dom / network / NetworkStatsServiceProxy.js
blob2990c1f349df20b117e7ee5a0428f3b6b610686a
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/. */
5 "use strict";
7 const DEBUG = false;
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() {
22   if (DEBUG) {
23     debug("Proxy started");
24   }
27 NetworkStatsServiceProxy.prototype = {
28   /*
29    * Function called in the protocol layer (HTTP, FTP, WebSocket ...etc)
30    * to pass the per-app stats to NetworkStatsService.
31    */
32   saveAppStats: function saveAppStats(aAppId, aIsInBrowser, aNetwork, aTimeStamp,
33                                       aRxBytes, aTxBytes, aIsAccumulative,
34                                       aCallback) {
35     if (!aNetwork) {
36       if (DEBUG) {
37         debug("|aNetwork| is not specified. Failed to save stats. Returning.");
38       }
39       return;
40     }
42     if (DEBUG) {
43       debug("saveAppStats: " + aAppId + " " + aIsInBrowser + " " +
44             aNetwork.type + " " + aTimeStamp + " " +
45             aRxBytes + " " + aTxBytes + " " + aIsAccumulative);
46     }
48     if (aCallback) {
49       aCallback = aCallback.notify;
50     }
52     NetworkStatsService.saveStats(aAppId, aIsInBrowser, "", aNetwork,
53                                   aTimeStamp, aRxBytes, aTxBytes,
54                                   aIsAccumulative, aCallback);
55   },
57   /*
58    * Function called in the points of different system services
59    * to pass the per-service stats to NetworkStatsService.
60    */
61   saveServiceStats: function saveServiceStats(aServiceType, aNetwork,
62                                               aTimeStamp, aRxBytes, aTxBytes,
63                                               aIsAccumulative, aCallback) {
64     if (!aNetwork) {
65       if (DEBUG) {
66         debug("|aNetwork| is not specified. Failed to save stats. Returning.");
67       }
68       return;
69     }
71     if (DEBUG) {
72       debug("saveServiceStats: " + aServiceType + " " + aNetwork.type + " " +
73             aTimeStamp + " " + aRxBytes + " " + aTxBytes + " " +
74             aIsAccumulative);
75     }
77     if (aCallback) {
78       aCallback = aCallback.notify;
79     }
81     NetworkStatsService.saveStats(0, false, aServiceType ,aNetwork, aTimeStamp,
82                                   aRxBytes, aTxBytes, aIsAccumulative,
83                                   aCallback);
84   },
86   classID : NETWORKSTATSSERVICEPROXY_CID,
87   QueryInterface : XPCOMUtils.generateQI([nsINetworkStatsServiceProxy]),
90 this.NSGetFactory = XPCOMUtils.generateNSGetFactory([NetworkStatsServiceProxy]);