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

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

Issue 27030012: Restoring notifications on startup (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: More rgustafson's 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
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 837d2b91f9625a4bf1cfbabde45bd13ceee3e882..13ce272fbee54c45eb2cf16c5a25f064cbc99759 100644
--- a/chrome/browser/resources/google_now/cards.js
+++ b/chrome/browser/resources/google_now/cards.js
@@ -54,6 +54,7 @@ var CardCreateInfo;
/**
* Names for tasks that can be created by the this file.
*/
+var SHOW_CARD_TASK_NAME = 'show-card';
var CLEAR_CARD_TASK_NAME = 'clear-card';
/**
@@ -89,6 +90,13 @@ function buildCardSet() {
console.log('cardManager.showNotification ' + cardId + ' ' +
JSON.stringify(cardCreateInfo));
+ if (cardCreateInfo.hideTime <= Date.now()) {
+ console.log('cardManager.showNotification ' + cardId + ': expired');
+ // Card has expired. Schedule hiding to delete asociated information.
+ scheduleHiding(cardId, cardCreateInfo.hideTime);
+ return;
+ }
+
if (cardCreateInfo.previousVersion !== cardCreateInfo.version) {
// Delete a notification with the specified id if it already exists, and
// then create a notification.
@@ -98,7 +106,7 @@ function buildCardSet() {
function(newNotificationId) {
if (!newNotificationId || chrome.runtime.lastError) {
var errorMessage = chrome.runtime.lastError &&
- chrome.runtime.lastError.message;
+ chrome.runtime.lastError.message;
console.error('notifications.create: ID=' + newNotificationId +
', ERROR=' + errorMessage);
return;
@@ -114,7 +122,7 @@ function buildCardSet() {
function(wasUpdated) {
if (!wasUpdated || chrome.runtime.lastError) {
var errorMessage = chrome.runtime.lastError &&
- chrome.runtime.lastError.message;
+ chrome.runtime.lastError.message;
console.error('notifications.update: UPDATED=' + wasUpdated +
', ERROR=' + errorMessage);
return;
@@ -211,16 +219,18 @@ function buildCardSet() {
if (alarm.name.indexOf(cardShowPrefix) == 0) {
// Alarm to show the card.
- var cardId = alarm.name.substring(cardShowPrefix.length);
- instrumented.storage.local.get('notificationsData', function(items) {
- console.log('cardManager.onAlarm.get ' + JSON.stringify(items));
- if (!items || !items.notificationsData)
- return;
- var notificationData = items.notificationsData[cardId];
- if (!notificationData)
- return;
-
- showNotification(cardId, notificationData.cardCreateInfo);
+ tasks.add(SHOW_CARD_TASK_NAME, function() {
+ var cardId = alarm.name.substring(cardShowPrefix.length);
+ instrumented.storage.local.get('notificationsData', function(items) {
+ console.log('cardManager.onAlarm.get ' + JSON.stringify(items));
+ if (!items || !items.notificationsData)
+ return;
+ var notificationData = items.notificationsData[cardId];
+ if (!notificationData)
+ return;
+
+ showNotification(cardId, notificationData.cardCreateInfo);
+ });
});
} else if (alarm.name.indexOf(cardHidePrefix) == 0) {
// Alarm to hide the card.

Powered by Google App Engine
This is Rietveld 408576698