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

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

Issue 21235008: Authentication Manager for Google Now (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@GeoSM-Diag
Patch Set: Fixes Created 7 years, 5 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_test_util.js » ('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 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');
« no previous file with comments | « no previous file | chrome/browser/resources/google_now/background_test_util.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698