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 5c7845c3a31053ee69903d35e0c00c23695e8765..42925e3ee54a444e8eed82b7bbd1d37870caba68 100644 |
--- a/chrome/browser/resources/google_now/cards.js |
+++ b/chrome/browser/resources/google_now/cards.js |
@@ -51,6 +51,11 @@ var MergedCard; |
*/ |
var CardCreateInfo; |
+/** |
+ * Names for tasks that can be created by the this file. |
+ */ |
+var CLEAR_CARD_TASK_NAME = 'clear-card'; |
+ |
/** |
* Builds an object to manage notification card set. |
* @return {Object} Card set interface. |
@@ -99,7 +104,7 @@ function buildCardSet() { |
return; |
} |
- scheduleHiding(cardId, cardCreateInfo.hideTime); |
+ scheduleHiding(cardId, cardCreateInfo.hideTime); |
}); |
} else { |
// Update existing notification. |
@@ -115,7 +120,7 @@ function buildCardSet() { |
return; |
} |
- scheduleHiding(cardId, cardCreateInfo.hideTime); |
+ scheduleHiding(cardId, cardCreateInfo.hideTime); |
}); |
} |
} |
@@ -168,13 +173,39 @@ function buildCardSet() { |
/** |
* Removes a card notification. |
* @param {string} cardId Card ID. |
+ * @param {boolean} clearStorage True if the information associated with the |
+ * card should be erased from chrome.storage. |
*/ |
- function clear(cardId) { |
+ function clear(cardId, clearStorage) { |
console.log('cardManager.clear ' + cardId); |
chrome.notifications.clear(cardId, function() {}); |
chrome.alarms.clear(cardShowPrefix + cardId); |
chrome.alarms.clear(cardHidePrefix + cardId); |
+ |
+ if (clearStorage) { |
+ instrumented.storage.local.get( |
+ ['notificationsData', 'notificationGroups'], |
+ function(items) { |
+ items = items || {}; |
+ items.notificationsData = items.notificationsData || {}; |
+ items.notificationGroups = items.notificationGroups || {}; |
+ |
+ delete items.notificationsData[cardId]; |
rgustafson
2013/09/27 18:57:20
Do you have to use delete vs setting to null in th
vadimt
2013/09/27 20:10:56
We'll never attempt to access this data after clea
rgustafson
2013/09/27 20:19:28
Then style says to set to null instead of delete.
vadimt
2013/09/27 20:25:24
"The delete keyword should be avoided except when
rgustafson
2013/09/27 22:53:01
It has a list of keys. It isn't necessary to remov
robliao
2013/09/27 22:59:13
The concern here is that deleting is slower than s
vadimt
2013/09/30 16:56:17
FWIW: I'm not null-ing it.
This is a map. No one d
rgustafson
2013/09/30 18:44:02
You still send reviews to arv, right? If the style
|
+ |
+ 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; |
+ } |
+ } |
+ } |
+ |
+ chrome.storage.local.set(items); |
+ }); |
+ } |
} |
instrumented.alarms.onAlarm.addListener(function(alarm) { |
@@ -195,8 +226,10 @@ function buildCardSet() { |
}); |
} else if (alarm.name.indexOf(cardHidePrefix) == 0) { |
// Alarm to hide the card. |
- var cardId = alarm.name.substring(cardHidePrefix.length); |
- clear(cardId); |
+ tasks.add(CLEAR_CARD_TASK_NAME, function() { |
+ var cardId = alarm.name.substring(cardHidePrefix.length); |
+ clear(cardId, true); |
+ }); |
} |
}); |