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 400409e630bec2dc23485853748e5ab47a3f700a..7f76a2e8f886a7dfdc863fd28e9795e7b18c2bd4 100644 |
| --- a/chrome/browser/resources/google_now/background.js |
| +++ b/chrome/browser/resources/google_now/background.js |
| @@ -1087,34 +1087,80 @@ function updateRunningState( |
| */ |
| function onStateChange() { |
| tasks.add(STATE_CHANGED_TASK_NAME, function() { |
| + Promise.all([ |
| + isSignedIn(), |
| + isGeolocationEnabled(), |
| + canEnableBackground(), |
| + isNotificationsEnabled(), |
| + isGoogleNowEnabled()]) |
| + .then(function(results) { |
| + updateRunningState.apply(null, results); |
| + }); |
| + }); |
| +} |
| + |
| +/** |
| + * Determines if the user is signed in. |
| + * @return {Promise} A promise to evaluate the signed in state. |
| + */ |
| +function isSignedIn() { |
| + return new Promise(function(onSuccess) { |
|
rgustafson
2014/02/11 03:18:59
Just out of curiosity, is onSuccess normal promise
robliao
2014/02/11 17:55:41
We've got terminology to use onSuccess in the card
|
| authenticationManager.isSignedIn(function(signedIn) { |
| - instrumented.metricsPrivate.getVariationParams( |
| - 'GoogleNow', |
| - function(response) { |
| - var canEnableBackground = |
| - (!response || (response.canEnableBackground != 'false')); |
| - instrumented.notifications.getPermissionLevel(function(level) { |
| - var notificationEnabled = (level == 'granted'); |
| - instrumented. |
| - preferencesPrivate. |
| - googleGeolocationAccessEnabled. |
| - get({}, function(prefValue) { |
| - var geolocationEnabled = !!prefValue.value; |
| - instrumented.storage.local.get( |
| - 'googleNowEnabled', |
| - function(items) { |
| - var googleNowEnabled = |
| - items && !!items.googleNowEnabled; |
| - updateRunningState( |
| - signedIn, |
| - geolocationEnabled, |
| - canEnableBackground, |
| - notificationEnabled, |
| - googleNowEnabled); |
| - }); |
| - }); |
| - }); |
| - }); |
| + onSuccess(signedIn); |
| + }); |
| + }); |
| +} |
| + |
| +/** |
| + * Gets the geolocation enabled preference. |
| + * @return {Promise} A promise to get the geolocation enabled preference. |
| + */ |
| +function isGeolocationEnabled() { |
| + return new Promise(function(onSuccess) { |
| + instrumented.preferencesPrivate.googleGeolocationAccessEnabled.get( |
| + {}, |
| + function(prefValue) { |
| + onSuccess(!!prefValue.value); |
| + }); |
| + }); |
| +} |
| + |
| +/** |
| + * Determines if background mode should be requested. |
| + * @return {Promise} A promise to determine if background can be enabled. |
| + */ |
| +function canEnableBackground() { |
| + return new Promise(function(onSuccess) { |
| + instrumented.metricsPrivate.getVariationParams( |
| + 'GoogleNow', |
| + function(response) { |
| + onSuccess(!response || (response.canEnableBackground != 'false')); |
| + }); |
| + }); |
| +} |
| + |
| +/** |
| + * Checks if Google Now is enabled in the notifications center. |
| + * @return {Promise} A promise to determine if Google Now is enabled |
| + * in the notifications center. |
| + */ |
| +function isNotificationsEnabled() { |
| + return new Promise(function(onSuccess) { |
| + instrumented.notifications.getPermissionLevel(function(level) { |
| + onSuccess(level == 'granted'); |
| + }); |
| + }); |
| +} |
| + |
| +/** |
| + * Gets the previous Google Now opt-in state |
|
rgustafson
2014/02/11 03:18:59
add .
robliao
2014/02/11 17:55:41
Done.
|
| + * @return {Promise} A promise to determine the previous Google Now |
| + * opt-in state. |
| + */ |
| +function isGoogleNowEnabled() { |
| + return new Promise(function(onSuccess) { |
| + instrumented.storage.local.get('googleNowEnabled', function(items) { |
| + onSuccess(items && !!items.googleNowEnabled); |
| }); |
| }); |
| } |