OLD | NEW |
(Empty) | |
| 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 void ConnectionReady(bool ready) override; |
| 33 |
| 34 // Used to properly set the time of the INITIALIZING state of the chromoting |
| 35 // connection. |
| 36 // Note: Initialize() should be called right before a chromoting client starts |
| 37 // a connection to accurately measure the time between INITIALIZING and |
| 38 // CONNECTING states. |
| 39 void Initialize(); |
| 40 |
| 41 // Prints out connection performance stats to STDOUT. |
| 42 void DisplayConnectionStats() const; |
| 43 |
| 44 // Returns the time delta in milliseconds between |start_state| and |
| 45 // |end_state| stored in |transition_times_map_|. |
| 46 base::TimeDelta GetStateTransitionTime( |
| 47 protocol::ConnectionToHost::State start_state, |
| 48 protocol::ConnectionToHost::State end_state) const; |
| 49 |
| 50 // Used to set fake state transition times for ConnectionTimeObserver tests. |
| 51 void SetTransitionTimesMapForTest( |
| 52 const std::map<protocol::ConnectionToHost::State, base::TimeTicks>& map); |
| 53 |
| 54 private: |
| 55 // Saves the current connection state of client to host. |
| 56 protocol::ConnectionToHost::State current_connection_state_ = |
| 57 protocol::ConnectionToHost::State::INITIALIZING; |
| 58 |
| 59 // The TimeTicks to get to a state from the previous state. |
| 60 std::map<protocol::ConnectionToHost::State, base::TimeTicks> |
| 61 transition_times_map_; |
| 62 |
| 63 DISALLOW_COPY_AND_ASSIGN(ConnectionTimeObserver); |
| 64 }; |
| 65 |
| 66 } // namespace test |
| 67 } // namespace remoting |
| 68 |
| 69 #endif // REMOTING_TEST_CONNECTION_TIME_OBSERVER_H_ |
OLD | NEW |