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

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

Issue 21985002: Add Finch Checks to the State Machine (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@SMLog
Patch Set: Created 7 years, 5 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/background_unittest.gtestjs » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 aa68162313ed48f53b2c64666c6a21d938af991c..4bb1fcbf7cf2f89e1c610710e5207c5e78b1d7aa 100644
--- a/chrome/browser/resources/google_now/background.js
+++ b/chrome/browser/resources/google_now/background.js
@@ -709,6 +709,9 @@ function setShouldPollCards(shouldPollCardsRequest, onSuccess) {
startPollingCards();
else
stopPollingCards();
+ } else {
+ console.log(
+ 'Action Ignored setShouldPollCards=' + shouldPollCardsRequest);
}
onSuccess();
});
@@ -734,6 +737,8 @@ function setToastVisible(visibleRequest, onSuccess) {
showWelcomeToast();
else
hideWelcomeToast();
+ } else {
+ console.log('Action Ignored setToastVisible=' + visibleRequest);
}
onSuccess();
@@ -741,6 +746,36 @@ function setToastVisible(visibleRequest, onSuccess) {
}
/**
+ * Enables or disables the Google Now background permission.
+ * @param {boolean} backgroundEnable true to run in the background.
+ * false to not run in the background.
+ * @param {function} onSuccess Called on completion.
+ */
+function setBackgroundEnable(backgroundEnable, onSuccess) {
vadimt 2013/08/02 21:54:43 onSuccess -> callback
robliao 2013/08/03 01:21:18 Kept this way to remain consistent with the above.
+ chrome.permissions.contains({permissions: ['background']},
vadimt 2013/08/02 21:54:43 Please instrument new APIs.
robliao 2013/08/03 01:21:18 Done.
+ function(hasPermission) {
+ if (backgroundEnable != hasPermission) {
+ console.log('Action Taken setBackgroundEnable=' + backgroundEnable);
+ if (backgroundEnable)
+ chrome.permissions.request(
+ {permissions: ['background']},
+ function() {
+ onSuccess();
+ });
+ else
+ chrome.permissions.remove(
+ {permissions: ['background']},
+ function() {
+ onSuccess();
+ });
+ } else {
+ console.log('Action Ignored setBackgroundEnable=' + backgroundEnable);
+ onSuccess();
+ }
+ });
+}
+
+/**
* Does the actual work of deciding what Google Now should do
* based off of the current state of Chrome.
* @param {boolean} signedIn true if the user is signed in.
@@ -748,23 +783,28 @@ function setToastVisible(visibleRequest, onSuccess) {
* the geolocation option is enabled.
* @param {boolean} userRespondedToToast true if
* the user has responded to the toast.
+ * @param {boolean} enableExperiment true if
+ * this extension should be running.
vadimt 2013/08/02 21:54:43 Actually, we need a flag that conditionally turns
robliao 2013/08/03 01:21:18 We will want to update the doc: S & L => poll + ba
vadimt 2013/08/03 02:07:53 The ultimate goal is to implement as described in
robliao 2013/08/09 21:46:44 Clarified with Modes without Background: EnableWit
* @param {function()} callback Call this function on completion.
*/
function updateRunningState(
signedIn,
geolocationEnabled,
userRespondedToToast,
+ enableExperiment,
callback) {
vadimt 2013/08/02 21:54:43 Are you going to get rid of callback and debugSetS
robliao 2013/08/03 01:21:18 That's the plan. I didn't know if you were doing t
vadimt 2013/08/03 02:07:53 Please do this only for your task. I'll take care
robliao 2013/08/09 21:46:44 Done. There was no debugSetStepName added in. On 2
vadimt 2013/08/09 22:13:39 OK :), but please plan a separate CL where you'll
console.log(
'State Update signedIn=' + signedIn + ' ' +
'geolocationEnabled=' + geolocationEnabled + ' ' +
- 'userRespondedToToast=' + userRespondedToToast);
+ 'userRespondedToToast=' + userRespondedToToast + ' ' +
+ 'enableExperiment=' + enableExperiment);
var shouldSetToastVisible = false;
var shouldPollCards = false;
+ var shouldSetBackground = false;
- if (signedIn) {
+ if (signedIn && enableExperiment) {
if (geolocationEnabled) {
if (!userRespondedToToast) {
// If the user enabled geolocation independently of Google Now,
@@ -774,6 +814,7 @@ function updateRunningState(
}
shouldPollCards = true;
+ shouldSetBackground = true;
} else {
if (userRespondedToToast) {
recordEvent(GoogleNowEvent.USER_SUPPRESSED);
@@ -786,11 +827,14 @@ function updateRunningState(
}
console.log(
- 'Requested Actions setToastVisible=' + shouldSetToastVisible + ' ' +
+ 'Requested Actions shouldSetBackground=' + shouldSetBackground + ' ' +
+ 'setToastVisible=' + shouldSetToastVisible + ' ' +
'setShouldPollCards=' + shouldPollCards);
- setToastVisible(shouldSetToastVisible, function() {
- setShouldPollCards(shouldPollCards, callback);
+ setBackgroundEnable(shouldSetBackground, function() {
+ setToastVisible(shouldSetToastVisible, function() {
+ setShouldPollCards(shouldPollCards, callback);
+ });
});
}
@@ -803,19 +847,26 @@ function onStateChange() {
tasks.debugSetStepName('onStateChange-isSignedIn');
authenticationManager.isSignedIn(function(token) {
var signedIn = !!token && !!NOTIFICATION_CARDS_URL;
- tasks.debugSetStepName(
- 'onStateChange-get-googleGeolocationAccessEnabledPref');
- googleGeolocationAccessEnabledPref.get({}, function(prefValue) {
- var geolocationEnabled = !!prefValue.value;
+ chrome.metricsPrivate.getFieldTrial('GoogleNow', function(response) {
vadimt 2013/08/02 21:54:43 How did you test this?
robliao 2013/08/03 01:21:18 Tested with my personal finch server. On 2013/08/0
+ // '' means we were enabled via the flags but not the experiment.
vadimt 2013/08/02 21:54:43 More precisely: // '' means we were enabled via th
robliao 2013/08/03 01:21:18 Done.
+ var enableExperiment = (response == 'EnableWithBackground' ||
+ (response == 'EnableWithFlag') ||
+ (response == ''));
tasks.debugSetStepName(
- 'onStateChange-get-userRespondedToToast');
- storage.get('userRespondedToToast', function(items) {
- var userRespondedToToast = !!items.userRespondedToToast;
- updateRunningState(
- signedIn,
- geolocationEnabled,
- userRespondedToToast,
- callback);
+ 'onStateChange-get-googleGeolocationAccessEnabledPref');
+ googleGeolocationAccessEnabledPref.get({}, function(prefValue) {
+ var geolocationEnabled = !!prefValue.value;
+ tasks.debugSetStepName(
+ 'onStateChange-get-userRespondedToToast');
+ storage.get('userRespondedToToast', function(items) {
+ var userRespondedToToast = !!items.userRespondedToToast;
+ updateRunningState(
+ signedIn,
+ geolocationEnabled,
+ userRespondedToToast,
+ enableExperiment,
+ callback);
+ });
});
});
});
« no previous file with comments | « no previous file | chrome/browser/resources/google_now/background_unittest.gtestjs » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698