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

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

Issue 171713007: Revert of Convert Google Now's Authentication Manager to use Promises (https://codereview.chromium.… (Closed) Base URL: svn://svn.chromium.org/chrome/
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
« no previous file with comments | « no previous file | trunk/src/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: trunk/src/chrome/browser/resources/google_now/background.js
===================================================================
--- trunk/src/chrome/browser/resources/google_now/background.js (revision 252133)
+++ trunk/src/chrome/browser/resources/google_now/background.js (working copy)
@@ -265,7 +265,12 @@
* parameter.
*/
function setAuthorization(request, callbackBoolean) {
- authenticationManager.getAuthToken().then(function(token) {
+ authenticationManager.getAuthToken(function(token) {
+ if (!token) {
+ callbackBoolean(false);
+ return;
+ }
+
request.setRequestHeader('Authorization', 'Bearer ' + token);
// Instrument onloadend to remove stale auth tokens.
@@ -273,7 +278,7 @@
request.onloadend = wrapper.wrapCallback(function(event) {
if (request.status == HTTP_FORBIDDEN ||
request.status == HTTP_UNAUTHORIZED) {
- authenticationManager.removeToken(token).then(function() {
+ authenticationManager.removeToken(token, function() {
originalOnLoadEnd(event);
});
} else {
@@ -282,8 +287,6 @@
});
callbackBoolean(true);
- }).catch(function() {
- callbackBoolean(false);
});
}
@@ -1085,7 +1088,7 @@
function onStateChange() {
tasks.add(STATE_CHANGED_TASK_NAME, function() {
Promise.all([
- authenticationManager.isSignedIn(),
+ isSignedIn(),
isGeolocationEnabled(),
canEnableBackground(),
isNotificationsEnabled(),
@@ -1097,6 +1100,18 @@
}
/**
+ * 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 | trunk/src/chrome/browser/resources/google_now/background_unittest.gtestjs » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698