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

Unified Diff: remoting/webapp/crd/js/it2me_helpee_channel.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 side-by-side diff with in-line comments
Download patch
Index: remoting/webapp/crd/js/it2me_helpee_channel.js
diff --git a/remoting/webapp/crd/js/it2me_helpee_channel.js b/remoting/webapp/crd/js/it2me_helpee_channel.js
index 65614f4566e2736826704b2c903325ba9d00e57e..34eee309d02350d4a297ca75be70501f340bf49f 100644
--- a/remoting/webapp/crd/js/it2me_helpee_channel.js
+++ b/remoting/webapp/crd/js/it2me_helpee_channel.js
@@ -354,36 +354,25 @@ remoting.It2MeHelpeeChannel.prototype.initializeHost_ = function() {
};
/**
- * @return {Promise<string>} Promise that resolves with the OAuth token as the
+ * @return {!Promise<string>} Promise that resolves with the OAuth token as the
* value.
*/
remoting.It2MeHelpeeChannel.prototype.fetchOAuthToken_ = function() {
if (base.isAppsV2()) {
- /**
- * @param {function(*=):void} resolve
- * @param {function(*=):void} reject
- */
- return new Promise(function(resolve, reject){
- remoting.identity.callWithToken(resolve, reject);
- });
+ return remoting.identity.getToken();
} else {
- /**
- * @param {function(*=):void} resolve
- * @param {function(*=):void} reject
- */
- return new Promise(function(resolve, reject) {
- /** @param {remoting.Error} error */
- var onError = function(error) {
+ var onError = function(/** * */ error) {
if (error === remoting.Error.NOT_AUTHENTICATED) {
- remoting.oauth2.doAuthRedirect(function() {
- remoting.identity.callWithToken(resolve, reject);
+ return new Promise(function(resolve, reject) {
+ remoting.oauth2.doAuthRedirect(function() {
+ remoting.identity.getToken().then(resolve);
+ });
});
- return;
}
- reject(new Error(remoting.Error.NOT_AUTHENTICATED));
+ throw Error(remoting.Error.NOT_AUTHENTICATED);
};
- remoting.identity.callWithToken(resolve, onError);
- });
+ return /** @type {!Promise<string>} */ (
+ remoting.identity.getToken().catch(onError));
}
};
@@ -393,17 +382,11 @@ remoting.It2MeHelpeeChannel.prototype.fetchOAuthToken_ = function() {
* of the user.
*/
remoting.It2MeHelpeeChannel.prototype.fetchEmail_ = function(token) {
- /**
- * @param {function(*=):void} resolve
- * @param {function(*=):void} reject
- */
- return new Promise(function(resolve, reject){
- /** @param {string} email */
- function onEmail (email) {
- resolve({ email: email, token: token });
- }
- remoting.identity.getEmail(onEmail, reject);
- });
+ /** @param {string} email */
+ function onEmail (email) {
+ return { email: email, token: token };
+ }
+ return remoting.identity.getEmail().then(onEmail);
};
/**

Powered by Google App Engine
This is Rietveld 408576698