| 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/log_to_server.h" | 5 #include "remoting/client/log_to_server.h" |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/rand_util.h" | 8 #include "base/rand_util.h" |
| 9 #include "remoting/base/constants.h" | 9 #include "remoting/base/constants.h" |
| 10 #include "remoting/client/chromoting_stats.h" | 10 #include "remoting/client/chromoting_stats.h" |
| 11 #include "remoting/client/server_log_entry_client.h" |
| 11 #include "remoting/jingle_glue/iq_sender.h" | 12 #include "remoting/jingle_glue/iq_sender.h" |
| 12 #include "remoting/jingle_glue/signal_strategy.h" | 13 #include "remoting/jingle_glue/signal_strategy.h" |
| 13 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h" | 14 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h" |
| 14 #include "third_party/libjingle/source/talk/xmpp/constants.h" | 15 #include "third_party/libjingle/source/talk/xmpp/constants.h" |
| 15 | 16 |
| 16 using buzz::QName; | 17 using buzz::QName; |
| 17 using buzz::XmlElement; | 18 using buzz::XmlElement; |
| 18 using remoting::protocol::ConnectionToHost; | 19 using remoting::protocol::ConnectionToHost; |
| 20 using remoting::protocol::ServerLogEntry; |
| 19 | 21 |
| 20 namespace { | 22 namespace { |
| 21 | 23 |
| 22 const char kSessionIdAlphabet[] = | 24 const char kSessionIdAlphabet[] = |
| 23 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"; | 25 "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"; |
| 24 const int kSessionIdLength = 20; | 26 const int kSessionIdLength = 20; |
| 25 | 27 |
| 26 const int kMaxSessionIdAgeDays = 1; | 28 const int kMaxSessionIdAgeDays = 1; |
| 27 | 29 |
| 28 bool IsStartOfSession(ConnectionToHost::State state) { | 30 bool IsStartOfSession(ConnectionToHost::State state) { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 LogToServer::~LogToServer() { | 64 LogToServer::~LogToServer() { |
| 63 signal_strategy_->RemoveListener(this); | 65 signal_strategy_->RemoveListener(this); |
| 64 } | 66 } |
| 65 | 67 |
| 66 void LogToServer::LogSessionStateChange( | 68 void LogToServer::LogSessionStateChange( |
| 67 protocol::ConnectionToHost::State state, | 69 protocol::ConnectionToHost::State state, |
| 68 protocol::ErrorCode error) { | 70 protocol::ErrorCode error) { |
| 69 DCHECK(CalledOnValidThread()); | 71 DCHECK(CalledOnValidThread()); |
| 70 | 72 |
| 71 scoped_ptr<ServerLogEntry> entry( | 73 scoped_ptr<ServerLogEntry> entry( |
| 72 ServerLogEntry::MakeForSessionStateChange(state, error)); | 74 MakeLogEntryForSessionStateChange(state, error)); |
| 73 entry->AddClientFields(); | 75 AddClientFieldsToLogEntry(entry.get()); |
| 74 entry->AddModeField(mode_); | 76 entry->AddModeField(mode_); |
| 75 | 77 |
| 76 MaybeExpireSessionId(); | 78 MaybeExpireSessionId(); |
| 77 if (IsStartOfSession(state)) { | 79 if (IsStartOfSession(state)) { |
| 78 // Maybe set the session ID and start time. | 80 // Maybe set the session ID and start time. |
| 79 if (session_id_.empty()) { | 81 if (session_id_.empty()) { |
| 80 GenerateSessionId(); | 82 GenerateSessionId(); |
| 81 } | 83 } |
| 82 if (session_start_time_.is_null()) { | 84 if (session_start_time_.is_null()) { |
| 83 session_start_time_ = base::TimeTicks::Now(); | 85 session_start_time_ = base::TimeTicks::Now(); |
| 84 } | 86 } |
| 85 } | 87 } |
| 86 | 88 |
| 87 if (!session_id_.empty()) { | 89 if (!session_id_.empty()) { |
| 88 entry->AddSessionId(session_id_); | 90 AddSessionIdToLogEntry(entry.get(), session_id_); |
| 89 } | 91 } |
| 90 | 92 |
| 91 // Maybe clear the session start time and log the session duration. | 93 // Maybe clear the session start time and log the session duration. |
| 92 if (ShouldAddDuration(state) && !session_start_time_.is_null()) { | 94 if (ShouldAddDuration(state) && !session_start_time_.is_null()) { |
| 93 entry->AddSessionDuration(base::TimeTicks::Now() - session_start_time_); | 95 AddSessionDurationToLogEntry(entry.get(), |
| 96 base::TimeTicks::Now() - session_start_time_); |
| 94 } | 97 } |
| 95 | 98 |
| 96 if (IsEndOfSession(state)) { | 99 if (IsEndOfSession(state)) { |
| 97 session_start_time_ = base::TimeTicks(); | 100 session_start_time_ = base::TimeTicks(); |
| 98 session_id_.clear(); | 101 session_id_.clear(); |
| 99 } | 102 } |
| 100 | 103 |
| 101 Log(*entry.get()); | 104 Log(*entry.get()); |
| 102 } | 105 } |
| 103 | 106 |
| 104 void LogToServer::LogStatistics(ChromotingStats* statistics) { | 107 void LogToServer::LogStatistics(ChromotingStats* statistics) { |
| 105 DCHECK(CalledOnValidThread()); | 108 DCHECK(CalledOnValidThread()); |
| 106 | 109 |
| 107 MaybeExpireSessionId(); | 110 MaybeExpireSessionId(); |
| 108 | 111 |
| 109 scoped_ptr<ServerLogEntry> entry( | 112 scoped_ptr<ServerLogEntry> entry(MakeLogEntryForStatistics(statistics)); |
| 110 ServerLogEntry::MakeForStatistics(statistics)); | 113 AddClientFieldsToLogEntry(entry.get()); |
| 111 entry->AddClientFields(); | |
| 112 entry->AddModeField(mode_); | 114 entry->AddModeField(mode_); |
| 113 entry->AddSessionId(session_id_); | 115 AddSessionIdToLogEntry(entry.get(), session_id_); |
| 114 Log(*entry.get()); | 116 Log(*entry.get()); |
| 115 } | 117 } |
| 116 | 118 |
| 117 void LogToServer::OnSignalStrategyStateChange(SignalStrategy::State state) { | 119 void LogToServer::OnSignalStrategyStateChange(SignalStrategy::State state) { |
| 118 DCHECK(CalledOnValidThread()); | 120 DCHECK(CalledOnValidThread()); |
| 119 | 121 |
| 120 if (state == SignalStrategy::CONNECTED) { | 122 if (state == SignalStrategy::CONNECTED) { |
| 121 iq_sender_.reset(new IqSender(signal_strategy_)); | 123 iq_sender_.reset(new IqSender(signal_strategy_)); |
| 122 SendPendingEntries(); | 124 SendPendingEntries(); |
| 123 } else if (state == SignalStrategy::DISCONNECTED) { | 125 } else if (state == SignalStrategy::DISCONNECTED) { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 } | 169 } |
| 168 | 170 |
| 169 void LogToServer::MaybeExpireSessionId() { | 171 void LogToServer::MaybeExpireSessionId() { |
| 170 if (session_id_.empty()) { | 172 if (session_id_.empty()) { |
| 171 return; | 173 return; |
| 172 } | 174 } |
| 173 | 175 |
| 174 base::TimeDelta max_age = base::TimeDelta::FromDays(kMaxSessionIdAgeDays); | 176 base::TimeDelta max_age = base::TimeDelta::FromDays(kMaxSessionIdAgeDays); |
| 175 if (base::TimeTicks::Now() - session_id_generation_time_ > max_age) { | 177 if (base::TimeTicks::Now() - session_id_generation_time_ > max_age) { |
| 176 // Log the old session ID. | 178 // Log the old session ID. |
| 177 scoped_ptr<ServerLogEntry> entry( | 179 scoped_ptr<ServerLogEntry> entry(MakeLogEntryForSessionIdOld(session_id_)); |
| 178 ServerLogEntry::MakeForSessionIdOld(session_id_)); | |
| 179 entry->AddModeField(mode_); | 180 entry->AddModeField(mode_); |
| 180 Log(*entry.get()); | 181 Log(*entry.get()); |
| 181 | 182 |
| 182 // Generate a new session ID. | 183 // Generate a new session ID. |
| 183 GenerateSessionId(); | 184 GenerateSessionId(); |
| 184 | 185 |
| 185 // Log the new session ID. | 186 // Log the new session ID. |
| 186 entry = ServerLogEntry::MakeForSessionIdNew(session_id_); | 187 entry = MakeLogEntryForSessionIdNew(session_id_); |
| 187 entry->AddModeField(mode_); | 188 entry->AddModeField(mode_); |
| 188 Log(*entry.get()); | 189 Log(*entry.get()); |
| 189 } | 190 } |
| 190 } | 191 } |
| 191 | 192 |
| 192 } // namespace client | 193 } // namespace client |
| 193 | 194 |
| 194 } // namespace remoting | 195 } // namespace remoting |
| OLD | NEW |