diff options
author | kelvinp <kelvinp@chromium.org> | 2015-10-12 17:01:19 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-10-13 00:02:04 +0000 |
commit | f5e3416c9113b77f4deb96e96603be3c18c18d66 (patch) | |
tree | 49d4243fde202634a5bd2871c06392e25c2c23a8 /remoting | |
parent | 99d9eeb9ad625be61df8e960e03284136b2bc769 (diff) | |
download | chromium_src-f5e3416c9113b77f4deb96e96603be3c18c18d66.zip chromium_src-f5e3416c9113b77f4deb96e96603be3c18c18d66.tar.gz chromium_src-f5e3416c9113b77f4deb96e96603be3c18c18d66.tar.bz2 |
[Chromoting] Cleans up legacy code for XMPP-based logging.
This CL cleans up the legacy code from the XMPP based logging solution
Summary of changes:
1. Remove Log_to_Server.js, Server_Log_Entry.js, logger.js,
buffered_signal_strategy.js
2. Use remoting.SessionLogger in host_screen.js
BUG=523423
Review URL: https://codereview.chromium.org/1399883005
Cr-Commit-Position: refs/heads/master@{#353634}
Diffstat (limited to 'remoting')
-rw-r--r-- | remoting/remoting_webapp_files.gypi | 5 | ||||
-rw-r--r-- | remoting/webapp/base/js/client_session.js | 7 | ||||
-rw-r--r-- | remoting/webapp/base/js/fallback_signal_strategy.js | 2 | ||||
-rw-r--r-- | remoting/webapp/base/js/log_to_server.js | 319 | ||||
-rw-r--r-- | remoting/webapp/base/js/logger.js | 105 | ||||
-rw-r--r-- | remoting/webapp/base/js/session_logger.js | 96 | ||||
-rw-r--r-- | remoting/webapp/base/js/session_logger_unittest.js | 6 | ||||
-rw-r--r-- | remoting/webapp/crd/js/buffered_signal_strategy.js | 91 | ||||
-rw-r--r-- | remoting/webapp/crd/js/host_screen.js | 64 | ||||
-rw-r--r-- | remoting/webapp/files.gni | 9 |
10 files changed, 114 insertions, 590 deletions
diff --git a/remoting/remoting_webapp_files.gypi b/remoting/remoting_webapp_files.gypi index b18e540..9e3e1fb 100644 --- a/remoting/remoting_webapp_files.gypi +++ b/remoting/remoting_webapp_files.gypi @@ -214,10 +214,7 @@ # Logging and stats JavaScript files. 'remoting_webapp_shared_js_logging_files': [ 'webapp/base/js/chromoting_event.js', - 'webapp/base/js/logger.js', 'webapp/base/js/format_iq.js', - 'webapp/base/js/log_to_server.js', - 'webapp/base/js/server_log_entry.js', 'webapp/base/js/session_logger.js', 'webapp/base/js/stats_accumulator.js', ], @@ -277,7 +274,6 @@ # Files for controlling the local machine as a host. # Includes both it2me and me2me files. 'remoting_webapp_js_host_control_files': [ - 'webapp/crd/js/buffered_signal_strategy.js', 'webapp/crd/js/host_controller.js', 'webapp/crd/js/host_daemon_facade.js', 'webapp/crd/js/host_screen.js', @@ -292,7 +288,6 @@ # Files for controlling the local it2me host. # Included by public_session.html. 'remoting_webapp_js_it2me_host_control_files': [ - 'webapp/crd/js/buffered_signal_strategy.js', 'webapp/crd/js/host_screen.js', 'webapp/crd/js/host_session.js', 'webapp/crd/js/host_install_dialog.js', diff --git a/remoting/webapp/base/js/client_session.js b/remoting/webapp/base/js/client_session.js index ebb0bb4..7160f6f 100644 --- a/remoting/webapp/base/js/client_session.js +++ b/remoting/webapp/base/js/client_session.js @@ -24,7 +24,7 @@ var remoting = remoting || {}; /** * @param {remoting.ClientPlugin} plugin * @param {remoting.SignalStrategy} signalStrategy Signal strategy. - * @param {remoting.Logger} logger + * @param {remoting.SessionLogger} logger * @param {remoting.ClientSession.EventHandler} listener * * @constructor @@ -57,7 +57,7 @@ remoting.ClientSession = function( /** @private */ this.hasReceivedFrame_ = false; - /** @private {remoting.Logger} */ + /** @private */ this.logger_ = logger; /** @private */ @@ -135,6 +135,7 @@ remoting.ClientSession.EventHandler.prototype.onDisconnected = // // TODO(kelvinp): Merge this enum with remoting.ChromotingEvent.SessionState // once we have migrated away from XMPP-based logging (crbug.com/523423). +// // NOTE: The enums here correspond to the Chromoting.Connections enumerated // histogram defined in src/tools/metrics/histograms/histograms.xml. UMA // histograms don't work well with negative values, so only non-negative values @@ -331,7 +332,7 @@ remoting.ClientSession.prototype.getState = function() { }; /** - * @return {remoting.Logger}. + * @return {remoting.SessionLogger}. */ remoting.ClientSession.prototype.getLogger = function() { return this.logger_; diff --git a/remoting/webapp/base/js/fallback_signal_strategy.js b/remoting/webapp/base/js/fallback_signal_strategy.js index 0596640..68623ae 100644 --- a/remoting/webapp/base/js/fallback_signal_strategy.js +++ b/remoting/webapp/base/js/fallback_signal_strategy.js @@ -73,7 +73,7 @@ remoting.FallbackSignalStrategy = function(primary, /** @private {number} */ this.primaryConnectTimerId_ = 0; - /** @private {remoting.Logger} */ + /** @private */ this.logger_ = new remoting.SessionLogger( remoting.ChromotingEvent.Role.CLIENT, remoting.TelemetryEventWriter.Client.write diff --git a/remoting/webapp/base/js/log_to_server.js b/remoting/webapp/base/js/log_to_server.js deleted file mode 100644 index dc9162c..0000000 --- a/remoting/webapp/base/js/log_to_server.js +++ /dev/null @@ -1,319 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -/** - * @fileoverview - * Module for sending log entries to the server. - */ - -'use strict'; - -/** @suppress {duplicate} */ -var remoting = remoting || {}; - -/** - * @param {remoting.SignalStrategy} signalStrategy Signal strategy. - * @param {boolean=} opt_isHost True if this instance should log role=host - * events rather than role=client. - * @constructor - * @implements {remoting.Logger} - */ -remoting.LogToServer = function(signalStrategy, opt_isHost) { - /** @private */ - this.statsAccumulator_ = new remoting.StatsAccumulator(); - /** @private */ - this.sessionId_ = ''; - /** @private */ - this.sessionIdGenerationTime_ = 0; - /** @private */ - this.sessionStartTime_ = new Date().getTime(); - /** @private */ - this.signalStrategy_ = signalStrategy; - /** @private {string} */ - this.connectionType_ = ''; - /** @private */ - this.authTotalTime_ = 0; - /** @private {string} */ - this.hostVersion_ = ''; - /** @private */ - this.logEntryMode_ = remoting.ServerLogEntry.VALUE_MODE_UNKNOWN; - /** @private */ - this.role_ = opt_isHost ? 'host' : 'client'; - - this.setSessionId(); -}; - -// Constants used for generating a session ID. -/** @private */ -remoting.LogToServer.SESSION_ID_ALPHABET_ = - 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'; -/** @private */ -remoting.LogToServer.SESSION_ID_LEN_ = 20; - -/** - * Logs a client session state change. - * - * @param {remoting.ClientSession.State} state - * @param {!remoting.Error} connectionError - * @param {?remoting.ChromotingEvent.XmppError} xmppError - */ -remoting.LogToServer.prototype.logClientSessionStateChange = - function(state, connectionError, xmppError) { - this.maybeExpireSessionId_(); - // Log the session state change. - var entry = remoting.ServerLogEntry.makeClientSessionStateChange( - state, connectionError, this.logEntryMode_, this.role_); - entry.addClientOSFields(); - entry.addChromeVersionField(); - entry.addWebappVersionField(); - entry.addSessionIdField(this.sessionId_); - entry.addXmppError(xmppError); - - this.log_(entry); - // Don't accumulate connection statistics across state changes. - this.logAccumulatedStatistics_(); - this.statsAccumulator_.empty(); - // Maybe clear the session ID. - if (remoting.LogToServer.isEndOfSession_(state)) { - this.clearSessionId_(); - } -}; - -/** - * Set the connection type (direct, stun relay). - * - * @param {string} connectionType - */ -remoting.LogToServer.prototype.setConnectionType = function(connectionType) { - this.connectionType_ = connectionType; -}; - -/** - * @param {remoting.ChromotingEvent.Mode} mode - */ -remoting.LogToServer.prototype.setLogEntryMode = function(mode) { - switch (mode) { - case remoting.ChromotingEvent.Mode.IT2ME: - this.logEntryMode_ = remoting.ServerLogEntry.VALUE_MODE_IT2ME; - break; - case remoting.ChromotingEvent.Mode.ME2ME: - this.logEntryMode_ = remoting.ServerLogEntry.VALUE_MODE_ME2ME; - break; - case remoting.ChromotingEvent.Mode.LGAPP: - this.logEntryMode_ = remoting.ServerLogEntry.VALUE_MODE_APP_REMOTING; - break; - default: - this.logEntryMode_ = remoting.ServerLogEntry.VALUE_MODE_UNKNOWN; - } -}; - -/** - * @param {remoting.SignalStrategy.Type} strategyType - * @param {remoting.FallbackSignalStrategy.Progress} progress - */ -remoting.LogToServer.prototype.logSignalStrategyProgress = - function(strategyType, progress) { - this.maybeExpireSessionId_(); - var entry = remoting.ServerLogEntry.makeSignalStrategyProgress( - this.sessionId_, strategyType, progress); - this.log_(entry); -}; - -/** - * @return {string} The current session id. This is random GUID, refreshed - * every 24hrs. - */ -remoting.LogToServer.prototype.getSessionId = function() { - return this.sessionId_; -}; - -/** - * Whether a session state is one of the states that occurs at the end of - * a session. - * - * @private - * @param {remoting.ClientSession.State} state - * @return {boolean} - */ -remoting.LogToServer.isEndOfSession_ = function(state) { - return ((state == remoting.ClientSession.State.CLOSED) || - (state == remoting.ClientSession.State.FAILED) || - (state == remoting.ClientSession.State.CONNECTION_DROPPED) || - (state == remoting.ClientSession.State.CONNECTION_CANCELED)); -}; - - -/** - * Logs connection statistics. - * @param {Object<number>} stats The connection statistics - */ -remoting.LogToServer.prototype.logStatistics = function(stats) { - this.maybeExpireSessionId_(); - // Store the statistics. - this.statsAccumulator_.add(stats); - // Send statistics to the server if they've been accumulating for at least - // 60 seconds. - if (this.statsAccumulator_.getTimeSinceFirstValue() >= - remoting.Logger.CONNECTION_STATS_ACCUMULATE_TIME) { - this.logAccumulatedStatistics_(); - } -}; - -/** - * Moves connection statistics from the accumulator to the log server. - * - * If all the statistics are zero, then the accumulator is still emptied, - * but the statistics are not sent to the log server. - * - * @private - */ -remoting.LogToServer.prototype.logAccumulatedStatistics_ = function() { - var entry = remoting.ServerLogEntry.makeStats(this.statsAccumulator_, - this.connectionType_, - this.logEntryMode_); - if (entry) { - entry.addClientOSFields(); - entry.addChromeVersionField(); - entry.addWebappVersionField(); - entry.addSessionIdField(this.sessionId_); - this.log_(entry); - } - this.statsAccumulator_.empty(); -}; - -/** - * Sends a log entry to the server. - * - * @private - * @param {remoting.ServerLogEntry} entry - */ -remoting.LogToServer.prototype.log_ = function(entry) { - // Log the time taken to get to this point from the time this session started. - // Exclude time taken for authorization. - var sessionDurationInSeconds = - (new Date().getTime() - this.sessionStartTime_ - - this.authTotalTime_) / 1000.0; - entry.addSessionDuration(sessionDurationInSeconds); - entry.addApplicationId(); - // The host-version/os/os-version will be blank for logs before a session has - // been created. For example, the signal-strategy log-entries won't have host - // version info. - entry.addHostVersion(this.hostVersion_); - - // Send the stanza to the debug log. - console.log('Enqueueing log entry:'); - entry.toDebugLog(1); - - var stanza = '<cli:iq to="' + remoting.settings.DIRECTORY_BOT_JID + '" ' + - 'type="set" xmlns:cli="jabber:client">' + - '<gr:log xmlns:gr="google:remoting">' + - entry.toStanza() + - '</gr:log>' + - '</cli:iq>'; - this.signalStrategy_.sendMessage(stanza); -}; - -/** - * Sets the session ID to a random string. - */ -remoting.LogToServer.prototype.setSessionId = function() { - this.sessionId_ = remoting.LogToServer.generateSessionId_(); - this.sessionIdGenerationTime_ = new Date().getTime(); -}; - -/** - * Clears the session ID. - * - * @private - */ -remoting.LogToServer.prototype.clearSessionId_ = function() { - this.sessionId_ = ''; - this.sessionIdGenerationTime_ = 0; -}; - -/** - * Sets a new session ID, if the current session ID has reached its maximum age. - * - * This method also logs the old and new session IDs to the server, in separate - * log entries. - * - * @private - */ -remoting.LogToServer.prototype.maybeExpireSessionId_ = function() { - if ((this.sessionId_ != '') && - (new Date().getTime() - this.sessionIdGenerationTime_ >= - remoting.Logger.MAX_SESSION_ID_AGE)) { - // Log the old session ID. - var entry = remoting.ServerLogEntry.makeSessionIdOld(this.sessionId_, - this.logEntryMode_); - this.log_(entry); - // Generate a new session ID. - this.setSessionId(); - // Log the new session ID. - entry = remoting.ServerLogEntry.makeSessionIdNew(this.sessionId_, - this.logEntryMode_); - this.log_(entry); - } -}; - -/** - * Generates a string that can be used as a session ID. - * - * @private - * @return {string} a session ID - */ -remoting.LogToServer.generateSessionId_ = function() { - var idArray = []; - for (var i = 0; i < remoting.LogToServer.SESSION_ID_LEN_; i++) { - var index = - Math.random() * remoting.LogToServer.SESSION_ID_ALPHABET_.length; - idArray.push( - remoting.LogToServer.SESSION_ID_ALPHABET_.slice(index, index + 1)); - } - return idArray.join(''); -}; - -/** - * @param {number} totalTime The value of time taken to complete authorization. - * @return {void} Nothing. - */ -remoting.LogToServer.prototype.setAuthTotalTime = function(totalTime) { - this.authTotalTime_ = totalTime; -}; - -/** - * @param {string} hostVersion Version of the host for current session. - * @return {void} Nothing. - */ -remoting.LogToServer.prototype.setHostVersion = function(hostVersion) { - this.hostVersion_ = hostVersion; -}; - -/** - * Stub. - * @param {remoting.ChromotingEvent.Os} hostOS Type of the host OS for - current session. - * @return {void} Nothing. - */ -remoting.LogToServer.prototype.setHostOS = function(hostOS) {}; - -/** - * Stub - * @override {remoting.Logger} - */ -remoting.LogToServer.prototype.setHostStatusUpdateElapsedTime = function(time) { -}; - -/** - * Stub. - * @param {string} hostOSVersion Version of the host OS for current session. - * @return {void} Nothing. - */ -remoting.LogToServer.prototype.setHostOSVersion = function(hostOSVersion) {}; - -/** - * Stub. - * @override {remoting.Logger} - */ -remoting.LogToServer.prototype.setAuthMethod = function(authMethod) {}; diff --git a/remoting/webapp/base/js/logger.js b/remoting/webapp/base/js/logger.js deleted file mode 100644 index 4a61f22..0000000 --- a/remoting/webapp/base/js/logger.js +++ /dev/null @@ -1,105 +0,0 @@ -// Copyright 2015 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - - -/** @suppress {duplicate} */ -var remoting = remoting || {}; - -(function() { - -'use strict'; - -/** - * @interface - */ -remoting.Logger = function() {}; - -/** - * @param {number} totalTime The value of time taken to complete authorization. - * @return {void} Nothing. - */ -remoting.Logger.prototype.setAuthTotalTime = function(totalTime) {}; - -/** - * @param {string} hostVersion Version of the host for current session. - * @return {void} Nothing. - */ -remoting.Logger.prototype.setHostVersion = function(hostVersion) {}; - -/** - * @param {remoting.ChromotingEvent.Os} hostOS Type of the OS the host - * for the current session. - * @return {void} Nothing. - */ -remoting.Logger.prototype.setHostOS = function(hostOS) {}; - -/** - * @param {string} hostOSVersion Version of the host Os for current session. - * @return {void} Nothing. - */ -remoting.Logger.prototype.setHostOSVersion = function(hostOSVersion) {}; - -/** - * @param {number} time Time in milliseconds since the last host status update. - * @return {void} Nothing. - */ -remoting.Logger.prototype.setHostStatusUpdateElapsedTime = function(time) {}; - -/** - * Set the connection type (direct, stun relay). - * - * @param {string} connectionType - */ -remoting.Logger.prototype.setConnectionType = function(connectionType) {}; - -/** - * @param {remoting.ChromotingEvent.Mode} mode - */ -remoting.Logger.prototype.setLogEntryMode = function(mode) {}; - -/** - * @param {remoting.ChromotingEvent.AuthMethod} method - */ -remoting.Logger.prototype.setAuthMethod = function(method) {}; - -/** - * @param {remoting.SignalStrategy.Type} strategyType - * @param {remoting.FallbackSignalStrategy.Progress} progress - */ -remoting.Logger.prototype.logSignalStrategyProgress = - function(strategyType, progress) {}; - -/** - * Logs a client session state change. - * - * @param {remoting.ClientSession.State} state - * @param {!remoting.Error} connectionError - * @param {?remoting.ChromotingEvent.XmppError} xmppError The XMPP error - * as described in http://xmpp.org/rfcs/rfc6120.html#stanzas-error. - * Set if the connecton error originates from the an XMPP stanza error. - */ -remoting.Logger.prototype.logClientSessionStateChange = - function(state, connectionError, xmppError) {}; - -/** - * Logs connection statistics. - * @param {Object<number>} stats The connection statistics - */ -remoting.Logger.prototype.logStatistics = function(stats) {}; - - -/** - * @return {string} The current session id. This is random GUID, refreshed - * every 24hrs. - */ -remoting.Logger.prototype.getSessionId = function() {}; - -// The maximum age of a session ID, in milliseconds. -remoting.Logger.MAX_SESSION_ID_AGE = 24 * 60 * 60 * 1000; - -// The time over which to accumulate connection statistics before logging them -// to the server, in milliseconds. -remoting.Logger.CONNECTION_STATS_ACCUMULATE_TIME = 60 * 1000; - -})(); diff --git a/remoting/webapp/base/js/session_logger.js b/remoting/webapp/base/js/session_logger.js index 34490f6..b3e7cdc 100644 --- a/remoting/webapp/base/js/session_logger.js +++ b/remoting/webapp/base/js/session_logger.js @@ -11,14 +11,13 @@ var remoting = remoting || {}; 'use strict'; /** - * This class defines a remoting.Logger implementation that generates - * log entries in the format of remoting.ChromotingEvent. + * |remoting.SessionLogger| is responsible for reporting telemetry entries for + * a Chromoting session. * * @param {remoting.ChromotingEvent.Role} role * @param {function(!Object)} writeLogEntry * * @constructor - * @implements {remoting.Logger} */ remoting.SessionLogger = function(role, writeLogEntry) { /** @private */ @@ -64,53 +63,83 @@ remoting.SessionLogger.prototype.setEntryPoint = function(entryPoint) { this.entryPoint_ = entryPoint; }; -/** @override {remoting.Logger} */ +/** + * @param {number} totalTime The value of time taken to complete authorization. + * @return {void} Nothing. + */ remoting.SessionLogger.prototype.setAuthTotalTime = function(totalTime) { this.authTotalTime_ = totalTime; }; -/** @override {remoting.Logger} */ +/** + * @param {string} hostVersion Version of the host for current session. + * @return {void} Nothing. + */ remoting.SessionLogger.prototype.setHostVersion = function(hostVersion) { this.hostVersion_ = hostVersion; }; -/** @override {remoting.Logger} */ +/** + * @param {remoting.ChromotingEvent.Os} hostOS Type of the OS the host + * for the current session. + * @return {void} Nothing. + */ remoting.SessionLogger.prototype.setHostOS = function(hostOS) { this.hostOS_ = hostOS; }; -/** @override {remoting.Logger} */ +/** + * @param {string} hostOSVersion Version of the host Os for current session. + * @return {void} Nothing. + */ +remoting.SessionLogger.prototype.setHostOSVersion = function(hostOSVersion) { + this.hostOSVersion_ = hostOSVersion; +}; + +/** + * @param {number} time Time in milliseconds since the last host status update. + * @return {void} Nothing. + */ remoting.SessionLogger.prototype.setHostStatusUpdateElapsedTime = function(time) { this.hostStatusUpdateElapsedTime_ = time; }; -/** @override {remoting.Logger} */ -remoting.SessionLogger.prototype.setHostOSVersion = function(hostOSVersion) { - this.hostOSVersion_ = hostOSVersion; -}; - -/** @override {remoting.Logger} */ +/** + * Set the connection type (direct, stun relay). + * + * @param {string} connectionType + */ remoting.SessionLogger.prototype.setConnectionType = function(connectionType) { this.connectionType_ = toConnectionType(connectionType); }; -/** @override {remoting.Logger} */ +/** + * @param {remoting.ChromotingEvent.Mode} mode + */ remoting.SessionLogger.prototype.setLogEntryMode = function(mode) { this.mode_ = mode; }; -/** @override {remoting.Logger} */ -remoting.SessionLogger.prototype.setAuthMethod = function(authMethod) { - this.authMethod_ = authMethod; +/** + * @param {remoting.ChromotingEvent.AuthMethod} method + */ +remoting.SessionLogger.prototype.setAuthMethod = function(method) { + this.authMethod_ = method; }; -/** @override {remoting.Logger} */ +/** + * @return {string} The current session id. This is random GUID, refreshed + * every 24hrs. + */ remoting.SessionLogger.prototype.getSessionId = function() { return this.sessionId_; }; -/** @override {remoting.Logger} */ +/** + * @param {remoting.SignalStrategy.Type} strategyType + * @param {remoting.FallbackSignalStrategy.Progress} progress + */ remoting.SessionLogger.prototype.logSignalStrategyProgress = function(strategyType, progress) { this.maybeExpireSessionId_(); @@ -123,7 +152,15 @@ remoting.SessionLogger.prototype.logSignalStrategyProgress = this.log_(entry); }; -/** @override {remoting.Logger} */ +/** + * Logs a client session state change. + * + * @param {remoting.ClientSession.State} state + * @param {!remoting.Error} stateError + * @param {?remoting.ChromotingEvent.XmppError} xmppError The XMPP error + * as described in http://xmpp.org/rfcs/rfc6120.html#stanzas-error. + * Set if the connecton error originates from the an XMPP stanza error. + */ remoting.SessionLogger.prototype.logClientSessionStateChange = function( state, stateError, xmppError) { this.logSessionStateChange( @@ -154,7 +191,11 @@ remoting.SessionLogger.prototype.logSessionStateChange = function( this.statsAccumulator_.empty(); }; -/** @override {remoting.Logger} */ +/** + * Logs connection statistics. + * + * @param {Object<number>} stats The connection statistics + */ remoting.SessionLogger.prototype.logStatistics = function(stats) { this.maybeExpireSessionId_(); // Store the statistics. @@ -162,7 +203,7 @@ remoting.SessionLogger.prototype.logStatistics = function(stats) { // Send statistics to the server if they've been accumulating for at least // 60 seconds. if (this.statsAccumulator_.getTimeSinceFirstValue() >= - remoting.Logger.CONNECTION_STATS_ACCUMULATE_TIME) { + remoting.SessionLogger.CONNECTION_STATS_ACCUMULATE_TIME) { this.logAccumulatedStatistics_(); } }; @@ -277,6 +318,7 @@ remoting.SessionLogger.prototype.fillEvent_ = function(entry) { /** * Sends a log entry to the server. + * * @param {remoting.ChromotingEvent} entry * @private */ @@ -286,6 +328,7 @@ remoting.SessionLogger.prototype.log_ = function(entry) { /** * Sets the session ID to a random string. + * * @private */ remoting.SessionLogger.prototype.setSessionId_ = function() { @@ -316,7 +359,7 @@ remoting.SessionLogger.prototype.clearSessionId_ = function() { remoting.SessionLogger.prototype.maybeExpireSessionId_ = function() { if ((this.sessionId_ !== '') && (new Date().getTime() - this.sessionIdGenerationTime_ >= - remoting.Logger.MAX_SESSION_ID_AGE)) { + remoting.SessionLogger.MAX_SESSION_ID_AGE)) { // Log the old session ID. var entry = this.makeSessionIdOld_(); this.log_(entry); @@ -419,4 +462,11 @@ function toConnectionType(type) { } } +// The maximum age of a session ID, in milliseconds. +remoting.SessionLogger.MAX_SESSION_ID_AGE = 24 * 60 * 60 * 1000; + +// The time over which to accumulate connection statistics before logging them +// to the server, in milliseconds. +remoting.SessionLogger.CONNECTION_STATS_ACCUMULATE_TIME = 60 * 1000; + })(); diff --git a/remoting/webapp/base/js/session_logger_unittest.js b/remoting/webapp/base/js/session_logger_unittest.js index 8bf4de8..4111ede 100644 --- a/remoting/webapp/base/js/session_logger_unittest.js +++ b/remoting/webapp/base/js/session_logger_unittest.js @@ -167,7 +167,7 @@ QUnit.test('logClientSessionStateChange() should handle sessionId change.', var oldSessionId = logger.getSessionId(); // Expires the session id. - clock.tick(remoting.Logger.MAX_SESSION_ID_AGE + 100); + clock.tick(remoting.SessionLogger.MAX_SESSION_ID_AGE + 100); // Logs the event. logger.logClientSessionStateChange( @@ -297,7 +297,7 @@ QUnit.test('logStatistics()', function(assert) { sinon.assert.notCalled(logWriterSpy); // Stats should only be accumulated at |CONNECTION_STATS_ACCUMULATE_TIME|. - clock.tick(remoting.Logger.CONNECTION_STATS_ACCUMULATE_TIME + 10); + clock.tick(remoting.SessionLogger.CONNECTION_STATS_ACCUMULATE_TIME + 10); logger.logStatistics({ videoBandwidth: 3.0, @@ -348,7 +348,7 @@ QUnit.test('logStatistics() should not log if all stats are zeros ', roundtripLatency: 0.0 }); - clock.tick(remoting.Logger.CONNECTION_STATS_ACCUMULATE_TIME + 10); + clock.tick(remoting.SessionLogger.CONNECTION_STATS_ACCUMULATE_TIME + 10); logger.logStatistics({ videoBandwidth: 0.0, diff --git a/remoting/webapp/crd/js/buffered_signal_strategy.js b/remoting/webapp/crd/js/buffered_signal_strategy.js deleted file mode 100644 index 67ae2f9..0000000 --- a/remoting/webapp/crd/js/buffered_signal_strategy.js +++ /dev/null @@ -1,91 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -'use strict'; - -/** @suppress {duplicate} */ -var remoting = remoting || {}; - -/** - * Simplified SignalStrategy implementation that wraps an underlying signal - * strategy and forwards messages when it is CONNECTED. It is used only to - * log status messages during IT2Me connection setup, and only those methods - * required for that are implemented. - * - * TODO(jamiewalch): Remove this class once a signal strategy is no longer - * required for logging (crbug.com/497269). - * - * @constructor - * @param {remoting.SignalStrategy} underlying The underlying implementation. - * @implements {remoting.SignalStrategy} - */ -remoting.BufferedSignalStrategy = function(underlying) { - /** @private */ - this.underlying_ = underlying; - /** @private {Array<string>} */ - this.pendingMessages_ = []; - - this.underlying_.setStateChangedCallback(this.flush_.bind(this)); -}; - -remoting.BufferedSignalStrategy.prototype.dispose = function() { - this.underlying_.dispose(); -}; - -/** - * Sends a message. Can be called only in CONNECTED state. - * @param {string} message - */ -remoting.BufferedSignalStrategy.prototype.sendMessage = function(message) { - this.pendingMessages_.push(message); - this.flush_(); -}; - -/** - * If the underlying implementation is connected, flush all pending messages. - * @private - */ -remoting.BufferedSignalStrategy.prototype.flush_ = function() { - if (this.underlying_.getState() !== remoting.SignalStrategy.State.CONNECTED) { - return; - } - for (var i = 0; i < this.pendingMessages_.length; ++i) { - this.underlying_.sendMessage(this.pendingMessages_[i]); - } - this.pendingMessages_ = []; -}; - - -// The following methods are not used by LogToServer and are not implemented. - -remoting.BufferedSignalStrategy.prototype.setStateChangedCallback = - function(onStateChangedCallback) { - console.error('Unexpected setStateChangedCallback().'); -}; - -remoting.BufferedSignalStrategy.prototype.setIncomingStanzaCallback = - function(onIncomingStanzaCallback) { - console.error('Unexpected setIncomingStanzaCallback().'); -}; - -remoting.BufferedSignalStrategy.prototype.connect = - function(server, username, authToken) { - console.error('Unexpected connect().'); -}; - -remoting.BufferedSignalStrategy.prototype.getState = function() { - console.error('Unexpected getState().'); -}; - -remoting.BufferedSignalStrategy.prototype.getError = function() { - console.error('Unexpected getError().'); -}; - -remoting.BufferedSignalStrategy.prototype.getJid = function() { - console.error('Unexpected getJid().'); -}; - -remoting.BufferedSignalStrategy.prototype.getType = function() { - console.error('Unexpected getType().'); -}; diff --git a/remoting/webapp/crd/js/host_screen.js b/remoting/webapp/crd/js/host_screen.js index b0b61b9..56890d7 100644 --- a/remoting/webapp/crd/js/host_screen.js +++ b/remoting/webapp/crd/js/host_screen.js @@ -24,7 +24,7 @@ var hostSession_ = null; var lastShareWasCancelled_ = false; /** - * @type {remoting.LogToServer} Logging instance for IT2Me host connection + * @type {remoting.SessionLogger} Logging instance for IT2Me host connection * status. */ var it2meLogger = null; @@ -36,10 +36,11 @@ var it2meLogger = null; * to install them if necessary. */ remoting.tryShare = function() { - ensureIT2MeLogger_(); - it2meLogger.setSessionId(); - it2meLogger.logClientSessionStateChange( - remoting.ClientSession.State.INITIALIZING, remoting.Error.none(), null); + it2meLogger = createLogger_(); + it2meLogger.logSessionStateChange( + remoting.ChromotingEvent.SessionState.STARTED, + remoting.ChromotingEvent.ConnectionError.NONE, + null); /** @type {remoting.It2MeHostFacade} */ var hostFacade = new remoting.It2MeHostFacade(); @@ -92,8 +93,10 @@ remoting.tryShareWithToken_ = function(hostFacade, token) { lastShareWasCancelled_ = false; onNatTraversalPolicyChanged_(true); // Hide warning by default. remoting.setMode(remoting.AppMode.HOST_WAITING_FOR_CODE); - it2meLogger.logClientSessionStateChange( - remoting.ClientSession.State.CONNECTING, remoting.Error.none(), null); + it2meLogger.logSessionStateChange( + remoting.ChromotingEvent.SessionState.CONNECTING, + remoting.ChromotingEvent.ConnectionError.NONE, + null); document.getElementById('cancel-share-button').disabled = false; disableTimeoutCountdown_(); @@ -206,17 +209,19 @@ function logDebugInfo_(msg) { function showShareError_(error) { if (error.hasTag(remoting.Error.Tag.CANCELLED)) { remoting.setMode(remoting.AppMode.HOME); - it2meLogger.logClientSessionStateChange( - remoting.ClientSession.State.CONNECTION_CANCELED, - remoting.Error.none(), + it2meLogger.logSessionStateChange( + remoting.ChromotingEvent.SessionState.CONNECTION_CANCELED, + remoting.ChromotingEvent.ConnectionError.NONE, null); } else { var errorDiv = document.getElementById('host-plugin-error'); l10n.localizeElementFromTag(errorDiv, error.getTag()); console.error('Sharing error: ' + error.toString()); remoting.setMode(remoting.AppMode.HOST_SHARE_FAILED); - it2meLogger.logClientSessionStateChange( - remoting.ClientSession.State.FAILED, error, null); + it2meLogger.logSessionStateChange( + remoting.ChromotingEvent.SessionState.CONNECTION_FAILED, + error.toConnectionError(), + null); } cleanUp(); @@ -247,9 +252,9 @@ remoting.cancelShare = function() { remoting.lastShareWasCancelled = true; try { hostSession_.disconnect(); - it2meLogger.logClientSessionStateChange( - remoting.ClientSession.State.CONNECTION_CANCELED, - remoting.Error.none(), + it2meLogger.logSessionStateChange( + remoting.ChromotingEvent.SessionState.CONNECTION_CANCELED, + remoting.ChromotingEvent.ConnectionError.NONE, null); } catch (/** @type {*} */ error) { console.error('Error disconnecting: ' + error + @@ -360,26 +365,17 @@ function onNatTraversalPolicyChanged_(enabled) { } /** - * Create an IT2Me LogToServer instance if one does not already exist. + * Create an IT2Me SessionLogger instance. + * + * @return {remoting.SessionLogger} */ -function ensureIT2MeLogger_() { - if (it2meLogger) { - return; - } - - var xmppConnection = new remoting.XmppConnection(); - var tokenPromise = remoting.identity.getToken(); - var emailPromise = remoting.identity.getEmail(); - tokenPromise.then(function(/** string */ token) { - emailPromise.then(function(/** string */ email) { - xmppConnection.connect(remoting.settings.XMPP_SERVER, email, token); - }); - }); - - var bufferedSignalStrategy = - new remoting.BufferedSignalStrategy(xmppConnection); - it2meLogger = new remoting.LogToServer(bufferedSignalStrategy, true); - it2meLogger.setLogEntryMode(remoting.ChromotingEvent.Mode.IT2ME); +function createLogger_() { + // Create a new logger for each session to refresh the session id. + var logger = new remoting.SessionLogger( + remoting.ChromotingEvent.Role.HOST, + remoting.TelemetryEventWriter.Client.write); + logger.setLogEntryMode(remoting.ChromotingEvent.Mode.IT2ME); + return logger; } })(); diff --git a/remoting/webapp/files.gni b/remoting/webapp/files.gni index 261d5a6..8fdc8d1 100644 --- a/remoting/webapp/files.gni +++ b/remoting/webapp/files.gni @@ -184,6 +184,7 @@ remoting_webapp_shared_js_core_files = [ "base/js/application.js", "base/js/base.js", "base/js/callstack.js", + "base/js/chromoting_event.js", "base/js/console_wrapper.js", "base/js/ipc.js", "base/js/modal_dialogs.js", @@ -208,11 +209,7 @@ remoting_webapp_shared_js_host_files = [ # Logging and stats JavaScript files. remoting_webapp_shared_js_logging_files = [ - "base/js/chromoting_event.js", "base/js/format_iq.js", - "base/js/logger.js", - "base/js/log_to_server.js", - "base/js/server_log_entry.js", "base/js/session_logger.js", "base/js/stats_accumulator.js", ] @@ -275,7 +272,6 @@ remoting_webapp_js_gnubby_auth_files = [ "crd/js/gnubby_auth_handler.js" ] # Files for controlling the local machine as a host. # Includes both it2me and me2me files. remoting_webapp_js_host_control_files = [ - "crd/js/buffered_signal_strategy.js", "crd/js/host_controller.js", "crd/js/host_daemon_facade.js", "crd/js/host_screen.js", @@ -291,7 +287,6 @@ remoting_webapp_js_host_control_files = [ # Files for controlling the local it2me host. # Included by public_session.html. remoting_webapp_js_it2me_host_control_files = [ - "crd/js/buffered_signal_strategy.js", "crd/js/host_screen.js", "crd/js/host_session.js", "crd/js/host_install_dialog.js", @@ -480,7 +475,9 @@ remoting_webapp_wcs_sandbox_html_js_files = [ remoting_webapp_wcs_sandbox_html_all_js_files = remoting_webapp_wcs_sandbox_html_js_files remoting_webapp_wcs_sandbox_html_all_js_files += [ + "base/js/chromoting_event.js", "base/js/error.js", + "base/js/platform.js", "base/js/plugin_settings.js", ] |