tonychun | 684d1414 | 2015-07-31 00:05:49 | [diff] [blame^] | 1 | // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef REMOTING_TEST_CONNECTION_TIME_OBSERVER_H_ |
| 6 | #define REMOTING_TEST_CONNECTION_TIME_OBSERVER_H_ |
| 7 | |
| 8 | #include <map> |
| 9 | |
| 10 | #include "remoting/test/remote_connection_observer.h" |
| 11 | |
| 12 | namespace base { |
| 13 | class TimeDelta; |
| 14 | class Timer; |
| 15 | } |
| 16 | |
| 17 | namespace remoting { |
| 18 | namespace test { |
| 19 | |
| 20 | // Observes and saves the times when a chromoting client changes its state. It |
| 21 | // allows for tests to access latency times between the different states the |
| 22 | // client transitioned through. |
| 23 | class ConnectionTimeObserver |
| 24 | : public RemoteConnectionObserver { |
| 25 | public: |
| 26 | ConnectionTimeObserver(); |
| 27 | ~ConnectionTimeObserver() override; |
| 28 | |
| 29 | // RemoteConnectionObserver interface. |
| 30 | void ConnectionStateChanged(protocol::ConnectionToHost::State state, |
| 31 | protocol::ErrorCode error_code) override; |
| 32 | |
| 33 | // Prints out connection performance stats to STDOUT. |
| 34 | void DisplayConnectionStats() const; |
| 35 | |
| 36 | // Returns the time delta in milliseconds between |start_state| and |
| 37 | // |end_state| stored in |transition_times_map_|. |
| 38 | base::TimeDelta GetStateTransitionTime( |
| 39 | protocol::ConnectionToHost::State start, |
| 40 | protocol::ConnectionToHost::State end) const; |
| 41 | |
| 42 | // Used to set fake state transition times for ConnectionTimeObserver tests. |
| 43 | void SetTransitionTimesMapForTest( |
| 44 | const std::map<protocol::ConnectionToHost::State, base::TimeTicks>& map); |
| 45 | |
| 46 | private: |
| 47 | // Saves the current connection state of client to host. |
| 48 | protocol::ConnectionToHost::State current_connection_state_ = |
| 49 | protocol::ConnectionToHost::State::INITIALIZING; |
| 50 | |
| 51 | // The TimeTicks to get to a state from the previous state. |
| 52 | std::map<protocol::ConnectionToHost::State, base::TimeTicks> |
| 53 | transition_times_map_; |
| 54 | |
| 55 | DISALLOW_COPY_AND_ASSIGN(ConnectionTimeObserver); |
| 56 | }; |
| 57 | |
| 58 | } // namespace test |
| 59 | } // namespace remoting |
| 60 | |
| 61 | #endif // REMOTING_TEST_CONNECTION_TIME_OBSERVER_H_ |