Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 The event page for Google Now for Chrome implementation. | 8 * @fileoverview The event page for Google Now for Chrome implementation. |
| 9 * The Google Now event page gets Google Now cards from the server and shows | 9 * The Google Now event page gets Google Now cards from the server and shows |
| 10 * them as Chrome notifications. | 10 * them as Chrome notifications. |
| (...skipping 686 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 697 * Starts or stops the polling of cards. | 697 * Starts or stops the polling of cards. |
| 698 * @param {boolean} shouldPollCardsRequest true to start and | 698 * @param {boolean} shouldPollCardsRequest true to start and |
| 699 * false to stop polling cards. | 699 * false to stop polling cards. |
| 700 * @param {function} onSuccess Called on completion. | 700 * @param {function} onSuccess Called on completion. |
| 701 */ | 701 */ |
| 702 function setShouldPollCards(shouldPollCardsRequest, onSuccess) { | 702 function setShouldPollCards(shouldPollCardsRequest, onSuccess) { |
| 703 tasks.debugSetStepName( | 703 tasks.debugSetStepName( |
| 704 'setShouldRun-shouldRun-updateCardsAttemptsIsRunning'); | 704 'setShouldRun-shouldRun-updateCardsAttemptsIsRunning'); |
| 705 updateCardsAttempts.isRunning(function(currentValue) { | 705 updateCardsAttempts.isRunning(function(currentValue) { |
| 706 if (shouldPollCardsRequest != currentValue) { | 706 if (shouldPollCardsRequest != currentValue) { |
| 707 console.log('Action Taken setShouldPollCards=' + shouldPollCardsRequest); | |
| 707 if (shouldPollCardsRequest) | 708 if (shouldPollCardsRequest) |
| 708 startPollingCards(); | 709 startPollingCards(); |
| 709 else | 710 else |
| 710 stopPollingCards(); | 711 stopPollingCards(); |
| 711 } | 712 } |
| 712 onSuccess(); | 713 onSuccess(); |
| 713 }); | 714 }); |
| 714 } | 715 } |
| 715 | 716 |
| 716 /** | 717 /** |
| 717 * Shows or hides the toast. | 718 * Shows or hides the toast. |
| 718 * @param {boolean} visibleRequest true to show the toast and | 719 * @param {boolean} visibleRequest true to show the toast and |
| 719 * false to hide the toast. | 720 * false to hide the toast. |
| 720 * @param {function} onSuccess Called on completion. | 721 * @param {function} onSuccess Called on completion. |
| 721 */ | 722 */ |
| 722 function setToastVisible(visibleRequest, onSuccess) { | 723 function setToastVisible(visibleRequest, onSuccess) { |
| 723 tasks.debugSetStepName( | 724 tasks.debugSetStepName( |
| 724 'setToastVisible-shouldSetToastVisible-getAllNotifications'); | 725 'setToastVisible-shouldSetToastVisible-getAllNotifications'); |
| 725 chrome.notifications.getAll(function(notifications) { | 726 chrome.notifications.getAll(function(notifications) { |
| 726 // TODO(vadimt): Figure out what to do when notifications are disabled for | 727 // TODO(vadimt): Figure out what to do when notifications are disabled for |
| 727 // our extension. | 728 // our extension. |
| 728 notifications = notifications || {}; | 729 notifications = notifications || {}; |
| 729 | 730 |
| 730 if (visibleRequest != !!notifications[WELCOME_TOAST_NOTIFICATION_ID]) { | 731 if (visibleRequest != !!notifications[WELCOME_TOAST_NOTIFICATION_ID]) { |
| 732 console.log('Action Taken setToastVisible=' + visibleRequest); | |
| 731 if (visibleRequest) | 733 if (visibleRequest) |
| 732 showWelcomeToast(); | 734 showWelcomeToast(); |
| 733 else | 735 else |
| 734 hideWelcomeToast(); | 736 hideWelcomeToast(); |
| 735 } | 737 } |
| 736 | 738 |
| 737 onSuccess(); | 739 onSuccess(); |
| 738 }); | 740 }); |
| 739 } | 741 } |
| 740 | 742 |
| 741 /** | 743 /** |
| 742 * Does the actual work of deciding what Google Now should do | 744 * Does the actual work of deciding what Google Now should do |
| 743 * based off of the current state of Chrome. | 745 * based off of the current state of Chrome. |
| 744 * @param {boolean} signedIn true if the user is signed in. | 746 * @param {boolean} signedIn true if the user is signed in. |
| 745 * @param {boolean} geolocationEnabled true if | 747 * @param {boolean} geolocationEnabled true if |
| 746 * the geolocation option is enabled. | 748 * the geolocation option is enabled. |
| 747 * @param {boolean} userRespondedToToast true if | 749 * @param {boolean} userRespondedToToast true if |
| 748 * the user has responded to the toast. | 750 * the user has responded to the toast. |
| 749 * @param {function()} callback Call this function on completion. | 751 * @param {function()} callback Call this function on completion. |
| 750 */ | 752 */ |
| 751 function updateRunningState( | 753 function updateRunningState( |
| 752 signedIn, | 754 signedIn, |
| 753 geolocationEnabled, | 755 geolocationEnabled, |
| 754 userRespondedToToast, | 756 userRespondedToToast, |
| 755 callback) { | 757 callback) { |
| 756 | 758 |
| 759 console.log( | |
| 760 'State Update signedIn=' + signedIn + ' ' + | |
| 761 'geolocationEnabled=' + geolocationEnabled + ' ' + | |
| 762 'userRespondedToToast=' + userRespondedToToast); | |
| 763 | |
| 757 var shouldSetToastVisible = false; | 764 var shouldSetToastVisible = false; |
| 758 var shouldPollCards = false; | 765 var shouldPollCards = false; |
| 759 | 766 |
| 760 if (signedIn) { | 767 if (signedIn) { |
| 761 if (geolocationEnabled) { | 768 if (geolocationEnabled) { |
| 762 if (!userRespondedToToast) { | 769 if (!userRespondedToToast) { |
| 763 // If the user enabled geolocation independently of Google Now, | 770 // If the user enabled geolocation independently of Google Now, |
| 764 // the user has implicitly responded to the toast. | 771 // the user has implicitly responded to the toast. |
| 765 // We do not want to show it again. | 772 // We do not want to show it again. |
| 766 storage.set({userRespondedToToast: true}); | 773 storage.set({userRespondedToToast: true}); |
| 767 } | 774 } |
| 768 | 775 |
| 769 shouldPollCards = true; | 776 shouldPollCards = true; |
| 770 } else { | 777 } else { |
| 771 if (userRespondedToToast) { | 778 if (userRespondedToToast) { |
| 772 recordEvent(GoogleNowEvent.USER_SUPPRESSED); | 779 recordEvent(GoogleNowEvent.USER_SUPPRESSED); |
| 773 } else { | 780 } else { |
| 774 shouldSetToastVisible = true; | 781 shouldSetToastVisible = true; |
| 775 } | 782 } |
| 776 } | 783 } |
| 777 } else { | 784 } else { |
| 778 recordEvent(GoogleNowEvent.STOPPED); | 785 recordEvent(GoogleNowEvent.STOPPED); |
| 779 } | 786 } |
| 780 | 787 |
| 788 | |
|
vadimt
2013/08/01 23:06:08
Extra line.
robliao
2013/08/01 23:16:58
Done.
| |
| 789 console.log( | |
| 790 'Requested Actions setToastVisible=' + shouldSetToastVisible + ' ' + | |
| 791 'setShouldPollCards=' + shouldPollCards); | |
| 792 | |
| 781 setToastVisible(shouldSetToastVisible, function() { | 793 setToastVisible(shouldSetToastVisible, function() { |
| 782 setShouldPollCards(shouldPollCards, callback); | 794 setShouldPollCards(shouldPollCards, callback); |
| 783 }); | 795 }); |
| 784 } | 796 } |
| 785 | 797 |
| 786 /** | 798 /** |
| 787 * Coordinates the behavior of Google Now for Chrome depending on | 799 * Coordinates the behavior of Google Now for Chrome depending on |
| 788 * Chrome and extension state. | 800 * Chrome and extension state. |
| 789 */ | 801 */ |
| 790 function onStateChange() { | 802 function onStateChange() { |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 892 | 904 |
| 893 chrome.location.onLocationUpdate.addListener(function(position) { | 905 chrome.location.onLocationUpdate.addListener(function(position) { |
| 894 recordEvent(GoogleNowEvent.LOCATION_UPDATE); | 906 recordEvent(GoogleNowEvent.LOCATION_UPDATE); |
| 895 updateNotificationsCards(position); | 907 updateNotificationsCards(position); |
| 896 }); | 908 }); |
| 897 | 909 |
| 898 chrome.omnibox.onInputEntered.addListener(function(text) { | 910 chrome.omnibox.onInputEntered.addListener(function(text) { |
| 899 localStorage['server_url'] = NOTIFICATION_CARDS_URL = text; | 911 localStorage['server_url'] = NOTIFICATION_CARDS_URL = text; |
| 900 initialize(); | 912 initialize(); |
| 901 }); | 913 }); |
| OLD | NEW |