Skip to content

Commit

Permalink
Converted remoting.Error to be a class rather than just a string.
Browse files Browse the repository at this point in the history
Review URL: https://codereview.chromium.org/955283002

Cr-Commit-Position: refs/heads/master@{#319824}
  • Loading branch information
jrw authored and Commit bot committed Mar 10, 2015
1 parent be2f4c3 commit 3cc9f0a
Show file tree
Hide file tree
Showing 45 changed files with 528 additions and 226 deletions.
6 changes: 3 additions & 3 deletions remoting/webapp/app_remoting/js/app_remoting.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ remoting.AppRemoting.prototype.start = function(connector, token) {
* Report an authentication error to the user. This is called in lieu of start()
* if the user cannot be authenticated or if they decline the app permissions.
*
* @param {remoting.Error} error The failure reason.
* @param {!remoting.Error} error The failure reason.
*/
remoting.AppRemoting.prototype.signInFailed = function(error) {
this.handleError(error);
Expand Down Expand Up @@ -252,7 +252,7 @@ remoting.AppRemoting.prototype.handleDisconnected = function() {
* Called when the current session's connection has failed.
*
* @param {remoting.SessionConnector} connector
* @param {remoting.Error} error
* @param {!remoting.Error} error
* @return {void} Nothing.
*/
remoting.AppRemoting.prototype.handleConnectionFailed = function(
Expand Down Expand Up @@ -328,7 +328,7 @@ remoting.AppRemoting.prototype.handleExtensionMessage = function(
/**
* Called when an error needs to be displayed to the user.
*
* @param {remoting.Error} errorTag The error to be localized and displayed.
* @param {!remoting.Error} errorTag The error to be localized and displayed.
* @return {void} Nothing.
*/
remoting.AppRemoting.prototype.handleError = function(errorTag) {
Expand Down
2 changes: 1 addition & 1 deletion remoting/webapp/app_remoting/js/loading_window.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ remoting.LoadingWindow = function() {};
remoting.LoadingWindow.onTimeout_ = function() {
remoting.MessageWindow.showErrorMessage(
remoting.app.getApplicationName(),
chrome.i18n.getMessage(remoting.Error.SERVICE_UNAVAILABLE));
chrome.i18n.getMessage(remoting.Error.Tag.SERVICE_UNAVAILABLE));
};

/**
Expand Down
10 changes: 5 additions & 5 deletions remoting/webapp/base/js/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ remoting.Application.prototype.onDisconnected = function() {
/**
* Called when the current session's connection has failed.
*
* @param {remoting.Error} error
* @param {!remoting.Error} error
* @return {void} Nothing.
*/
remoting.Application.prototype.onConnectionFailed = function(error) {
Expand Down Expand Up @@ -193,7 +193,7 @@ remoting.Application.prototype.onExtensionMessage = function(type, data) {
/**
* Called when an error needs to be displayed to the user.
*
* @param {remoting.Error} errorTag The error to be localized and displayed.
* @param {!remoting.Error} errorTag The error to be localized and displayed.
* @return {void} Nothing.
*/
remoting.Application.prototype.onError = function(errorTag) {
Expand Down Expand Up @@ -289,7 +289,7 @@ remoting.Application.Delegate.prototype.start = function(connector, token) {};
* Report an authentication error to the user. This is called in lieu of start()
* if the user cannot be authenticated.
*
* @param {remoting.Error} error The failure reason.
* @param {!remoting.Error} error The failure reason.
*/
remoting.Application.Delegate.prototype.signInFailed = function(error) {};

Expand Down Expand Up @@ -323,7 +323,7 @@ remoting.Application.Delegate.prototype.handleDisconnected = function() {};
* Called when the current session's connection has failed.
*
* @param {remoting.SessionConnector} connector
* @param {remoting.Error} error
* @param {!remoting.Error} error
* @return {void} Nothing.
*/
remoting.Application.Delegate.prototype.handleConnectionFailed =
Expand Down Expand Up @@ -351,7 +351,7 @@ remoting.Application.Delegate.prototype.handleExtensionMessage =
/**
* Called when an error needs to be displayed to the user.
*
* @param {remoting.Error} errorTag The error to be localized and displayed.
* @param {!remoting.Error} errorTag The error to be localized and displayed.
* @return {void} Nothing.
*/
remoting.Application.Delegate.prototype.handleError = function(errorTag) {};
Expand Down
2 changes: 1 addition & 1 deletion remoting/webapp/browser_test/browser_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ browserTest.enterPIN = function(pin, opt_expectError) {
if (opt_expectError) {
return browserTest.expectConnectionError(
remoting.DesktopConnectedView.Mode.ME2ME,
remoting.Error.INVALID_ACCESS_CODE);
remoting.Error.Tag.INVALID_ACCESS_CODE);
} else {
return browserTest.expectConnected();
}
Expand Down
2 changes: 1 addition & 1 deletion remoting/webapp/browser_test/it2me_browser_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ browserTest.InvalidAccessCode.prototype.run = function(data) {
browserTest.clickOnControl('connect-button');
return browserTest.expectConnectionError(
remoting.DesktopConnectedView.Mode.IT2ME,
remoting.Error.INVALID_ACCESS_CODE);
remoting.Error.Tag.INVALID_ACCESS_CODE);
}).then(function() {
browserTest.pass();
}, function(/** * */reason) {
Expand Down
6 changes: 3 additions & 3 deletions remoting/webapp/browser_test/mock_host_list_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ remoting.MockHostListApi = function() {

/**
* @param {function(Array<remoting.Host>):void} onDone
* @param {function(remoting.Error):void} onError
* @param {function(!remoting.Error):void} onError
*/
remoting.MockHostListApi.prototype.get = function(onDone, onError) {
remoting.mockIdentity.validateTokenAndCall(onDone, onError, [this.hosts]);
Expand All @@ -53,7 +53,7 @@ remoting.MockHostListApi.prototype.get = function(onDone, onError) {
* @param {string} hostName
* @param {string} hostPublicKey
* @param {function():void} onDone
* @param {function(remoting.Error):void} onError
* @param {function(!remoting.Error):void} onError
*/
remoting.MockHostListApi.prototype.put =
function(hostId, hostName, hostPublicKey, onDone, onError) {
Expand All @@ -79,7 +79,7 @@ remoting.MockHostListApi.prototype.put =
/**
* @param {string} hostId
* @param {function():void} onDone
* @param {function(remoting.Error):void} onError
* @param {function(!remoting.Error):void} onError
*/
remoting.MockHostListApi.prototype.remove =
function(hostId, onDone, onError) {
Expand Down
4 changes: 2 additions & 2 deletions remoting/webapp/browser_test/mock_identity.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ remoting.MockIdentity.prototype.setAccessToken = function(accessToken) {
/**
* @param {string} token
* @param {Function} onDone
* @param {function(remoting.Error)} onError
* @param {function(!remoting.Error)} onError
* @param {Array<*>} values
*/
remoting.MockIdentity.validateTokenAndCall =
Expand All @@ -86,7 +86,7 @@ remoting.MockIdentity.validateTokenAndCall =

/**
* @param {Function} onDone
* @param {function(remoting.Error)} onError
* @param {function(!remoting.Error)} onError
* @param {Array<*>} values
*/
remoting.MockIdentity.prototype.validateTokenAndCall =
Expand Down
8 changes: 4 additions & 4 deletions remoting/webapp/browser_test/mock_oauth2_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ remoting.MockOAuth2Api = function() {

/**
* @param {function(string, number): void} onDone
* @param {function(remoting.Error):void} onError
* @param {function(!remoting.Error):void} onError
* @param {string} clientId
* @param {string} clientSecret
* @param {string} refreshToken
Expand All @@ -47,7 +47,7 @@ remoting.MockOAuth2Api.prototype.refreshAccessToken = function(

/**
* @param {function(string, string, number): void} onDone
* @param {function(remoting.Error):void} onError
* @param {function(!remoting.Error):void} onError
* @param {string} clientId
* @param {string} clientSecret
* @param {string} code
Expand All @@ -63,7 +63,7 @@ remoting.MockOAuth2Api.prototype.exchangeCodeForTokens = function(

/**
* @param {function(string,string)} onDone
* @param {function(remoting.Error)} onError
* @param {function(!remoting.Error)} onError
* @param {string} token
*/
remoting.MockOAuth2Api.prototype.getEmail = function(onDone, onError, token) {
Expand All @@ -73,7 +73,7 @@ remoting.MockOAuth2Api.prototype.getEmail = function(onDone, onError, token) {

/**
* @param {function(string,string)} onDone
* @param {function(remoting.Error)} onError
* @param {function(!remoting.Error)} onError
* @param {string} token
*/
remoting.MockOAuth2Api.prototype.getUserInfo =
Expand Down
8 changes: 4 additions & 4 deletions remoting/webapp/browser_test/mock_session_connector.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ var remoting = remoting || {};
* @param {HTMLElement} clientContainer Container element for the client view.
* @param {function(remoting.ClientSession):void} onConnected Callback on
* success.
* @param {function(remoting.Error):void} onError Callback on error.
* @param {function(!remoting.Error):void} onError Callback on error.
* @param {function(string, string):boolean} onExtensionMessage The handler for
* protocol extension messages. Returns true if a message is recognized;
* false otherwise.
* @param {function(remoting.Error):void} onConnectionFailed Callback for when
* @param {function(!remoting.Error):void} onConnectionFailed Callback for when
* the connection fails.
* @param {Array<string>} requiredCapabilities Connector capabilities
* required by this application.
Expand Down Expand Up @@ -162,11 +162,11 @@ remoting.MockSessionConnectorFactory = function() {};
* @param {HTMLElement} clientContainer Container element for the client view.
* @param {function(remoting.ClientSession):void} onConnected Callback on
* success.
* @param {function(remoting.Error):void} onError Callback on error.
* @param {function(!remoting.Error):void} onError Callback on error.
* @param {function(string, string):boolean} onExtensionMessage The handler for
* protocol extension messages. Returns true if a message is recognized;
* false otherwise.
* @param {function(remoting.Error):void} onConnectionFailed Callback for when
* @param {function(!remoting.Error):void} onConnectionFailed Callback for when
* the connection fails.
* @param {Array<string>} requiredCapabilities Connector capabilities
* required by this application.
Expand Down
16 changes: 8 additions & 8 deletions remoting/webapp/crd/js/client_session.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ remoting.ClientSession = function(plugin, host, signalStrategy, mode) {
/** @private */
this.state_ = remoting.ClientSession.State.CREATED;

/** @private */
/** @private {!remoting.Error} */
this.error_ = remoting.Error.NONE;

/** @private */
Expand Down Expand Up @@ -259,14 +259,14 @@ remoting.ClientSession.prototype.removePlugin = function() {
* raise a |stateChanged| event in response to it. The caller should then call
* dispose() to remove and destroy the <embed> element.
*
* @param {remoting.Error} error The reason for the disconnection. Use
* @param {!remoting.Error} error The reason for the disconnection. Use
* remoting.Error.NONE if there is no error.
* @return {void} Nothing.
*/
remoting.ClientSession.prototype.disconnect = function(error) {
var state = (error == remoting.Error.NONE) ?
remoting.ClientSession.State.CLOSED :
remoting.ClientSession.State.FAILED;
var state = error.isError() ?
remoting.ClientSession.State.FAILED :
remoting.ClientSession.State.CLOSED;

// The plugin won't send a state change notification, so we explicitly log
// the fact that the connection has closed.
Expand Down Expand Up @@ -305,7 +305,7 @@ remoting.ClientSession.prototype.getState = function() {
};

/**
* @return {remoting.Error} The current error code.
* @return {!remoting.Error} The current error code.
*/
remoting.ClientSession.prototype.getError = function() {
return this.error_;
Expand Down Expand Up @@ -492,7 +492,7 @@ remoting.ClientSession.prototype.setState_ = function(newState) {
if (this.state_ == remoting.ClientSession.State.CLOSED) {
state = remoting.ClientSession.State.CONNECTION_CANCELED;
} else if (this.state_ == remoting.ClientSession.State.FAILED &&
this.error_ == remoting.Error.HOST_IS_OFFLINE &&
this.error_.tag == remoting.Error.Tag.HOST_IS_OFFLINE &&
!this.logHostOfflineErrors_) {
// The application requested host-offline errors to be suppressed, for
// example, because this connection attempt is using a cached host JID.
Expand Down Expand Up @@ -637,7 +637,7 @@ remoting.ClientSession.prototype.sendGoogleDriveAccessToken_ = function() {
var sendToken = function(token) {
remoting.clientSession.sendClientMessage('accessToken', token);
};
/** @param {remoting.Error} error */
/** @param {!remoting.Error} error */
var sendError = function(error) {
console.log('Failed to refresh access token: ' + error);
};
Expand Down
2 changes: 1 addition & 1 deletion remoting/webapp/crd/js/crd_main.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ remoting.updateLocalHostState = function() {
*/
var onHasFeatureResponse = function(response) {
/**
* @param {remoting.Error} error
* @param {!remoting.Error} error
*/
var onError = function(error) {
console.error('Failed to get pairing status: ' + error);
Expand Down
16 changes: 8 additions & 8 deletions remoting/webapp/crd/js/desktop_remoting.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ remoting.DesktopRemoting.prototype.start = function(connector, token) {
* Report an authentication error to the user. This is called in lieu of start()
* if the user cannot be authenticated or if they decline the app permissions.
*
* @param {remoting.Error} error The failure reason.
* @param {!remoting.Error} error The failure reason.
*/
remoting.DesktopRemoting.prototype.signInFailed = function(error) {
remoting.showErrorMessage(error);
Expand Down Expand Up @@ -246,7 +246,7 @@ remoting.DesktopRemoting.prototype.handleDisconnected = function() {
* Called when the current session's connection has failed.
*
* @param {remoting.SessionConnector} connector
* @param {remoting.Error} error
* @param {!remoting.Error} error
* @return {void} Nothing.
*/
remoting.DesktopRemoting.prototype.handleConnectionFailed = function(
Expand All @@ -266,7 +266,7 @@ remoting.DesktopRemoting.prototype.handleConnectionFailed = function(
that.handleError(error);
};

if (error == remoting.Error.HOST_IS_OFFLINE &&
if (error.tag == remoting.Error.Tag.HOST_IS_OFFLINE &&
that.refreshHostJidIfOffline_) {
that.refreshHostJidIfOffline_ = false;
// The plugin will be re-created when the host finished refreshing
Expand Down Expand Up @@ -298,14 +298,14 @@ remoting.DesktopRemoting.prototype.handleExtensionMessage = function(
/**
* Called when an error needs to be displayed to the user.
*
* @param {remoting.Error} errorTag The error to be localized and displayed.
* @param {!remoting.Error} error The error to be localized and displayed.
* @return {void} Nothing.
*/
remoting.DesktopRemoting.prototype.handleError = function(errorTag) {
console.error('Connection failed: ' + errorTag);
remoting.DesktopRemoting.prototype.handleError = function(error) {
console.error('Connection failed:', error.tag);
remoting.accessCode = '';

if (errorTag === remoting.Error.AUTHENTICATION_FAILED) {
if (error.tag === remoting.Error.Tag.AUTHENTICATION_FAILED) {
remoting.setMode(remoting.AppMode.HOME);
remoting.handleAuthFailureAndRelaunch();
return;
Expand All @@ -315,7 +315,7 @@ remoting.DesktopRemoting.prototype.handleError = function(errorTag) {
this.refreshHostJidIfOffline_ = true;

var errorDiv = document.getElementById('connect-error-message');
l10n.localizeElementFromTag(errorDiv, /** @type {string} */ (errorTag));
l10n.localizeElementFromTag(errorDiv, error.tag);

var mode = remoting.clientSession ? remoting.desktopConnectedView.getMode()
: this.app_.getSessionConnector().getConnectionMode();
Expand Down
Loading

0 comments on commit 3cc9f0a

Please sign in to comment.