MD Downloads: prevent search text from overlapping with the cancel search (X)
[chromium-blink-merge.git] / remoting / test / connection_time_observer.h
blobe5d83b88e623c035c96eff06dffbc2b1d6b024ff
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_
8 #include <map>
10 #include "remoting/test/remote_connection_observer.h"
12 namespace base {
13 class TimeDelta;
14 class Timer;
17 namespace remoting {
18 namespace test {
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;
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);
46 private:
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);
58 } // namespace test
59 } // namespace remoting
61 #endif // REMOTING_TEST_CONNECTION_TIME_OBSERVER_H_