Chromium Code Reviews| Index: remoting/webapp/base/js/stats_accumulator.js |
| diff --git a/remoting/webapp/base/js/stats_accumulator.js b/remoting/webapp/base/js/stats_accumulator.js |
| index e8bda09ff0a11752131ec6af1e1d9604f223c917..8d4cb6b7ef7446c6e133b300409ed5e877c265a3 100644 |
| --- a/remoting/webapp/base/js/stats_accumulator.js |
| +++ b/remoting/webapp/base/js/stats_accumulator.js |
| @@ -16,6 +16,8 @@ |
| /** @suppress {duplicate} */ |
| var remoting = remoting || {}; |
| +(function() { |
| + |
| /** |
| * @constructor |
| */ |
| @@ -35,11 +37,28 @@ remoting.StatsAccumulator = function() { |
| }; |
| /** |
| - * Adds values to this object. |
| + * @param {Object<number>} stats |
|
Yuwei
2016/05/23 18:16:40
Oops... That should be Object<!number> or PerfStat
|
| + * @return {boolean} true if there is any non-zero value in stats, false |
| + * otherwise. |
| + */ |
| +function hasValidField(stats) { |
| + for (var key in stats) { |
| + if (stats[key] !== 0) { |
| + return true; |
| + } |
| + } |
| + return false; |
| +} |
| + |
| +/** |
| + * Adds values to this object. Do nothing if newValues has no valid field. |
| * |
| * @param {Object<number>} newValues |
| */ |
| remoting.StatsAccumulator.prototype.add = function(newValues) { |
| + if (!hasValidField(newValues)) { |
| + return; |
| + } |
| for (var key in newValues) { |
| this.getValueList(key).push(newValues[key]); |
| } |
| @@ -161,10 +180,7 @@ remoting.StatsAccumulator.prototype.getPerfStats = function() { |
| stats.roundtripLatency = this.calcMean('roundtripLatency'); |
| stats.maxRoundtripLatency = this.calcMax('maxRoundtripLatency'); |
| - for (var key in stats) { |
| - if (stats[key] !== 0) { |
| - return stats; |
| - } |
| - } |
| - return null; |
| -}; |
| + return hasValidField(stats) ? stats : null; |
| +}; |
| + |
| +})(); |