Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(177)

Side by Side Diff: remoting/client/log_to_server.cc

Issue 282063005: Pull out common code from client and host versions of ServerLogEntry. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Move ServerLogEntry to jingle_glue Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « remoting/client/log_to_server.h ('k') | remoting/client/server_log_entry.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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;
19 20
20 namespace { 21 namespace {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 LogToServer::~LogToServer() { 63 LogToServer::~LogToServer() {
63 signal_strategy_->RemoveListener(this); 64 signal_strategy_->RemoveListener(this);
64 } 65 }
65 66
66 void LogToServer::LogSessionStateChange( 67 void LogToServer::LogSessionStateChange(
67 protocol::ConnectionToHost::State state, 68 protocol::ConnectionToHost::State state,
68 protocol::ErrorCode error) { 69 protocol::ErrorCode error) {
69 DCHECK(CalledOnValidThread()); 70 DCHECK(CalledOnValidThread());
70 71
71 scoped_ptr<ServerLogEntry> entry( 72 scoped_ptr<ServerLogEntry> entry(
72 ServerLogEntry::MakeForSessionStateChange(state, error)); 73 MakeLogEntryForSessionStateChange(state, error));
73 entry->AddClientFields(); 74 AddClientFieldsToLogEntry(entry.get());
74 entry->AddModeField(mode_); 75 entry->AddModeField(mode_);
75 76
76 MaybeExpireSessionId(); 77 MaybeExpireSessionId();
77 if (IsStartOfSession(state)) { 78 if (IsStartOfSession(state)) {
78 // Maybe set the session ID and start time. 79 // Maybe set the session ID and start time.
79 if (session_id_.empty()) { 80 if (session_id_.empty()) {
80 GenerateSessionId(); 81 GenerateSessionId();
81 } 82 }
82 if (session_start_time_.is_null()) { 83 if (session_start_time_.is_null()) {
83 session_start_time_ = base::TimeTicks::Now(); 84 session_start_time_ = base::TimeTicks::Now();
84 } 85 }
85 } 86 }
86 87
87 if (!session_id_.empty()) { 88 if (!session_id_.empty()) {
88 entry->AddSessionId(session_id_); 89 AddSessionIdToLogEntry(entry.get(), session_id_);
89 } 90 }
90 91
91 // Maybe clear the session start time and log the session duration. 92 // Maybe clear the session start time and log the session duration.
92 if (ShouldAddDuration(state) && !session_start_time_.is_null()) { 93 if (ShouldAddDuration(state) && !session_start_time_.is_null()) {
93 entry->AddSessionDuration(base::TimeTicks::Now() - session_start_time_); 94 AddSessionDurationToLogEntry(entry.get(),
95 base::TimeTicks::Now() - session_start_time_);
94 } 96 }
95 97
96 if (IsEndOfSession(state)) { 98 if (IsEndOfSession(state)) {
97 session_start_time_ = base::TimeTicks(); 99 session_start_time_ = base::TimeTicks();
98 session_id_.clear(); 100 session_id_.clear();
99 } 101 }
100 102
101 Log(*entry.get()); 103 Log(*entry.get());
102 } 104 }
103 105
104 void LogToServer::LogStatistics(ChromotingStats* statistics) { 106 void LogToServer::LogStatistics(ChromotingStats* statistics) {
105 DCHECK(CalledOnValidThread()); 107 DCHECK(CalledOnValidThread());
106 108
107 MaybeExpireSessionId(); 109 MaybeExpireSessionId();
108 110
109 scoped_ptr<ServerLogEntry> entry( 111 scoped_ptr<ServerLogEntry> entry(MakeLogEntryForStatistics(statistics));
110 ServerLogEntry::MakeForStatistics(statistics)); 112 AddClientFieldsToLogEntry(entry.get());
111 entry->AddClientFields();
112 entry->AddModeField(mode_); 113 entry->AddModeField(mode_);
113 entry->AddSessionId(session_id_); 114 AddSessionIdToLogEntry(entry.get(), session_id_);
114 Log(*entry.get()); 115 Log(*entry.get());
115 } 116 }
116 117
117 void LogToServer::OnSignalStrategyStateChange(SignalStrategy::State state) { 118 void LogToServer::OnSignalStrategyStateChange(SignalStrategy::State state) {
118 DCHECK(CalledOnValidThread()); 119 DCHECK(CalledOnValidThread());
119 120
120 if (state == SignalStrategy::CONNECTED) { 121 if (state == SignalStrategy::CONNECTED) {
121 iq_sender_.reset(new IqSender(signal_strategy_)); 122 iq_sender_.reset(new IqSender(signal_strategy_));
122 SendPendingEntries(); 123 SendPendingEntries();
123 } else if (state == SignalStrategy::DISCONNECTED) { 124 } else if (state == SignalStrategy::DISCONNECTED) {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 } 168 }
168 169
169 void LogToServer::MaybeExpireSessionId() { 170 void LogToServer::MaybeExpireSessionId() {
170 if (session_id_.empty()) { 171 if (session_id_.empty()) {
171 return; 172 return;
172 } 173 }
173 174
174 base::TimeDelta max_age = base::TimeDelta::FromDays(kMaxSessionIdAgeDays); 175 base::TimeDelta max_age = base::TimeDelta::FromDays(kMaxSessionIdAgeDays);
175 if (base::TimeTicks::Now() - session_id_generation_time_ > max_age) { 176 if (base::TimeTicks::Now() - session_id_generation_time_ > max_age) {
176 // Log the old session ID. 177 // Log the old session ID.
177 scoped_ptr<ServerLogEntry> entry( 178 scoped_ptr<ServerLogEntry> entry(MakeLogEntryForSessionIdOld(session_id_));
178 ServerLogEntry::MakeForSessionIdOld(session_id_));
179 entry->AddModeField(mode_); 179 entry->AddModeField(mode_);
180 Log(*entry.get()); 180 Log(*entry.get());
181 181
182 // Generate a new session ID. 182 // Generate a new session ID.
183 GenerateSessionId(); 183 GenerateSessionId();
184 184
185 // Log the new session ID. 185 // Log the new session ID.
186 entry = ServerLogEntry::MakeForSessionIdNew(session_id_); 186 entry = MakeLogEntryForSessionIdNew(session_id_);
187 entry->AddModeField(mode_); 187 entry->AddModeField(mode_);
188 Log(*entry.get()); 188 Log(*entry.get());
189 } 189 }
190 } 190 }
191 191
192 } // namespace client 192 } // namespace client
193 193
194 } // namespace remoting 194 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/client/log_to_server.h ('k') | remoting/client/server_log_entry.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698