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 {remoting.DesktopConnectedView.Mode} mode The mode of this connection. | 17 * @param {remoting.DesktopConnectedView.Mode} mode The mode of this connection. |
18 * @constructor | 18 * @constructor |
19 */ | 19 */ |
20 remoting.LogToServer = function(signalStrategy, mode) { | 20 remoting.LogToServer = function(signalStrategy, mode) { |
21 /** @private */ | 21 /** @private */ |
22 this.statsAccumulator_ = new remoting.StatsAccumulator(); | 22 this.statsAccumulator_ = new remoting.StatsAccumulator(); |
23 /** @private */ | 23 /** @private */ |
24 this.sessionId_ = ''; | 24 this.sessionId_ = ''; |
25 /** @private */ | 25 /** @private */ |
26 this.sessionIdGenerationTime_ = 0; | 26 this.sessionIdGenerationTime_ = 0; |
27 /** @private */ | 27 /** @private */ |
28 this.sessionStartTime_ = 0; | 28 this.sessionStartTime_ = new Date().getTime(); |
29 /** @private */ | 29 /** @private */ |
30 this.signalStrategy_ = signalStrategy; | 30 this.signalStrategy_ = signalStrategy; |
31 /** @private */ | 31 /** @private */ |
32 this.mode_ = mode; | 32 this.mode_ = mode; |
33 /** @type {string} @private */ | 33 /** @type {string} @private */ |
34 this.connectionType_ = ''; | 34 this.connectionType_ = ''; |
35 | 35 |
36 this.setSessionId_(); | 36 this.setSessionId_(); |
37 signalStrategy.sendConnectionSetupResults(this); | 37 signalStrategy.sendConnectionSetupResults(this); |
38 }; | 38 }; |
(...skipping 14 matching lines...) Expand all Loading... | |
53 | 53 |
54 /** | 54 /** |
55 * Logs a client session state change. | 55 * Logs a client session state change. |
56 * | 56 * |
57 * @param {remoting.ClientSession.State} state | 57 * @param {remoting.ClientSession.State} state |
58 * @param {remoting.Error} connectionError | 58 * @param {remoting.Error} connectionError |
59 */ | 59 */ |
60 remoting.LogToServer.prototype.logClientSessionStateChange = | 60 remoting.LogToServer.prototype.logClientSessionStateChange = |
61 function(state, connectionError) { | 61 function(state, connectionError) { |
62 this.maybeExpireSessionId_(); | 62 this.maybeExpireSessionId_(); |
63 // Set the session start time if we haven't done so already. | |
64 if (remoting.LogToServer.isStartOfSession_(state)) { | |
65 if (this.sessionStartTime_ == 0) { | |
66 this.sessionStartTime_ = new Date().getTime(); | |
67 } | |
68 } | |
69 // Log the session state change. | 63 // Log the session state change. |
70 var entry = remoting.ServerLogEntry.makeClientSessionStateChange( | 64 var entry = remoting.ServerLogEntry.makeClientSessionStateChange( |
71 state, connectionError, this.mode_); | 65 state, connectionError, this.mode_); |
72 entry.addHostFields(); | 66 entry.addHostFields(); |
73 entry.addChromeVersionField(); | 67 entry.addChromeVersionField(); |
74 entry.addWebappVersionField(); | 68 entry.addWebappVersionField(); |
75 entry.addSessionIdField(this.sessionId_); | 69 entry.addSessionIdField(this.sessionId_); |
76 // Maybe clear the session start time, and log the session duration. | 70 // Maybe clear the session start time, and log the session duration. |
77 if (remoting.LogToServer.shouldAddDuration_(state) && | 71 if (remoting.LogToServer.shouldAddDuration_(state)) { |
78 (this.sessionStartTime_ != 0)) { | |
79 entry.addSessionDurationField( | 72 entry.addSessionDurationField( |
80 (new Date().getTime() - this.sessionStartTime_) / 1000.0); | 73 (new Date().getTime() - this.sessionStartTime_) / 1000.0); |
81 if (remoting.LogToServer.isEndOfSession_(state)) { | |
82 this.sessionStartTime_ = 0; | |
83 } | |
84 } | 74 } |
75 | |
85 this.log_(entry); | 76 this.log_(entry); |
86 // Don't accumulate connection statistics across state changes. | 77 // Don't accumulate connection statistics across state changes. |
87 this.logAccumulatedStatistics_(); | 78 this.logAccumulatedStatistics_(); |
88 this.statsAccumulator_.empty(); | 79 this.statsAccumulator_.empty(); |
89 // Maybe clear the session ID. | 80 // Maybe clear the session ID. |
90 if (remoting.LogToServer.isEndOfSession_(state)) { | 81 if (remoting.LogToServer.isEndOfSession_(state)) { |
91 this.clearSessionId_(); | 82 this.clearSessionId_(); |
92 } | 83 } |
84 | |
93 }; | 85 }; |
94 | 86 |
95 /** | 87 /** |
96 * Set the connection type (direct, stun relay). | 88 * Set the connection type (direct, stun relay). |
97 * | 89 * |
98 * @param {string} connectionType | 90 * @param {string} connectionType |
99 */ | 91 */ |
100 remoting.LogToServer.prototype.setConnectionType = function(connectionType) { | 92 remoting.LogToServer.prototype.setConnectionType = function(connectionType) { |
101 this.connectionType_ = connectionType; | 93 this.connectionType_ = connectionType; |
102 }; | 94 }; |
103 | 95 |
104 /** | 96 /** |
105 * @param {remoting.SignalStrategy.Type} strategyType | 97 * @param {remoting.SignalStrategy.Type} strategyType |
106 * @param {remoting.FallbackSignalStrategy.Progress} progress | 98 * @param {remoting.FallbackSignalStrategy.Progress} progress |
107 * @param {number} elapsedTimeInMs | |
108 */ | 99 */ |
109 remoting.LogToServer.prototype.logSignalStrategyProgress = | 100 remoting.LogToServer.prototype.logSignalStrategyProgress = |
110 function(strategyType, progress, elapsedTimeInMs) { | 101 function(strategyType, progress) { |
111 this.maybeExpireSessionId_(); | 102 this.maybeExpireSessionId_(); |
112 var entry = remoting.ServerLogEntry.makeSignalStrategyProgress( | 103 var entry = remoting.ServerLogEntry.makeSignalStrategyProgress( |
113 this.sessionId_, strategyType, progress, elapsedTimeInMs); | 104 this.sessionId_, strategyType, progress); |
114 this.log_(entry); | 105 this.log_(entry); |
115 }; | 106 }; |
116 | 107 |
117 /** | 108 /** |
118 * Whether a session state is one of the states that occurs at the start of | 109 * Whether a session state is one of the states that occurs at the start of |
119 * a session. | 110 * a session. |
120 * | 111 * |
121 * @private | 112 * @private |
122 * @param {remoting.ClientSession.State} state | 113 * @param {remoting.ClientSession.State} state |
123 * @return {boolean} | 114 * @return {boolean} |
(...skipping 24 matching lines...) Expand all Loading... | |
148 * | 139 * |
149 * @private | 140 * @private |
150 * @param {remoting.ClientSession.State} state | 141 * @param {remoting.ClientSession.State} state |
151 * @return {boolean} | 142 * @return {boolean} |
152 */ | 143 */ |
153 remoting.LogToServer.shouldAddDuration_ = function(state) { | 144 remoting.LogToServer.shouldAddDuration_ = function(state) { |
154 // Duration is added to log entries at the end of the session, as well as at | 145 // Duration is added to log entries at the end of the session, as well as at |
155 // some intermediate states where it is relevant (e.g. to determine how long | 146 // some intermediate states where it is relevant (e.g. to determine how long |
156 // it took for a session to become CONNECTED). | 147 // it took for a session to become CONNECTED). |
157 return (remoting.LogToServer.isEndOfSession_(state) || | 148 return (remoting.LogToServer.isEndOfSession_(state) || |
158 (state == remoting.ClientSession.State.CONNECTED)); | 149 (state == remoting.ClientSession.State.CONNECTED)); |
anandc
2015/02/28 01:20:27
I think this function should be removed, now that
Jamie
2015/02/28 01:52:34
Yes, the session duration field isn't buying us an
| |
159 }; | 150 }; |
160 | 151 |
161 /** | 152 /** |
162 * Logs connection statistics. | 153 * Logs connection statistics. |
163 * @param {Object<string, number>} stats The connection statistics | 154 * @param {Object<string, number>} stats The connection statistics |
164 */ | 155 */ |
165 remoting.LogToServer.prototype.logStatistics = function(stats) { | 156 remoting.LogToServer.prototype.logStatistics = function(stats) { |
166 this.maybeExpireSessionId_(); | 157 this.maybeExpireSessionId_(); |
167 // Store the statistics. | 158 // Store the statistics. |
168 this.statsAccumulator_.add(stats); | 159 this.statsAccumulator_.add(stats); |
(...skipping 27 matching lines...) Expand all Loading... | |
196 this.statsAccumulator_.empty(); | 187 this.statsAccumulator_.empty(); |
197 }; | 188 }; |
198 | 189 |
199 /** | 190 /** |
200 * Sends a log entry to the server. | 191 * Sends a log entry to the server. |
201 * | 192 * |
202 * @private | 193 * @private |
203 * @param {remoting.ServerLogEntry} entry | 194 * @param {remoting.ServerLogEntry} entry |
204 */ | 195 */ |
205 remoting.LogToServer.prototype.log_ = function(entry) { | 196 remoting.LogToServer.prototype.log_ = function(entry) { |
197 // Log the time taken to get to this point from the time this session started. | |
198 var elapsedTimeInMs = new Date().getTime() - this.sessionStartTime_; | |
199 entry.addElapsedTimeMs(elapsedTimeInMs); | |
200 | |
206 // Send the stanza to the debug log. | 201 // Send the stanza to the debug log. |
207 console.log('Enqueueing log entry:'); | 202 console.log('Enqueueing log entry:'); |
208 entry.toDebugLog(1); | 203 entry.toDebugLog(1); |
209 | 204 |
210 var stanza = '<cli:iq to="' + remoting.settings.DIRECTORY_BOT_JID + '" ' + | 205 var stanza = '<cli:iq to="' + remoting.settings.DIRECTORY_BOT_JID + '" ' + |
211 'type="set" xmlns:cli="jabber:client">' + | 206 'type="set" xmlns:cli="jabber:client">' + |
212 '<gr:log xmlns:gr="google:remoting">' + | 207 '<gr:log xmlns:gr="google:remoting">' + |
213 entry.toStanza() + | 208 entry.toStanza() + |
214 '</gr:log>' + | 209 '</gr:log>' + |
215 '</cli:iq>'; | 210 '</cli:iq>'; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
270 remoting.LogToServer.generateSessionId_ = function() { | 265 remoting.LogToServer.generateSessionId_ = function() { |
271 var idArray = []; | 266 var idArray = []; |
272 for (var i = 0; i < remoting.LogToServer.SESSION_ID_LEN_; i++) { | 267 for (var i = 0; i < remoting.LogToServer.SESSION_ID_LEN_; i++) { |
273 var index = | 268 var index = |
274 Math.random() * remoting.LogToServer.SESSION_ID_ALPHABET_.length; | 269 Math.random() * remoting.LogToServer.SESSION_ID_ALPHABET_.length; |
275 idArray.push( | 270 idArray.push( |
276 remoting.LogToServer.SESSION_ID_ALPHABET_.slice(index, index + 1)); | 271 remoting.LogToServer.SESSION_ID_ALPHABET_.slice(index, index + 1)); |
277 } | 272 } |
278 return idArray.join(''); | 273 return idArray.join(''); |
279 }; | 274 }; |
OLD | NEW |