Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(520)

Side by Side Diff: remoting/webapp/crd/js/client_session.js

Issue 1004513002: Eliminated named constants for instances of remoting.Error. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « remoting/webapp/base/js/application.js ('k') | remoting/webapp/crd/js/crd_connect.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 * @fileoverview 6 * @fileoverview
7 * Class handling creation and teardown of a remoting client session. 7 * Class handling creation and teardown of a remoting client session.
8 * 8 *
9 * The ClientSession class controls lifetime of the client plugin 9 * The ClientSession class controls lifetime of the client plugin
10 * object and provides the plugin with the functionality it needs to 10 * object and provides the plugin with the functionality it needs to
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 * @extends {base.EventSourceImpl} 44 * @extends {base.EventSourceImpl}
45 * @implements {base.Disposable} 45 * @implements {base.Disposable}
46 * @implements {remoting.ClientPlugin.ConnectionEventHandler} 46 * @implements {remoting.ClientPlugin.ConnectionEventHandler}
47 */ 47 */
48 remoting.ClientSession = function(plugin, host, signalStrategy, mode, 48 remoting.ClientSession = function(plugin, host, signalStrategy, mode,
49 onExtensionMessage) { 49 onExtensionMessage) {
50 /** @private */ 50 /** @private */
51 this.state_ = remoting.ClientSession.State.CREATED; 51 this.state_ = remoting.ClientSession.State.CREATED;
52 52
53 /** @private {!remoting.Error} */ 53 /** @private {!remoting.Error} */
54 this.error_ = remoting.Error.NONE; 54 this.error_ = remoting.Error.none();
55 55
56 /** @private */ 56 /** @private */
57 this.host_ = host; 57 this.host_ = host;
58 58
59 /** @private */ 59 /** @private */
60 this.sessionId_ = ''; 60 this.sessionId_ = '';
61 61
62 /** @private */ 62 /** @private */
63 this.hasReceivedFrame_ = false; 63 this.hasReceivedFrame_ = false;
64 this.logToServer = new remoting.LogToServer(signalStrategy, mode); 64 this.logToServer = new remoting.LogToServer(signalStrategy, mode);
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 remoting.ClientSession.prototype.removePlugin = function() { 246 remoting.ClientSession.prototype.removePlugin = function() {
247 this.plugin_ = null; 247 this.plugin_ = null;
248 }; 248 };
249 249
250 /** 250 /**
251 * Disconnect the current session with a particular |error|. The session will 251 * Disconnect the current session with a particular |error|. The session will
252 * raise a |stateChanged| event in response to it. The caller should then call 252 * raise a |stateChanged| event in response to it. The caller should then call
253 * dispose() to remove and destroy the <embed> element. 253 * dispose() to remove and destroy the <embed> element.
254 * 254 *
255 * @param {!remoting.Error} error The reason for the disconnection. Use 255 * @param {!remoting.Error} error The reason for the disconnection. Use
256 * remoting.Error.NONE if there is no error. 256 * remoting.Error.none() if there is no error.
257 * @return {void} Nothing. 257 * @return {void} Nothing.
258 */ 258 */
259 remoting.ClientSession.prototype.disconnect = function(error) { 259 remoting.ClientSession.prototype.disconnect = function(error) {
260 var state = error.isError() ? 260 var state = error.isNone() ?
261 remoting.ClientSession.State.FAILED : 261 remoting.ClientSession.State.CLOSED :
262 remoting.ClientSession.State.CLOSED; 262 remoting.ClientSession.State.FAILED;
263 263
264 // The plugin won't send a state change notification, so we explicitly log 264 // The plugin won't send a state change notification, so we explicitly log
265 // the fact that the connection has closed. 265 // the fact that the connection has closed.
266 this.logToServer.logClientSessionStateChange(state, error); 266 this.logToServer.logClientSessionStateChange(state, error);
267 this.error_ = error; 267 this.error_ = error;
268 this.setState_(state); 268 this.setState_(state);
269 }; 269 };
270 270
271 /** 271 /**
272 * Deletes the <embed> element from the container and disconnects. 272 * Deletes the <embed> element from the container and disconnects.
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 * @param {remoting.ClientSession.ConnectionError} error The plugin's error 385 * @param {remoting.ClientSession.ConnectionError} error The plugin's error
386 * state, if any. 386 * state, if any.
387 */ 387 */
388 remoting.ClientSession.prototype.onConnectionStatusUpdate = 388 remoting.ClientSession.prototype.onConnectionStatusUpdate =
389 function(status, error) { 389 function(status, error) {
390 if (status == remoting.ClientSession.State.CONNECTED) { 390 if (status == remoting.ClientSession.State.CONNECTED) {
391 remoting.desktopConnectedView.onConnected(); 391 remoting.desktopConnectedView.onConnected();
392 } else if (status == remoting.ClientSession.State.FAILED) { 392 } else if (status == remoting.ClientSession.State.FAILED) {
393 switch (error) { 393 switch (error) {
394 case remoting.ClientSession.ConnectionError.HOST_IS_OFFLINE: 394 case remoting.ClientSession.ConnectionError.HOST_IS_OFFLINE:
395 this.error_ = remoting.Error.HOST_IS_OFFLINE; 395 this.error_ = new remoting.Error(
396 remoting.Error.Tag.HOST_IS_OFFLINE);
396 break; 397 break;
397 case remoting.ClientSession.ConnectionError.SESSION_REJECTED: 398 case remoting.ClientSession.ConnectionError.SESSION_REJECTED:
398 this.error_ = remoting.Error.INVALID_ACCESS_CODE; 399 this.error_ = new remoting.Error(
400 remoting.Error.Tag.INVALID_ACCESS_CODE);
399 break; 401 break;
400 case remoting.ClientSession.ConnectionError.INCOMPATIBLE_PROTOCOL: 402 case remoting.ClientSession.ConnectionError.INCOMPATIBLE_PROTOCOL:
401 this.error_ = remoting.Error.INCOMPATIBLE_PROTOCOL; 403 this.error_ = new remoting.Error(
404 remoting.Error.Tag.INCOMPATIBLE_PROTOCOL);
402 break; 405 break;
403 case remoting.ClientSession.ConnectionError.NETWORK_FAILURE: 406 case remoting.ClientSession.ConnectionError.NETWORK_FAILURE:
404 this.error_ = remoting.Error.P2P_FAILURE; 407 this.error_ = new remoting.Error(
408 remoting.Error.Tag.P2P_FAILURE);
405 break; 409 break;
406 case remoting.ClientSession.ConnectionError.HOST_OVERLOAD: 410 case remoting.ClientSession.ConnectionError.HOST_OVERLOAD:
407 this.error_ = remoting.Error.HOST_OVERLOAD; 411 this.error_ = new remoting.Error(
412 remoting.Error.Tag.HOST_OVERLOAD);
408 break; 413 break;
409 default: 414 default:
410 this.error_ = remoting.Error.UNEXPECTED; 415 this.error_ = remoting.Error.unexpected();
411 } 416 }
412 } 417 }
413 this.setState_(status); 418 this.setState_(status);
414 }; 419 };
415 420
416 /** 421 /**
417 * Callback that the plugin invokes to indicate that the connection type for 422 * Callback that the plugin invokes to indicate that the connection type for
418 * a channel has changed. 423 * a channel has changed.
419 * 424 *
420 * @param {string} channel The channel name. 425 * @param {string} channel The channel name.
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 * @private 495 * @private
491 */ 496 */
492 remoting.ClientSession.prototype.setState_ = function(newState) { 497 remoting.ClientSession.prototype.setState_ = function(newState) {
493 var oldState = this.state_; 498 var oldState = this.state_;
494 this.state_ = newState; 499 this.state_ = newState;
495 var state = this.state_; 500 var state = this.state_;
496 if (oldState == remoting.ClientSession.State.CONNECTING) { 501 if (oldState == remoting.ClientSession.State.CONNECTING) {
497 if (this.state_ == remoting.ClientSession.State.CLOSED) { 502 if (this.state_ == remoting.ClientSession.State.CLOSED) {
498 state = remoting.ClientSession.State.CONNECTION_CANCELED; 503 state = remoting.ClientSession.State.CONNECTION_CANCELED;
499 } else if (this.state_ == remoting.ClientSession.State.FAILED && 504 } else if (this.state_ == remoting.ClientSession.State.FAILED &&
500 this.error_.tag == remoting.Error.Tag.HOST_IS_OFFLINE && 505 this.error_.hasTag(remoting.Error.Tag.HOST_IS_OFFLINE) &&
501 !this.logHostOfflineErrors_) { 506 !this.logHostOfflineErrors_) {
502 // The application requested host-offline errors to be suppressed, for 507 // The application requested host-offline errors to be suppressed, for
503 // example, because this connection attempt is using a cached host JID. 508 // example, because this connection attempt is using a cached host JID.
504 console.log('Suppressing host-offline error.'); 509 console.log('Suppressing host-offline error.');
505 state = remoting.ClientSession.State.CONNECTION_CANCELED; 510 state = remoting.ClientSession.State.CONNECTION_CANCELED;
506 } 511 }
507 } else if (oldState == remoting.ClientSession.State.CONNECTED && 512 } else if (oldState == remoting.ClientSession.State.CONNECTED &&
508 this.state_ == remoting.ClientSession.State.FAILED) { 513 this.state_ == remoting.ClientSession.State.FAILED) {
509 state = remoting.ClientSession.State.CONNECTION_DROPPED; 514 state = remoting.ClientSession.State.CONNECTION_DROPPED;
510 } 515 }
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
592 } 597 }
593 /** @type {remoting.ClientSession} */ 598 /** @type {remoting.ClientSession} */
594 var that = this; 599 var that = this;
595 600
596 /** @param {string} token */ 601 /** @param {string} token */
597 var sendToken = function(token) { 602 var sendToken = function(token) {
598 remoting.clientSession.sendClientMessage('accessToken', token); 603 remoting.clientSession.sendClientMessage('accessToken', token);
599 }; 604 };
600 /** @param {!remoting.Error} error */ 605 /** @param {!remoting.Error} error */
601 var sendError = function(error) { 606 var sendError = function(error) {
602 console.log('Failed to refresh access token: ' + error); 607 console.log('Failed to refresh access token: ' + error.toString());
603 }; 608 };
604 remoting.identity.getNewToken(). 609 remoting.identity.getNewToken().
605 then(sendToken). 610 then(sendToken).
606 catch(remoting.Error.handler(sendError)); 611 catch(remoting.Error.handler(sendError));
607 window.setTimeout(this.sendGoogleDriveAccessToken_.bind(this), 612 window.setTimeout(this.sendGoogleDriveAccessToken_.bind(this),
608 remoting.ACCESS_TOKEN_RESEND_INTERVAL_MS); 613 remoting.ACCESS_TOKEN_RESEND_INTERVAL_MS);
609 }; 614 };
610 615
611 /** 616 /**
612 * Enables or disables rendering of dirty regions for debugging. 617 * Enables or disables rendering of dirty regions for debugging.
613 * @param {boolean} enable True to enable rendering. 618 * @param {boolean} enable True to enable rendering.
614 */ 619 */
615 remoting.ClientSession.prototype.enableDebugRegion = function(enable) { 620 remoting.ClientSession.prototype.enableDebugRegion = function(enable) {
616 if (enable) { 621 if (enable) {
617 this.plugin_.setDebugDirtyRegionHandler( 622 this.plugin_.setDebugDirtyRegionHandler(
618 remoting.desktopConnectedView.handleDebugRegion.bind( 623 remoting.desktopConnectedView.handleDebugRegion.bind(
619 remoting.desktopConnectedView)); 624 remoting.desktopConnectedView));
620 } else { 625 } else {
621 this.plugin_.setDebugDirtyRegionHandler(null); 626 this.plugin_.setDebugDirtyRegionHandler(null);
622 } 627 }
623 } 628 }
OLDNEW
« no previous file with comments | « remoting/webapp/base/js/application.js ('k') | remoting/webapp/crd/js/crd_connect.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698