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 8a04423e05fb113a3abaf38da062dff3cbd8b23a..e5ffeda79924c359a0b7edb9c42c7ad565a5d629 100644 |
--- a/chrome/browser/resources/google_now/background.js |
+++ b/chrome/browser/resources/google_now/background.js |
@@ -120,8 +120,6 @@ var googleGeolocationAccessEnabledPref = |
var tasks = buildTaskManager(areTasksConflicting); |
// Add error processing to API calls. |
-tasks.instrumentApiFunction(chrome.identity, 'getAuthToken', 1); |
-tasks.instrumentApiFunction(chrome.identity, 'removeCachedAuthToken', 1); |
tasks.instrumentApiFunction(chrome.location.onLocationUpdate, 'addListener', 0); |
tasks.instrumentApiFunction(chrome.notifications, 'create', 2); |
tasks.instrumentApiFunction(chrome.notifications, 'update', 2); |
@@ -151,6 +149,8 @@ var dismissalAttempts = buildAttemptManager( |
MAXIMUM_RETRY_DISMISS_PERIOD_SECONDS); |
var cardSet = buildCardSet(); |
+var authenticationManager = buildAuthenticationManager(); |
+ |
/** |
* Google Now UMA event identifier. |
* @enum {number} |
@@ -194,13 +194,9 @@ function recordEvent(event) { |
* parameter. |
*/ |
function setAuthorization(request, callbackBoolean) { |
- tasks.debugSetStepName('setAuthorization-getAuthToken'); |
- chrome.identity.getAuthToken({interactive: false}, function(token) { |
- var errorMessage = |
- chrome.runtime.lastError && chrome.runtime.lastError.message; |
- console.log('setAuthorization: error=' + errorMessage + |
- ', token=' + (token && 'non-empty')); |
- if (chrome.runtime.lastError || !token) { |
+ tasks.debugSetStepName('setAuthorization-isSignedIn'); |
+ authenticationManager.isSignedIn(function(token) { |
+ if (!token) { |
callbackBoolean(false); |
return; |
} |
@@ -212,11 +208,8 @@ function setAuthorization(request, callbackBoolean) { |
request.onloadend = tasks.wrapCallback(function(event) { |
if (request.status == HTTP_FORBIDDEN || |
request.status == HTTP_UNAUTHORIZED) { |
- tasks.debugSetStepName('setAuthorization-removeCachedAuthToken'); |
- chrome.identity.removeCachedAuthToken({token: token}, function() { |
- // After purging the token cache, call getAuthToken() again to let |
- // Chrome know about the problem with the token. |
- chrome.identity.getAuthToken({interactive: false}, function() {}); |
+ tasks.debugSetStepName('setAuthorization-removeToken'); |
+ authenticationManager.removeToken(token, function() { |
originalOnLoadEnd(event); |
}); |
} else { |
@@ -792,12 +785,9 @@ function updateRunningState( |
*/ |
function onStateChange() { |
tasks.add(STATE_CHANGED_TASK_NAME, function(callback) { |
- tasks.debugSetStepName('onStateChange-getAuthToken'); |
- chrome.identity.getAuthToken({interactive: false}, function(token) { |
- var signedIn = |
- !chrome.runtime.lastError && |
- token && |
- !!NOTIFICATION_CARDS_URL; |
+ tasks.debugSetStepName('onStateChange-isSignedIn'); |
+ authenticationManager.isSignedIn(function(token) { |
+ var signedIn = !!token && !!NOTIFICATION_CARDS_URL; |
tasks.debugSetStepName( |
'onStateChange-get-googleGeolocationAccessEnabledPref'); |
googleGeolocationAccessEnabledPref.get({}, function(prefValue) { |
@@ -865,6 +855,11 @@ googleGeolocationAccessEnabledPref.onChange.addListener(function(prefValue) { |
onStateChange(); |
}); |
+authenticationManager.addListener(function() { |
+ console.log('signIn State Change'); |
+ onStateChange(); |
+}); |
+ |
chrome.notifications.onClicked.addListener( |
function(notificationId) { |
chrome.metricsPrivate.recordUserAction('GoogleNow.MessageClicked'); |