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

Unified Diff: chrome/browser/resources/google_now/background.js

Issue 162273002: Convert Google Now's Authentication Manager to use Promises (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merging in https://codereview.chromium.org/174053003/ Created 6 years, 10 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 | « no previous file | chrome/browser/resources/google_now/background_unittest.gtestjs » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.
*/
« no previous file with comments | « no previous file | chrome/browser/resources/google_now/background_unittest.gtestjs » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698