diff options
author | jamiewalch@chromium.org <jamiewalch@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-04 02:58:19 +0000 |
---|---|---|
committer | jamiewalch@chromium.org <jamiewalch@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-04 02:58:19 +0000 |
commit | 47b7d4b321c090d77ced65c8e3fa25cbb15ee3e8 (patch) | |
tree | f58929b775c5fe7e2c5133edffa400f432ba0fd8 /remoting | |
parent | 7c16976ce7a48a9cd9715c1ed87696386a743ad6 (diff) | |
download | chromium_src-47b7d4b321c090d77ced65c8e3fa25cbb15ee3e8.zip chromium_src-47b7d4b321c090d77ced65c8e3fa25cbb15ee3e8.tar.gz chromium_src-47b7d4b321c090d77ced65c8e3fa25cbb15ee3e8.tar.bz2 |
Add support for suppressing error logging, and don't log errors due to cached host information or client device suspend.
BUG=139389
Review URL: https://chromiumcodereview.appspot.com/10825187
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@150004 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting')
-rw-r--r-- | remoting/remoting.gyp | 1 | ||||
-rw-r--r-- | remoting/webapp/client_screen.js | 4 | ||||
-rw-r--r-- | remoting/webapp/client_session.js | 29 | ||||
-rw-r--r-- | remoting/webapp/main.html | 1 | ||||
-rw-r--r-- | remoting/webapp/remoting.js | 7 | ||||
-rw-r--r-- | remoting/webapp/suspend_monitor.js | 51 |
6 files changed, 90 insertions, 3 deletions
diff --git a/remoting/remoting.gyp b/remoting/remoting.gyp index 9fc0bfd..4d76aa5 100644 --- a/remoting/remoting.gyp +++ b/remoting/remoting.gyp @@ -172,6 +172,7 @@ 'webapp/server_log_entry.js', 'webapp/spinner.gif', 'webapp/stats_accumulator.js', + 'webapp/suspend_monitor.js', 'webapp/toolbar.css', 'webapp/toolbar.js', 'webapp/ui_mode.js', diff --git a/remoting/webapp/client_screen.js b/remoting/webapp/client_screen.js index 9cdd87e..0432a36 100644 --- a/remoting/webapp/client_screen.js +++ b/remoting/webapp/client_screen.js @@ -246,7 +246,7 @@ function onClientStateChange_(oldState, newState) { } else if (newState == remoting.ClientSession.State.FAILED) { console.error('Client plugin reported connection failed: ' + - remoting.clientSession.error); + remoting.clientSession.error); clearPin = true; if (remoting.clientSession.error == remoting.ClientSession.ConnectionError.HOST_IS_OFFLINE) { @@ -530,6 +530,8 @@ function connectMe2MeWithAccessToken_(token) { pin, 'spake2_hmac,spake2_plain', remoting.hostId, /** @type {string} */ (remoting.oauth2.getCachedEmail()), remoting.ClientSession.Mode.ME2ME, onClientStateChange_); + // Don't log errors for cached JIDs. + remoting.clientSession.logErrors(!remoting.retryIfOffline); remoting.clientSession.createPluginAndConnect( document.getElementById('session-mode'), token); diff --git a/remoting/webapp/client_session.js b/remoting/webapp/client_session.js index da8051e..f11f52d 100644 --- a/remoting/webapp/client_session.js +++ b/remoting/webapp/client_session.js @@ -94,6 +94,13 @@ remoting.ClientSession = function(hostJid, hostPublicKey, sharedSecret, this.fullScreen_.addEventListener('click', this.callToggleFullScreen_, false); /** @type {number?} @private */ this.bumpScrollTimer_ = null; + /** + * Allow error reporting to be suppressed in situations where it would not + * be useful, for example, when the device is offline. + * + * @type {boolean} @private + */ + this.logErrors_ = true; }; // Note that the positive values in both of these enums are copied directly @@ -521,8 +528,15 @@ remoting.ClientSession.prototype.setState_ = function(newState) { if (this.onStateChange) { this.onStateChange(oldState, newState); } - this.logToServer.logClientSessionStateChange(this.state, this.error, - this.mode); + // If connection errors are being suppressed from the logs, translate + // FAILED to CLOSED here. This ensures that the duration is still logged. + var state = this.state; + if (this.state == remoting.ClientSession.State.FAILED && + !this.logErrors_) { + console.log('Suppressing error.'); + state = remoting.ClientSession.State.CLOSED; + } + this.logToServer.logClientSessionStateChange(state, this.error, this.mode); }; /** @@ -649,6 +663,17 @@ remoting.ClientSession.prototype.logStatistics = function(stats) { }; /** + * Enable or disable logging of connection errors. For example, if attempting + * a connection using a cached JID, errors should not be logged because the + * JID will be refreshed and the connection retried. + * + * @param {boolean} enable True to log errors; false to suppress them. + */ +remoting.ClientSession.prototype.logErrors = function(enable) { + this.logErrors_ = enable; +}; + +/** * Toggles between full-screen and windowed mode. * @return {void} Nothing. * @private diff --git a/remoting/webapp/main.html b/remoting/webapp/main.html index 9cb104c..c4afdad 100644 --- a/remoting/webapp/main.html +++ b/remoting/webapp/main.html @@ -39,6 +39,7 @@ found in the LICENSE file. <script src="remoting.js"></script> <script src="server_log_entry.js"></script> <script src="stats_accumulator.js"></script> + <script src="suspend_monitor.js"></script> <script src="toolbar.js"></script> <script src="ui_mode.js"></script> <script src="xhr.js"></script> diff --git a/remoting/webapp/remoting.js b/remoting/webapp/remoting.js index bcd29a2..2fb14f9 100644 --- a/remoting/webapp/remoting.js +++ b/remoting/webapp/remoting.js @@ -46,6 +46,13 @@ remoting.init = function() { remoting.toolbar = new remoting.Toolbar( document.getElementById('session-toolbar')); remoting.clipboard = new remoting.Clipboard(); + remoting.suspendMonitor = new remoting.SuspendMonitor( + function() { + if (remoting.clientSession) { + remoting.clientSession.logErrors(false); + } + } + ); remoting.oauth2.getEmail(remoting.onEmail, remoting.showErrorMessage); diff --git a/remoting/webapp/suspend_monitor.js b/remoting/webapp/suspend_monitor.js new file mode 100644 index 0000000..ec45444 --- /dev/null +++ b/remoting/webapp/suspend_monitor.js @@ -0,0 +1,51 @@ +// 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 + * Class to detect when the device is suspended, for example when a laptop's + * lid is closed. + */ + + +'use strict'; + +/** @suppress {duplicate} */ +var remoting = remoting || {}; + +/** + * @param {function():void} callback Callback function to invoke when a + * suspend+resume operation has been detected. + * + * @constructor + */ +remoting.SuspendMonitor = function (callback) { + /** @type {function():void} @private */ + this.callback_ = callback; + /** @type {number} @private */ + this.timerIntervalMs_ = 60 * 1000; + /** @type {number} @private */ + this.lateToleranceMs_ = 60 * 1000; + /** @type {number} @private */ + this.callbackExpectedTime_ = 0; + this.start_(); +}; + +/** @private */ +remoting.SuspendMonitor.prototype.start_ = function() { + window.setTimeout(this.checkSuspend_.bind(this), this.timerIntervalMs_); + this.callbackExpectedTime_ = new Date().getTime() + this.timerIntervalMs_; +}; + +/** @private */ +remoting.SuspendMonitor.prototype.checkSuspend_ = function() { + var lateByMs = new Date().getTime() - this.callbackExpectedTime_; + if (lateByMs > this.lateToleranceMs_) { + this.callback_(); + } + this.start_(); +}; + +/** @type {remoting.SuspendMonitor?} */ +remoting.suspendMonitor = null;
\ No newline at end of file |