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

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

Issue 937593002: Changed identity API to use promises instead of callbacks. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 340
341 var normalizedAccessCode = this.normalizeAccessCode_(accessCode); 341 var normalizedAccessCode = this.normalizeAccessCode_(accessCode);
342 if (normalizedAccessCode.length != kAccessCodeLen) { 342 if (normalizedAccessCode.length != kAccessCodeLen) {
343 this.onError_(remoting.Error.INVALID_ACCESS_CODE); 343 this.onError_(remoting.Error.INVALID_ACCESS_CODE);
344 return; 344 return;
345 } 345 }
346 346
347 this.hostId_ = normalizedAccessCode.substring(0, kSupportIdLen); 347 this.hostId_ = normalizedAccessCode.substring(0, kSupportIdLen);
348 this.passPhrase_ = normalizedAccessCode; 348 this.passPhrase_ = normalizedAccessCode;
349 this.connectionMode_ = remoting.ClientSession.Mode.IT2ME; 349 this.connectionMode_ = remoting.ClientSession.Mode.IT2ME;
350 remoting.identity.callWithToken(this.connectIT2MeWithToken_.bind(this), 350 remoting.identity.getToken().then(
351 this.onError_); 351 this.connectIT2MeWithToken_.bind(this),
352 remoting.Error.handler(this.onError_));
352 }; 353 };
353 354
354 /** 355 /**
355 * Reconnect a closed connection. 356 * Reconnect a closed connection.
356 * 357 *
357 * @return {void} Nothing. 358 * @return {void} Nothing.
358 */ 359 */
359 remoting.SessionConnectorImpl.prototype.reconnect = function() { 360 remoting.SessionConnectorImpl.prototype.reconnect = function() {
360 if (this.connectionMode_ == remoting.ClientSession.Mode.IT2ME) { 361 if (this.connectionMode_ == remoting.ClientSession.Mode.IT2ME) {
361 console.error('reconnect not supported for IT2Me.'); 362 console.error('reconnect not supported for IT2Me.');
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 */ 407 */
407 remoting.SessionConnectorImpl.prototype.connectSignaling_ = function() { 408 remoting.SessionConnectorImpl.prototype.connectSignaling_ = function() {
408 base.dispose(this.signalStrategy_); 409 base.dispose(this.signalStrategy_);
409 this.signalStrategy_ = null; 410 this.signalStrategy_ = null;
410 411
411 /** @type {remoting.SessionConnectorImpl} */ 412 /** @type {remoting.SessionConnectorImpl} */
412 var that = this; 413 var that = this;
413 414
414 /** @param {string} token */ 415 /** @param {string} token */
415 function connectSignalingWithToken(token) { 416 function connectSignalingWithToken(token) {
416 remoting.identity.getUserInfo( 417 remoting.identity.getUserInfo().then(
417 connectSignalingWithTokenAndUserInfo.bind(null, token), that.onError_); 418 connectSignalingWithTokenAndUserInfo.bind(null, token),
419 remoting.Error.handler(that.onError_));
418 } 420 }
419 421
420 /** 422 /**
421 * Success callback for when the email and fullName have been retrieved 423 * Success callback for when the email and fullName have been retrieved
422 * for this user. 424 * for this user.
423 * Note that the full name will be null unless the webapp has requested 425 * Note that the full name will be null unless the webapp has requested
424 * and been granted the userinfo.profile permission. 426 * and been granted the userinfo.profile permission.
425 * 427 *
426 * @param {string} token 428 * @param {string} token
427 * @param {string} email 429 * @param {{email: string, name: string}} userInfo
428 * @param {string} fullName
429 */ 430 */
430 function connectSignalingWithTokenAndUserInfo(token, email, fullName) { 431 function connectSignalingWithTokenAndUserInfo(token, userInfo) {
431 that.signalStrategy_.connect( 432 that.signalStrategy_.connect(
432 remoting.settings.XMPP_SERVER_FOR_CLIENT, email, token); 433 remoting.settings.XMPP_SERVER_FOR_CLIENT, userInfo.email, token);
433 } 434 }
434 435
435 this.signalStrategy_ = remoting.SignalStrategy.create(); 436 this.signalStrategy_ = remoting.SignalStrategy.create();
436 this.signalStrategy_.setStateChangedCallback( 437 this.signalStrategy_.setStateChangedCallback(
437 this.onSignalingState_.bind(this)); 438 this.onSignalingState_.bind(this));
438 439
439 remoting.identity.callWithToken(connectSignalingWithToken, this.onError_); 440 remoting.identity.getToken().then(
441 connectSignalingWithToken,
442 remoting.Error.handler(this.onError_));
440 }; 443 };
441 444
442 /** 445 /**
443 * @private 446 * @private
444 * @param {remoting.SignalStrategy.State} state 447 * @param {remoting.SignalStrategy.State} state
445 */ 448 */
446 remoting.SessionConnectorImpl.prototype.onSignalingState_ = function(state) { 449 remoting.SessionConnectorImpl.prototype.onSignalingState_ = function(state) {
447 switch (state) { 450 switch (state) {
448 case remoting.SignalStrategy.State.CONNECTED: 451 case remoting.SignalStrategy.State.CONNECTED:
449 // Proceed only if the connection hasn't been canceled. 452 // Proceed only if the connection hasn't been canceled.
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
655 */ 658 */
656 remoting.DefaultSessionConnectorFactory.prototype.createConnector = 659 remoting.DefaultSessionConnectorFactory.prototype.createConnector =
657 function(clientContainer, onConnected, onError, onExtensionMessage, 660 function(clientContainer, onConnected, onError, onExtensionMessage,
658 onConnectionFailed, requiredCapabilities, defaultRemapKeys) { 661 onConnectionFailed, requiredCapabilities, defaultRemapKeys) {
659 return new remoting.SessionConnectorImpl(clientContainer, onConnected, 662 return new remoting.SessionConnectorImpl(clientContainer, onConnected,
660 onError, onExtensionMessage, 663 onError, onExtensionMessage,
661 onConnectionFailed, 664 onConnectionFailed,
662 requiredCapabilities, 665 requiredCapabilities,
663 defaultRemapKeys); 666 defaultRemapKeys);
664 }; 667 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698