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