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 032df708ea2a3b9798e31f82b1d8728b629a41bc..b5718f80f0ed24420ab5b824c0dd9d8bd7968686 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); |
}); |
} |
@@ -1090,7 +1087,7 @@ function updateRunningState( |
function onStateChange() { |
tasks.add(STATE_CHANGED_TASK_NAME, function() { |
Promise.all([ |
- isSignedIn(), |
+ authenticationManager.isSignedIn(), |
isGeolocationEnabled(), |
canEnableBackground(), |
isNotificationsEnabled(), |
@@ -1102,18 +1099,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. |
*/ |