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

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

Issue 35413005: Using instrumented.identity.onSignInChanged to track signed-in state changes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 2 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/utility_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/utility.js
diff --git a/chrome/browser/resources/google_now/utility.js b/chrome/browser/resources/google_now/utility.js
index 418b6f3098d3e81e8fbfbdd80a4b7a8e218d6507..1a2a06a522827b53ff402d9c2508e4810a3e0482 100644
--- a/chrome/browser/resources/google_now/utility.js
+++ b/chrome/browser/resources/google_now/utility.js
@@ -393,6 +393,7 @@ var wrapper = (function() {
wrapper.instrumentChromeApiFunction('alarms.get', 1);
wrapper.instrumentChromeApiFunction('alarms.onAlarm.addListener', 0);
wrapper.instrumentChromeApiFunction('identity.getAuthToken', 1);
+wrapper.instrumentChromeApiFunction('identity.onSignInChanged.addListener', 0);
wrapper.instrumentChromeApiFunction('identity.removeCachedAuthToken', 1);
/**
@@ -663,18 +664,12 @@ function buildAttemptManager(
};
}
-// TODO(robliao): Ideally, the authentication watcher infrastructure
-// below would be an API change to chrome.identity.
-// When this happens, remove the code below.
-
/**
* Wraps chrome.identity to provide limited listening support for
* the sign in state by polling periodically for the auth token.
* @return {Object} The Authentication Manager interface.
*/
function buildAuthenticationManager() {
- var alarmName = 'sign-in-alarm';
-
/**
* Determines if the user is signed in and provides a token if signed in.
* @param {function(string=)} callback Called on completion.
@@ -684,7 +679,6 @@ function buildAuthenticationManager() {
instrumented.identity.getAuthToken({interactive: false}, function(token) {
token = chrome.runtime.lastError ? undefined : token;
callback(token);
- checkAndNotifyListeners(!!token);
});
}
@@ -695,54 +689,22 @@ function buildAuthenticationManager() {
*/
function removeToken(token, callback) {
instrumented.identity.removeCachedAuthToken({token: token}, function() {
- // Removing the token from the cache will change the sign in state.
- // Repoll now to check the state and notify listeners.
- // This also lets Chrome now about a possible problem with the token.
+ // Attempting to get a fresh token will let Chrome know about a possible
+ // problem with the token.
robliao 2013/10/23 17:11:48 Once Chrome gets a fresh token, will the onSignInC
isSignedIn(function() {});
callback();
});
}
- var listeners = [];
-
/**
* Registers a listener that gets called back when the signed in state
* is found to be changed.
* @param {function} callback Called when the answer to isSignedIn changes.
*/
function addListener(callback) {
- listeners.push(callback);
+ instrumented.identity.onSignInChanged.addListener(callback);
}
- /**
- * Checks if the last signed in state matches the specified one.
- * If it doesn't, it notifies the listeners of the change.
- * @param {boolean} currentSignedInState The current signed in state.
- */
- function checkAndNotifyListeners(currentSignedInState) {
- instrumented.storage.local.get('lastSignedInState', function(items) {
- items = items || {};
- if (items.lastSignedInState != currentSignedInState) {
- chrome.storage.local.set(
- {lastSignedInState: currentSignedInState});
- if (items.lastSignedInState != undefined) {
- listeners.forEach(function(callback) {
- callback();
- });
- }
- }
- });
- }
-
- instrumented.alarms.onAlarm.addListener(function(alarm) {
- if (alarm.name == alarmName)
- isSignedIn(function() {});
- });
-
- // Poll for the sign in state every hour.
- // One hour is just an arbitrary amount of time chosen.
- chrome.alarms.create(alarmName, {periodInMinutes: 60});
-
return {
addListener: addListener,
isSignedIn: isSignedIn,
« no previous file with comments | « no previous file | chrome/browser/resources/google_now/utility_test_util.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698