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..2fb9e6739dc46f2a913cce78914305e84fcce2cd |
--- /dev/null |
+++ b/blimp/net/blimp_connection_details.cc |
@@ -0,0 +1,74 @@ |
+// 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( |
Kevin M
2016/05/18 18:38:28
The name "Connection Details" isn't a good fit her
shaktisahu
2016/05/19 21:39:19
Done.
|
+ base::WeakPtr<NetworkActivityObserver> observer, |
+ 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), |
+ observer_(observer), |
+ main_thread_task_runner_(main_thread_task_runner), |
+ io_thread_task_runner_(io_thread_task_runner), |
+ weak_factory_(this) {} |
+ |
+BlimpConnectionDetails::~BlimpConnectionDetails() {} |
+ |
+void BlimpConnectionDetails::EnableDebugInfo(bool enable) { |
+ 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_, |
Kevin M
2016/05/18 18:38:28
I think that this push approach is really ineffici
Khushal
2016/05/18 20:41:10
I'm not sure how that will run, Java will make a c
shaktisahu
2016/05/19 21:39:19
Done.
|
+ bytes_received_, bytes_sent_, commits_)); |
+ } |
+} |
+ |
+void BlimpConnectionDetails::OnPacketSent(int bytes) { |
Kevin M
2016/05/18 18:38:28
There is a lot of code duplication with the way th
shaktisahu
2016/05/19 21:39:19
Done.
|
+ 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() { |
Khushal
2016/05/18 20:41:10
I think this call is made on the main thread, you
shaktisahu
2016/05/19 21:39:19
Done.
|
+ 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() { |
Kevin M
2016/05/18 18:38:28
I don't think we should add resetting at this leve
Khushal
2016/05/18 20:41:10
We'll either way not have per navigation data even
shaktisahu
2016/05/19 21:39:19
Done.
|
+ io_thread_task_runner_->PostTask( |
+ FROM_HERE, base::Bind(&BlimpConnectionDetails::ResetStatsOnIOThread, |
+ weak_factory_.GetWeakPtr())); |
+ commits_ = 0; |
+} |
+ |
+void BlimpConnectionDetails::ResetStatsOnIOThread() { |
+ bytes_received_ = 0; |
+ bytes_sent_ = 0; |
+} |
+ |
+} // namespace blimp |