From ae107087691f95237dc2bec124f7c2b1e368aed6 Mon Sep 17 00:00:00 2001 From: Albert Crespell Date: Tue, 11 Feb 2014 12:35:28 +0100 Subject: [PATCH] Bug 966244 - Alarms are not updated after clearStats. r=gene, r=jshih --- dom/network/src/NetworkStatsDB.jsm | 30 +++++++++++++++++++++++-- dom/network/src/NetworkStatsService.jsm | 9 ++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/dom/network/src/NetworkStatsDB.jsm b/dom/network/src/NetworkStatsDB.jsm index d7e12c9f6646..31578dd5d608 100644 --- a/dom/network/src/NetworkStatsDB.jsm +++ b/dom/network/src/NetworkStatsDB.jsm @@ -576,7 +576,7 @@ NetworkStatsDB.prototype = { }, clearInterfaceStats: function clearInterfaceStats(aNetwork, aResultCb) { - let network = [aNetwork.id, aNetwork.type]; + let network = [aNetwork.network.id, aNetwork.network.type]; let self = this; // Clear and save an empty sample to keep sync with system counters @@ -609,7 +609,7 @@ NetworkStatsDB.prototype = { self._saveStats(aTxn, aStore, sample); } }; - }, aResultCb); + }, this._resetAlarms.bind(this, aNetwork.networkId, aResultCb)); }, clearStats: function clearStats(aNetworks, aResultCb) { @@ -863,6 +863,7 @@ NetworkStatsDB.prototype = { let record = { networkId: aAlarm.networkId, absoluteThreshold: aAlarm.absoluteThreshold, relativeThreshold: aAlarm.relativeThreshold, + startTime: aAlarm.startTime, data: aAlarm.data, manifestURL: aAlarm.manifestURL, pageURL: aAlarm.pageURL }; @@ -878,6 +879,7 @@ NetworkStatsDB.prototype = { let alarm = { networkId: aRecord.networkId, absoluteThreshold: aRecord.absoluteThreshold, relativeThreshold: aRecord.relativeThreshold, + startTime: aRecord.startTime, data: aRecord.data, manifestURL: aRecord.manifestURL, pageURL: aRecord.pageURL }; @@ -1004,5 +1006,29 @@ NetworkStatsDB.prototype = { cursor.continue(); } }, aResultCb); + }, + + _resetAlarms: function _resetAlarms(aNetworkId, aResultCb) { + this.dbNewTxn(ALARMS_STORE_NAME, "readwrite", function(txn, store) { + if (DEBUG) { + debug("Reset alarms for network " + aNetworkId); + } + + let lowerFilter = [aNetworkId, 0]; + let upperFilter = [aNetworkId, ""]; + let range = IDBKeyRange.bound(lowerFilter, upperFilter); + + store.index("alarm").openCursor(range).onsuccess = function onsuccess(event) { + let cursor = event.target.result; + if (cursor) { + if (cursor.value.startTime) { + cursor.value.relativeThreshold = cursor.value.threshold; + cursor.update(cursor.value); + } + cursor.continue(); + return; + } + }; + }, aResultCb); } }; diff --git a/dom/network/src/NetworkStatsService.jsm b/dom/network/src/NetworkStatsService.jsm index 95d28ffc3fb3..fa6e59ff5230 100644 --- a/dom/network/src/NetworkStatsService.jsm +++ b/dom/network/src/NetworkStatsService.jsm @@ -465,7 +465,9 @@ this.NetworkStatsService = { return; } + network = {network: network, networkId: aNetId}; self._db.clearInterfaceStats(network, function onDBCleared(aError, aResult) { + self._updateCurrentAlarm(aNetId); mm.sendAsyncMessage("NetworkStats:Clear:Return", { id: msg.id, error: aError, result: aResult }); }); @@ -482,7 +484,14 @@ this.NetworkStatsService = { } let networks = aResult; + networks.forEach(function(network, index) { + networks[index] = {network: network, networkId: self.getNetworkId(network.id, network.type)}; + }, self); + self._db.clearStats(networks, function onDBCleared(aError, aResult) { + networks.forEach(function(network, index) { + self._updateCurrentAlarm(network.networkId); + }, self); mm.sendAsyncMessage("NetworkStats:ClearAll:Return", { id: msg.id, error: aError, result: aResult }); });