зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1044737
- 1/3: don't use Date in nsINetworkStatsCallback::networkStatsAvailable. r=vchang
This commit is contained in:
Родитель
68822d0535
Коммит
a06a387b4c
|
@ -124,41 +124,35 @@ NetworkService.prototype = {
|
|||
getNetworkInterfaceStats: function(networkName, callback) {
|
||||
if(DEBUG) debug("getNetworkInterfaceStats for " + networkName);
|
||||
|
||||
if (this.shutdown) {
|
||||
return;
|
||||
}
|
||||
|
||||
let file = new FileUtils.File("/proc/net/dev");
|
||||
if (!file) {
|
||||
callback.networkStatsAvailable(false, -1, -1, new Date());
|
||||
callback.networkStatsAvailable(false, 0, 0, Date.now());
|
||||
return;
|
||||
}
|
||||
|
||||
NetUtil.asyncFetch(file, function(inputStream, status) {
|
||||
let result = {
|
||||
success: true, // netd always return success even interface doesn't exist.
|
||||
rxBytes: 0,
|
||||
txBytes: 0
|
||||
};
|
||||
result.date = new Date();
|
||||
let rxBytes = 0,
|
||||
txBytes = 0,
|
||||
now = Date.now();
|
||||
|
||||
if (Components.isSuccessCode(status)) {
|
||||
// Find record for corresponding interface.
|
||||
let statExpr = /(\S+): +(\d+) +\d+ +\d+ +\d+ +\d+ +\d+ +\d+ +\d+ +(\d+) +\d+ +\d+ +\d+ +\d+ +\d+ +\d+ +\d+/;
|
||||
let data = NetUtil.readInputStreamToString(inputStream,
|
||||
inputStream.available()).split("\n");
|
||||
let data =
|
||||
NetUtil.readInputStreamToString(inputStream, inputStream.available())
|
||||
.split("\n");
|
||||
for (let i = 2; i < data.length; i++) {
|
||||
let parseResult = statExpr.exec(data[i]);
|
||||
if (parseResult && parseResult[1] === networkName) {
|
||||
result.rxBytes = parseInt(parseResult[2], 10);
|
||||
result.txBytes = parseInt(parseResult[3], 10);
|
||||
rxBytes = parseInt(parseResult[2], 10);
|
||||
txBytes = parseInt(parseResult[3], 10);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
callback.networkStatsAvailable(result.success, result.rxBytes,
|
||||
result.txBytes, result.date);
|
||||
// netd always return success even interface doesn't exist.
|
||||
callback.networkStatsAvailable(true, rxBytes, txBytes, now);
|
||||
});
|
||||
},
|
||||
|
||||
|
|
|
@ -19,13 +19,13 @@ interface nsIWifiTetheringCallback : nsISupports
|
|||
void wifiTetheringEnabledChange(in jsval error);
|
||||
};
|
||||
|
||||
[scriptable, function, uuid(e079aa2a-ec0a-4bbd-b1a4-d81a9faae464)]
|
||||
[scriptable, function, uuid(9c128e68-5e4b-4626-bb88-84ec54cce5d8)]
|
||||
interface nsINetworkStatsCallback : nsISupports
|
||||
{
|
||||
void networkStatsAvailable(in boolean success,
|
||||
in unsigned long rxBytes,
|
||||
in unsigned long txBytes,
|
||||
in jsval date);
|
||||
in unsigned long long timestamp);
|
||||
};
|
||||
|
||||
[scriptable, function, uuid(0706bfa2-ac2d-11e2-9a8d-7b6d988d4767)]
|
||||
|
|
Загрузка…
Ссылка в новой задаче