Chromium Code Reviews| Index: remoting/webapp/oauth2.js |
| diff --git a/remoting/webapp/oauth2.js b/remoting/webapp/oauth2.js |
| index e2dc9334cbf5c4b3e91472495e2691a724d65a56..1072035a7ac16a71756ef768d7ee3da75713019e 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.'; |
| + try { |
| + myfunc(this.getAccessToken()); |
|
simonmorris
2012/04/25 16:59:41
If myfunc throws an exception, the following code
Jamie
2012/04/25 17:29:09
As discussed off-line, it's makes the test less ra
|
| + } catch (err) { |
| + /** @type {remoting.OAuth2} */ |
| + var that = this; |
| + var onRefresh = function() { |
| + try { |
| + myfunc(that.getAccessToken()); |
| + } catch (err) { |
| + myfunc(null); |
| } |
| - myfunc(that.getAccessToken()); |
| - }); |
| - return; |
| + }; |
| + remoting.oauth2.refreshAccessToken(onRefresh); |
| } |
| - |
| - 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); |