Commit 7b6ab410 authored by jamiewalch's avatar jamiewalch Committed by Commit bot

Remove getCached* methods from remoting.Identity.

These methods were introduced before Promises were implemented to simplify
code that just needs an email address but wouldn't otherwise need to be
written asynchronously. With Promises, asynchronous code reads a lot more
naturally, and it's less of a concern.

Having explicit accessors for cached state means that there needs to be
some (asynchronous) initialization code to save them, which complicates
some of the changes I'm planning on making to application start-up. The
simplest fix is eliminate them altogether and make all the call-sites
asynchronous.

Review URL: https://codereview.chromium.org/963103004

Cr-Commit-Position: refs/heads/master@{#318794}
parent 3b0ed8bb
......@@ -238,9 +238,12 @@ remoting.AppRemoting.prototype.getDefaultRemapKeys = function() {
* @return {void} Nothing.
*/
remoting.AppRemoting.prototype.handleConnected = function(clientSession) {
remoting.clientSession.sendClientMessage(
'setUserDisplayInfo',
JSON.stringify({fullName: remoting.identity.getCachedUserFullName()}));
remoting.identity.getUserInfo().then(
function(userInfo) {
remoting.clientSession.sendClientMessage(
'setUserDisplayInfo',
JSON.stringify({fullName: userInfo.name}));
});
// Set up a ping at 10-second intervals to test the connection speed.
function ping() {
......
......@@ -184,16 +184,18 @@ remoting.HostController.prototype.start = function(hostPin, consent, onDone,
private_key: privateKey
};
var hostOwner = clientBaseJid;
var hostOwnerEmail = remoting.identity.getCachedEmail();
if (hostOwner != xmppLogin) {
hostConfig['host_owner'] = hostOwner;
if (hostOwnerEmail != hostOwner) {
hostConfig['host_owner_email'] = hostOwnerEmail;
}
}
that.hostDaemonFacade_.startDaemon(
hostConfig, consent, onStarted.bind(null, hostName, publicKey),
onStartError);
remoting.identity.getEmail().then(
function(/** string */ hostOwnerEmail) {
if (hostOwner != xmppLogin) {
hostConfig['host_owner'] = hostOwner;
if (hostOwnerEmail != hostOwner) {
hostConfig['host_owner_email'] = hostOwnerEmail;
}
}
that.hostDaemonFacade_.startDaemon(
hostConfig, consent, onStarted.bind(null, hostName, publicKey),
onStartError);
});
}
/**
......@@ -248,13 +250,14 @@ remoting.HostController.prototype.start = function(hostPin, consent, onDone,
onError);
} else {
// No authorization code returned, use regular user credential flow.
that.hostDaemonFacade_.getPinHash(
newHostId, hostPin, startHostWithHash.bind(
null, hostName, publicKey, privateKey,
remoting.identity.getCachedEmail(),
remoting.oauth2.getRefreshToken(),
remoting.identity.getCachedEmail()),
onError);
remoting.identity.getEmail().then(
function(/** string */ email) {
that.hostDaemonFacade_.getPinHash(
newHostId, hostPin, startHostWithHash.bind(
null, hostName, publicKey, privateKey,
email, remoting.oauth2.getRefreshToken(), email),
onError);
});
}
} else {
console.log('Failed to register the host. Status: ' + xhr.status +
......
......@@ -94,10 +94,12 @@ remoting.tryShareWithToken_ = function(hostFacade, token) {
base.debug.assert(hostSession_ === null);
hostSession_ = new remoting.HostSession();
var email = /** @type {string} */ (remoting.identity.getCachedEmail());
hostSession_.connect(
hostFacade, email, token, onHostStateChanged_,
onNatTraversalPolicyChanged_, logDebugInfo_, it2meConnectFailed_);
remoting.identity.getEmail().then(
function(/** string */ email) {
hostSession_.connect(
hostFacade, email, token, onHostStateChanged_,
onNatTraversalPolicyChanged_, logDebugInfo_, it2meConnectFailed_);
});
};
/**
......@@ -336,4 +338,4 @@ function onNatTraversalPolicyChanged_(enabled) {
}
}
})();
\ No newline at end of file
})();
......@@ -13,9 +13,6 @@
var remoting = remoting || {};
/**
* TODO(jamiewalch): Remove remoting.OAuth2 from this type annotation when
* the Apps v2 work is complete.
*
* @type {remoting.Identity}
*/
remoting.identity = null;
......@@ -162,29 +159,6 @@ remoting.Identity.prototype.getEmail = function() {
});
};
/**
* Gets the user's email address, or null if no successful call to
* getUserInfo has been made.
*
* @return {?string} The cached email address, if available.
*/
remoting.Identity.prototype.getCachedEmail = function() {
return this.email_;
};
/**
* Gets the user's full name.
*
* This will return null if either:
* No successful call to getUserInfo has been made, or
* The webapp doesn't have permission to access this value.
*
* @return {?string} The cached user's full name, if available.
*/
remoting.Identity.prototype.getCachedUserFullName = function() {
return this.fullName_;
};
/**
* Callback for the getAuthToken API.
*
......
......@@ -448,31 +448,3 @@ remoting.OAuth2.prototype.getUserInfo = function() {
reject);
});
};
/**
* If the user's email address is cached, return it, otherwise return null.
*
* @return {?string} The email address, if it has been cached by a previous call
* to getEmail or getUserInfo, otherwise null.
*/
remoting.OAuth2.prototype.getCachedEmail = function() {
var value = window.localStorage.getItem(this.KEY_EMAIL_);
if (typeof value == 'string') {
return value;
}
return null;
};
/**
* If the user's full name is cached, return it, otherwise return null.
*
* @return {?string} The user's full name, if it has been cached by a previous
* call to getUserInfo, otherwise null.
*/
remoting.OAuth2.prototype.getCachedUserFullName = function() {
var value = window.localStorage.getItem(this.KEY_FULLNAME_);
if (typeof value == 'string') {
return value;
}
return null;
};
......@@ -483,7 +483,10 @@ remoting.SessionConnectorImpl.prototype.onStateChange_ = function(event) {
break;
case remoting.ClientSession.State.CONNECTING:
console.log('Connecting as ' + remoting.identity.getCachedEmail());
remoting.identity.getEmail().then(
function(/** string */ email) {
console.log('Connecting as ' + email);
});
break;
case remoting.ClientSession.State.INITIALIZING:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment