| OLD | NEW |
| 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 Loading... |
| 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('showNotificationCards-delete-check ' + | 297 console.log('showNotificationCards-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 495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 808 chrome.storage.local.set({userRespondedToToast: true}); | 808 chrome.storage.local.set({userRespondedToToast: true}); |
| 809 return; | 809 return; |
| 810 } | 810 } |
| 811 | 811 |
| 812 // At this point we are guaranteed that the notification is a now card. | 812 // At this point we are guaranteed that the notification is a now card. |
| 813 chrome.metricsPrivate.recordUserAction('GoogleNow.Dismissed'); | 813 chrome.metricsPrivate.recordUserAction('GoogleNow.Dismissed'); |
| 814 | 814 |
| 815 tasks.add(DISMISS_CARD_TASK_NAME, function() { | 815 tasks.add(DISMISS_CARD_TASK_NAME, function() { |
| 816 dismissalAttempts.start(); | 816 dismissalAttempts.start(); |
| 817 | 817 |
| 818 // Deleting the notification in case it was re-added while this task was | |
| 819 // scheduled, waiting for execution. | |
| 820 cardSet.clear(chromeNotificationId); | |
| 821 | |
| 822 instrumented.storage.local.get( | 818 instrumented.storage.local.get( |
| 823 ['pendingDismissals', 'notificationsData'], function(items) { | 819 ['pendingDismissals', 'notificationsData'], function(items) { |
| 824 items.pendingDismissals = items.pendingDismissals || []; | 820 items.pendingDismissals = items.pendingDismissals || []; |
| 825 items.notificationsData = items.notificationsData || {}; | 821 items.notificationsData = items.notificationsData || {}; |
| 826 | 822 |
| 823 // Deleting the notification in case it was re-added while this task was |
| 824 // scheduled, waiting for execution; also cleaning notification's data |
| 825 // from storage. |
| 826 cardSet.clear(chromeNotificationId, true); |
| 827 |
| 827 var notificationData = items.notificationsData[chromeNotificationId]; | 828 var notificationData = items.notificationsData[chromeNotificationId]; |
| 828 | 829 |
| 829 if (notificationData && notificationData.dismissals) { | 830 if (notificationData && notificationData.dismissals) { |
| 830 for (var i = 0; i < notificationData.dismissals.length; i++) { | 831 for (var i = 0; i < notificationData.dismissals.length; i++) { |
| 831 var dismissal = { | 832 var dismissal = { |
| 832 chromeNotificationId: chromeNotificationId, | 833 chromeNotificationId: chromeNotificationId, |
| 833 time: Date.now(), | 834 time: Date.now(), |
| 834 dismissalData: notificationData.dismissals[i] | 835 dismissalData: notificationData.dismissals[i] |
| 835 }; | 836 }; |
| 836 items.pendingDismissals.push(dismissal); | 837 items.pendingDismissals.push(dismissal); |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1155 | 1156 |
| 1156 instrumented.location.onLocationUpdate.addListener(function(position) { | 1157 instrumented.location.onLocationUpdate.addListener(function(position) { |
| 1157 recordEvent(GoogleNowEvent.LOCATION_UPDATE); | 1158 recordEvent(GoogleNowEvent.LOCATION_UPDATE); |
| 1158 updateNotificationsCards(position); | 1159 updateNotificationsCards(position); |
| 1159 }); | 1160 }); |
| 1160 | 1161 |
| 1161 instrumented.omnibox.onInputEntered.addListener(function(text) { | 1162 instrumented.omnibox.onInputEntered.addListener(function(text) { |
| 1162 localStorage['server_url'] = NOTIFICATION_CARDS_URL = text; | 1163 localStorage['server_url'] = NOTIFICATION_CARDS_URL = text; |
| 1163 initialize(); | 1164 initialize(); |
| 1164 }); | 1165 }); |
| OLD | NEW |