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

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

Issue 25097002: Cleaning data associated with the card upon deletion. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixing missing argument. 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
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 fa873318f595b09ac59d08aa66598d4c1da4bf30..393c8aea6c9758b6f1674433aa9eef30af4305cb 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.
@@ -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];
+
+ 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);
+ });
}
});
« no previous file with comments | « chrome/browser/resources/google_now/background.js ('k') | chrome/browser/resources/google_now/cards_unittest.gtestjs » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698