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

Unified Diff: chrome/browser/resources/google_now/cards.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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/google_now/cards.js
diff --git a/chrome/browser/resources/google_now/cards.js b/chrome/browser/resources/google_now/cards.js
index 547730f4a9c8d6139bef75c6f7d122933c1df26f..98ff5f56405d930c98a46d280021a90b18ea23c9 100644
--- a/chrome/browser/resources/google_now/cards.js
+++ b/chrome/browser/resources/google_now/cards.js
@@ -183,12 +183,14 @@ function buildCardSet() {
* based on the current time and show-hide intervals in the combined card.
* @param {ChromeNotificationId} cardId Card ID.
* @param {CombinedCard} combinedCard Combined cards with |cardId|.
+ * @param {Object.<string, StoredNotificationGroup>} notificationGroups
+ * Map from group name to group information.
* @param {function(ReceivedNotification)=} onCardShown Optional parameter
* called when each card is shown.
* @return {(NotificationDataEntry|undefined)} Notification data entry for
* this card. It's 'undefined' if the card's life is over.
*/
- function update(cardId, combinedCard, onCardShown) {
+ function update(cardId, combinedCard, notificationGroups, onCardShown) {
console.log('cardManager.update ' + JSON.stringify(combinedCard));
chrome.alarms.clear(alarmPrefix + cardId);
@@ -254,7 +256,7 @@ function buildCardSet() {
// If there are no more events, we are done with this card. Note that all
// received notifications have hideTime.
verify(!winningCard, 'No events left, but card is shown.');
- clearCardFromGroups(cardId);
+ clearCardFromGroups(cardId, notificationGroups);
return undefined;
}
}
@@ -298,29 +300,22 @@ function buildCardSet() {
}
/**
- * Removes card information from 'notificationGroups'.
+ * Removes card information from |notificationGroups|.
* @param {ChromeNotificationId} cardId Card ID.
+ * @param {Object.<string, StoredNotificationGroup>} notificationGroups
+ * Map from group name to group information.
*/
- function clearCardFromGroups(cardId) {
+ function clearCardFromGroups(cardId, notificationGroups) {
console.log('cardManager.clearCardFromGroups ' + cardId);
-
- instrumented.storage.local.get('notificationGroups', function(items) {
- items = items || {};
- /** @type {Object.<string, StoredNotificationGroup>} */
- items.notificationGroups = items.notificationGroups || {};
-
- for (var groupName in items.notificationGroups) {
- var group = items.notificationGroups[groupName];
- for (var i = 0; i != group.cards.length; ++i) {
- if (group.cards[i].chromeNotificationId == cardId) {
- group.cards.splice(i, 1);
- break;
- }
+ for (var groupName in notificationGroups) {
+ var group = notificationGroups[groupName];
+ for (var i = 0; i != group.cards.length; ++i) {
+ if (group.cards[i].chromeNotificationId == cardId) {
+ group.cards.splice(i, 1);
+ break;
}
}
-
- chrome.storage.local.set(items);
- });
+ }
}
instrumented.alarms.onAlarm.addListener(function(alarm) {

Powered by Google App Engine
This is Rietveld 408576698