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.
5 #ifndef REMOTING_TEST_CONNECTION_TIME_OBSERVER_H_
6 #define REMOTING_TEST_CONNECTION_TIME_OBSERVER_H_
10 #include "remoting/test/remote_connection_observer.h"
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
{
26 ConnectionTimeObserver();
27 ~ConnectionTimeObserver() override
;
29 // RemoteConnectionObserver interface.
30 void ConnectionStateChanged(protocol::ConnectionToHost::State state
,
31 protocol::ErrorCode error_code
) override
;
33 // Prints out connection performance stats to STDOUT.
34 void DisplayConnectionStats() const;
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;
42 // Used to set fake state transition times for ConnectionTimeObserver tests.
43 void SetTransitionTimesMapForTest(
44 const std::map
<protocol::ConnectionToHost::State
, base::TimeTicks
>& map
);
47 // Saves the current connection state of client to host.
48 protocol::ConnectionToHost::State current_connection_state_
=
49 protocol::ConnectionToHost::State::INITIALIZING
;
51 // The TimeTicks to get to a state from the previous state.
52 std::map
<protocol::ConnectionToHost::State
, base::TimeTicks
>
53 transition_times_map_
;
55 DISALLOW_COPY_AND_ASSIGN(ConnectionTimeObserver
);
59 } // namespace remoting
61 #endif // REMOTING_TEST_CONNECTION_TIME_OBSERVER_H_