Bumping gaia.json for 1 gaia revision(s) a=gaia-bump
[gecko.git] / dom / network / NetworkStatsServiceProxy.js
blob8586cd4bad9db799f67c1ae96436c7f13d0bf6f9
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("705c01d6-8574-464c-8ec9-ac1522a45546");
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, 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 + " " + aNetwork.type + " " + aTimeStamp +
44             " " + aRxBytes + " " + aTxBytes + " " + aIsAccumulative);
45     }
47     if (aCallback) {
48       aCallback = aCallback.notify;
49     }
51     NetworkStatsService.saveStats(aAppId, "", aNetwork, aTimeStamp,
52                                   aRxBytes, aTxBytes, aIsAccumulative,
53                                   aCallback);
54   },
56   /*
57    * Function called in the points of different system services
58    * to pass the per-serive stats to NetworkStatsService.
59    */
60   saveServiceStats: function saveServiceStats(aServiceType, aNetwork,
61                                               aTimeStamp, aRxBytes, aTxBytes,
62                                               aIsAccumulative, aCallback) {
63     if (!aNetwork) {
64       if (DEBUG) {
65         debug("|aNetwork| is not specified. Failed to save stats. Returning.");
66       }
67       return;
68     }
70     if (DEBUG) {
71       debug("saveServiceStats: " + aServiceType + " " + aNetwork.type + " " +
72             aTimeStamp + " " + aRxBytes + " " + aTxBytes + " " +
73             aIsAccumulative);
74     }
76     if (aCallback) {
77       aCallback = aCallback.notify;
78     }
80     NetworkStatsService.saveStats(0, aServiceType ,aNetwork, aTimeStamp,
81                                   aRxBytes, aTxBytes, aIsAccumulative,
82                                   aCallback);
83   },
85   classID : NETWORKSTATSSERVICEPROXY_CID,
86   QueryInterface : XPCOMUtils.generateQI([nsINetworkStatsServiceProxy]),
89 this.NSGetFactory = XPCOMUtils.generateNSGetFactory([NetworkStatsServiceProxy]);