Index: remoting/test/connection_time_observer.h |
diff --git a/remoting/test/connection_time_observer.h b/remoting/test/connection_time_observer.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..4090a0108f276e61710aa03a4a6ce4898462e81b |
--- /dev/null |
+++ b/remoting/test/connection_time_observer.h |
@@ -0,0 +1,70 @@ |
+// 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. |
+ |
+#ifndef REMOTING_TEST_CONNECTION_TIME_OBSERVER_H_ |
+#define REMOTING_TEST_CONNECTION_TIME_OBSERVER_H_ |
+ |
+#include <map> |
+ |
+#include "remoting/test/remote_connection_observer.h" |
+ |
+namespace base { |
+class TimeDelta; |
+class Timer; |
+} |
+ |
+namespace remoting { |
+namespace test { |
+ |
+// Observes and saves the times when a chromoting client changes its state. It |
+// allows for tests to access latency times between the different states the |
+// client transitioned through. |
+class ConnectionTimeObserver |
+ : public RemoteConnectionObserver { |
+ public: |
+ explicit ConnectionTimeObserver(base::Timer* timer); |
+ ~ConnectionTimeObserver() override; |
+ |
+ // RemoteConnectionObserver interface. |
+ void ConnectionStateChanged(protocol::ConnectionToHost::State state, |
+ protocol::ErrorCode error_code) override; |
+ void ConnectionReady(bool ready) override; |
+ |
+ // Initializes INITIALIZING state's TimeTicks. |
joedow
2015/07/27 16:25:39
This comment is awkward, I think the method name i
tonychun
2015/07/27 21:20:42
I've added clearer comments and changed the name t
|
+ void SetInitializingState(); |
+ |
+ // Prints out connection performance stats to STDOUT. |
+ void DisplayConnectionStats() const; |
+ |
+ // Returns the time delta in milliseconds between |start_state| and |
+ // |end_state| stored in |transition_times_map_|. |
+ base::TimeDelta GetStateTransitionDelayTimeDelta( |
anandc
2015/07/27 18:22:29
GetStateTransitionTime.
tonychun
2015/07/27 21:20:42
Done.
|
+ protocol::ConnectionToHost::State start_state, |
+ protocol::ConnectionToHost::State end_state) const; |
+ |
+ // Used to set fake state transition times for ConnectionTimeObserver tests. |
+ void SetTransitionTimesMapForTest( |
+ const std::map<protocol::ConnectionToHost::State, base::TimeTicks>& map); |
+ |
+ private: |
+ // Saves the current connection state of client to host. |
+ protocol::ConnectionToHost::State current_connection_state_ = |
+ protocol::ConnectionToHost::State::INITIALIZING; |
+ |
+ // Stores TimeTick of states the client changes to. |
anandc
2015/07/27 18:22:29
"The TimeTicks to get to a state from the previous
tonychun
2015/07/27 21:20:42
Done.
|
+ std::map<protocol::ConnectionToHost::State, base::TimeTicks> |
+ transition_times_map_; |
+ |
+ // Allows for observer to run timer's closure. ConnectionTimeObserver does not |
+ // does not own the lifetime of the timer, so the timer should outlast the |
+ // chromoting connection time and the ConnectionTimeObserver. |
+ base::Timer* timer_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(ConnectionTimeObserver); |
+}; |
+ |
+} // namespace test |
+} // namespace remoting |
+ |
+#endif // REMOTING_TEST_CONNECTION_TIME_OBSERVER_H_ |