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

Side by Side 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: Restoring polling 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/resources/google_now/utility_test_util.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 'use strict'; 5 'use strict';
6 6
7 /** 7 /**
8 * @fileoverview Utility objects and functions for Google Now extension. 8 * @fileoverview Utility objects and functions for Google Now extension.
9 * Most important entities here: 9 * Most important entities here:
10 * (1) 'wrapper' is a module used to add error handling and other services to 10 * (1) 'wrapper' is a module used to add error handling and other services to
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 instrumentChromeApiFunction: instrumentChromeApiFunction, 386 instrumentChromeApiFunction: instrumentChromeApiFunction,
387 registerWrapperPluginFactory: registerWrapperPluginFactory, 387 registerWrapperPluginFactory: registerWrapperPluginFactory,
388 checkInWrappedCallback: checkInWrappedCallback, 388 checkInWrappedCallback: checkInWrappedCallback,
389 debugGetStateString: debugGetStateString 389 debugGetStateString: debugGetStateString
390 }; 390 };
391 })(); 391 })();
392 392
393 wrapper.instrumentChromeApiFunction('alarms.get', 1); 393 wrapper.instrumentChromeApiFunction('alarms.get', 1);
394 wrapper.instrumentChromeApiFunction('alarms.onAlarm.addListener', 0); 394 wrapper.instrumentChromeApiFunction('alarms.onAlarm.addListener', 0);
395 wrapper.instrumentChromeApiFunction('identity.getAuthToken', 1); 395 wrapper.instrumentChromeApiFunction('identity.getAuthToken', 1);
396 wrapper.instrumentChromeApiFunction('identity.onSignInChanged.addListener', 0);
396 wrapper.instrumentChromeApiFunction('identity.removeCachedAuthToken', 1); 397 wrapper.instrumentChromeApiFunction('identity.removeCachedAuthToken', 1);
397 398
398 /** 399 /**
399 * Builds the object to manage tasks (mutually exclusive chains of events). 400 * Builds the object to manage tasks (mutually exclusive chains of events).
400 * @param {function(string, string): boolean} areConflicting Function that 401 * @param {function(string, string): boolean} areConflicting Function that
401 * checks if a new task can't be added to a task queue that contains an 402 * checks if a new task can't be added to a task queue that contains an
402 * existing task. 403 * existing task.
403 * @return {Object} Task manager interface. 404 * @return {Object} Task manager interface.
404 */ 405 */
405 function buildTaskManager(areConflicting) { 406 function buildTaskManager(areConflicting) {
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
656 }); 657 });
657 658
658 return { 659 return {
659 start: start, 660 start: start,
660 planForNext: planForNext, 661 planForNext: planForNext,
661 stop: stop, 662 stop: stop,
662 isRunning: isRunning 663 isRunning: isRunning
663 }; 664 };
664 } 665 }
665 666
666 // TODO(robliao): Ideally, the authentication watcher infrastructure 667 // TODO(robliao): Use signed-in state change watch API when it's available.
667 // below would be an API change to chrome.identity.
668 // When this happens, remove the code below.
669
670 /** 668 /**
671 * Wraps chrome.identity to provide limited listening support for 669 * Wraps chrome.identity to provide limited listening support for
672 * the sign in state by polling periodically for the auth token. 670 * the sign in state by polling periodically for the auth token.
673 * @return {Object} The Authentication Manager interface. 671 * @return {Object} The Authentication Manager interface.
674 */ 672 */
675 function buildAuthenticationManager() { 673 function buildAuthenticationManager() {
676 var alarmName = 'sign-in-alarm'; 674 var alarmName = 'sign-in-alarm';
677 675
678 /** 676 /**
679 * Determines if the user is signed in and provides a token if signed in. 677 * Determines if the user is signed in and provides a token if signed in.
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
727 {lastSignedInState: currentSignedInState}); 725 {lastSignedInState: currentSignedInState});
728 if (items.lastSignedInState != undefined) { 726 if (items.lastSignedInState != undefined) {
729 listeners.forEach(function(callback) { 727 listeners.forEach(function(callback) {
730 callback(); 728 callback();
731 }); 729 });
732 } 730 }
733 } 731 }
734 }); 732 });
735 } 733 }
736 734
735 instrumented.identity.onSignInChanged.addListener(function() {
736 isSignedIn(function() {});
737 });
738
737 instrumented.alarms.onAlarm.addListener(function(alarm) { 739 instrumented.alarms.onAlarm.addListener(function(alarm) {
738 if (alarm.name == alarmName) 740 if (alarm.name == alarmName)
739 isSignedIn(function() {}); 741 isSignedIn(function() {});
740 }); 742 });
741 743
742 // Poll for the sign in state every hour. 744 // Poll for the sign in state every hour.
743 // One hour is just an arbitrary amount of time chosen. 745 // One hour is just an arbitrary amount of time chosen.
744 chrome.alarms.create(alarmName, {periodInMinutes: 60}); 746 chrome.alarms.create(alarmName, {periodInMinutes: 60});
745 747
746 return { 748 return {
747 addListener: addListener, 749 addListener: addListener,
748 isSignedIn: isSignedIn, 750 isSignedIn: isSignedIn,
749 removeToken: removeToken 751 removeToken: removeToken
750 }; 752 };
751 } 753 }
OLDNEW
« 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