OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "remoting/client/client_status_logger.h" | 5 #include "remoting/client/client_status_logger.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "base/rand_util.h" | 9 #include "base/rand_util.h" |
10 #include "remoting/client/server_log_entry_client.h" | 10 #include "remoting/client/server_log_entry_client.h" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 } | 50 } |
51 | 51 |
52 ClientStatusLogger::~ClientStatusLogger() { | 52 ClientStatusLogger::~ClientStatusLogger() { |
53 } | 53 } |
54 | 54 |
55 void ClientStatusLogger::LogSessionStateChange( | 55 void ClientStatusLogger::LogSessionStateChange( |
56 protocol::ConnectionToHost::State state, | 56 protocol::ConnectionToHost::State state, |
57 protocol::ErrorCode error) { | 57 protocol::ErrorCode error) { |
58 DCHECK(CalledOnValidThread()); | 58 DCHECK(CalledOnValidThread()); |
59 | 59 |
60 scoped_ptr<ServerLogEntry> entry( | 60 std::unique_ptr<ServerLogEntry> entry( |
61 MakeLogEntryForSessionStateChange(state, error)); | 61 MakeLogEntryForSessionStateChange(state, error)); |
62 AddClientFieldsToLogEntry(entry.get()); | 62 AddClientFieldsToLogEntry(entry.get()); |
63 entry->AddModeField(log_to_server_.mode()); | 63 entry->AddModeField(log_to_server_.mode()); |
64 | 64 |
65 MaybeExpireSessionId(); | 65 MaybeExpireSessionId(); |
66 if (IsStartOfSession(state)) { | 66 if (IsStartOfSession(state)) { |
67 // Maybe set the session ID and start time. | 67 // Maybe set the session ID and start time. |
68 if (session_id_.empty()) { | 68 if (session_id_.empty()) { |
69 GenerateSessionId(); | 69 GenerateSessionId(); |
70 } | 70 } |
(...skipping 19 matching lines...) Expand all Loading... |
90 | 90 |
91 log_to_server_.Log(*entry.get()); | 91 log_to_server_.Log(*entry.get()); |
92 } | 92 } |
93 | 93 |
94 void ClientStatusLogger::LogStatistics( | 94 void ClientStatusLogger::LogStatistics( |
95 protocol::PerformanceTracker* perf_tracker) { | 95 protocol::PerformanceTracker* perf_tracker) { |
96 DCHECK(CalledOnValidThread()); | 96 DCHECK(CalledOnValidThread()); |
97 | 97 |
98 MaybeExpireSessionId(); | 98 MaybeExpireSessionId(); |
99 | 99 |
100 scoped_ptr<ServerLogEntry> entry(MakeLogEntryForStatistics(perf_tracker)); | 100 std::unique_ptr<ServerLogEntry> entry( |
| 101 MakeLogEntryForStatistics(perf_tracker)); |
101 AddClientFieldsToLogEntry(entry.get()); | 102 AddClientFieldsToLogEntry(entry.get()); |
102 entry->AddModeField(log_to_server_.mode()); | 103 entry->AddModeField(log_to_server_.mode()); |
103 AddSessionIdToLogEntry(entry.get(), session_id_); | 104 AddSessionIdToLogEntry(entry.get(), session_id_); |
104 log_to_server_.Log(*entry.get()); | 105 log_to_server_.Log(*entry.get()); |
105 } | 106 } |
106 | 107 |
107 void ClientStatusLogger::SetSignalingStateForTest(SignalStrategy::State state) { | 108 void ClientStatusLogger::SetSignalingStateForTest(SignalStrategy::State state) { |
108 log_to_server_.OnSignalStrategyStateChange(state); | 109 log_to_server_.OnSignalStrategyStateChange(state); |
109 } | 110 } |
110 | 111 |
111 void ClientStatusLogger::GenerateSessionId() { | 112 void ClientStatusLogger::GenerateSessionId() { |
112 session_id_.resize(kSessionIdLength); | 113 session_id_.resize(kSessionIdLength); |
113 for (int i = 0; i < kSessionIdLength; i++) { | 114 for (int i = 0; i < kSessionIdLength; i++) { |
114 const int alphabet_size = arraysize(kSessionIdAlphabet) - 1; | 115 const int alphabet_size = arraysize(kSessionIdAlphabet) - 1; |
115 session_id_[i] = kSessionIdAlphabet[base::RandGenerator(alphabet_size)]; | 116 session_id_[i] = kSessionIdAlphabet[base::RandGenerator(alphabet_size)]; |
116 } | 117 } |
117 session_id_generation_time_ = base::TimeTicks::Now(); | 118 session_id_generation_time_ = base::TimeTicks::Now(); |
118 } | 119 } |
119 | 120 |
120 void ClientStatusLogger::MaybeExpireSessionId() { | 121 void ClientStatusLogger::MaybeExpireSessionId() { |
121 if (session_id_.empty()) { | 122 if (session_id_.empty()) { |
122 return; | 123 return; |
123 } | 124 } |
124 | 125 |
125 base::TimeDelta max_age = base::TimeDelta::FromDays(kMaxSessionIdAgeDays); | 126 base::TimeDelta max_age = base::TimeDelta::FromDays(kMaxSessionIdAgeDays); |
126 if (base::TimeTicks::Now() - session_id_generation_time_ > max_age) { | 127 if (base::TimeTicks::Now() - session_id_generation_time_ > max_age) { |
127 // Log the old session ID. | 128 // Log the old session ID. |
128 scoped_ptr<ServerLogEntry> entry(MakeLogEntryForSessionIdOld(session_id_)); | 129 std::unique_ptr<ServerLogEntry> entry( |
| 130 MakeLogEntryForSessionIdOld(session_id_)); |
129 entry->AddModeField(log_to_server_.mode()); | 131 entry->AddModeField(log_to_server_.mode()); |
130 log_to_server_.Log(*entry.get()); | 132 log_to_server_.Log(*entry.get()); |
131 | 133 |
132 // Generate a new session ID. | 134 // Generate a new session ID. |
133 GenerateSessionId(); | 135 GenerateSessionId(); |
134 | 136 |
135 // Log the new session ID. | 137 // Log the new session ID. |
136 entry = MakeLogEntryForSessionIdNew(session_id_); | 138 entry = MakeLogEntryForSessionIdNew(session_id_); |
137 entry->AddModeField(log_to_server_.mode()); | 139 entry->AddModeField(log_to_server_.mode()); |
138 log_to_server_.Log(*entry.get()); | 140 log_to_server_.Log(*entry.get()); |
139 } | 141 } |
140 } | 142 } |
141 | 143 |
142 } // namespace remoting | 144 } // namespace remoting |
OLD | NEW |