Chromium Code Reviews| 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 #include "remoting/test/connection_time_observer.h" | |
| 6 | |
| 7 #include <utility> | |
| 8 | |
| 9 #include "base/time/time.h" | |
| 10 | |
| 11 namespace { | |
|
Sergey Ulanov
2015/07/23 19:20:57
Move this inside remoting::test namespace then you
tonychun
2015/07/24 01:41:47
Done.
| |
| 12 | |
| 13 std::string GetStateAsString( | |
| 14 const remoting::protocol::ConnectionToHost::State& state) { | |
| 15 switch (state) { | |
| 16 case remoting::protocol::ConnectionToHost::State::INITIALIZING: | |
| 17 return "INITIALIZING"; | |
| 18 case remoting::protocol::ConnectionToHost::State::CONNECTING: | |
| 19 return "CONNECTING"; | |
| 20 case remoting::protocol::ConnectionToHost::State::AUTHENTICATED: | |
| 21 return "AUTHENTICATED"; | |
| 22 case remoting::protocol::ConnectionToHost::State::CONNECTED: | |
| 23 return "CONNECTED"; | |
| 24 case remoting::protocol::ConnectionToHost::State::FAILED: | |
| 25 return "FAILED"; | |
| 26 case remoting::protocol::ConnectionToHost::State::CLOSED: | |
| 27 return "CLOSED"; | |
| 28 default: | |
| 29 LOG(ERROR) << "Unknown current state"; | |
|
joedow
2015/07/23 16:57:54
When printing errors in default cases it is useful
tonychun
2015/07/24 01:41:47
Done.
| |
| 30 NOTREACHED(); | |
| 31 return std::string(); | |
| 32 } | |
| 33 } | |
| 34 | |
| 35 } // namespace | |
| 36 | |
| 37 namespace remoting { | |
| 38 namespace test { | |
| 39 | |
| 40 ConnectionTimeObserver::ConnectionTimeObserver() { | |
| 41 // Stores TimeTicks at INITIALIZING state when observer is constructed. | |
| 42 transition_times_map_.insert( | |
| 43 std::make_pair(current_state_, base::TimeTicks::Now())); | |
|
joedow
2015/07/23 16:57:54
I don't think this should occur in the C'Tor, you
tonychun
2015/07/24 01:41:47
Done.
| |
| 44 } | |
| 45 | |
| 46 ConnectionTimeObserver::~ConnectionTimeObserver() { | |
| 47 } | |
| 48 | |
| 49 void ConnectionTimeObserver::ConnectionStateChanged( | |
| 50 protocol::ConnectionToHost::State state, | |
| 51 protocol::ErrorCode error_code) { | |
| 52 // Save the current TimeTick of the new state into |transition_times_map_|. | |
|
joedow
2015/07/23 16:57:54
Please remove comment, it is just stating what the
tonychun
2015/07/24 01:41:47
Done.
| |
| 53 transition_times_map_.insert(std::make_pair(state, base::TimeTicks::Now())); | |
| 54 | |
| 55 VLOG(1) << "Delta Time from " << GetStateAsString(current_state_) | |
| 56 << " to " << GetStateAsString(state) | |
| 57 << ": " << GetStateTransitionDelay(current_state_, state) << " ms"; | |
| 58 | |
| 59 // Update the current state of the client. | |
|
joedow
2015/07/23 16:57:54
please remove comment, documenting code, same as o
tonychun
2015/07/24 01:41:46
Done.
| |
| 60 current_state_ = state; | |
| 61 } | |
| 62 | |
| 63 int ConnectionTimeObserver::GetStateTransitionDelay( | |
|
joedow
2015/07/23 16:57:54
Can you update the function name? It isn't obviou
tonychun
2015/07/24 01:41:47
I'm keeping it the way it is, but returning base::
| |
| 64 const protocol::ConnectionToHost::State& start_state, | |
| 65 const protocol::ConnectionToHost::State& end_state) const { | |
| 66 auto iter_start_state = transition_times_map_.find(start_state); | |
| 67 auto iter_end_state = transition_times_map_.find(end_state); | |
| 68 auto iter_end = transition_times_map_.end(); | |
| 69 | |
| 70 // If either one of the states aren't found, log an error and return -1. | |
| 71 // Otherwise, return the delta time between the two states. | |
|
joedow
2015/07/23 16:57:54
This comment isn't really needed, I can see what i
tonychun
2015/07/24 01:41:47
Good point. Thanks.
| |
| 72 if (iter_start_state == iter_end) { | |
|
joedow
2015/07/23 16:57:54
A better pattern for the return values would be to
tonychun
2015/07/24 01:41:47
Done.
| |
| 73 LOG(ERROR) << "No time found for state " << GetStateAsString(start_state); | |
| 74 } else if (iter_end_state == iter_end) { | |
| 75 LOG(ERROR) << "No time found for state " << GetStateAsString(end_state); | |
| 76 } else { | |
| 77 return (iter_end_state->second - iter_start_state->second).InMilliseconds(); | |
|
joedow
2015/07/23 16:57:54
You may want to check this value to ensure it isn'
tonychun
2015/07/24 01:41:47
Done.
| |
| 78 } | |
| 79 return -1; | |
|
joedow
2015/07/23 16:57:54
I wonder if 0 is a better option. No action shoul
Sergey Ulanov
2015/07/23 19:20:57
Normally we handle error cases first, and the end
Sergey Ulanov
2015/07/23 19:20:57
With base::TimeDelta result this can TimeDelta::Ma
tonychun
2015/07/24 01:41:47
Done.
| |
| 80 } | |
| 81 | |
|
joedow
2015/07/23 16:57:54
I think it would be good to add a function that ro
tonychun
2015/07/24 01:41:47
Done.
| |
| 82 } // namespace test | |
| 83 } // namespace remoting | |
| OLD | NEW |