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 explicit ConnectionTimeObserver(base::Timer* timer); | |
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 // Initializes INITIALIZING state's TimeTicks. | |
joedow
2015/07/27 16:25:39
This comment is awkward, I think the method name i
tonychun
2015/07/27 21:20:42
I've added clearer comments and changed the name t
| |
35 void SetInitializingState(); | |
36 | |
37 // Prints out connection performance stats to STDOUT. | |
38 void DisplayConnectionStats() const; | |
39 | |
40 // Returns the time delta in milliseconds between |start_state| and | |
41 // |end_state| stored in |transition_times_map_|. | |
42 base::TimeDelta GetStateTransitionDelayTimeDelta( | |
anandc
2015/07/27 18:22:29
GetStateTransitionTime.
tonychun
2015/07/27 21:20:42
Done.
| |
43 protocol::ConnectionToHost::State start_state, | |
44 protocol::ConnectionToHost::State end_state) const; | |
45 | |
46 // Used to set fake state transition times for ConnectionTimeObserver tests. | |
47 void SetTransitionTimesMapForTest( | |
48 const std::map<protocol::ConnectionToHost::State, base::TimeTicks>& map); | |
49 | |
50 private: | |
51 // Saves the current connection state of client to host. | |
52 protocol::ConnectionToHost::State current_connection_state_ = | |
53 protocol::ConnectionToHost::State::INITIALIZING; | |
54 | |
55 // Stores TimeTick of states the client changes to. | |
anandc
2015/07/27 18:22:29
"The TimeTicks to get to a state from the previous
tonychun
2015/07/27 21:20:42
Done.
| |
56 std::map<protocol::ConnectionToHost::State, base::TimeTicks> | |
57 transition_times_map_; | |
58 | |
59 // Allows for observer to run timer's closure. ConnectionTimeObserver does not | |
60 // does not own the lifetime of the timer, so the timer should outlast the | |
61 // chromoting connection time and the ConnectionTimeObserver. | |
62 base::Timer* timer_; | |
63 | |
64 DISALLOW_COPY_AND_ASSIGN(ConnectionTimeObserver); | |
65 }; | |
66 | |
67 } // namespace test | |
68 } // namespace remoting | |
69 | |
70 #endif // REMOTING_TEST_CONNECTION_TIME_OBSERVER_H_ | |
OLD | NEW |