Chromium Code Reviews| Index: chrome/browser/resources/google_now/background.js |
| diff --git a/chrome/browser/resources/google_now/background.js b/chrome/browser/resources/google_now/background.js |
| index fc487cf10cf2ff0f18fc88031dc66cefdd52639f..9f7d55e1f02e481997ebc46b2b4e5573c5aa5b3d 100644 |
| --- a/chrome/browser/resources/google_now/background.js |
| +++ b/chrome/browser/resources/google_now/background.js |
| @@ -265,12 +265,7 @@ function recordEvent(event) { |
| * parameter. |
| */ |
| function setAuthorization(request, callbackBoolean) { |
| - authenticationManager.getAuthToken(function(token) { |
| - if (!token) { |
| - callbackBoolean(false); |
| - return; |
| - } |
| - |
| + authenticationManager.getAuthToken().then(function(token) { |
| request.setRequestHeader('Authorization', 'Bearer ' + token); |
| // Instrument onloadend to remove stale auth tokens. |
| @@ -278,7 +273,7 @@ function setAuthorization(request, callbackBoolean) { |
| request.onloadend = wrapper.wrapCallback(function(event) { |
| if (request.status == HTTP_FORBIDDEN || |
| request.status == HTTP_UNAUTHORIZED) { |
| - authenticationManager.removeToken(token, function() { |
| + authenticationManager.removeToken(token).then(function() { |
| originalOnLoadEnd(event); |
| }); |
| } else { |
| @@ -287,6 +282,8 @@ function setAuthorization(request, callbackBoolean) { |
| }); |
| callbackBoolean(true); |
| + }).catch(function() { |
| + callbackBoolean(false); |
| }); |
| } |
| @@ -1088,7 +1085,7 @@ function updateRunningState( |
| function onStateChange() { |
| tasks.add(STATE_CHANGED_TASK_NAME, function() { |
| Promise.all([ |
| - isSignedIn(), |
| + authenticationManager.isSignedIn(), |
|
vadimt
2014/02/14 20:45:30
If isSignedIn() calls reject(), will .then still b
robliao
2014/02/14 22:01:49
Nope. A reject here rejects the whole promise. The
vadimt
2014/02/14 22:05:10
I see. It's getAuthToken() who can reject.
|
| isGeolocationEnabled(), |
| canEnableBackground(), |
| isNotificationsEnabled(), |
| @@ -1100,18 +1097,6 @@ function onStateChange() { |
| } |
| /** |
| - * Determines if the user is signed in. |
| - * @return {Promise} A promise to evaluate the signed in state. |
| - */ |
| -function isSignedIn() { |
| - return new Promise(function(resolve) { |
| - authenticationManager.isSignedIn(function(signedIn) { |
| - resolve(signedIn); |
| - }); |
| - }); |
| -} |
| - |
| -/** |
| * Gets the geolocation enabled preference. |
| * @return {Promise} A promise to get the geolocation enabled preference. |
| */ |