зеркало из https://github.com/mozilla/gecko-dev.git
Bug 736096 - Reprioritize networks when the priorities get too high to prevent overflow. r=cjones
This commit is contained in:
Родитель
94773c89ac
Коммит
1b186a273f
|
@ -1212,6 +1212,8 @@ function WifiWorker() {
|
|||
return;
|
||||
}
|
||||
|
||||
this._highestPriority = -1;
|
||||
|
||||
// Convert between netId-based and ssid-based indexing.
|
||||
for (let net in networks) {
|
||||
let network = networks[net];
|
||||
|
@ -1455,6 +1457,72 @@ WifiWorker.prototype = {
|
|||
this._lastConnectionInfo = null;
|
||||
},
|
||||
|
||||
// Important side effect: calls WifiManager.saveConfig.
|
||||
_reprioritizeNetworks: function(callback) {
|
||||
// First, sort the networks in orer of their priority.
|
||||
var ordered = Object.getOwnPropertyNames(this.configuredNetworks);
|
||||
let self = this;
|
||||
ordered.sort(function(a, b) {
|
||||
var neta = self.configuredNetworks[a],
|
||||
netb = self.configuredNetworks[b];
|
||||
|
||||
// Sort unsorted networks to the end of the list.
|
||||
if (isNaN(neta.priority))
|
||||
return isNaN(netb.priority) ? 0 : 1;
|
||||
if (isNaN(netb.priority))
|
||||
return -1;
|
||||
return netb.priority - neta.priority;
|
||||
});
|
||||
|
||||
// Skip unsorted networks.
|
||||
let newPriority = 0, i;
|
||||
for (i = ordered.length - 1; i >= 0; --i) {
|
||||
if (!isNaN(this.configuredNetworks[ordered[i]].priority))
|
||||
break;
|
||||
}
|
||||
|
||||
// No networks we care about?
|
||||
if (i < 0) {
|
||||
WifiManager.saveConfig(callback);
|
||||
return;
|
||||
}
|
||||
|
||||
// Now assign priorities from 0 to length, starting with the smallest
|
||||
// priority and heading towards the highest (note the dependency between
|
||||
// total and i here).
|
||||
let done = 0, errors = 0, total = i + 1;
|
||||
for (; i >= 0; --i) {
|
||||
let network = this.configuredNetworks[ordered[i]];
|
||||
network.priority = newPriority++;
|
||||
|
||||
// Note: networkUpdated declared below since it happens logically after
|
||||
// this loop.
|
||||
WifiManager.updateNetwork(network, networkUpdated);
|
||||
}
|
||||
|
||||
function networkUpdated(ok) {
|
||||
if (!ok)
|
||||
++errors;
|
||||
if (++done === total) {
|
||||
if (errors > 0) {
|
||||
callback(false);
|
||||
return;
|
||||
}
|
||||
|
||||
WifiManager.saveConfig(function(ok) {
|
||||
if (!ok) {
|
||||
callback(false);
|
||||
return;
|
||||
}
|
||||
|
||||
self._reloadConfiguredNetworks(function(ok) {
|
||||
callback(ok);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
// nsIWifi
|
||||
|
||||
_fireEvent: function(message, data) {
|
||||
|
@ -1505,12 +1573,13 @@ WifiWorker.prototype = {
|
|||
},
|
||||
|
||||
associate: function(network, rid, mid) {
|
||||
const MAX_PRIORITY = 9999;
|
||||
const message = "WifiManager:associate:Return";
|
||||
let privnet = network;
|
||||
let self = this;
|
||||
function networkReady() {
|
||||
// saveConfig now before we disable most of the other networks.
|
||||
WifiManager.saveConfig(function() {
|
||||
function selectAndConnect() {
|
||||
WifiManager.enableNetwork(privnet.netId, true, function (ok) {
|
||||
if (ok)
|
||||
self._needToEnableNetworks = true;
|
||||
|
@ -1523,7 +1592,12 @@ WifiWorker.prototype = {
|
|||
self._sendMessage(message, ok, ok, rid, mid);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
if (self._highestPriority >= MAX_PRIORITY)
|
||||
self._reprioritizeNetworks(selectAndConnect);
|
||||
else
|
||||
WifiManager.saveConfig(selectAndConnect);
|
||||
}
|
||||
|
||||
let ssid = privnet.ssid;
|
||||
|
@ -1534,7 +1608,6 @@ WifiWorker.prototype = {
|
|||
|
||||
netFromDOM(privnet, configured);
|
||||
|
||||
// XXX Do we have to worry about overflow/going too high here?
|
||||
privnet.priority = ++this._highestPriority;
|
||||
if (configured) {
|
||||
privnet.netId = configured.netId;
|
||||
|
|
Загрузка…
Ссылка в новой задаче