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

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

Issue 217263005: Add Optin Retry Logic to Google Now (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Word change Created 6 years, 9 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/utility.js » ('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 f5ddd231a23841d2dc04dd9352a5d9f89b10c446..de130965c1d1b0add55994bff434856e53d56b65 100644
--- a/chrome/browser/resources/google_now/background.js
+++ b/chrome/browser/resources/google_now/background.js
@@ -52,6 +52,19 @@ var MINIMUM_POLLING_PERIOD_SECONDS = 5 * 60; // 5 minutes
var MAXIMUM_POLLING_PERIOD_SECONDS = 60 * 60; // 1 hour
/**
+ * Initial period for polling for Google Now optin notification after push
+ * messaging indicates Google Now is enabled.
+ */
+var INITIAL_OPTIN_POLLING_PERIOD_SECONDS = 60; // 1 minute
+
+/**
+ * Maximum period for polling for Google Now optin notification after push
+ * messaging indicates Google Now is enabled. It is expected that the alarm
+ * will be stopped after this.
+ */
+var MAXIMUM_OPTIN_POLLING_PERIOD_SECONDS = 16 * 60; // 16 minutes
+
+/**
* Initial period for retrying the server request for dismissing cards.
*/
var INITIAL_RETRY_DISMISS_PERIOD_SECONDS = 60; // 1 minute
@@ -202,6 +215,11 @@ var updateCardsAttempts = buildAttemptManager(
requestCards,
INITIAL_POLLING_PERIOD_SECONDS,
MAXIMUM_POLLING_PERIOD_SECONDS);
+var optInCheckAttempts = buildAttemptManager(
+ 'optin',
+ pollOptedIn,
+ INITIAL_OPTIN_POLLING_PERIOD_SECONDS,
+ MAXIMUM_OPTIN_POLLING_PERIOD_SECONDS);
var dismissalAttempts = buildAttemptManager(
'dismiss',
retryPendingDismissals,
@@ -1096,6 +1114,48 @@ function isGoogleNowEnabled() {
});
}
+/**
+ * Polls the optin state.
+ * Sometimes we get the response to the opted in result too soon during
+ * push messaging. We'll recheck the optin state a few times before giving up.
+ */
+function pollOptedIn() {
+ /**
+ * Cleans up any state used to recheck the opt-in poll.
+ */
+ function clearPollingState() {
+ localStorage.removeItem('optedInCheckCount');
+ optInCheckAttempts.stop();
+ }
+
+ /**
+ * Performs the actual work for checking the opt-in state and requesting cards
+ * on opted-in.
+ */
+ function checkOptedIn() {
+ // Limit retries to 5.
+ if (localStorage.optedInCheckCount < 5) {
+ console.log(new Date() +
+ ' checkOptedIn Attempt ' + localStorage.optedInCheckCount);
+ localStorage.optedInCheckCount++;
+ requestOptedIn(function() {
+ clearPollingState();
+ requestCards();
+ });
+ } else {
+ clearPollingState();
+ }
+ }
+
+ if (localStorage.optedInCheckCount === undefined) {
+ localStorage.optedInCheckCount = 0;
+ optInCheckAttempts.start();
+ checkOptedIn();
+ } else {
+ optInCheckAttempts.planForNext(checkOptedIn);
+ }
+}
+
instrumented.runtime.onInstalled.addListener(function(details) {
console.log('onInstalled ' + JSON.stringify(details));
if (details.reason != 'chrome_update') {
@@ -1202,7 +1262,7 @@ instrumented.pushMessaging.onMessage.addListener(function(message) {
notificationGroups: items.notificationGroups
});
- requestCards();
+ pollOptedIn();
}
});
});
« no previous file with comments | « no previous file | chrome/browser/resources/google_now/utility.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698