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 b914e14dc28991bd2f7488cc25b688c0255d230c..9d6154066f991e7e08e71f733e6d6ac8b99fe096 100644 |
| --- a/chrome/browser/resources/google_now/background.js |
| +++ b/chrome/browser/resources/google_now/background.js |
| @@ -485,6 +485,7 @@ function parseAndShowNotificationCards(response) { |
| // TODO(vadimt): Remove the line below once the server stops sending groups |
| // with 'googleNowDisabled' responses. |
| parsedResponse.groups = {}; |
| + onStateChange(); |
|
robliao
2013/10/31 18:29:41
Comment that if we make it here, Google Now was pr
vadimt
2013/10/31 20:14:08
Done.
|
| } |
| var receivedGroups = parsedResponse.groups; |
| @@ -604,6 +605,7 @@ function requestOptedIn(optedInCallback) { |
| if (parsedResponse.value) { |
| chrome.storage.local.set({googleNowEnabled: true}); |
| optedInCallback(); |
| + onStateChange(); |
|
robliao
2013/10/31 18:29:41
Same here. If we're here, Google Now was previousl
vadimt
2013/10/31 20:14:08
Done.
|
| } else { |
| scheduleNextPoll({}); |
| } |
| @@ -925,10 +927,9 @@ function startPollingCards() { |
| */ |
| function stopPollingCards() { |
| stopRequestLocation(); |
| - |
| updateCardsAttempts.stop(); |
| - |
| removeAllCards(); |
| + chrome.storage.local.set({googleNowEnabled: false}); |
|
robliao
2013/10/31 18:29:41
Semantically, this isn't necessarily correct if th
vadimt
2013/10/31 20:14:08
When the user checks us again in NC, we should sta
robliao
2013/10/31 23:05:01
This would be an excellent place for a comment.
On
vadimt
2013/11/01 00:49:47
Done.
|
| } |
| /** |
| @@ -985,21 +986,25 @@ function setBackgroundEnable(backgroundEnable) { |
| * @param {boolean} signedIn true if the user is signed in. |
| * @param {boolean} geolocationEnabled true if |
| * the geolocation option is enabled. |
| - * @param {boolean} enableBackground true if |
| - * the background permission should be requested. |
| + * @param {boolean} canEnableBackground true if |
| + * the background permission can be requested. |
| * @param {boolean} notificationEnabled true if |
| * Google Now for Chrome is allowed to show notifications. |
| + * @param {boolean} googleNowEnabled true if |
| + * the Google Now is enabled for the user. |
| */ |
| function updateRunningState( |
| signedIn, |
| geolocationEnabled, |
| - enableBackground, |
| - notificationEnabled) { |
| + canEnableBackground, |
| + notificationEnabled, |
| + googleNowEnabled) { |
| console.log( |
| 'State Update signedIn=' + signedIn + ' ' + |
| 'geolocationEnabled=' + geolocationEnabled + ' ' + |
| - 'enableBackground=' + enableBackground + ' ' + |
| - 'notificationEnabled=' + notificationEnabled); |
| + 'canEnableBackground=' + canEnableBackground + ' ' + |
| + 'notificationEnabled=' + notificationEnabled + ' ' + |
| + 'googleNowEnabled=' + googleNowEnabled); |
| // TODO(vadimt): Remove this line once state machine design is finalized. |
| geolocationEnabled = true; |
| @@ -1009,7 +1014,7 @@ function updateRunningState( |
| if (signedIn && notificationEnabled) { |
| if (geolocationEnabled) { |
| - if (enableBackground) |
| + if (canEnableBackground && googleNowEnabled) |
| shouldSetBackground = true; |
| shouldPollCards = true; |
| @@ -1037,8 +1042,8 @@ function onStateChange() { |
| instrumented.metricsPrivate.getVariationParams( |
| 'GoogleNow', |
| function(response) { |
| - var enableBackground = |
| - (!response || (response.enableBackground != 'false')); |
| + var canEnableBackground = |
| + (!response || (response.canEnableBackground != 'false')); |
| instrumented.notifications.getPermissionLevel(function(level) { |
| var notificationEnabled = (level == 'granted'); |
| instrumented. |
| @@ -1046,11 +1051,18 @@ function onStateChange() { |
| googleGeolocationAccessEnabled. |
| get({}, function(prefValue) { |
| var geolocationEnabled = !!prefValue.value; |
| - updateRunningState( |
| - signedIn, |
| - geolocationEnabled, |
| - enableBackground, |
| - notificationEnabled); |
| + instrumented.storage.local.get( |
| + 'googleNowEnabled', |
| + function(items) { |
| + var googleNowEnabled = |
| + items && !!items.googleNowEnabled; |
| + updateRunningState( |
| + signedIn, |
| + geolocationEnabled, |
| + canEnableBackground, |
| + notificationEnabled, |
| + googleNowEnabled); |
| + }); |
| }); |
| }); |
| }); |