OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 /** | 5 /** |
6 * @fileoverview | 6 * @fileoverview |
7 * Module for sending log entries to the server. | 7 * Module for sending log entries to the server. |
8 */ | 8 */ |
9 | 9 |
10 'use strict'; | 10 'use strict'; |
11 | 11 |
12 /** @suppress {duplicate} */ | 12 /** @suppress {duplicate} */ |
13 var remoting = remoting || {}; | 13 var remoting = remoting || {}; |
14 | 14 |
15 /** | 15 /** |
16 * @param {remoting.SignalStrategy} signalStrategy Signal strategy. | 16 * @param {remoting.SignalStrategy} signalStrategy Signal strategy. |
| 17 * @param {boolean=} opt_isHost True if this instance should log role=host |
| 18 * events rather than role=client. |
17 * @constructor | 19 * @constructor |
18 */ | 20 */ |
19 remoting.LogToServer = function(signalStrategy) { | 21 remoting.LogToServer = function(signalStrategy, opt_isHost) { |
20 /** @private */ | 22 /** @private */ |
21 this.statsAccumulator_ = new remoting.StatsAccumulator(); | 23 this.statsAccumulator_ = new remoting.StatsAccumulator(); |
22 /** @private */ | 24 /** @private */ |
23 this.sessionId_ = ''; | 25 this.sessionId_ = ''; |
24 /** @private */ | 26 /** @private */ |
25 this.sessionIdGenerationTime_ = 0; | 27 this.sessionIdGenerationTime_ = 0; |
26 /** @private */ | 28 /** @private */ |
27 this.sessionStartTime_ = new Date().getTime(); | 29 this.sessionStartTime_ = new Date().getTime(); |
28 /** @private */ | 30 /** @private */ |
29 this.signalStrategy_ = signalStrategy; | 31 this.signalStrategy_ = signalStrategy; |
30 /** @private {string} */ | 32 /** @private {string} */ |
31 this.connectionType_ = ''; | 33 this.connectionType_ = ''; |
32 /** @private */ | 34 /** @private */ |
33 this.authTotalTime_ = 0; | 35 this.authTotalTime_ = 0; |
34 /** @private {string} */ | 36 /** @private {string} */ |
35 this.hostVersion_ = ''; | 37 this.hostVersion_ = ''; |
36 /** @private */ | 38 /** @private */ |
37 this.logEntryMode_ = remoting.ServerLogEntry.VALUE_MODE_UNKNOWN; | 39 this.logEntryMode_ = remoting.ServerLogEntry.VALUE_MODE_UNKNOWN; |
| 40 /** @private */ |
| 41 this.role_ = opt_isHost ? 'host' : 'client'; |
38 | 42 |
39 this.setSessionId_(); | 43 this.setSessionId(); |
40 signalStrategy.sendConnectionSetupResults(this); | 44 signalStrategy.sendConnectionSetupResults(this); |
41 }; | 45 }; |
42 | 46 |
43 // Constants used for generating a session ID. | 47 // Constants used for generating a session ID. |
44 /** @private */ | 48 /** @private */ |
45 remoting.LogToServer.SESSION_ID_ALPHABET_ = | 49 remoting.LogToServer.SESSION_ID_ALPHABET_ = |
46 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'; | 50 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'; |
47 /** @private */ | 51 /** @private */ |
48 remoting.LogToServer.SESSION_ID_LEN_ = 20; | 52 remoting.LogToServer.SESSION_ID_LEN_ = 20; |
49 | 53 |
50 // The maximum age of a session ID, in milliseconds. | 54 // The maximum age of a session ID, in milliseconds. |
51 remoting.LogToServer.MAX_SESSION_ID_AGE = 24 * 60 * 60 * 1000; | 55 remoting.LogToServer.MAX_SESSION_ID_AGE = 24 * 60 * 60 * 1000; |
52 | 56 |
53 // The time over which to accumulate connection statistics before logging them | 57 // The time over which to accumulate connection statistics before logging them |
54 // to the server, in milliseconds. | 58 // to the server, in milliseconds. |
55 remoting.LogToServer.CONNECTION_STATS_ACCUMULATE_TIME = 60 * 1000; | 59 remoting.LogToServer.CONNECTION_STATS_ACCUMULATE_TIME = 60 * 1000; |
56 | 60 |
57 /** | 61 /** |
58 * Logs a client session state change. | 62 * Logs a client session state change. |
59 * | 63 * |
60 * @param {remoting.ClientSession.State} state | 64 * @param {remoting.ClientSession.State} state |
61 * @param {!remoting.Error} connectionError | 65 * @param {!remoting.Error} connectionError |
62 */ | 66 */ |
63 remoting.LogToServer.prototype.logClientSessionStateChange = | 67 remoting.LogToServer.prototype.logClientSessionStateChange = |
64 function(state, connectionError) { | 68 function(state, connectionError) { |
65 this.maybeExpireSessionId_(); | 69 this.maybeExpireSessionId_(); |
66 // Log the session state change. | 70 // Log the session state change. |
67 var entry = remoting.ServerLogEntry.makeClientSessionStateChange( | 71 var entry = remoting.ServerLogEntry.makeClientSessionStateChange( |
68 state, connectionError, this.logEntryMode_); | 72 state, connectionError, this.logEntryMode_, this.role_); |
69 entry.addClientOSFields(); | 73 entry.addClientOSFields(); |
70 entry.addChromeVersionField(); | 74 entry.addChromeVersionField(); |
71 entry.addWebappVersionField(); | 75 entry.addWebappVersionField(); |
72 entry.addSessionIdField(this.sessionId_); | 76 entry.addSessionIdField(this.sessionId_); |
73 this.log_(entry); | 77 this.log_(entry); |
74 // Don't accumulate connection statistics across state changes. | 78 // Don't accumulate connection statistics across state changes. |
75 this.logAccumulatedStatistics_(); | 79 this.logAccumulatedStatistics_(); |
76 this.statsAccumulator_.empty(); | 80 this.statsAccumulator_.empty(); |
77 // Maybe clear the session ID. | 81 // Maybe clear the session ID. |
78 if (remoting.LogToServer.isEndOfSession_(state)) { | 82 if (remoting.LogToServer.isEndOfSession_(state)) { |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 'type="set" xmlns:cli="jabber:client">' + | 201 'type="set" xmlns:cli="jabber:client">' + |
198 '<gr:log xmlns:gr="google:remoting">' + | 202 '<gr:log xmlns:gr="google:remoting">' + |
199 entry.toStanza() + | 203 entry.toStanza() + |
200 '</gr:log>' + | 204 '</gr:log>' + |
201 '</cli:iq>'; | 205 '</cli:iq>'; |
202 this.signalStrategy_.sendMessage(stanza); | 206 this.signalStrategy_.sendMessage(stanza); |
203 }; | 207 }; |
204 | 208 |
205 /** | 209 /** |
206 * Sets the session ID to a random string. | 210 * Sets the session ID to a random string. |
207 * | |
208 * @private | |
209 */ | 211 */ |
210 remoting.LogToServer.prototype.setSessionId_ = function() { | 212 remoting.LogToServer.prototype.setSessionId = function() { |
211 this.sessionId_ = remoting.LogToServer.generateSessionId_(); | 213 this.sessionId_ = remoting.LogToServer.generateSessionId_(); |
212 this.sessionIdGenerationTime_ = new Date().getTime(); | 214 this.sessionIdGenerationTime_ = new Date().getTime(); |
213 }; | 215 }; |
214 | 216 |
215 /** | 217 /** |
216 * Clears the session ID. | 218 * Clears the session ID. |
217 * | 219 * |
218 * @private | 220 * @private |
219 */ | 221 */ |
220 remoting.LogToServer.prototype.clearSessionId_ = function() { | 222 remoting.LogToServer.prototype.clearSessionId_ = function() { |
(...skipping 11 matching lines...) Expand all Loading... |
232 */ | 234 */ |
233 remoting.LogToServer.prototype.maybeExpireSessionId_ = function() { | 235 remoting.LogToServer.prototype.maybeExpireSessionId_ = function() { |
234 if ((this.sessionId_ != '') && | 236 if ((this.sessionId_ != '') && |
235 (new Date().getTime() - this.sessionIdGenerationTime_ >= | 237 (new Date().getTime() - this.sessionIdGenerationTime_ >= |
236 remoting.LogToServer.MAX_SESSION_ID_AGE)) { | 238 remoting.LogToServer.MAX_SESSION_ID_AGE)) { |
237 // Log the old session ID. | 239 // Log the old session ID. |
238 var entry = remoting.ServerLogEntry.makeSessionIdOld(this.sessionId_, | 240 var entry = remoting.ServerLogEntry.makeSessionIdOld(this.sessionId_, |
239 this.logEntryMode_); | 241 this.logEntryMode_); |
240 this.log_(entry); | 242 this.log_(entry); |
241 // Generate a new session ID. | 243 // Generate a new session ID. |
242 this.setSessionId_(); | 244 this.setSessionId(); |
243 // Log the new session ID. | 245 // Log the new session ID. |
244 entry = remoting.ServerLogEntry.makeSessionIdNew(this.sessionId_, | 246 entry = remoting.ServerLogEntry.makeSessionIdNew(this.sessionId_, |
245 this.logEntryMode_); | 247 this.logEntryMode_); |
246 this.log_(entry); | 248 this.log_(entry); |
247 } | 249 } |
248 }; | 250 }; |
249 | 251 |
250 /** | 252 /** |
251 * Generates a string that can be used as a session ID. | 253 * Generates a string that can be used as a session ID. |
252 * | 254 * |
(...skipping 19 matching lines...) Expand all Loading... |
272 this.authTotalTime_ = totalTime; | 274 this.authTotalTime_ = totalTime; |
273 }; | 275 }; |
274 | 276 |
275 /** | 277 /** |
276 * @param {string} hostVersion Version of the host for current session. | 278 * @param {string} hostVersion Version of the host for current session. |
277 * @return {void} Nothing. | 279 * @return {void} Nothing. |
278 */ | 280 */ |
279 remoting.LogToServer.prototype.setHostVersion = function(hostVersion) { | 281 remoting.LogToServer.prototype.setHostVersion = function(hostVersion) { |
280 this.hostVersion_ = hostVersion; | 282 this.hostVersion_ = hostVersion; |
281 }; | 283 }; |
OLD | NEW |