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

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: 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
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..377d3f12fbb4b1695b1be288f36420ac22835e0d 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.
@@ -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(),
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.
*/

Powered by Google App Engine
This is Rietveld 408576698