Index: blimp/net/blimp_connection_details.cc |
diff --git a/blimp/net/blimp_connection_details.cc b/blimp/net/blimp_connection_details.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..af674ad314f638ac74b88220be3c5742a9983520 |
--- /dev/null |
+++ b/blimp/net/blimp_connection_details.cc |
@@ -0,0 +1,71 @@ |
+// 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_details.h" |
+ |
+#include "base/bind.h" |
+#include "base/logging.h" |
+#include "base/threading/thread.h" |
+ |
+namespace blimp { |
+ |
+BlimpConnectionDetails::BlimpConnectionDetails( |
+ const scoped_refptr<base::TaskRunner>& main_thread_task_runner, |
+ const scoped_refptr<base::TaskRunner>& io_thread_task_runner) |
+ : debug_info_enabled_(false), |
+ bytes_received_(0), |
+ bytes_sent_(0), |
+ commits_(0), |
+ main_thread_task_runner_(main_thread_task_runner), |
+ io_thread_task_runner_(io_thread_task_runner) {} |
Khushal
2016/05/18 00:23:00
DCHECK that this is created on the correct thread.
|
+ |
+BlimpConnectionDetails::~BlimpConnectionDetails() {} |
Khushal
2016/05/18 00:23:00
ditto for the dtor.
|
+ |
+void BlimpConnectionDetails::EnableDebugInfo(bool enable) { |
Khushal
2016/05/18 00:23:00
Since this class is used on multiple threads, plea
|
+ debug_info_enabled_ = enable; |
+} |
+ |
+void BlimpConnectionDetails::OnPacketReceived(int bytes) { |
+ bytes_received_ += bytes; |
+ if (debug_info_enabled_) { |
+ main_thread_task_runner_->PostTask( |
+ FROM_HERE, |
+ base::Bind(&NetworkActivityObserver::UpdateDebugInfo, observer_, |
+ bytes_received_, bytes_sent_, commits_)); |
+ } |
+} |
+ |
+void BlimpConnectionDetails::OnPacketSent(int bytes) { |
+ bytes_sent_ += bytes; |
+ if (debug_info_enabled_) { |
+ main_thread_task_runner_->PostTask( |
+ FROM_HERE, |
+ base::Bind(&NetworkActivityObserver::UpdateDebugInfo, observer_, |
+ bytes_received_, bytes_sent_, commits_)); |
+ } |
+} |
+ |
+void BlimpConnectionDetails::OnCommit() { |
+ commits_++; |
+ if (debug_info_enabled_) { |
+ main_thread_task_runner_->PostTask( |
+ FROM_HERE, |
+ base::Bind(&NetworkActivityObserver::UpdateDebugInfo, observer_, |
+ bytes_received_, bytes_sent_, commits_)); |
+ } |
+} |
+ |
+void BlimpConnectionDetails::ResetStats() { |
+ io_thread_task_runner_->PostTask( |
+ FROM_HERE, base::Bind(&BlimpConnectionDetails::ResetStatsOnIOThread, |
+ base::Unretained(this))); |
Khushal
2016/05/18 00:23:01
Are you sure its safe to use Unretained here? Can
shaktisahu
2016/05/19 21:39:18
Acknowledged.
|
+ commits_ = 0; |
+} |
+ |
+void BlimpConnectionDetails::ResetStatsOnIOThread() { |
+ bytes_received_ = 0; |
+ bytes_sent_ = 0; |
+} |
+ |
+} // namespace blimp |