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

Unified Diff: remoting/webapp/oauth2.js

Issue 10207028: Fixed callWithToken error handling. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Reviewer feedback. Created 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « remoting/webapp/host_list.js ('k') | remoting/webapp/wcs.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: remoting/webapp/oauth2.js
diff --git a/remoting/webapp/oauth2.js b/remoting/webapp/oauth2.js
index e2dc9334cbf5c4b3e91472495e2691a724d65a56..5d61c4a71904e277a7fccbf0daa93603b9701992 100644
--- a/remoting/webapp/oauth2.js
+++ b/remoting/webapp/oauth2.js
@@ -339,25 +339,24 @@ remoting.OAuth2.prototype.revokeToken_ = function(token) {
*
* The access token will remain valid for at least 2 minutes.
*
- * @param {function(string):void} myfunc
- * Function to invoke with access token.
+ * @param {function(string?):void} myfunc Function to invoke with access token.
* @return {void} Nothing.
*/
remoting.OAuth2.prototype.callWithToken = function(myfunc) {
/** @type {remoting.OAuth2} */
var that = this;
- if (remoting.oauth2.needsNewAccessToken()) {
- remoting.oauth2.refreshAccessToken(function() {
- if (remoting.oauth2.needsNewAccessToken()) {
- // If we still need it, we're going to infinite loop.
- throw 'Unable to get access token.';
+ if (this.needsNewAccessToken()) {
+ var onRefresh = function() {
+ if (that.needsNewAccessToken()) {
+ myfunc(null);
+ } else {
+ myfunc(that.getAccessToken());
}
- myfunc(that.getAccessToken());
- });
- return;
+ };
+ this.refreshAccessToken(onRefresh);
+ } else {
+ myfunc(this.getAccessToken());
}
-
- myfunc(this.getAccessToken());
};
/**
@@ -381,12 +380,16 @@ remoting.OAuth2.prototype.getEmail = function(setEmail) {
setEmail(that.email);
};
- /** @param {string} token The access token. */
+ /** @param {string?} token The access token. */
var getEmailFromToken = function(token) {
- var headers = { 'Authorization': 'OAuth ' + token };
- // TODO(ajwong): Update to new v2 API.
- remoting.xhr.get('https://www.googleapis.com/userinfo/email',
- onResponse, '', headers);
+ if (token) {
+ var headers = { 'Authorization': 'OAuth ' + token };
+ // TODO(ajwong): Update to new v2 API.
+ remoting.xhr.get('https://www.googleapis.com/userinfo/email',
+ onResponse, '', headers);
+ } else {
+ setEmail(null);
+ }
};
this.callWithToken(getEmailFromToken);
« no previous file with comments | « remoting/webapp/host_list.js ('k') | remoting/webapp/wcs.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698