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

Side by Side Diff: chrome/browser/resources/google_now/background.js

Issue 114533002: Chrome Now notificationGroups Storage Race Condition Fix (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years 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
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 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 originalOnLoadEnd(event); 286 originalOnLoadEnd(event);
287 } 287 }
288 }); 288 });
289 289
290 callbackBoolean(true); 290 callbackBoolean(true);
291 }); 291 });
292 } 292 }
293 293
294 /** 294 /**
295 * Shows parsed and combined cards as notifications. 295 * Shows parsed and combined cards as notifications.
296 * @param {Object.<string, StoredNotificationGroup>} notificationGroups Map from
297 * group name to group information.
296 * @param {Object.<ChromeNotificationId, CombinedCard>} cards Map from 298 * @param {Object.<ChromeNotificationId, CombinedCard>} cards Map from
297 * chromeNotificationId to the combined card, containing cards to show. 299 * chromeNotificationId to the combined card, containing cards to show.
298 * @param {function(ReceivedNotification)=} onCardShown Optional parameter 300 * @param {function(ReceivedNotification)=} onCardShown Optional parameter
299 * called when each card is shown. 301 * called when each card is shown.
300 */ 302 */
301 function showNotificationCards(cards, onCardShown) { 303 function showNotificationCards(notificationGroups, cards, onCardShown) {
302 console.log('showNotificationCards ' + JSON.stringify(cards)); 304 console.log('showNotificationCards ' + JSON.stringify(cards));
303 305
304 instrumented.notifications.getAll(function(notifications) { 306 instrumented.notifications.getAll(function(notifications) {
305 console.log('showNotificationCards-getAll ' + 307 console.log('showNotificationCards-getAll ' +
306 JSON.stringify(notifications)); 308 JSON.stringify(notifications));
307 notifications = notifications || {}; 309 notifications = notifications || {};
308 310
309 // Mark notifications that didn't receive an update as having received 311 // Mark notifications that didn't receive an update as having received
310 // an empty update. 312 // an empty update.
311 for (var chromeNotificationId in notifications) { 313 for (var chromeNotificationId in notifications) {
312 cards[chromeNotificationId] = cards[chromeNotificationId] || []; 314 cards[chromeNotificationId] = cards[chromeNotificationId] || [];
313 } 315 }
314 316
315 /** @type {Object.<string, NotificationDataEntry>} */ 317 /** @type {Object.<string, NotificationDataEntry>} */
316 var notificationsData = {}; 318 var notificationsData = {};
317 319
318 // Create/update/delete notifications. 320 // Create/update/delete notifications.
319 for (var chromeNotificationId in cards) { 321 for (var chromeNotificationId in cards) {
320 notificationsData[chromeNotificationId] = cardSet.update( 322 notificationsData[chromeNotificationId] = cardSet.update(
321 chromeNotificationId, 323 chromeNotificationId,
322 cards[chromeNotificationId], 324 cards[chromeNotificationId],
325 notificationGroups,
323 onCardShown); 326 onCardShown);
324 } 327 }
325 chrome.storage.local.set({notificationsData: notificationsData}); 328 chrome.storage.local.set({notificationsData: notificationsData});
vadimt 2013/12/13 18:20:54 Please set notificationGroups here. getAll is an a
robliao 2013/12/13 19:31:26 Took a different approach here and delegated that
326 }); 329 });
327 } 330 }
328 331
329 /** 332 /**
330 * Removes all cards and card state on Google Now close down. 333 * Removes all cards and card state on Google Now close down.
331 * For example, this occurs when the geolocation preference is unchecked in the 334 * For example, this occurs when the geolocation preference is unchecked in the
332 * content settings. 335 * content settings.
333 */ 336 */
334 function removeAllCards() { 337 function removeAllCards() {
335 console.log('removeAllCards'); 338 console.log('removeAllCards');
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 */ 425 */
423 function combineAndShowNotificationCards(notificationGroups, onCardShown) { 426 function combineAndShowNotificationCards(notificationGroups, onCardShown) {
424 console.log('combineAndShowNotificationCards ' + 427 console.log('combineAndShowNotificationCards ' +
425 JSON.stringify(notificationGroups)); 428 JSON.stringify(notificationGroups));
426 /** @type {Object.<ChromeNotificationId, CombinedCard>} */ 429 /** @type {Object.<ChromeNotificationId, CombinedCard>} */
427 var combinedCards = {}; 430 var combinedCards = {};
428 431
429 for (var groupName in notificationGroups) 432 for (var groupName in notificationGroups)
430 combineGroup(combinedCards, notificationGroups[groupName]); 433 combineGroup(combinedCards, notificationGroups[groupName]);
431 434
432 showNotificationCards(combinedCards, onCardShown); 435 showNotificationCards(notificationGroups, combinedCards, onCardShown);
433 } 436 }
434 437
435 /** 438 /**
436 * Parses JSON response from the notification server, shows notifications and 439 * Parses JSON response from the notification server, shows notifications and
437 * schedules next update. 440 * schedules next update.
438 * @param {string} response Server response. 441 * @param {string} response Server response.
439 * @param {function(ReceivedNotification)=} onCardShown Optional parameter 442 * @param {function(ReceivedNotification)=} onCardShown Optional parameter
440 * called when each card is shown. 443 * called when each card is shown.
441 */ 444 */
442 function parseAndShowNotificationCards(response, onCardShown) { 445 function parseAndShowNotificationCards(response, onCardShown) {
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 // cards updates. 527 // cards updates.
525 if (receivedGroup.nextPollSeconds !== undefined) { 528 if (receivedGroup.nextPollSeconds !== undefined) {
526 storedGroup.nextPollTime = 529 storedGroup.nextPollTime =
527 now + receivedGroup.nextPollSeconds * MS_IN_SECOND; 530 now + receivedGroup.nextPollSeconds * MS_IN_SECOND;
528 } 531 }
529 532
530 updatedGroups[groupName] = storedGroup; 533 updatedGroups[groupName] = storedGroup;
531 } 534 }
532 535
533 scheduleNextPoll(updatedGroups, !parsedResponse.googleNowDisabled); 536 scheduleNextPoll(updatedGroups, !parsedResponse.googleNowDisabled);
537 combineAndShowNotificationCards(updatedGroups, onCardShown);
534 chrome.storage.local.set({ 538 chrome.storage.local.set({
535 notificationGroups: updatedGroups, 539 notificationGroups: updatedGroups,
536 recentDismissals: updatedRecentDismissals 540 recentDismissals: updatedRecentDismissals
537 }); 541 });
538 combineAndShowNotificationCards(updatedGroups, onCardShown);
539 recordEvent(GoogleNowEvent.CARDS_PARSE_SUCCESS); 542 recordEvent(GoogleNowEvent.CARDS_PARSE_SUCCESS);
rgustafson 2013/12/12 22:52:27 tiny comment: This should probably be before the s
robliao 2013/12/12 23:01:21 Indeed. I was going to save this for the unchained
robliao 2013/12/13 19:31:26 Well, now it does. On 2013/12/12 23:01:21, robliao
540 }); 543 });
541 } 544 }
542 545
543 /** 546 /**
544 * Update Location Cards Shown Count. 547 * Update Location Cards Shown Count.
545 * @param {ReceivedNotification} receivedNotification Notification as it was 548 * @param {ReceivedNotification} receivedNotification Notification as it was
546 * received from the server. 549 * received from the server.
547 */ 550 */
548 function countLocationCard(receivedNotification) { 551 function countLocationCard(receivedNotification) {
549 if (receivedNotification.locationBased) { 552 if (receivedNotification.locationBased) {
(...skipping 666 matching lines...) Expand 10 before | Expand all | Expand 10 after
1216 lastPollNowPayloads: items.lastPollNowPayloads, 1219 lastPollNowPayloads: items.lastPollNowPayloads,
1217 notificationGroups: items.notificationGroups 1220 notificationGroups: items.notificationGroups
1218 }); 1221 });
1219 1222
1220 updateNotificationsCards(); 1223 updateNotificationsCards();
1221 } 1224 }
1222 }); 1225 });
1223 }); 1226 });
1224 } 1227 }
1225 }); 1228 });
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/resources/google_now/cards.js » ('j') | chrome/browser/resources/google_now/cards.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698