Chromium Code Reviews| 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 bb98b91bceee65dd06a8b7d93659c0564276ef76..72ebbc212668f1c17c8b8005335d0be5a9606757 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) { |
|
vadimt
2013/07/30 23:27:23
Why not move the whole setAuthorization into authe
robliao
2013/07/30 23:58:03
I wanted to keep the HTTP portion out of the ident
|
| - 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(signedIn, token) { |
| + if (!signedIn) { |
| 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(signedIn) { |
| + signedIn = signedIn && !!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'); |