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

Side by Side 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: Created 6 years, 8 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/resources/google_now/utility.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 */ 45 */
46 var MINIMUM_POLLING_PERIOD_SECONDS = 5 * 60; // 5 minutes 46 var MINIMUM_POLLING_PERIOD_SECONDS = 5 * 60; // 5 minutes
47 47
48 /** 48 /**
49 * Maximal period for polling for Google Now Notifications cards to use when the 49 * Maximal period for polling for Google Now Notifications cards to use when the
50 * period from the server is not available. 50 * period from the server is not available.
51 */ 51 */
52 var MAXIMUM_POLLING_PERIOD_SECONDS = 60 * 60; // 1 hour 52 var MAXIMUM_POLLING_PERIOD_SECONDS = 60 * 60; // 1 hour
53 53
54 /** 54 /**
55 * Initial period for polling for Google Now optin notification after push
56 * messaging indicates Google Now is enabled.
57 */
58 var INITIAL_OPTIN_POLLING_PERIOD_SECONDS = 60; // 1 minute
59
60 /**
61 * Maximum period for polling for Google Now optin notification after push
62 * messaging indicates Google Now is enabled. It is expected that the alarm
63 * will be stopped after this.
64 */
65 var MAXIMUM_OPTIN_POLLING_PERIOD_SECONDS = 16 * 60; // 16 minutes
66
67 /**
55 * Initial period for retrying the server request for dismissing cards. 68 * Initial period for retrying the server request for dismissing cards.
56 */ 69 */
57 var INITIAL_RETRY_DISMISS_PERIOD_SECONDS = 60; // 1 minute 70 var INITIAL_RETRY_DISMISS_PERIOD_SECONDS = 60; // 1 minute
58 71
59 /** 72 /**
60 * Maximum period for retrying the server request for dismissing cards. 73 * Maximum period for retrying the server request for dismissing cards.
61 */ 74 */
62 var MAXIMUM_RETRY_DISMISS_PERIOD_SECONDS = 60 * 60; // 1 hour 75 var MAXIMUM_RETRY_DISMISS_PERIOD_SECONDS = 60 * 60; // 1 hour
63 76
64 /** 77 /**
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 wrapper.instrumentChromeApiFunction('pushMessaging.onMessage.addListener', 0); 208 wrapper.instrumentChromeApiFunction('pushMessaging.onMessage.addListener', 0);
196 wrapper.instrumentChromeApiFunction('runtime.onInstalled.addListener', 0); 209 wrapper.instrumentChromeApiFunction('runtime.onInstalled.addListener', 0);
197 wrapper.instrumentChromeApiFunction('runtime.onStartup.addListener', 0); 210 wrapper.instrumentChromeApiFunction('runtime.onStartup.addListener', 0);
198 wrapper.instrumentChromeApiFunction('tabs.create', 1); 211 wrapper.instrumentChromeApiFunction('tabs.create', 1);
199 212
200 var updateCardsAttempts = buildAttemptManager( 213 var updateCardsAttempts = buildAttemptManager(
201 'cards-update', 214 'cards-update',
202 requestCards, 215 requestCards,
203 INITIAL_POLLING_PERIOD_SECONDS, 216 INITIAL_POLLING_PERIOD_SECONDS,
204 MAXIMUM_POLLING_PERIOD_SECONDS); 217 MAXIMUM_POLLING_PERIOD_SECONDS);
218 var optInCheckAttempts = buildAttemptManager(
219 'optin',
220 pollOptedIn,
221 INITIAL_OPTIN_POLLING_PERIOD_SECONDS,
222 MAXIMUM_OPTIN_POLLING_PERIOD_SECONDS);
205 var dismissalAttempts = buildAttemptManager( 223 var dismissalAttempts = buildAttemptManager(
206 'dismiss', 224 'dismiss',
207 retryPendingDismissals, 225 retryPendingDismissals,
208 INITIAL_RETRY_DISMISS_PERIOD_SECONDS, 226 INITIAL_RETRY_DISMISS_PERIOD_SECONDS,
209 MAXIMUM_RETRY_DISMISS_PERIOD_SECONDS); 227 MAXIMUM_RETRY_DISMISS_PERIOD_SECONDS);
210 var cardSet = buildCardSet(); 228 var cardSet = buildCardSet();
211 229
212 var authenticationManager = buildAuthenticationManager(); 230 var authenticationManager = buildAuthenticationManager();
213 231
214 /** 232 /**
(...skipping 874 matching lines...) Expand 10 before | Expand all | Expand 10 after
1089 * @return {Promise} A promise to determine the previous Google Now 1107 * @return {Promise} A promise to determine the previous Google Now
1090 * opt-in state. 1108 * opt-in state.
1091 */ 1109 */
1092 function isGoogleNowEnabled() { 1110 function isGoogleNowEnabled() {
1093 return fillFromChromeLocalStorage({googleNowEnabled: false}) 1111 return fillFromChromeLocalStorage({googleNowEnabled: false})
1094 .then(function(items) { 1112 .then(function(items) {
1095 return items.googleNowEnabled; 1113 return items.googleNowEnabled;
1096 }); 1114 });
1097 } 1115 }
1098 1116
1117 /**
1118 * Sometimes we get the response to the opted in result too soon during
rgustafson 2014/03/28 20:59:48 Match the other function comment format. Start wit
robliao 2014/03/28 21:03:06 Done. checkOptedIn does start with a verb... On 20
1119 * push messaging. We'll recheck the optin state a few times before giving up.
1120 */
1121 function pollOptedIn() {
1122 /**
1123 * Cleans up any state used to recheck the opt-in poll.
1124 */
1125 function clearPollingState() {
1126 localStorage.removeItem('optedInCheckCount');
1127 optInCheckAttempts.stop();
1128 }
1129
1130 /**
1131 * Does the actual work for checking the opt-in state and requesting cards
1132 * on opted-in.
1133 */
1134 function checkOptedIn() {
1135 // Limit retries to 5.
1136 if (localStorage.optedInCheckCount < 5) {
1137 console.log(new Date() +
1138 'checkOptedIn Attempt ' + localStorage.optedInCheckCount);
1139 localStorage.optedInCheckCount++;
1140 requestOptedIn(function() {
1141 clearPollingState();
1142 requestCards();
1143 });
1144 } else {
1145 clearPollingState();
1146 }
1147 }
1148
1149 if (localStorage.optedInCheckCount === undefined) {
1150 localStorage.optedInCheckCount = 0;
1151 optInCheckAttempts.start();
1152 checkOptedIn();
1153 } else {
1154 optInCheckAttempts.planForNext(checkOptedIn);
1155 }
1156 }
1157
1099 instrumented.runtime.onInstalled.addListener(function(details) { 1158 instrumented.runtime.onInstalled.addListener(function(details) {
1100 console.log('onInstalled ' + JSON.stringify(details)); 1159 console.log('onInstalled ' + JSON.stringify(details));
1101 if (details.reason != 'chrome_update') { 1160 if (details.reason != 'chrome_update') {
1102 initialize(); 1161 initialize();
1103 } 1162 }
1104 }); 1163 });
1105 1164
1106 instrumented.runtime.onStartup.addListener(function() { 1165 instrumented.runtime.onStartup.addListener(function() {
1107 console.log('onStartup'); 1166 console.log('onStartup');
1108 1167
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
1195 items.notificationGroups['PUSH' + message.subchannelId] = { 1254 items.notificationGroups['PUSH' + message.subchannelId] = {
1196 cards: [], 1255 cards: [],
1197 nextPollTime: Date.now() 1256 nextPollTime: Date.now()
1198 }; 1257 };
1199 1258
1200 chrome.storage.local.set({ 1259 chrome.storage.local.set({
1201 lastPollNowPayloads: items.lastPollNowPayloads, 1260 lastPollNowPayloads: items.lastPollNowPayloads,
1202 notificationGroups: items.notificationGroups 1261 notificationGroups: items.notificationGroups
1203 }); 1262 });
1204 1263
1205 requestCards(); 1264 pollOptedIn();
1206 } 1265 }
1207 }); 1266 });
1208 }); 1267 });
1209 } 1268 }
1210 }); 1269 });
OLDNEW
« 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