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

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

Issue 25097002: Cleaning data associated with the card upon deletion. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Cosmetics 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 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 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 } 292 }
293 } 293 }
294 294
295 // Delete notifications that didn't receive an update. 295 // Delete notifications that didn't receive an update.
296 for (var chromeNotificationId in notifications) { 296 for (var chromeNotificationId in notifications) {
297 console.log('parseAndShowNotificationCards-delete-check ' + 297 console.log('parseAndShowNotificationCards-delete-check ' +
298 chromeNotificationId); 298 chromeNotificationId);
299 if (!(chromeNotificationId in cards)) { 299 if (!(chromeNotificationId in cards)) {
300 console.log( 300 console.log(
301 'showNotificationCards-delete ' + chromeNotificationId); 301 'showNotificationCards-delete ' + chromeNotificationId);
302 cardSet.clear(chromeNotificationId); 302 cardSet.clear(chromeNotificationId, false);
303 } 303 }
304 } 304 }
305 305
306 // Create/update notifications and store their new properties. 306 // Create/update notifications and store their new properties.
307 var newNotificationsData = {}; 307 var newNotificationsData = {};
308 for (var chromeNotificationId in cards) { 308 for (var chromeNotificationId in cards) {
309 var notificationData = 309 var notificationData =
310 items.notificationsData[chromeNotificationId]; 310 items.notificationsData[chromeNotificationId];
311 var previousVersion = notifications[chromeNotificationId] && 311 var previousVersion = notifications[chromeNotificationId] &&
312 notificationData && 312 notificationData &&
(...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after
806 chrome.storage.local.set({userRespondedToToast: true}); 806 chrome.storage.local.set({userRespondedToToast: true});
807 return; 807 return;
808 } 808 }
809 809
810 // At this point we are guaranteed that the notification is a now card. 810 // At this point we are guaranteed that the notification is a now card.
811 chrome.metricsPrivate.recordUserAction('GoogleNow.Dismissed'); 811 chrome.metricsPrivate.recordUserAction('GoogleNow.Dismissed');
812 812
813 tasks.add(DISMISS_CARD_TASK_NAME, function() { 813 tasks.add(DISMISS_CARD_TASK_NAME, function() {
814 dismissalAttempts.start(); 814 dismissalAttempts.start();
815 815
816 // Deleting the notification in case it was re-added while this task was
817 // scheduled, waiting for execution.
818 cardSet.clear(chromeNotificationId);
819
820 instrumented.storage.local.get( 816 instrumented.storage.local.get(
821 ['pendingDismissals', 'notificationsData'], function(items) { 817 ['pendingDismissals', 'notificationsData'], function(items) {
822 items.pendingDismissals = items.pendingDismissals || []; 818 items.pendingDismissals = items.pendingDismissals || [];
823 items.notificationsData = items.notificationsData || {}; 819 items.notificationsData = items.notificationsData || {};
824 820
821 // Deleting the notification in case it was re-added while this task was
822 // scheduled, waiting for execution; also cleaning notification's data
823 // from storage.
824 cardSet.clear(chromeNotificationId, true);
825
825 var notificationData = items.notificationsData[chromeNotificationId]; 826 var notificationData = items.notificationsData[chromeNotificationId];
826 827
827 if (notificationData && notificationData.dismissals) { 828 if (notificationData && notificationData.dismissals) {
828 for (var i = 0; i < notificationData.dismissals.length; i++) { 829 for (var i = 0; i < notificationData.dismissals.length; i++) {
829 var dismissal = { 830 var dismissal = {
830 chromeNotificationId: chromeNotificationId, 831 chromeNotificationId: chromeNotificationId,
831 time: Date.now(), 832 time: Date.now(),
832 dismissalData: notificationData.dismissals[i] 833 dismissalData: notificationData.dismissals[i]
833 }; 834 };
834 items.pendingDismissals.push(dismissal); 835 items.pendingDismissals.push(dismissal);
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
1153 1154
1154 instrumented.location.onLocationUpdate.addListener(function(position) { 1155 instrumented.location.onLocationUpdate.addListener(function(position) {
1155 recordEvent(GoogleNowEvent.LOCATION_UPDATE); 1156 recordEvent(GoogleNowEvent.LOCATION_UPDATE);
1156 updateNotificationsCards(position); 1157 updateNotificationsCards(position);
1157 }); 1158 });
1158 1159
1159 instrumented.omnibox.onInputEntered.addListener(function(text) { 1160 instrumented.omnibox.onInputEntered.addListener(function(text) {
1160 localStorage['server_url'] = NOTIFICATION_CARDS_URL = text; 1161 localStorage['server_url'] = NOTIFICATION_CARDS_URL = text;
1161 initialize(); 1162 initialize();
1162 }); 1163 });
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