summaryrefslogtreecommitdiffstats
path: root/remoting/test/connection_time_observer.h
blob: e5d83b88e623c035c96eff06dffbc2b1d6b024ff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef REMOTING_TEST_CONNECTION_TIME_OBSERVER_H_
#define REMOTING_TEST_CONNECTION_TIME_OBSERVER_H_

#include <map>

#include "remoting/test/remote_connection_observer.h"

namespace base {
class TimeDelta;
class Timer;
}

namespace remoting {
namespace test {

// Observes and saves the times when a chromoting client changes its state. It
// allows for tests to access latency times between the different states the
// client transitioned through.
class ConnectionTimeObserver
    : public RemoteConnectionObserver {
 public:
  ConnectionTimeObserver();
  ~ConnectionTimeObserver() override;

  // RemoteConnectionObserver interface.
  void ConnectionStateChanged(protocol::ConnectionToHost::State state,
                              protocol::ErrorCode error_code) override;

  // Prints out connection performance stats to STDOUT.
  void DisplayConnectionStats() const;

  // Returns the time delta in milliseconds between |start_state| and
  // |end_state| stored in |transition_times_map_|.
  base::TimeDelta GetStateTransitionTime(
      protocol::ConnectionToHost::State start,
      protocol::ConnectionToHost::State end) const;

  // Used to set fake state transition times for ConnectionTimeObserver tests.
  void SetTransitionTimesMapForTest(
      const std::map<protocol::ConnectionToHost::State, base::TimeTicks>& map);

 private:
  // Saves the current connection state of client to host.
  protocol::ConnectionToHost::State current_connection_state_ =
      protocol::ConnectionToHost::State::INITIALIZING;

  // The TimeTicks to get to a state from the previous state.
  std::map<protocol::ConnectionToHost::State, base::TimeTicks>
      transition_times_map_;

  DISALLOW_COPY_AND_ASSIGN(ConnectionTimeObserver);
};

}  // namespace test
}  // namespace remoting

#endif  // REMOTING_TEST_CONNECTION_TIME_OBSERVER_H_