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

Unified Diff: blimp/net/blimp_connection_statistics.cc

Issue 1962393004: Added a debug info UI for Blimp (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed Kevin's comments 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
Index: blimp/net/blimp_connection_statistics.cc
diff --git a/blimp/net/blimp_connection_statistics.cc b/blimp/net/blimp_connection_statistics.cc
new file mode 100644
index 0000000000000000000000000000000000000000..1c7d3983717c9ff0b13f56c0a7bffbef6492cdc9
--- /dev/null
+++ b/blimp/net/blimp_connection_statistics.cc
@@ -0,0 +1,47 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <blimp/net/blimp_connection_statistics.h>
+#include "base/bind.h"
+#include "base/logging.h"
+#include "base/threading/thread.h"
+
+namespace blimp {
+
+BlimpConnectionStatistics::BlimpConnectionStatistics(
+ const scoped_refptr<base::TaskRunner>& main_thread_task_runner)
+ : main_thread_task_runner_(main_thread_task_runner), weak_factory_(this) {}
+
+BlimpConnectionStatistics::~BlimpConnectionStatistics() {}
+
+void BlimpConnectionStatistics::Add(EventType type, int data) {
+ main_thread_task_runner_->PostTask(
+ FROM_HERE, base::Bind(&BlimpConnectionStatistics::AddOnMain,
+ weak_factory_.GetWeakPtr(), type, data));
+}
+
+void BlimpConnectionStatistics::Increment(EventType type) {
+ main_thread_task_runner_->PostTask(
+ FROM_HERE, base::Bind(&BlimpConnectionStatistics::IncrementOnMain,
+ weak_factory_.GetWeakPtr(), type));
+}
+
+void BlimpConnectionStatistics::AddOnMain(EventType type, int data) {
+ DCHECK(main_thread_task_runner_->RunsTasksOnCurrentThread());
+ statistics_[type] += data;
+}
+
+void BlimpConnectionStatistics::IncrementOnMain(EventType type) {
Kevin M 2016/05/20 01:02:03 No need for this function; increment is basically
shaktisahu 2016/05/22 22:36:57 Ok.
+ DCHECK(main_thread_task_runner_->RunsTasksOnCurrentThread());
+ statistics_[type]++;
+}
+
+void BlimpConnectionStatistics::GetDebugInfo(
+ const base::Callback<void(StatisticsMap stats)>& callback) {
+ DCHECK(main_thread_task_runner_->RunsTasksOnCurrentThread());
+ VLOG(0) << "statistics_" << statistics_[BYTES_RECEIVED];
Kevin M 2016/05/20 01:02:03 This logging line doesn't look very useful; remove
shaktisahu 2016/05/22 22:36:57 Done.
+ callback.Run(statistics_);
+}
+
+} // namespace blimp

Powered by Google App Engine
This is Rietveld 408576698