| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 /** @suppress {duplicate} */ | 6 /** @suppress {duplicate} */ |
| 7 var remoting = remoting || {}; | 7 var remoting = remoting || {}; |
| 8 | 8 |
| 9 (function() { | 9 (function() { |
| 10 | 10 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 /** @private {remoting.ChromotingEvent.Os}*/ | 45 /** @private {remoting.ChromotingEvent.Os}*/ |
| 46 this.hostOs_ = remoting.ChromotingEvent.Os.OTHER; | 46 this.hostOs_ = remoting.ChromotingEvent.Os.OTHER; |
| 47 /** @private */ | 47 /** @private */ |
| 48 this.hostOsVersion_ = ''; | 48 this.hostOsVersion_ = ''; |
| 49 /** @private {number} */ | 49 /** @private {number} */ |
| 50 this.hostStatusUpdateElapsedTime_; | 50 this.hostStatusUpdateElapsedTime_; |
| 51 /** @private */ | 51 /** @private */ |
| 52 this.mode_ = remoting.ChromotingEvent.Mode.ME2ME; | 52 this.mode_ = remoting.ChromotingEvent.Mode.ME2ME; |
| 53 /** @private {remoting.ChromotingEvent.AuthMethod} */ | 53 /** @private {remoting.ChromotingEvent.AuthMethod} */ |
| 54 this.authMethod_; | 54 this.authMethod_; |
| 55 /** @private */ | |
| 56 this.pluginError_ = ''; | |
| 57 | 55 |
| 58 this.setSessionId_(); | 56 this.setSessionId_(); |
| 59 }; | 57 }; |
| 60 | 58 |
| 61 /** | 59 /** |
| 62 * @param {remoting.ChromotingEvent.SessionEntryPoint} entryPoint | 60 * @param {remoting.ChromotingEvent.SessionEntryPoint} entryPoint |
| 63 */ | 61 */ |
| 64 remoting.SessionLogger.prototype.setEntryPoint = function(entryPoint) { | 62 remoting.SessionLogger.prototype.setEntryPoint = function(entryPoint) { |
| 65 this.entryPoint_ = entryPoint; | 63 this.entryPoint_ = entryPoint; |
| 66 }; | 64 }; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 }; | 122 }; |
| 125 | 123 |
| 126 /** | 124 /** |
| 127 * @param {remoting.ChromotingEvent.AuthMethod} method | 125 * @param {remoting.ChromotingEvent.AuthMethod} method |
| 128 */ | 126 */ |
| 129 remoting.SessionLogger.prototype.setAuthMethod = function(method) { | 127 remoting.SessionLogger.prototype.setAuthMethod = function(method) { |
| 130 this.authMethod_ = method; | 128 this.authMethod_ = method; |
| 131 }; | 129 }; |
| 132 | 130 |
| 133 /** | 131 /** |
| 134 * @param {string} error The error string of the plugin error. | |
| 135 */ | |
| 136 remoting.SessionLogger.prototype.setPluginError = function(error) { | |
| 137 this.pluginError_ = error; | |
| 138 }; | |
| 139 | |
| 140 /** | |
| 141 * @return {string} The current session id. This is random GUID, refreshed | 132 * @return {string} The current session id. This is random GUID, refreshed |
| 142 * every 24hrs. | 133 * every 24hrs. |
| 143 */ | 134 */ |
| 144 remoting.SessionLogger.prototype.getSessionId = function() { | 135 remoting.SessionLogger.prototype.getSessionId = function() { |
| 145 return this.sessionId_; | 136 return this.sessionId_; |
| 146 }; | 137 }; |
| 147 | 138 |
| 148 /** | 139 /** |
| 149 * @param {remoting.SignalStrategy.Type} strategyType | 140 * @param {remoting.SignalStrategy.Type} strategyType |
| 150 * @param {remoting.FallbackSignalStrategy.Progress} progress | 141 * @param {remoting.FallbackSignalStrategy.Progress} progress |
| 151 */ | 142 */ |
| 152 remoting.SessionLogger.prototype.logSignalStrategyProgress = | 143 remoting.SessionLogger.prototype.logSignalStrategyProgress = |
| 153 function(strategyType, progress) { | 144 function(strategyType, progress) { |
| 154 this.maybeExpireSessionId_(); | 145 this.maybeExpireSessionId_(); |
| 155 var entry = new remoting.ChromotingEvent( | 146 var entry = new remoting.ChromotingEvent( |
| 156 remoting.ChromotingEvent.Type.SIGNAL_STRATEGY_PROGRESS); | 147 remoting.ChromotingEvent.Type.SIGNAL_STRATEGY_PROGRESS); |
| 157 entry.signal_strategy_type = toSignalStrategyType(strategyType); | 148 entry.signal_strategy_type = toSignalStrategyType(strategyType); |
| 158 entry.signal_strategy_progress = toSignalStrategyProgress(progress); | 149 entry.signal_strategy_progress = toSignalStrategyProgress(progress); |
| 159 | 150 |
| 160 this.fillEvent_(entry); | 151 this.fillEvent_(entry); |
| 161 this.log_(entry); | 152 this.log_(entry); |
| 162 }; | 153 }; |
| 163 | 154 |
| 164 /** | 155 /** |
| 165 * Logs a client session state change. | |
| 166 * | |
| 167 * @param {remoting.ClientSession.State} state | |
| 168 * @param {!remoting.Error} stateError | |
| 169 * @param {?remoting.ChromotingEvent.XmppError} xmppError The XMPP error | |
| 170 * as described in http://xmpp.org/rfcs/rfc6120.html#stanzas-error. | |
| 171 * Set if the connecton error originates from the an XMPP stanza error. | |
| 172 */ | |
| 173 remoting.SessionLogger.prototype.logClientSessionStateChange = function( | |
| 174 state, stateError, xmppError) { | |
| 175 this.logSessionStateChange( | |
| 176 toSessionState(state), | |
| 177 stateError.toConnectionError(), | |
| 178 xmppError); | |
| 179 }; | |
| 180 | |
| 181 /** | |
| 182 * @param {remoting.ChromotingEvent.SessionState} state | 156 * @param {remoting.ChromotingEvent.SessionState} state |
| 183 * @param {remoting.ChromotingEvent.ConnectionError} error | 157 * @param {remoting.Error=} opt_error |
| 184 * @param {remoting.ChromotingEvent.XmppError=} opt_XmppError | |
| 185 */ | 158 */ |
| 186 remoting.SessionLogger.prototype.logSessionStateChange = function( | 159 remoting.SessionLogger.prototype.logSessionStateChange = |
| 187 state, error, opt_XmppError) { | 160 function(state, opt_error) { |
| 188 this.maybeExpireSessionId_(); | 161 this.maybeExpireSessionId_(); |
| 189 | 162 |
| 190 var entry = this.makeSessionStateChange_( | 163 var entry = this.makeSessionStateChange_(state, opt_error); |
| 191 state, error, | |
| 192 /** @type {?remoting.ChromotingEvent.XmppError} */ (opt_XmppError)); | |
| 193 entry.previous_session_state = this.previousSessionState_; | 164 entry.previous_session_state = this.previousSessionState_; |
| 194 this.previousSessionState_ = state; | 165 this.previousSessionState_ = state; |
| 195 | 166 |
| 196 this.log_(entry); | 167 this.log_(entry); |
| 197 | 168 |
| 198 // Don't accumulate connection statistics across state changes. | 169 // Don't accumulate connection statistics across state changes. |
| 199 this.logAccumulatedStatistics_(); | 170 this.logAccumulatedStatistics_(); |
| 200 this.statsAccumulator_.empty(); | 171 this.statsAccumulator_.empty(); |
| 201 }; | 172 }; |
| 202 | 173 |
| 203 /** | 174 /** |
| 204 * Logs connection statistics. | 175 * Logs connection statistics. |
| 205 * | 176 * |
| 206 * @param {Object<number>} stats The connection statistics | 177 * @param {Object<number>} stats The connection statistics |
| 207 */ | 178 */ |
| 208 remoting.SessionLogger.prototype.logStatistics = function(stats) { | 179 remoting.SessionLogger.prototype.logStatistics = function(stats) { |
| 209 this.maybeExpireSessionId_(); | 180 this.maybeExpireSessionId_(); |
| 210 // Store the statistics. | 181 // Store the statistics. |
| 211 this.statsAccumulator_.add(stats); | 182 this.statsAccumulator_.add(stats); |
| 212 // Send statistics to the server if they've been accumulating for at least | 183 // Send statistics to the server if they've been accumulating for at least |
| 213 // 60 seconds. | 184 // 60 seconds. |
| 214 if (this.statsAccumulator_.getTimeSinceFirstValue() >= | 185 if (this.statsAccumulator_.getTimeSinceFirstValue() >= |
| 215 remoting.SessionLogger.CONNECTION_STATS_ACCUMULATE_TIME) { | 186 remoting.SessionLogger.CONNECTION_STATS_ACCUMULATE_TIME) { |
| 216 this.logAccumulatedStatistics_(); | 187 this.logAccumulatedStatistics_(); |
| 217 } | 188 } |
| 218 }; | 189 }; |
| 219 | 190 |
| 220 /** | 191 /** |
| 221 * @param {remoting.ChromotingEvent.SessionState} state | 192 * @param {remoting.ChromotingEvent.SessionState} state |
| 222 * @param {remoting.ChromotingEvent.ConnectionError} error | 193 * @param {remoting.Error=} opt_error |
| 223 * @param {?remoting.ChromotingEvent.XmppError} xmppError | |
| 224 * @return {remoting.ChromotingEvent} | 194 * @return {remoting.ChromotingEvent} |
| 225 * @private | 195 * @private |
| 226 */ | 196 */ |
| 227 remoting.SessionLogger.prototype.makeSessionStateChange_ = | 197 remoting.SessionLogger.prototype.makeSessionStateChange_ = |
| 228 function(state, error, xmppError) { | 198 function(state, opt_error) { |
| 229 var entry = new remoting.ChromotingEvent( | 199 var entry = new remoting.ChromotingEvent( |
| 230 remoting.ChromotingEvent.Type.SESSION_STATE); | 200 remoting.ChromotingEvent.Type.SESSION_STATE); |
| 231 entry.connection_error = error; | 201 |
| 202 var ConnectionError = remoting.ChromotingEvent.ConnectionError; |
| 203 |
| 204 if (!opt_error) { |
| 205 entry.connection_error = ConnectionError.NONE; |
| 206 } else if (opt_error instanceof remoting.Error) { |
| 207 entry.setError(opt_error); |
| 208 } else { |
| 209 entry.connection_error = ConnectionError.UNKNOWN_ERROR; |
| 210 } |
| 211 |
| 232 entry.session_state = state; | 212 entry.session_state = state; |
| 233 | 213 |
| 234 if (Boolean(xmppError)) { | |
| 235 entry.xmpp_error = xmppError; | |
| 236 } | |
| 237 | |
| 238 this.fillEvent_(entry); | 214 this.fillEvent_(entry); |
| 239 return entry; | 215 return entry; |
| 240 }; | 216 }; |
| 241 | 217 |
| 242 /** | 218 /** |
| 243 * @return {remoting.ChromotingEvent} | 219 * @return {remoting.ChromotingEvent} |
| 244 * @private | 220 * @private |
| 245 */ | 221 */ |
| 246 remoting.SessionLogger.prototype.makeSessionIdNew_ = function() { | 222 remoting.SessionLogger.prototype.makeSessionIdNew_ = function() { |
| 247 var entry = new remoting.ChromotingEvent( | 223 var entry = new remoting.ChromotingEvent( |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 entry.session_duration = sessionDurationInSeconds; | 289 entry.session_duration = sessionDurationInSeconds; |
| 314 if (Boolean(this.connectionType_)) { | 290 if (Boolean(this.connectionType_)) { |
| 315 entry.connection_type = this.connectionType_; | 291 entry.connection_type = this.connectionType_; |
| 316 } | 292 } |
| 317 if (this.hostStatusUpdateElapsedTime_ != undefined) { | 293 if (this.hostStatusUpdateElapsedTime_ != undefined) { |
| 318 entry.host_status_update_elapsed_time = this.hostStatusUpdateElapsedTime_; | 294 entry.host_status_update_elapsed_time = this.hostStatusUpdateElapsedTime_; |
| 319 } | 295 } |
| 320 if (this.authMethod_ != undefined) { | 296 if (this.authMethod_ != undefined) { |
| 321 entry.auth_method = this.authMethod_; | 297 entry.auth_method = this.authMethod_; |
| 322 } | 298 } |
| 323 if (Boolean(this.pluginError_)) { | |
| 324 entry.raw_plugin_error = this.pluginError_; | |
| 325 } | |
| 326 entry.host_version = this.hostVersion_; | 299 entry.host_version = this.hostVersion_; |
| 327 entry.host_os = this.hostOs_; | 300 entry.host_os = this.hostOs_; |
| 328 entry.host_os_version = this.hostOsVersion_; | 301 entry.host_os_version = this.hostOsVersion_; |
| 329 }; | 302 }; |
| 330 | 303 |
| 331 /** | 304 /** |
| 332 * Sends a log entry to the server. | 305 * Sends a log entry to the server. |
| 333 * | 306 * |
| 334 * @param {remoting.ChromotingEvent} entry | 307 * @param {remoting.ChromotingEvent} entry |
| 335 * @private | 308 * @private |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 } | 356 } |
| 384 }; | 357 }; |
| 385 | 358 |
| 386 /** @return {remoting.SessionLogger} */ | 359 /** @return {remoting.SessionLogger} */ |
| 387 remoting.SessionLogger.createForClient = function() { | 360 remoting.SessionLogger.createForClient = function() { |
| 388 return new remoting.SessionLogger(remoting.ChromotingEvent.Role.CLIENT, | 361 return new remoting.SessionLogger(remoting.ChromotingEvent.Role.CLIENT, |
| 389 remoting.TelemetryEventWriter.Client.write); | 362 remoting.TelemetryEventWriter.Client.write); |
| 390 }; | 363 }; |
| 391 | 364 |
| 392 /** | 365 /** |
| 393 * TODO(kelvinp): Consolidate the two enums (crbug.com/504200) | |
| 394 * @param {remoting.ClientSession.State} state | |
| 395 * @return {remoting.ChromotingEvent.SessionState} | |
| 396 */ | |
| 397 function toSessionState(state) { | |
| 398 var SessionState = remoting.ChromotingEvent.SessionState; | |
| 399 switch(state) { | |
| 400 case remoting.ClientSession.State.UNKNOWN: | |
| 401 return SessionState.UNKNOWN; | |
| 402 case remoting.ClientSession.State.INITIALIZING: | |
| 403 return SessionState.INITIALIZING; | |
| 404 case remoting.ClientSession.State.CONNECTING: | |
| 405 return SessionState.CONNECTING; | |
| 406 case remoting.ClientSession.State.AUTHENTICATED: | |
| 407 return SessionState.AUTHENTICATED; | |
| 408 case remoting.ClientSession.State.CONNECTED: | |
| 409 return SessionState.CONNECTED; | |
| 410 case remoting.ClientSession.State.CLOSED: | |
| 411 return SessionState.CLOSED; | |
| 412 case remoting.ClientSession.State.FAILED: | |
| 413 return SessionState.CONNECTION_FAILED; | |
| 414 case remoting.ClientSession.State.CONNECTION_DROPPED: | |
| 415 return SessionState.CONNECTION_DROPPED; | |
| 416 case remoting.ClientSession.State.CONNECTION_CANCELED: | |
| 417 return SessionState.CONNECTION_CANCELED; | |
| 418 default: | |
| 419 throw new Error('Unknown session state : ' + state); | |
| 420 } | |
| 421 } | |
| 422 | |
| 423 /** | |
| 424 * @param {remoting.SignalStrategy.Type} type | 366 * @param {remoting.SignalStrategy.Type} type |
| 425 * @return {remoting.ChromotingEvent.SignalStrategyType} | 367 * @return {remoting.ChromotingEvent.SignalStrategyType} |
| 426 */ | 368 */ |
| 427 function toSignalStrategyType(type) { | 369 function toSignalStrategyType(type) { |
| 428 switch (type) { | 370 switch (type) { |
| 429 case remoting.SignalStrategy.Type.XMPP: | 371 case remoting.SignalStrategy.Type.XMPP: |
| 430 return remoting.ChromotingEvent.SignalStrategyType.XMPP; | 372 return remoting.ChromotingEvent.SignalStrategyType.XMPP; |
| 431 case remoting.SignalStrategy.Type.WCS: | 373 case remoting.SignalStrategy.Type.WCS: |
| 432 return remoting.ChromotingEvent.SignalStrategyType.WCS; | 374 return remoting.ChromotingEvent.SignalStrategyType.WCS; |
| 433 default: | 375 default: |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 475 } | 417 } |
| 476 | 418 |
| 477 // The maximum age of a session ID, in milliseconds. | 419 // The maximum age of a session ID, in milliseconds. |
| 478 remoting.SessionLogger.MAX_SESSION_ID_AGE = 24 * 60 * 60 * 1000; | 420 remoting.SessionLogger.MAX_SESSION_ID_AGE = 24 * 60 * 60 * 1000; |
| 479 | 421 |
| 480 // The time over which to accumulate connection statistics before logging them | 422 // The time over which to accumulate connection statistics before logging them |
| 481 // to the server, in milliseconds. | 423 // to the server, in milliseconds. |
| 482 remoting.SessionLogger.CONNECTION_STATS_ACCUMULATE_TIME = 60 * 1000; | 424 remoting.SessionLogger.CONNECTION_STATS_ACCUMULATE_TIME = 60 * 1000; |
| 483 | 425 |
| 484 })(); | 426 })(); |
| OLD | NEW |