Chromium Code Reviews| 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'; |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 25 /** @private */ | 25 /** @private */ |
| 26 this.sessionIdGenerationTime_ = 0; | 26 this.sessionIdGenerationTime_ = 0; |
| 27 /** @private */ | 27 /** @private */ |
| 28 this.sessionStartTime_ = 0; | 28 this.sessionStartTime_ = 0; |
| 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 | |
| 36 signalStrategy.sendConnectionSetupResults(this); | |
| 35 }; | 37 }; |
| 36 | 38 |
| 37 // Constants used for generating a session ID. | 39 // Constants used for generating a session ID. |
| 38 /** @private */ | 40 /** @private */ |
| 39 remoting.LogToServer.SESSION_ID_ALPHABET_ = | 41 remoting.LogToServer.SESSION_ID_ALPHABET_ = |
| 40 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'; | 42 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'; |
| 41 /** @private */ | 43 /** @private */ |
| 42 remoting.LogToServer.SESSION_ID_LEN_ = 20; | 44 remoting.LogToServer.SESSION_ID_LEN_ = 20; |
| 43 | 45 |
| 44 // The maximum age of a session ID, in milliseconds. | 46 // The maximum age of a session ID, in milliseconds. |
| 45 remoting.LogToServer.MAX_SESSION_ID_AGE = 24 * 60 * 60 * 1000; | 47 remoting.LogToServer.MAX_SESSION_ID_AGE = 24 * 60 * 60 * 1000; |
| 46 | 48 |
| 47 // The time over which to accumulate connection statistics before logging them | 49 // The time over which to accumulate connection statistics before logging them |
| 48 // to the server, in milliseconds. | 50 // to the server, in milliseconds. |
| 49 remoting.LogToServer.CONNECTION_STATS_ACCUMULATE_TIME = 60 * 1000; | 51 remoting.LogToServer.CONNECTION_STATS_ACCUMULATE_TIME = 60 * 1000; |
| 50 | 52 |
| 51 /** | 53 /** |
| 52 * Logs a client session state change. | 54 * Logs a client session state change. |
| 53 * | 55 * |
| 54 * @param {remoting.ClientSession.State} state | 56 * @param {remoting.ClientSession.State} state |
| 55 * @param {remoting.Error} connectionError | 57 * @param {remoting.Error} connectionError |
| 56 */ | 58 */ |
| 57 remoting.LogToServer.prototype.logClientSessionStateChange = | 59 remoting.LogToServer.prototype.logClientSessionStateChange = |
| 58 function(state, connectionError) { | 60 function(state, connectionError) { |
| 59 this.maybeExpireSessionId(); | 61 this.maybeExpireSessionId_(); |
|
Jamie
2015/01/16 22:17:46
Fixed naming convention for consistency.
| |
| 60 // Maybe set the session ID and start time. | 62 // Maybe set the session ID and start time. |
| 61 if (remoting.LogToServer.isStartOfSession(state)) { | 63 if (remoting.LogToServer.isStartOfSession_(state)) { |
| 62 if (this.sessionId_ == '') { | 64 if (this.sessionId_ == '') { |
| 63 this.setSessionId(); | 65 this.setSessionId_(); |
| 64 } | 66 } |
| 65 if (this.sessionStartTime_ == 0) { | 67 if (this.sessionStartTime_ == 0) { |
| 66 this.sessionStartTime_ = new Date().getTime(); | 68 this.sessionStartTime_ = new Date().getTime(); |
| 67 } | 69 } |
| 68 } | 70 } |
| 69 // Log the session state change. | 71 // Log the session state change. |
| 70 var entry = remoting.ServerLogEntry.makeClientSessionStateChange( | 72 var entry = remoting.ServerLogEntry.makeClientSessionStateChange( |
| 71 state, connectionError, this.mode_); | 73 state, connectionError, this.mode_); |
| 72 entry.addHostFields(); | 74 entry.addHostFields(); |
| 73 entry.addChromeVersionField(); | 75 entry.addChromeVersionField(); |
| 74 entry.addWebappVersionField(); | 76 entry.addWebappVersionField(); |
| 75 entry.addSessionIdField(this.sessionId_); | 77 entry.addSessionIdField(this.sessionId_); |
| 76 // Maybe clear the session start time, and log the session duration. | 78 // Maybe clear the session start time, and log the session duration. |
| 77 if (remoting.LogToServer.shouldAddDuration(state) && | 79 if (remoting.LogToServer.shouldAddDuration_(state) && |
| 78 (this.sessionStartTime_ != 0)) { | 80 (this.sessionStartTime_ != 0)) { |
| 79 entry.addSessionDurationField( | 81 entry.addSessionDurationField( |
| 80 (new Date().getTime() - this.sessionStartTime_) / 1000.0); | 82 (new Date().getTime() - this.sessionStartTime_) / 1000.0); |
| 81 if (remoting.LogToServer.isEndOfSession(state)) { | 83 if (remoting.LogToServer.isEndOfSession_(state)) { |
| 82 this.sessionStartTime_ = 0; | 84 this.sessionStartTime_ = 0; |
| 83 } | 85 } |
| 84 } | 86 } |
| 85 this.log(entry); | 87 this.log_(entry); |
| 86 // Don't accumulate connection statistics across state changes. | 88 // Don't accumulate connection statistics across state changes. |
| 87 this.logAccumulatedStatistics(); | 89 this.logAccumulatedStatistics_(); |
| 88 this.statsAccumulator_.empty(); | 90 this.statsAccumulator_.empty(); |
| 89 // Maybe clear the session ID. | 91 // Maybe clear the session ID. |
| 90 if (remoting.LogToServer.isEndOfSession(state)) { | 92 if (remoting.LogToServer.isEndOfSession_(state)) { |
| 91 this.clearSessionId(); | 93 this.clearSessionId_(); |
| 92 } | 94 } |
| 93 }; | 95 }; |
| 94 | 96 |
| 95 /** | 97 /** |
| 96 * Set the connection type (direct, stun relay). | 98 * Set the connection type (direct, stun relay). |
| 97 * | 99 * |
| 98 * @param {string} connectionType | 100 * @param {string} connectionType |
| 99 */ | 101 */ |
| 100 remoting.LogToServer.prototype.setConnectionType = function(connectionType) { | 102 remoting.LogToServer.prototype.setConnectionType = function(connectionType) { |
| 101 this.connectionType_ = connectionType; | 103 this.connectionType_ = connectionType; |
| 102 }; | 104 }; |
| 103 | 105 |
| 104 /** | 106 /** |
| 107 * @param {remoting.FallbackSignalStrategy.Progress} progress | |
| 108 * @param {number} elapsedTimeInMs | |
| 109 */ | |
| 110 remoting.LogToServer.prototype.logSignalStrategyProgress = | |
| 111 function(progress, elapsedTimeInMs) { | |
| 112 this.maybeExpireSessionId_(); | |
| 113 var entry = remoting.ServerLogEntry.makeSignalStrategyProgress( | |
| 114 this.sessionId_, progress, elapsedTimeInMs); | |
| 115 this.log_(entry); | |
| 116 }; | |
| 117 | |
| 118 /** | |
| 105 * Whether a session state is one of the states that occurs at the start of | 119 * Whether a session state is one of the states that occurs at the start of |
| 106 * a session. | 120 * a session. |
| 107 * | 121 * |
| 108 * @private | 122 * @private |
| 109 * @param {remoting.ClientSession.State} state | 123 * @param {remoting.ClientSession.State} state |
| 110 * @return {boolean} | 124 * @return {boolean} |
| 111 */ | 125 */ |
| 112 remoting.LogToServer.isStartOfSession = function(state) { | 126 remoting.LogToServer.isStartOfSession_ = function(state) { |
| 113 return ((state == remoting.ClientSession.State.CONNECTING) || | 127 return ((state == remoting.ClientSession.State.CONNECTING) || |
| 114 (state == remoting.ClientSession.State.INITIALIZING) || | 128 (state == remoting.ClientSession.State.INITIALIZING) || |
| 115 (state == remoting.ClientSession.State.CONNECTED)); | 129 (state == remoting.ClientSession.State.CONNECTED)); |
| 116 }; | 130 }; |
| 117 | 131 |
| 118 /** | 132 /** |
| 119 * Whether a session state is one of the states that occurs at the end of | 133 * Whether a session state is one of the states that occurs at the end of |
| 120 * a session. | 134 * a session. |
| 121 * | 135 * |
| 122 * @private | 136 * @private |
| 123 * @param {remoting.ClientSession.State} state | 137 * @param {remoting.ClientSession.State} state |
| 124 * @return {boolean} | 138 * @return {boolean} |
| 125 */ | 139 */ |
| 126 remoting.LogToServer.isEndOfSession = function(state) { | 140 remoting.LogToServer.isEndOfSession_ = function(state) { |
| 127 return ((state == remoting.ClientSession.State.CLOSED) || | 141 return ((state == remoting.ClientSession.State.CLOSED) || |
| 128 (state == remoting.ClientSession.State.FAILED) || | 142 (state == remoting.ClientSession.State.FAILED) || |
| 129 (state == remoting.ClientSession.State.CONNECTION_DROPPED) || | 143 (state == remoting.ClientSession.State.CONNECTION_DROPPED) || |
| 130 (state == remoting.ClientSession.State.CONNECTION_CANCELED)); | 144 (state == remoting.ClientSession.State.CONNECTION_CANCELED)); |
| 131 }; | 145 }; |
| 132 | 146 |
| 133 /** | 147 /** |
| 134 * Whether the duration should be added to the log entry for this state. | 148 * Whether the duration should be added to the log entry for this state. |
| 135 * | 149 * |
| 136 * @private | 150 * @private |
| 137 * @param {remoting.ClientSession.State} state | 151 * @param {remoting.ClientSession.State} state |
| 138 * @return {boolean} | 152 * @return {boolean} |
| 139 */ | 153 */ |
| 140 remoting.LogToServer.shouldAddDuration = function(state) { | 154 remoting.LogToServer.shouldAddDuration_ = function(state) { |
| 141 // Duration is added to log entries at the end of the session, as well as at | 155 // Duration is added to log entries at the end of the session, as well as at |
| 142 // some intermediate states where it is relevant (e.g. to determine how long | 156 // some intermediate states where it is relevant (e.g. to determine how long |
| 143 // it took for a session to become CONNECTED). | 157 // it took for a session to become CONNECTED). |
| 144 return (remoting.LogToServer.isEndOfSession(state) || | 158 return (remoting.LogToServer.isEndOfSession_(state) || |
| 145 (state == remoting.ClientSession.State.CONNECTED)); | 159 (state == remoting.ClientSession.State.CONNECTED)); |
| 146 }; | 160 }; |
| 147 | 161 |
| 148 /** | 162 /** |
| 149 * Logs connection statistics. | 163 * Logs connection statistics. |
| 150 * @param {Object.<string, number>} stats The connection statistics | 164 * @param {Object.<string, number>} stats The connection statistics |
| 151 */ | 165 */ |
| 152 remoting.LogToServer.prototype.logStatistics = function(stats) { | 166 remoting.LogToServer.prototype.logStatistics = function(stats) { |
| 153 this.maybeExpireSessionId(); | 167 this.maybeExpireSessionId_(); |
| 154 // Store the statistics. | 168 // Store the statistics. |
| 155 this.statsAccumulator_.add(stats); | 169 this.statsAccumulator_.add(stats); |
| 156 // Send statistics to the server if they've been accumulating for at least | 170 // Send statistics to the server if they've been accumulating for at least |
| 157 // 60 seconds. | 171 // 60 seconds. |
| 158 if (this.statsAccumulator_.getTimeSinceFirstValue() >= | 172 if (this.statsAccumulator_.getTimeSinceFirstValue() >= |
| 159 remoting.LogToServer.CONNECTION_STATS_ACCUMULATE_TIME) { | 173 remoting.LogToServer.CONNECTION_STATS_ACCUMULATE_TIME) { |
| 160 this.logAccumulatedStatistics(); | 174 this.logAccumulatedStatistics_(); |
| 161 } | 175 } |
| 162 }; | 176 }; |
| 163 | 177 |
| 164 /** | 178 /** |
| 165 * Moves connection statistics from the accumulator to the log server. | 179 * Moves connection statistics from the accumulator to the log server. |
| 166 * | 180 * |
| 167 * If all the statistics are zero, then the accumulator is still emptied, | 181 * If all the statistics are zero, then the accumulator is still emptied, |
| 168 * but the statistics are not sent to the log server. | 182 * but the statistics are not sent to the log server. |
| 169 * | 183 * |
| 170 * @private | 184 * @private |
| 171 */ | 185 */ |
| 172 remoting.LogToServer.prototype.logAccumulatedStatistics = function() { | 186 remoting.LogToServer.prototype.logAccumulatedStatistics_ = function() { |
| 173 var entry = remoting.ServerLogEntry.makeStats(this.statsAccumulator_, | 187 var entry = remoting.ServerLogEntry.makeStats(this.statsAccumulator_, |
| 174 this.connectionType_, | 188 this.connectionType_, |
| 175 this.mode_); | 189 this.mode_); |
| 176 if (entry) { | 190 if (entry) { |
| 177 entry.addHostFields(); | 191 entry.addHostFields(); |
| 178 entry.addChromeVersionField(); | 192 entry.addChromeVersionField(); |
| 179 entry.addWebappVersionField(); | 193 entry.addWebappVersionField(); |
| 180 entry.addSessionIdField(this.sessionId_); | 194 entry.addSessionIdField(this.sessionId_); |
| 181 this.log(entry); | 195 this.log_(entry); |
| 182 } | 196 } |
| 183 this.statsAccumulator_.empty(); | 197 this.statsAccumulator_.empty(); |
| 184 }; | 198 }; |
| 185 | 199 |
| 186 /** | 200 /** |
| 187 * Sends a log entry to the server. | 201 * Sends a log entry to the server. |
| 188 * | 202 * |
| 189 * @private | 203 * @private |
| 190 * @param {remoting.ServerLogEntry} entry | 204 * @param {remoting.ServerLogEntry} entry |
| 191 */ | 205 */ |
| 192 remoting.LogToServer.prototype.log = function(entry) { | 206 remoting.LogToServer.prototype.log_ = function(entry) { |
| 193 // Send the stanza to the debug log. | 207 // Send the stanza to the debug log. |
| 194 console.log('Enqueueing log entry:'); | 208 console.log('Enqueueing log entry:'); |
| 195 entry.toDebugLog(1); | 209 entry.toDebugLog(1); |
| 196 | 210 |
| 197 var stanza = '<cli:iq to="' + remoting.settings.DIRECTORY_BOT_JID + '" ' + | 211 var stanza = '<cli:iq to="' + remoting.settings.DIRECTORY_BOT_JID + '" ' + |
| 198 'type="set" xmlns:cli="jabber:client">' + | 212 'type="set" xmlns:cli="jabber:client">' + |
| 199 '<gr:log xmlns:gr="google:remoting">' + | 213 '<gr:log xmlns:gr="google:remoting">' + |
| 200 entry.toStanza() + | 214 entry.toStanza() + |
| 201 '</gr:log>' + | 215 '</gr:log>' + |
| 202 '</cli:iq>'; | 216 '</cli:iq>'; |
| 203 this.signalStrategy_.sendMessage(stanza); | 217 this.signalStrategy_.sendMessage(stanza); |
| 204 }; | 218 }; |
| 205 | 219 |
| 206 /** | 220 /** |
| 207 * Sets the session ID to a random string. | 221 * Sets the session ID to a random string. |
| 208 * | 222 * |
| 209 * @private | 223 * @private |
| 210 */ | 224 */ |
| 211 remoting.LogToServer.prototype.setSessionId = function() { | 225 remoting.LogToServer.prototype.setSessionId_ = function() { |
| 212 this.sessionId_ = remoting.LogToServer.generateSessionId(); | 226 this.sessionId_ = remoting.LogToServer.generateSessionId_(); |
| 213 this.sessionIdGenerationTime_ = new Date().getTime(); | 227 this.sessionIdGenerationTime_ = new Date().getTime(); |
| 214 }; | 228 }; |
| 215 | 229 |
| 216 /** | 230 /** |
| 217 * Clears the session ID. | 231 * Clears the session ID. |
| 218 * | 232 * |
| 219 * @private | 233 * @private |
| 220 */ | 234 */ |
| 221 remoting.LogToServer.prototype.clearSessionId = function() { | 235 remoting.LogToServer.prototype.clearSessionId_ = function() { |
| 222 this.sessionId_ = ''; | 236 this.sessionId_ = ''; |
| 223 this.sessionIdGenerationTime_ = 0; | 237 this.sessionIdGenerationTime_ = 0; |
| 224 }; | 238 }; |
| 225 | 239 |
| 226 /** | 240 /** |
| 227 * Sets a new session ID, if the current session ID has reached its maximum age. | 241 * Sets a new session ID, if the current session ID has reached its maximum age. |
| 228 * | 242 * |
| 229 * This method also logs the old and new session IDs to the server, in separate | 243 * This method also logs the old and new session IDs to the server, in separate |
| 230 * log entries. | 244 * log entries. |
| 231 * | 245 * |
| 232 * @private | 246 * @private |
| 233 */ | 247 */ |
| 234 remoting.LogToServer.prototype.maybeExpireSessionId = function() { | 248 remoting.LogToServer.prototype.maybeExpireSessionId_ = function() { |
| 235 if ((this.sessionId_ != '') && | 249 if ((this.sessionId_ != '') && |
| 236 (new Date().getTime() - this.sessionIdGenerationTime_ >= | 250 (new Date().getTime() - this.sessionIdGenerationTime_ >= |
| 237 remoting.LogToServer.MAX_SESSION_ID_AGE)) { | 251 remoting.LogToServer.MAX_SESSION_ID_AGE)) { |
| 238 // Log the old session ID. | 252 // Log the old session ID. |
| 239 var entry = remoting.ServerLogEntry.makeSessionIdOld(this.sessionId_, | 253 var entry = remoting.ServerLogEntry.makeSessionIdOld(this.sessionId_, |
| 240 this.mode_); | 254 this.mode_); |
| 241 this.log(entry); | 255 this.log_(entry); |
| 242 // Generate a new session ID. | 256 // Generate a new session ID. |
| 243 this.setSessionId(); | 257 this.setSessionId_(); |
| 244 // Log the new session ID. | 258 // Log the new session ID. |
| 245 entry = remoting.ServerLogEntry.makeSessionIdNew(this.sessionId_, | 259 entry = remoting.ServerLogEntry.makeSessionIdNew(this.sessionId_, |
| 246 this.mode_); | 260 this.mode_); |
| 247 this.log(entry); | 261 this.log_(entry); |
| 248 } | 262 } |
| 249 }; | 263 }; |
| 250 | 264 |
| 251 /** | 265 /** |
| 252 * Generates a string that can be used as a session ID. | 266 * Generates a string that can be used as a session ID. |
| 253 * | 267 * |
| 254 * @private | 268 * @private |
| 255 * @return {string} a session ID | 269 * @return {string} a session ID |
| 256 */ | 270 */ |
| 257 remoting.LogToServer.generateSessionId = function() { | 271 remoting.LogToServer.generateSessionId_ = function() { |
| 258 var idArray = []; | 272 var idArray = []; |
| 259 for (var i = 0; i < remoting.LogToServer.SESSION_ID_LEN_; i++) { | 273 for (var i = 0; i < remoting.LogToServer.SESSION_ID_LEN_; i++) { |
| 260 var index = | 274 var index = |
| 261 Math.random() * remoting.LogToServer.SESSION_ID_ALPHABET_.length; | 275 Math.random() * remoting.LogToServer.SESSION_ID_ALPHABET_.length; |
| 262 idArray.push( | 276 idArray.push( |
| 263 remoting.LogToServer.SESSION_ID_ALPHABET_.slice(index, index + 1)); | 277 remoting.LogToServer.SESSION_ID_ALPHABET_.slice(index, index + 1)); |
| 264 } | 278 } |
| 265 return idArray.join(''); | 279 return idArray.join(''); |
| 266 }; | 280 }; |
| OLD | NEW |