mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-28 15:23:51 +00:00
bug 931856 http data usage telemetry updates r=jduell
This commit is contained in:
parent
3dc028c926
commit
b4f57f6b35
@ -35,8 +35,7 @@ HttpDataUsage.prototype = {
|
||||
|
||||
_isIdleObserver: false,
|
||||
_locked : false,
|
||||
_do_telemetry : false,
|
||||
_idle_timeout : 60 * 3,
|
||||
_idle_timeout : 15,
|
||||
_quanta : 86400000, // per day
|
||||
|
||||
_logtime : new Date(),
|
||||
@ -74,13 +73,16 @@ HttpDataUsage.prototype = {
|
||||
if (this._dataUsage == null)
|
||||
return;
|
||||
|
||||
Services.obs.addObserver(this, "quit-application", false);
|
||||
idleService.addIdleObserver(this, this._idle_timeout);
|
||||
this._isIdleObserver = true;
|
||||
},
|
||||
|
||||
shutdown: function shutdown() {
|
||||
if (this._isIdleObserver)
|
||||
if (this._isIdleObserver) {
|
||||
idleService.removeIdleObserver(this, this._idle_timeout);
|
||||
Services.obs.removeObserver(this, "quit-application");
|
||||
}
|
||||
this._isIdleObserver = false;
|
||||
},
|
||||
|
||||
@ -88,10 +90,6 @@ HttpDataUsage.prototype = {
|
||||
gDataUsage.updateStats2(stream, result);
|
||||
},
|
||||
|
||||
sGatherTelemetry2: function sGatherTelemetry2(stream, result) {
|
||||
gDataUsage.gatherTelemetry2(stream, result);
|
||||
},
|
||||
|
||||
readCounters: function readCounters(stream, result) {
|
||||
if (Components.isSuccessCode(result)) {
|
||||
let count = stream.available();
|
||||
@ -113,7 +111,6 @@ HttpDataUsage.prototype = {
|
||||
this._dataUsage.resetHttpDataUsage();
|
||||
},
|
||||
|
||||
// writeCounters also releases the lock
|
||||
writeCounters: function writeCounters() {
|
||||
var dataout = this._logtime.getTime().toString() + "," +
|
||||
this._ethernetRead.toString() + "," +
|
||||
@ -132,17 +129,15 @@ HttpDataUsage.prototype = {
|
||||
|
||||
updateStats2: function updateStats2(stream, result) {
|
||||
this.readCounters(stream, result);
|
||||
this.writeCounters();
|
||||
this.submitTelemetry();
|
||||
},
|
||||
|
||||
gatherTelemetry2: function gatherTelemetry2(stream, result) {
|
||||
this.readCounters(stream, result);
|
||||
|
||||
submitTelemetry: function submitTelemetry() {
|
||||
var now = new Date();
|
||||
var elapsed = now.getTime() - this._logtime.getTime();
|
||||
// make sure we have at least 1 day of data
|
||||
// make sure we have at least 1 day of data.. if not just write new data out
|
||||
if (elapsed < this._quanta) {
|
||||
this.finishedWriting();
|
||||
this.writeCounters();
|
||||
return;
|
||||
}
|
||||
|
||||
@ -171,16 +166,13 @@ HttpDataUsage.prototype = {
|
||||
this._cellWritten -= cOutPerQuanta;
|
||||
}
|
||||
this._logtime = new Date(now.getTime() - elapsed);
|
||||
|
||||
|
||||
// need to write back the decremented counters
|
||||
this.writeCounters();
|
||||
},
|
||||
|
||||
finishedWriting : function finishedWriting() {
|
||||
this._locked = false;
|
||||
if (this._do_telemetry) {
|
||||
this._do_telemetry = false;
|
||||
this.gatherTelemetry();
|
||||
}
|
||||
this._locked = false; // all done
|
||||
},
|
||||
|
||||
updateStats: function updateStats() {
|
||||
@ -191,32 +183,20 @@ HttpDataUsage.prototype = {
|
||||
NetUtil.asyncFetch(this._dataFile, this.sUpdateStats2);
|
||||
},
|
||||
|
||||
gatherTelemetry: function gatherTelemetry() {
|
||||
if (this._locked)
|
||||
return; // oh well, maybe next time
|
||||
this._locked = true;
|
||||
|
||||
NetUtil.asyncFetch(this._dataFile, this.sGatherTelemetry2);
|
||||
},
|
||||
|
||||
observe: function (aSubject, aTopic, aData) {
|
||||
switch (aTopic) {
|
||||
case "profile-after-change":
|
||||
this.setup();
|
||||
break;
|
||||
case "gather-telemetry":
|
||||
this._do_telemetry = true;
|
||||
this.updateStats();
|
||||
break;
|
||||
case "idle":
|
||||
this.updateStats();
|
||||
break;
|
||||
case "profile-change-net-teardown":
|
||||
case "quit-application":
|
||||
this.updateStats();
|
||||
this.shutdown();
|
||||
break;
|
||||
}
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
this.NSGetFactory = XPCOMUtils.generateNSGetFactory([HttpDataUsage]);
|
||||
|
Loading…
Reference in New Issue
Block a user