Chromium Code Reviews| Index: chrome/browser/resources/google_now/utility.js |
| diff --git a/chrome/browser/resources/google_now/utility.js b/chrome/browser/resources/google_now/utility.js |
| index aa20066306585f1ed6b2194fd1716085e9f063eb..aada2e59f5cdb182b8c7b4adcca2462392a28be7 100644 |
| --- a/chrome/browser/resources/google_now/utility.js |
| +++ b/chrome/browser/resources/google_now/utility.js |
| @@ -726,36 +726,45 @@ function buildAuthenticationManager() { |
| /** |
| * Gets an OAuth2 access token. |
| - * @param {function(string=)} callback Called on completion. |
| - * The string contains the token. It's undefined if there was an error. |
| + * @return {Promise} A promise to get the authentication token. If there is |
| + * no token, the request is rejected. |
| */ |
| - function getAuthToken(callback) { |
| - instrumented.identity.getAuthToken({interactive: false}, function(token) { |
| - token = chrome.runtime.lastError ? undefined : token; |
| - callback(token); |
| + function getAuthToken() { |
| + return new Promise(function(resolve, reject) { |
| + instrumented.identity.getAuthToken({interactive: false}, function(token) { |
| + if (chrome.runtime.lastError || !token) { |
| + reject(); |
| + } else { |
| + resolve(token); |
| + } |
| + }); |
| }); |
| } |
| /** |
| * Determines whether there is an account attached to the profile. |
| - * @param {function(boolean)} callback Called on completion. |
| + * @return {Promise} A promise to determine if there is an account attached |
| + * to the profile. |
| */ |
| - function isSignedIn(callback) { |
| - instrumented.webstorePrivate.getBrowserLogin(function(accountInfo) { |
| - callback(!!accountInfo.login); |
| + function isSignedIn() { |
| + return new Promise(function(resolve) { |
| + instrumented.webstorePrivate.getBrowserLogin(function(accountInfo) { |
| + resolve(!!accountInfo.login); |
| + }); |
| }); |
| } |
| /** |
| * Removes the specified cached token. |
| * @param {string} token Authentication Token to remove from the cache. |
| - * @param {function()} callback Called on completion. |
| + * @return {Promise} A promise that resolves on completion. |
| */ |
| - function removeToken(token, callback) { |
| - instrumented.identity.removeCachedAuthToken({token: token}, function() { |
| - // Let Chrome now about a possible problem with the token. |
|
rgustafson
2014/02/13 21:31:40
Keep the comment in, but now -> know. It's not imm
robliao
2014/02/13 21:41:33
Done.
|
| - getAuthToken(function() {}); |
| - callback(); |
| + function removeToken(token) { |
| + return new Promise(function(resolve) { |
| + instrumented.identity.removeCachedAuthToken({token: token}, function() { |
| + getAuthToken(); |
| + resolve(); |
| + }); |
| }); |
| } |