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

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

Issue 1067133002: Move ProtocolExtensionManager from SessionConnector into its own class (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 * Connect set-up state machine for Me2Me and IT2Me 7 * Connect set-up state machine for Me2Me and IT2Me
8 */ 8 */
9 9
10 'use strict'; 10 'use strict';
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 this.logHostOfflineErrors_ = false; 82 this.logHostOfflineErrors_ = false;
83 83
84 /** @private {remoting.ClientPlugin} */ 84 /** @private {remoting.ClientPlugin} */
85 this.plugin_ = null; 85 this.plugin_ = null;
86 86
87 /** @private {remoting.ClientSession} */ 87 /** @private {remoting.ClientSession} */
88 this.clientSession_ = null; 88 this.clientSession_ = null;
89 89
90 /** @private {remoting.CredentialsProvider} */ 90 /** @private {remoting.CredentialsProvider} */
91 this.credentialsProvider_ = null; 91 this.credentialsProvider_ = null;
92
93 /** @private {Object<string,remoting.ProtocolExtension>} */
94 this.protocolExtensions_ = {};
95
96 /**
97 * True once a session has been created and we've started the extensions.
98 * This is used to immediately start any extensions that are registered
99 * after the CONNECTED state change.
100 * @private {boolean}
101 */
102 this.protocolExtensionsStarted_ = false;
103 }; 92 };
104 93
105 /** 94 /**
106 * Initiate a Me2Me connection. 95 * Initiate a Me2Me connection.
107 * 96 *
108 * This doesn't report host-offline errors because the connection will 97 * This doesn't report host-offline errors because the connection will
109 * be retried and retryConnectMe2Me is responsible for reporting these errors. 98 * be retried and retryConnectMe2Me is responsible for reporting these errors.
110 * 99 *
111 * @param {remoting.Host} host The Me2Me host to which to connect. 100 * @param {remoting.Host} host The Me2Me host to which to connect.
112 * @param {function(boolean, function(string):void):void} fetchPin Function to 101 * @param {function(boolean, function(string):void):void} fetchPin Function to
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 } 309 }
321 310
322 if (!this.plugin_.isSupportedVersion()) { 311 if (!this.plugin_.isSupportedVersion()) {
323 console.error('ERROR: bad plugin version'); 312 console.error('ERROR: bad plugin version');
324 this.pluginError_(new remoting.Error( 313 this.pluginError_(new remoting.Error(
325 remoting.Error.Tag.BAD_PLUGIN_VERSION)); 314 remoting.Error.Tag.BAD_PLUGIN_VERSION));
326 return; 315 return;
327 } 316 }
328 317
329 this.clientSession_ = new remoting.ClientSession( 318 this.clientSession_ = new remoting.ClientSession(
330 this.plugin_, this.host_, this.signalStrategy_, 319 this.plugin_, this.host_, this.signalStrategy_);
331 this.onProtocolExtensionMessage_.bind(this));
332 remoting.clientSession = this.clientSession_; 320 remoting.clientSession = this.clientSession_;
333 321
334 this.clientSession_.logHostOfflineErrors(this.logHostOfflineErrors_); 322 this.clientSession_.logHostOfflineErrors(this.logHostOfflineErrors_);
335 this.clientSession_.addEventListener( 323 this.clientSession_.addEventListener(
336 remoting.ClientSession.Events.stateChanged, 324 remoting.ClientSession.Events.stateChanged,
337 this.bound_.onStateChange); 325 this.bound_.onStateChange);
338 326
339 this.plugin_.connect( 327 this.plugin_.connect(
340 this.host_, this.signalStrategy_.getJid(), this.credentialsProvider_); 328 this.host_, this.signalStrategy_.getJid(), this.credentialsProvider_);
341 }; 329 };
(...skipping 11 matching lines...) Expand all
353 remoting.SessionConnectorImpl.prototype.closeSession = function() { 341 remoting.SessionConnectorImpl.prototype.closeSession = function() {
354 base.dispose(this.clientSession_); 342 base.dispose(this.clientSession_);
355 this.clientSession_ = null; 343 this.clientSession_ = null;
356 remoting.clientSession = null; 344 remoting.clientSession = null;
357 345
358 base.dispose(this.plugin_); 346 base.dispose(this.plugin_);
359 this.plugin_ = null; 347 this.plugin_ = null;
360 }; 348 };
361 349
362 /** 350 /**
363 * @param {remoting.ProtocolExtension} extension
364 */
365 remoting.SessionConnectorImpl.prototype.registerProtocolExtension =
366 function(extension) {
367 var types = extension.getExtensionTypes();
368
369 // Make sure we don't have an extension of that type already registered.
370 for (var i=0, len=types.length; i < len; i++) {
371 if (types[i] in this.protocolExtensions_) {
372 console.error(
373 'Attempt to register multiple extensions of the same type: ', type);
374 return;
375 }
376 }
377
378 for (var i=0, len=types.length; i < len; i++) {
379 var type = types[i];
380 this.protocolExtensions_[type] = extension;
381 if (this.protocolExtensionsStarted_) {
382 this.startProtocolExtension_(type);
383 }
384 }
385 };
386
387 /** @private */
388 remoting.SessionConnectorImpl.prototype.initProtocolExtensions_ = function() {
389 base.debug.assert(!this.protocolExtensionsStarted_);
390 for (var type in this.protocolExtensions_) {
391 this.startProtocolExtension_(type);
392 }
393 this.protocolExtensionsStarted_ = true;
394 };
395
396 /**
397 * @param {string} type
398 * @private
399 */
400 remoting.SessionConnectorImpl.prototype.startProtocolExtension_ =
401 function(type) {
402 var extension = this.protocolExtensions_[type];
403 extension.startExtension(this.plugin_.sendClientMessage.bind(this.plugin_));
404 };
405
406 /**
407 * Called when an extension message needs to be handled.
408 *
409 * @param {string} type The type of the extension message.
410 * @param {string} data The payload of the extension message.
411 * @return {boolean} Return true if the extension message was recognized.
412 * @private
413 */
414 remoting.SessionConnectorImpl.prototype.onProtocolExtensionMessage_ =
415 function(type, data) {
416 if (type == 'test-echo-reply') {
417 console.log('Got echo reply: ' + data);
418 return true;
419 }
420
421 var message = base.jsonParseSafe(data);
422 if (typeof message != 'object') {
423 console.error('Error parsing extension json data: ' + data);
424 return false;
425 }
426
427 if (type in this.protocolExtensions_) {
428 /** @type {remoting.ProtocolExtension} */
429 var extension = this.protocolExtensions_[type];
430 var handled = false;
431 try {
432 handled = extension.onExtensionMessage(type, message);
433 } catch (/** @type {*} */ err) {
434 console.error('Failed to process protocol extension ' + type +
435 ' message: ' + err);
436 }
437 if (handled) {
438 return true;
439 }
440 }
441
442 return false;
443 };
444
445 /**
446 * Handle a change in the state of the client session prior to successful 351 * Handle a change in the state of the client session prior to successful
447 * connection (after connection, this class no longer handles state change 352 * connection (after connection, this class no longer handles state change
448 * events). Errors that occur while connecting either trigger a reconnect 353 * events). Errors that occur while connecting either trigger a reconnect
449 * or notify the onError handler. 354 * or notify the onError handler.
450 * 355 *
451 * @param {remoting.ClientSession.StateEvent=} event 356 * @param {remoting.ClientSession.StateEvent=} event
452 * @return {void} Nothing. 357 * @return {void} Nothing.
453 * @private 358 * @private
454 */ 359 */
455 remoting.SessionConnectorImpl.prototype.onStateChange_ = function(event) { 360 remoting.SessionConnectorImpl.prototype.onStateChange_ = function(event) {
456 switch (event.current) { 361 switch (event.current) {
457 case remoting.ClientSession.State.CONNECTED: 362 case remoting.ClientSession.State.CONNECTED:
458 // When the connection succeeds, deregister for state-change callbacks 363 // When the connection succeeds, deregister for state-change callbacks
459 // and pass the session to the onConnected callback. It is expected that 364 // and pass the session to the onConnected callback. It is expected that
460 // it will register a new state-change callback to handle disconnect 365 // it will register a new state-change callback to handle disconnect
461 // or error conditions. 366 // or error conditions.
462 this.clientSession_.removeEventListener( 367 this.clientSession_.removeEventListener(
463 remoting.ClientSession.Events.stateChanged, 368 remoting.ClientSession.Events.stateChanged,
464 this.bound_.onStateChange); 369 this.bound_.onStateChange);
465 370
466 base.dispose(this.reconnector_); 371 base.dispose(this.reconnector_);
467 if (remoting.app.getConnectionMode() != remoting.Application.Mode.IT2ME) { 372 if (remoting.app.getConnectionMode() != remoting.Application.Mode.IT2ME) {
468 this.reconnector_ = 373 this.reconnector_ =
469 new remoting.SmartReconnector(this, this.clientSession_); 374 new remoting.SmartReconnector(this, this.clientSession_);
470 } 375 }
471 var connectionInfo = new remoting.ConnectionInfo( 376 var connectionInfo = new remoting.ConnectionInfo(
472 this.host_, this.credentialsProvider_, this.clientSession_, 377 this.host_, this.credentialsProvider_, this.clientSession_,
473 this.plugin_); 378 this.plugin_);
474 this.onConnected_(connectionInfo); 379 this.onConnected_(connectionInfo);
475 // Initialize any protocol extensions that may have been added by the app.
476 this.initProtocolExtensions_();
477 break; 380 break;
478 381
479 case remoting.ClientSession.State.CONNECTING: 382 case remoting.ClientSession.State.CONNECTING:
480 remoting.identity.getEmail().then( 383 remoting.identity.getEmail().then(
481 function(/** string */ email) { 384 function(/** string */ email) {
482 console.log('Connecting as ' + email); 385 console.log('Connecting as ' + email);
483 }); 386 });
484 break; 387 break;
485 388
486 case remoting.ClientSession.State.AUTHENTICATED: 389 case remoting.ClientSession.State.AUTHENTICATED:
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 * @return {remoting.SessionConnector} 441 * @return {remoting.SessionConnector}
539 */ 442 */
540 remoting.DefaultSessionConnectorFactory.prototype.createConnector = 443 remoting.DefaultSessionConnectorFactory.prototype.createConnector =
541 function(clientContainer, onConnected, onError, 444 function(clientContainer, onConnected, onError,
542 onConnectionFailed, requiredCapabilities) { 445 onConnectionFailed, requiredCapabilities) {
543 return new remoting.SessionConnectorImpl(clientContainer, onConnected, 446 return new remoting.SessionConnectorImpl(clientContainer, onConnected,
544 onError, 447 onError,
545 onConnectionFailed, 448 onConnectionFailed,
546 requiredCapabilities); 449 requiredCapabilities);
547 }; 450 };
OLDNEW
« remoting/webapp/crd/js/client_plugin_impl.js ('K') | « remoting/webapp/crd/js/session_connector.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698