mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1167132 - Part 14: [NetworkManager] Move network information into a separate interface (NetStats). r=ethan
This commit is contained in:
parent
1946d8f903
commit
8caf6fbd12
@ -26,8 +26,8 @@ const NET_NETWORKSTATSSERVICE_CID = Components.ID("{18725604-e9ac-488a-8aa0-2471
|
||||
const TOPIC_BANDWIDTH_CONTROL = "netd-bandwidth-control"
|
||||
|
||||
const TOPIC_CONNECTION_STATE_CHANGED = "network-connection-state-changed";
|
||||
const NET_TYPE_WIFI = Ci.nsINetworkInterface.NETWORK_TYPE_WIFI;
|
||||
const NET_TYPE_MOBILE = Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE;
|
||||
const NET_TYPE_WIFI = Ci.nsINetworkInfo.NETWORK_TYPE_WIFI;
|
||||
const NET_TYPE_MOBILE = Ci.nsINetworkInfo.NETWORK_TYPE_MOBILE;
|
||||
|
||||
// Networks have different status that NetworkStats API needs to be aware of.
|
||||
// Network is present and ready, so NetworkManager provides the whole info.
|
||||
@ -192,10 +192,10 @@ this.NetworkStatsService = {
|
||||
// the stats are updated for the new interface without waiting to
|
||||
// complete the updating period.
|
||||
|
||||
let network = aSubject.QueryInterface(Ci.nsINetworkInterface);
|
||||
debug("Network " + network.name + " of type " + network.type + " status change");
|
||||
let networkInfo = aSubject.QueryInterface(Ci.nsINetworkInfo);
|
||||
debug("Network " + networkInfo.name + " of type " + networkInfo.type + " status change");
|
||||
|
||||
let netId = this.convertNetworkInterface(network);
|
||||
let netId = this.convertNetworkInfo(networkInfo);
|
||||
if (!netId) {
|
||||
break;
|
||||
}
|
||||
@ -269,33 +269,33 @@ this.NetworkStatsService = {
|
||||
return networks;
|
||||
},
|
||||
|
||||
convertNetworkInterface: function(aNetwork) {
|
||||
if (aNetwork.type != NET_TYPE_MOBILE &&
|
||||
aNetwork.type != NET_TYPE_WIFI) {
|
||||
convertNetworkInfo: function(aNetworkInfo) {
|
||||
if (aNetworkInfo.type != NET_TYPE_MOBILE &&
|
||||
aNetworkInfo.type != NET_TYPE_WIFI) {
|
||||
return null;
|
||||
}
|
||||
|
||||
let id = '0';
|
||||
if (aNetwork.type == NET_TYPE_MOBILE) {
|
||||
if (!(aNetwork instanceof Ci.nsIRilNetworkInterface)) {
|
||||
debug("Error! Mobile network should be an nsIRilNetworkInterface!");
|
||||
if (aNetworkInfo.type == NET_TYPE_MOBILE) {
|
||||
if (!(aNetworkInfo instanceof Ci.nsIRilNetworkInfo)) {
|
||||
debug("Error! Mobile network should be an nsIRilNetworkInfo!");
|
||||
return null;
|
||||
}
|
||||
|
||||
let rilNetwork = aNetwork.QueryInterface(Ci.nsIRilNetworkInterface);
|
||||
let rilNetwork = aNetworkInfo.QueryInterface(Ci.nsIRilNetworkInfo);
|
||||
id = rilNetwork.iccId;
|
||||
}
|
||||
|
||||
let netId = this.getNetworkId(id, aNetwork.type);
|
||||
let netId = this.getNetworkId(id, aNetworkInfo.type);
|
||||
|
||||
if (!this._networks[netId]) {
|
||||
this._networks[netId] = Object.create(null);
|
||||
this._networks[netId].network = { id: id,
|
||||
type: aNetwork.type };
|
||||
type: aNetworkInfo.type };
|
||||
}
|
||||
|
||||
this._networks[netId].status = NETWORK_STATUS_READY;
|
||||
this._networks[netId].interfaceName = aNetwork.name;
|
||||
this._networks[netId].interfaceName = aNetworkInfo.name;
|
||||
return netId;
|
||||
},
|
||||
|
||||
@ -738,10 +738,10 @@ this.NetworkStatsService = {
|
||||
/*
|
||||
* Function responsible for receiving stats which are not from netd.
|
||||
*/
|
||||
saveStats: function saveStats(aAppId, aIsInBrowser, aServiceType, aNetwork,
|
||||
saveStats: function saveStats(aAppId, aIsInBrowser, aServiceType, aNetworkInfo,
|
||||
aTimeStamp, aRxBytes, aTxBytes, aIsAccumulative,
|
||||
aCallback) {
|
||||
let netId = this.convertNetworkInterface(aNetwork);
|
||||
let netId = this.convertNetworkInfo(aNetworkInfo);
|
||||
if (!netId) {
|
||||
if (aCallback) {
|
||||
aCallback(false, "Invalid network type");
|
||||
|
@ -29,19 +29,19 @@ NetworkStatsServiceProxy.prototype = {
|
||||
* Function called in the protocol layer (HTTP, FTP, WebSocket ...etc)
|
||||
* to pass the per-app stats to NetworkStatsService.
|
||||
*/
|
||||
saveAppStats: function saveAppStats(aAppId, aIsInBrowser, aNetwork, aTimeStamp,
|
||||
saveAppStats: function saveAppStats(aAppId, aIsInBrowser, aNetworkInfo, aTimeStamp,
|
||||
aRxBytes, aTxBytes, aIsAccumulative,
|
||||
aCallback) {
|
||||
if (!aNetwork) {
|
||||
if (!aNetworkInfo) {
|
||||
if (DEBUG) {
|
||||
debug("|aNetwork| is not specified. Failed to save stats. Returning.");
|
||||
debug("|aNetworkInfo| is not specified. Failed to save stats. Returning.");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (DEBUG) {
|
||||
debug("saveAppStats: " + aAppId + " " + aIsInBrowser + " " +
|
||||
aNetwork.type + " " + aTimeStamp + " " +
|
||||
aNetworkInfo.type + " " + aTimeStamp + " " +
|
||||
aRxBytes + " " + aTxBytes + " " + aIsAccumulative);
|
||||
}
|
||||
|
||||
@ -49,7 +49,7 @@ NetworkStatsServiceProxy.prototype = {
|
||||
aCallback = aCallback.notify;
|
||||
}
|
||||
|
||||
NetworkStatsService.saveStats(aAppId, aIsInBrowser, "", aNetwork,
|
||||
NetworkStatsService.saveStats(aAppId, aIsInBrowser, "", aNetworkInfo,
|
||||
aTimeStamp, aRxBytes, aTxBytes,
|
||||
aIsAccumulative, aCallback);
|
||||
},
|
||||
@ -58,18 +58,18 @@ NetworkStatsServiceProxy.prototype = {
|
||||
* Function called in the points of different system services
|
||||
* to pass the per-service stats to NetworkStatsService.
|
||||
*/
|
||||
saveServiceStats: function saveServiceStats(aServiceType, aNetwork,
|
||||
saveServiceStats: function saveServiceStats(aServiceType, aNetworkInfo,
|
||||
aTimeStamp, aRxBytes, aTxBytes,
|
||||
aIsAccumulative, aCallback) {
|
||||
if (!aNetwork) {
|
||||
if (!aNetworkInfo) {
|
||||
if (DEBUG) {
|
||||
debug("|aNetwork| is not specified. Failed to save stats. Returning.");
|
||||
debug("|aNetworkInfo| is not specified. Failed to save stats. Returning.");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (DEBUG) {
|
||||
debug("saveServiceStats: " + aServiceType + " " + aNetwork.type + " " +
|
||||
debug("saveServiceStats: " + aServiceType + " " + aNetworkInfo.type + " " +
|
||||
aTimeStamp + " " + aRxBytes + " " + aTxBytes + " " +
|
||||
aIsAccumulative);
|
||||
}
|
||||
@ -78,7 +78,7 @@ NetworkStatsServiceProxy.prototype = {
|
||||
aCallback = aCallback.notify;
|
||||
}
|
||||
|
||||
NetworkStatsService.saveStats(0, false, aServiceType ,aNetwork, aTimeStamp,
|
||||
NetworkStatsService.saveStats(0, false, aServiceType , aNetworkInfo, aTimeStamp,
|
||||
aRxBytes, aTxBytes, aIsAccumulative,
|
||||
aCallback);
|
||||
},
|
||||
|
@ -185,7 +185,7 @@ TCPSocket.prototype = {
|
||||
_rxBytes: 0,
|
||||
_appId: Ci.nsIScriptSecurityManager.NO_APP_ID,
|
||||
_inBrowser: false,
|
||||
_activeNetwork: null,
|
||||
_activeNetworkInfo: null,
|
||||
#endif
|
||||
|
||||
// Public accessors.
|
||||
@ -374,7 +374,7 @@ TCPSocket.prototype = {
|
||||
LOG("Error: Ci.nsINetworkStatsServiceProxy service is not available.");
|
||||
return;
|
||||
}
|
||||
nssProxy.saveAppStats(this._appId, this._inBrowser, this._activeNetwork,
|
||||
nssProxy.saveAppStats(this._appId, this._inBrowser, this._activeNetworkInfo,
|
||||
Date.now(), this._rxBytes, this._txBytes, false);
|
||||
|
||||
// Reset the counters once the statistics is saved to NetworkStatsServiceProxy.
|
||||
@ -616,12 +616,12 @@ TCPSocket.prototype = {
|
||||
that._initStream(that._binaryType);
|
||||
|
||||
#ifdef MOZ_WIDGET_GONK
|
||||
// Set _activeNetwork, which is only required for network statistics.
|
||||
// Set _activeNetworkInfo, which is only required for network statistics.
|
||||
// Note that nsINetworkManager, as well as nsINetworkStatsServiceProxy, is
|
||||
// Gonk-specific.
|
||||
let networkManager = Cc["@mozilla.org/network/manager;1"].getService(Ci.nsINetworkManager);
|
||||
if (networkManager) {
|
||||
that._activeNetwork = networkManager.active;
|
||||
that._activeNetworkInfo = networkManager.activeNetworkInfo;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
interface nsINetworkInterface;
|
||||
interface nsINetworkInfo;
|
||||
|
||||
[scriptable, function, uuid(5f821529-1d80-4ab5-a933-4e1b3585b6bc)]
|
||||
interface nsINetworkStatsServiceProxyCallback : nsISupports
|
||||
@ -16,7 +16,7 @@ interface nsINetworkStatsServiceProxyCallback : nsISupports
|
||||
void notify(in boolean aResult, in jsval aMessage);
|
||||
};
|
||||
|
||||
[scriptable, uuid(98fd8f69-784e-4626-aa59-56d6436a3c24)]
|
||||
[scriptable, uuid(f4f3e901-e102-499d-9d37-dc9951f52df7)]
|
||||
interface nsINetworkStatsServiceProxy : nsISupports
|
||||
{
|
||||
/*
|
||||
@ -32,7 +32,7 @@ interface nsINetworkStatsServiceProxy : nsISupports
|
||||
*/
|
||||
void saveAppStats(in unsigned long aAppId,
|
||||
in boolean aIsInBrowser,
|
||||
in nsINetworkInterface aNetwork,
|
||||
in nsINetworkInfo aNetworkInfo,
|
||||
in unsigned long long aTimeStamp,
|
||||
in unsigned long long aRxBytes,
|
||||
in unsigned long long aTxBytes,
|
||||
@ -50,7 +50,7 @@ interface nsINetworkStatsServiceProxy : nsISupports
|
||||
* @param aCallback an optional callback
|
||||
*/
|
||||
void saveServiceStats(in string aServiceType,
|
||||
in nsINetworkInterface aNetwork,
|
||||
in nsINetworkInfo aNetworkInfo,
|
||||
in unsigned long long aTimeStamp,
|
||||
in unsigned long long aRxBytes,
|
||||
in unsigned long long aTxBytes,
|
||||
|
@ -936,7 +936,7 @@ add_test(function test_addAlarm() {
|
||||
netStatsDb.addAlarm(alarms[0], function(error, result) {
|
||||
do_check_eq(error, null);
|
||||
alarmsDbId = result;
|
||||
netStatsDb.getAlarms(Ci.nsINetworkInterface.NETWORK_TYPE_WIFI, exampleManifestURL, function(error, result) {
|
||||
netStatsDb.getAlarms(Ci.nsINetworkInfo.NETWORK_TYPE_WIFI, exampleManifestURL, function(error, result) {
|
||||
do_check_eq(error, null);
|
||||
do_check_eq(result.length, 1);
|
||||
do_check_eq(result[0].id, alarmsDbId);
|
||||
|
@ -260,7 +260,7 @@ add_test(function test_fireAlarm() {
|
||||
NetworkStatsService._networks[wifiId].status = NETWORK_STATUS_STANDBY;
|
||||
|
||||
NetworkStatsService._db.addAlarm(alarm, function addSuccessCb(error, newId) {
|
||||
NetworkStatsService._db.getAlarms(Ci.nsINetworkInterface.NETWORK_TYPE_WIFI,
|
||||
NetworkStatsService._db.getAlarms(Ci.nsINetworkInfo.NETWORK_TYPE_WIFI,
|
||||
testManifestURL, function onGet(error, result) {
|
||||
do_check_eq(error, null);
|
||||
do_check_eq(result.length, 1);
|
||||
@ -272,7 +272,7 @@ add_test(function test_fireAlarm() {
|
||||
result[0].manifestURL = testManifestURL;
|
||||
|
||||
NetworkStatsService._fireAlarm(result[0], false);
|
||||
NetworkStatsService._db.getAlarms(Ci.nsINetworkInterface.NETWORK_TYPE_WIFI,
|
||||
NetworkStatsService._db.getAlarms(Ci.nsINetworkInfo.NETWORK_TYPE_WIFI,
|
||||
testManifestURL, function onGet(error, result) {
|
||||
do_check_eq(error, undefined);
|
||||
do_check_eq(result.length, 0);
|
||||
|
@ -9,24 +9,24 @@ XPCOMUtils.defineLazyServiceGetter(this, "nssProxy",
|
||||
"@mozilla.org/networkstatsServiceProxy;1",
|
||||
"nsINetworkStatsServiceProxy");
|
||||
|
||||
function mokConvertNetworkInterface() {
|
||||
NetworkStatsService.convertNetworkInterface = function(aNetwork) {
|
||||
if (aNetwork.type != Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE &&
|
||||
aNetwork.type != Ci.nsINetworkInterface.NETWORK_TYPE_WIFI) {
|
||||
function mokConvertNetworkInfo() {
|
||||
NetworkStatsService.convertNetworkInfo = function(aNetworkInfo) {
|
||||
if (aNetworkInfo.type != Ci.nsINetworkInfo.NETWORK_TYPE_MOBILE &&
|
||||
aNetworkInfo.type != Ci.nsINetworkInfo.NETWORK_TYPE_WIFI) {
|
||||
return null;
|
||||
}
|
||||
|
||||
let id = '0';
|
||||
if (aNetwork.type == Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE) {
|
||||
if (aNetworkInfo.type == Ci.nsINetworkInfo.NETWORK_TYPE_MOBILE) {
|
||||
id = '1234'
|
||||
}
|
||||
|
||||
let netId = this.getNetworkId(id, aNetwork.type);
|
||||
let netId = this.getNetworkId(id, aNetworkInfo.type);
|
||||
|
||||
if (!this._networks[netId]) {
|
||||
this._networks[netId] = Object.create(null);
|
||||
this._networks[netId].network = { id: id,
|
||||
type: aNetwork.type };
|
||||
type: aNetworkInfo.type };
|
||||
}
|
||||
|
||||
return netId;
|
||||
@ -37,13 +37,12 @@ add_test(function test_saveAppStats() {
|
||||
var cachedStats = NetworkStatsService.cachedStats;
|
||||
var timestamp = NetworkStatsService.cachedStatsDate.getTime();
|
||||
|
||||
// Create to fake nsINetworkInterfaces. As nsINetworkInterface can not
|
||||
// be instantiated, these two vars will emulate it by filling the properties
|
||||
// that will be used.
|
||||
var wifi = {type: Ci.nsINetworkInterface.NETWORK_TYPE_WIFI, id: "0"};
|
||||
var mobile = {type: Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE, id: "1234"};
|
||||
// Create to fake nsINetworkInfos. As nsINetworkInfo can not be instantiated,
|
||||
// these two vars will emulate it by filling the properties that will be used.
|
||||
var wifi = {type: Ci.nsINetworkInfo.NETWORK_TYPE_WIFI, id: "0"};
|
||||
var mobile = {type: Ci.nsINetworkInfo.NETWORK_TYPE_MOBILE, id: "1234"};
|
||||
|
||||
// Insert fake mobile network interface in NetworkStatsService
|
||||
// Insert fake mobile network info in NetworkStatsService
|
||||
var mobileNetId = NetworkStatsService.getNetworkId(mobile.id, mobile.type);
|
||||
|
||||
do_check_eq(Object.keys(cachedStats).length, 0);
|
||||
@ -83,13 +82,12 @@ add_test(function test_saveAppStats() {
|
||||
add_test(function test_saveServiceStats() {
|
||||
var timestamp = NetworkStatsService.cachedStatsDate.getTime();
|
||||
|
||||
// Create to fake nsINetworkInterfaces. As nsINetworkInterface can not
|
||||
// be instantiated, these two vars will emulate it by filling the properties
|
||||
// that will be used.
|
||||
var wifi = {type: Ci.nsINetworkInterface.NETWORK_TYPE_WIFI, id: "0"};
|
||||
var mobile = {type: Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE, id: "1234"};
|
||||
// Create to fake nsINetworkInfos. As nsINetworkInfo can not be instantiated,
|
||||
// these two vars will emulate it by filling the properties that will be used.
|
||||
var wifi = {type: Ci.nsINetworkInfo.NETWORK_TYPE_WIFI, id: "0"};
|
||||
var mobile = {type: Ci.nsINetworkInfo.NETWORK_TYPE_MOBILE, id: "1234"};
|
||||
|
||||
// Insert fake mobile network interface in NetworkStatsService
|
||||
// Insert fake mobile network info in NetworkStatsService
|
||||
var mobileNetId = NetworkStatsService.getNetworkId(mobile.id, mobile.type);
|
||||
|
||||
NetworkStatsService.updateCachedStats(function (success, msg) {
|
||||
@ -138,7 +136,7 @@ add_test(function test_saveStatsWithDifferentDates() {
|
||||
var today = NetworkStatsService.cachedStatsDate;
|
||||
var tomorrow = new Date(today.getTime() + (24 * 60 * 60 * 1000));
|
||||
|
||||
var mobile = {type: Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE, id: "1234"};
|
||||
var mobile = {type: Ci.nsINetworkInfo.NETWORK_TYPE_MOBILE, id: "1234"};
|
||||
|
||||
NetworkStatsService.updateCachedStats(function (success, message) {
|
||||
do_check_eq(success, true);
|
||||
@ -173,7 +171,7 @@ add_test(function test_saveStatsWithDifferentDates() {
|
||||
add_test(function test_saveStatsWithMaxCachedTraffic() {
|
||||
var timestamp = NetworkStatsService.cachedStatsDate.getTime();
|
||||
var maxtraffic = NetworkStatsService.maxCachedTraffic;
|
||||
var wifi = {type: Ci.nsINetworkInterface.NETWORK_TYPE_WIFI, id: "0"};
|
||||
var wifi = {type: Ci.nsINetworkInfo.NETWORK_TYPE_WIFI, id: "0"};
|
||||
|
||||
NetworkStatsService.updateCachedStats(function (success, message) {
|
||||
do_check_eq(success, true);
|
||||
@ -199,11 +197,11 @@ add_test(function test_saveAppStats() {
|
||||
var cachedStats = NetworkStatsService.cachedStats;
|
||||
var timestamp = NetworkStatsService.cachedStatsDate.getTime();
|
||||
|
||||
// Create to fake nsINetworkInterfaces. As nsINetworkInterface can not
|
||||
// Create to fake nsINetworkInfo. As nsINetworkInfo can not
|
||||
// be instantiated, these two vars will emulate it by filling the properties
|
||||
// that will be used.
|
||||
var wifi = {type: Ci.nsINetworkInterface.NETWORK_TYPE_WIFI, id: "0"};
|
||||
var mobile = {type: Ci.nsINetworkInterface.NETWORK_TYPE_MOBILE, id: "1234"};
|
||||
var wifi = {type: Ci.nsINetworkInfo.NETWORK_TYPE_WIFI, id: "0"};
|
||||
var mobile = {type: Ci.nsINetworkInfo.NETWORK_TYPE_MOBILE, id: "1234"};
|
||||
|
||||
// Insert fake mobile network interface in NetworkStatsService
|
||||
var mobileNetId = NetworkStatsService.getNetworkId(mobile.id, mobile.type);
|
||||
@ -232,9 +230,9 @@ function run_test() {
|
||||
|
||||
Cu.import("resource://gre/modules/NetworkStatsService.jsm");
|
||||
|
||||
// Function convertNetworkInterface of NetworkStatsService causes errors when dealing
|
||||
// Function convertNetworkInfo of NetworkStatsService causes errors when dealing
|
||||
// with RIL to get the iccid, so overwrite it.
|
||||
mokConvertNetworkInterface();
|
||||
mokConvertNetworkInfo();
|
||||
|
||||
run_next_test();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user