blob: 374ec13aa2e39727842a4184d7265d0ea3cc59c3 [file] [log] [blame]
tonychun684d14142015-07-31 00:05:491// 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
avi5a080f012015-12-22 23:15:4310#include "base/macros.h"
tonychun684d14142015-07-31 00:05:4911#include "remoting/test/remote_connection_observer.h"
12
13namespace base {
14class TimeDelta;
tonychun684d14142015-07-31 00:05:4915}
16
17namespace remoting {
18namespace 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.
23class 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_