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

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

Issue 33433003: Processing groups with nextPollSeconds === undefined (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: robliao@ comments. Created 7 years, 2 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 | no next file » | 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 0d8de446b052525c584f95529db8ccefd22915d8..6b7085fd110abb96813d1bc0552c9accc6792ebb 100644
--- a/chrome/browser/resources/google_now/background.js
+++ b/chrome/browser/resources/google_now/background.js
@@ -108,12 +108,15 @@ var UnmergedNotification;
/**
* Notification group as the client stores it. |cardsTimestamp| and |rank| are
- * defined if |cards| is non-empty.
+ * defined if |cards| is non-empty. |nextPollTime| is undefined if the server
+ * (1) never sent 'nextPollSeconds' for the group or
+ * (2) didn't send 'nextPollSeconds' with the last group update containing a
+ * cards update and all the times after that.
*
* @typedef {{
* cards: Array.<UnmergedNotification>,
* cardsTimestamp: number=,
- * nextPollTime: number,
+ * nextPollTime: number=,
* rank: number=
* }}
*/
@@ -432,10 +435,13 @@ function scheduleNextPoll(groups) {
for (var groupName in groups) {
var group = groups[groupName];
- nextPollTime = nextPollTime == null ?
- group.nextPollTime : Math.min(group.nextPollTime, nextPollTime);
+ if (group.nextPollTime !== undefined) {
+ nextPollTime = nextPollTime == null ?
+ group.nextPollTime : Math.min(group.nextPollTime, nextPollTime);
+ }
}
+ // At least one of the groups must have nextPollTime.
verify(nextPollTime != null, 'scheduleNextPoll: nextPollTime is null');
var nextPollDelaySeconds = Math.max(
@@ -494,7 +500,7 @@ function parseAndShowNotificationCards(response) {
var storageGroup = items.notificationGroups[groupName] || {
cards: [],
cardsTimestamp: undefined,
- nextPollTime: now,
+ nextPollTime: undefined,
rank: undefined
};
@@ -502,11 +508,20 @@ function parseAndShowNotificationCards(response) {
receivedGroup.cards = receivedGroup.cards || [];
if (receivedGroup.cards) {
+ // If the group contains a cards update, all its fields will get new
+ // values.
storageGroup.cards = receivedGroup.cards;
storageGroup.cardsTimestamp = now;
storageGroup.rank = receivedGroup.rank;
+ storageGroup.nextPollTime = undefined;
+ // The code below assigns nextPollTime a defined value if
+ // nextPollSeconds is specified in the received group.
+ // If the group's cards are not updated, and nextPollSeconds is
+ // unspecified, this method doesn't change group's nextPollTime.
}
+ // 'nextPollSeconds' may be sent even for groups that don't contain cards
+ // updates.
if (receivedGroup.nextPollSeconds !== undefined) {
storageGroup.nextPollTime =
now + receivedGroup.nextPollSeconds * MS_IN_SECOND;
@@ -579,7 +594,7 @@ function requestNotificationCards(position) {
for (var groupName in items.notificationGroups) {
var group = items.notificationGroups[groupName];
- if (group.nextPollTime <= now)
+ if (group.nextPollTime !== undefined && group.nextPollTime <= now)
groupsToRequest.push(groupName);
}
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698