Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(244)

Unified Diff: remoting/webapp/base/js/stats_accumulator.js

Issue 2004673002: Initialize remoting.ClientSession.PerfStats with zeros (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Reviewer's Feedback Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « remoting/webapp/base/js/connection_stats.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
+ * @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;
+};
+
+})();
« no previous file with comments | « remoting/webapp/base/js/connection_stats.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698