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

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

Issue 1410563006: [Chromoting] SessionLogger refactor. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 1 month 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
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 438 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 * Callback that the plugin invokes to indicate that the connection 449 * Callback that the plugin invokes to indicate that the connection
450 * status has changed. 450 * status has changed.
451 * 451 *
452 * @param {remoting.ClientSession.State} status The plugin's status. 452 * @param {remoting.ClientSession.State} status The plugin's status.
453 * @param {remoting.ClientSession.ConnectionError} error The plugin's error 453 * @param {remoting.ClientSession.ConnectionError} error The plugin's error
454 * state, if any. 454 * state, if any.
455 */ 455 */
456 remoting.ClientSession.prototype.onConnectionStatusUpdate = 456 remoting.ClientSession.prototype.onConnectionStatusUpdate =
457 function(status, error) { 457 function(status, error) {
458 if (status == remoting.ClientSession.State.FAILED) { 458 if (status == remoting.ClientSession.State.FAILED) {
459 var errorTag = remoting.Error.Tag.UNEXPECTED;
459 switch (error) { 460 switch (error) {
460 case remoting.ClientSession.ConnectionError.HOST_IS_OFFLINE: 461 case remoting.ClientSession.ConnectionError.HOST_IS_OFFLINE:
461 this.error_ = new remoting.Error(remoting.Error.Tag.HOST_IS_OFFLINE); 462 errorTag = remoting.Error.Tag.HOST_IS_OFFLINE;
462 break; 463 break;
463 case remoting.ClientSession.ConnectionError.SESSION_REJECTED: 464 case remoting.ClientSession.ConnectionError.SESSION_REJECTED:
464 this.error_ = 465 errorTag = remoting.Error.Tag.INVALID_ACCESS_CODE;
465 new remoting.Error(remoting.Error.Tag.INVALID_ACCESS_CODE);
466 break; 466 break;
467 case remoting.ClientSession.ConnectionError.INCOMPATIBLE_PROTOCOL: 467 case remoting.ClientSession.ConnectionError.INCOMPATIBLE_PROTOCOL:
468 this.error_ = 468 errorTag = remoting.Error.Tag.INCOMPATIBLE_PROTOCOL;
469 new remoting.Error(remoting.Error.Tag.INCOMPATIBLE_PROTOCOL);
470 break; 469 break;
471 case remoting.ClientSession.ConnectionError.NETWORK_FAILURE: 470 case remoting.ClientSession.ConnectionError.NETWORK_FAILURE:
472 this.error_ = new remoting.Error(remoting.Error.Tag.P2P_FAILURE); 471 errorTag = remoting.Error.Tag.P2P_FAILURE;
473 break; 472 break;
474 case remoting.ClientSession.ConnectionError.HOST_OVERLOAD: 473 case remoting.ClientSession.ConnectionError.HOST_OVERLOAD:
475 this.error_ = new remoting.Error(remoting.Error.Tag.HOST_OVERLOAD); 474 errorTag = remoting.Error.Tag.HOST_OVERLOAD;
476 break; 475 break;
477 case remoting.ClientSession.ConnectionError.MAX_SESSION_LENGTH: 476 case remoting.ClientSession.ConnectionError.MAX_SESSION_LENGTH:
478 this.error_ = new remoting.Error(remoting.Error.Tag.MAX_SESSION_LENGTH); 477 errorTag = remoting.Error.Tag.MAX_SESSION_LENGTH;
479 break; 478 break;
480 case remoting.ClientSession.ConnectionError.HOST_CONFIGURATION_ERROR: 479 case remoting.ClientSession.ConnectionError.HOST_CONFIGURATION_ERROR:
481 this.error_ = 480 errorTag = remoting.Error.Tag.HOST_CONFIGURATION_ERROR;
482 new remoting.Error(remoting.Error.Tag.HOST_CONFIGURATION_ERROR);
483 break; 481 break;
484 default: 482 default:
485 this.error_ = remoting.Error.unexpected(); 483 this.error_ = remoting.Error.unexpected();
486 } 484 }
485 this.error_ = new remoting.Error(
486 errorTag, this.xmppErrorCache_.getFirstErrorStanza());
487 } 487 }
488 this.setState_(status); 488 this.setState_(status);
489 }; 489 };
490 490
491 /** 491 /**
492 * Callback that the plugin invokes to indicate that the connection type for 492 * Callback that the plugin invokes to indicate that the connection type for
493 * a channel has changed. 493 * a channel has changed.
494 * 494 *
495 * @param {string} channel The channel name. 495 * @param {string} channel The channel name.
496 * @param {string} connectionType The new connection type. 496 * @param {string} connectionType The new connection type.
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
555 } 555 }
556 } else if (this.isFinished()) { 556 } else if (this.isFinished()) {
557 base.dispose(this.connectedDisposables_); 557 base.dispose(this.connectedDisposables_);
558 this.connectedDisposables_ = null; 558 this.connectedDisposables_ = null;
559 } 559 }
560 560
561 this.logAuthMethod_(); 561 this.logAuthMethod_();
562 this.notifyStateChanges_(oldState, this.state_); 562 this.notifyStateChanges_(oldState, this.state_);
563 // Record state count in an UMA enumerated histogram. 563 // Record state count in an UMA enumerated histogram.
564 recordState(this.state_); 564 recordState(this.state_);
565 this.logger_.logClientSessionStateChange( 565 this.logger_.logSessionStateChange(toSessionState(this.state_), this.error_);
566 this.state_, this.error_, this.xmppErrorCache_.getFirstError());
567 }; 566 };
568 567
569 /** @private */ 568 /** @private */
570 remoting.ClientSession.prototype.logAuthMethod_ = function() { 569 remoting.ClientSession.prototype.logAuthMethod_ = function() {
571 // The AuthMethod is undefined before the AUTHENTICATED stage for a 570 // The AuthMethod is undefined before the AUTHENTICATED stage for a
572 // successful connection or the FAILED stage for a failed connection. 571 // successful connection or the FAILED stage for a failed connection.
573 if (this.state_ == remoting.ClientSession.State.AUTHENTICATED || 572 if (this.state_ == remoting.ClientSession.State.AUTHENTICATED ||
574 this.state_ == remoting.ClientSession.State.FAILED) { 573 this.state_ == remoting.ClientSession.State.FAILED) {
575 var authMethod = this.credentialsProvider_.getAuthMethod(); 574 var authMethod = this.credentialsProvider_.getAuthMethod();
576 if (authMethod != null) { 575 if (authMethod != null) {
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
654 console.error('Connection dropped: ' + error.toString()); 653 console.error('Connection dropped: ' + error.toString());
655 this.listener_.onDisconnected(error); 654 this.listener_.onDisconnected(error);
656 break; 655 break;
657 656
658 default: 657 default:
659 console.error('Unexpected client plugin state: ' + newState); 658 console.error('Unexpected client plugin state: ' + newState);
660 } 659 }
661 }; 660 };
662 661
663 /** 662 /**
663 * TODO(kelvinp): Consolidate the two enums (crbug.com/504200)
664 * @param {remoting.ClientSession.State} state
665 * @return {remoting.ChromotingEvent.SessionState}
666 */
667 function toSessionState(state) {
668 var SessionState = remoting.ChromotingEvent.SessionState;
669 switch(state) {
670 case remoting.ClientSession.State.UNKNOWN:
671 return SessionState.UNKNOWN;
672 case remoting.ClientSession.State.INITIALIZING:
673 return SessionState.INITIALIZING;
674 case remoting.ClientSession.State.CONNECTING:
675 return SessionState.CONNECTING;
676 case remoting.ClientSession.State.AUTHENTICATED:
677 return SessionState.AUTHENTICATED;
678 case remoting.ClientSession.State.CONNECTED:
679 return SessionState.CONNECTED;
680 case remoting.ClientSession.State.CLOSED:
681 return SessionState.CLOSED;
682 case remoting.ClientSession.State.FAILED:
683 return SessionState.CONNECTION_FAILED;
684 case remoting.ClientSession.State.CONNECTION_DROPPED:
685 return SessionState.CONNECTION_DROPPED;
686 case remoting.ClientSession.State.CONNECTION_CANCELED:
687 return SessionState.CONNECTION_CANCELED;
688 default:
689 throw new Error('Unknown session state : ' + state);
690 }
691 }
692
693 /**
664 * @param {remoting.ClientSession.State} previous 694 * @param {remoting.ClientSession.State} previous
665 * @param {remoting.ClientSession.State} current 695 * @param {remoting.ClientSession.State} current
666 * @return {remoting.ClientSession.State} 696 * @return {remoting.ClientSession.State}
667 * @private 697 * @private
668 */ 698 */
669 remoting.ClientSession.prototype.translateState_ = function(previous, current) { 699 remoting.ClientSession.prototype.translateState_ = function(previous, current) {
670 var State = remoting.ClientSession.State; 700 var State = remoting.ClientSession.State;
671 if (previous == State.CONNECTING || previous == State.AUTHENTICATED) { 701 if (previous == State.CONNECTING || previous == State.AUTHENTICATED) {
672 if (current == State.CLOSED) { 702 if (current == State.CLOSED) {
673 return remoting.ClientSession.State.CONNECTION_CANCELED; 703 return remoting.ClientSession.State.CONNECTION_CANCELED;
674 } 704 }
675 } else if (previous == State.CONNECTED && current == State.FAILED) { 705 } else if (previous == State.CONNECTED && current == State.FAILED) {
676 return State.CONNECTION_DROPPED; 706 return State.CONNECTION_DROPPED;
677 } 707 }
678 return current; 708 return current;
679 }; 709 };
680 710
681 /** @private */ 711 /** @private */
682 remoting.ClientSession.prototype.reportStatistics = function() { 712 remoting.ClientSession.prototype.reportStatistics = function() {
683 this.logger_.logStatistics(this.plugin_.getPerfStats()); 713 this.logger_.logStatistics(this.plugin_.getPerfStats());
684 }; 714 };
OLDNEW
« no previous file with comments | « remoting/webapp/base/js/chromoting_event.js ('k') | remoting/webapp/base/js/client_session_factory.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698