Index: remoting/test/connection_time_observer.cc |
diff --git a/remoting/test/connection_time_observer.cc b/remoting/test/connection_time_observer.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..1da5cdb237dcd72e016263b5d42c987c51043a5d |
--- /dev/null |
+++ b/remoting/test/connection_time_observer.cc |
@@ -0,0 +1,62 @@ |
+// Copyright 2015 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 "remoting/test/connection_time_observer.h" |
+ |
+#include "base/time/time.h" |
+ |
+namespace { |
+ |
+std::string GetStateAsString( |
+ const remoting::protocol::ConnectionToHost::State& state) { |
+ switch (state) { |
+ case remoting::protocol::ConnectionToHost::State::INITIALIZING: |
+ return "INITIALIZING"; |
+ case remoting::protocol::ConnectionToHost::State::CONNECTING: |
+ return "CONNECTING"; |
+ case remoting::protocol::ConnectionToHost::State::AUTHENTICATED: |
+ return "AUTHENTICATED"; |
+ case remoting::protocol::ConnectionToHost::State::CONNECTED: |
+ return "CONNECTED"; |
+ case remoting::protocol::ConnectionToHost::State::FAILED: |
+ return "FAILED"; |
+ case remoting::protocol::ConnectionToHost::State::CLOSED: |
+ return "CLOSED"; |
+ default: |
+ LOG(ERROR) << "Unknown current state"; |
+ NOTREACHED(); |
+ } |
+} |
+ |
+} // namespace |
+ |
+namespace remoting { |
+namespace test { |
+ |
+ConnectionTimeObserver::ConnectionTimeObserver() |
+ : current_state_(protocol::ConnectionToHost::State::INITIALIZING), |
Sergey Ulanov
2015/07/20 23:04:04
nit: move this initializer to .h
tonychun
2015/07/23 03:31:04
Done.
|
+ last_state_change_time_ticks(base::TimeTicks::Now()) { |
+} |
+ |
+ConnectionTimeObserver::~ConnectionTimeObserver() { |
+} |
+ |
+void ConnectionTimeObserver::ConnectionStateChanged( |
+ protocol::ConnectionToHost::State state, |
+ protocol::ErrorCode error_code) { |
+ int state_change_time = |
+ (base::TimeTicks::Now() - last_state_change_time_ticks).InMilliseconds(); |
+ |
+ std::string current_state_string = GetStateAsString(current_state_); |
+ std::string next_state_string = GetStateAsString(state); |
+ |
+ VLOG(1) << current_state_string << " to " << next_state_string |
+ << " Delta Time: " << state_change_time << " ms"; |
+ |
+ current_state_ = state; |
+ last_state_change_time_ticks = base::TimeTicks::Now(); |
+} |
+ |
+} // namespace test |
+} // namespace remoting |