Add support for suppressing error logging, and don't log errors due to cached...

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
parent 7c16976c
......@@ -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',
......
......@@ -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);
......
......@@ -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);
};
/**
......@@ -648,6 +662,17 @@ remoting.ClientSession.prototype.logStatistics = function(stats) {
this.logToServer.logStatistics(stats, this.mode);
};
/**
* 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.
......
......@@ -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>
......
......@@ -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);
......
// 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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment