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

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

Issue 19749007: Processing timefences from the server. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixing manifest typo Created 7 years, 5 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/background.js
diff --git a/chrome/browser/resources/google_now/background.js b/chrome/browser/resources/google_now/background.js
index e651a18c5676448240c59511113df7ba9a95070e..64e74ebaf84c9b17e88e93d5caf7c8d41c4edd6d 100644
--- a/chrome/browser/resources/google_now/background.js
+++ b/chrome/browser/resources/google_now/background.js
@@ -115,6 +115,7 @@ function areTasksConflicting(newTaskName, scheduledTaskName) {
var tasks = buildTaskManager(areTasksConflicting);
// Add error processing to API calls.
+tasks.instrumentApiFunction(chrome.alarms, 'getAll', 0);
rgustafson 2013/07/19 23:37:12 Where is alarms.getAll used?
vadimt 2013/07/22 19:22:52 Done.
tasks.instrumentApiFunction(chrome.identity, 'getAuthToken', 1);
tasks.instrumentApiFunction(chrome.identity, 'removeCachedAuthToken', 1);
tasks.instrumentApiFunction(chrome.location.onLocationUpdate, 'addListener', 0);
@@ -140,6 +141,7 @@ var dismissalAttempts = buildAttemptManager(
retryPendingDismissals,
INITIAL_RETRY_DISMISS_PERIOD_SECONDS,
MAXIMUM_RETRY_DISMISS_PERIOD_SECONDS);
+var cardSet = buildCardManager();
/**
* Diagnostic event identifier.
@@ -217,68 +219,6 @@ function setAuthorization(request, callbackBoolean) {
}
/**
- * Shows a notification and remembers information associated with it.
- * @param {Object} card Google Now card represented as a set of parameters for
- * showing a Chrome notification.
- * @param {Object} notificationsData Map from notification id to the data
- * associated with a notification.
- * @param {number=} opt_previousVersion The version of the shown card with this
- * id, if it exists, undefined otherwise.
- */
-function showNotification(card, notificationsData, opt_previousVersion) {
- console.log('showNotification ' + JSON.stringify(card) + ' ' +
- opt_previousVersion);
-
- if (typeof card.version != 'number') {
- console.error('card.version is not a number');
- // Fix card version.
- card.version = opt_previousVersion !== undefined ? opt_previousVersion : 0;
- }
-
- if (opt_previousVersion !== card.version) {
- try {
- // Delete a notification with the specified id if it already exists, and
- // then create a notification.
- chrome.notifications.create(
- card.notificationId,
- card.notification,
- function(notificationId) {
- if (!notificationId || chrome.runtime.lastError) {
- var errorMessage =
- chrome.runtime.lastError && chrome.runtime.lastError.message;
- console.error('notifications.create: ID=' + notificationId +
- ', ERROR=' + errorMessage);
- }
- });
- } catch (error) {
- console.error('Error in notifications.create: ' + error);
- }
- } else {
- try {
- // Update existing notification.
- chrome.notifications.update(
- card.notificationId,
- card.notification,
- function(wasUpdated) {
- if (!wasUpdated || chrome.runtime.lastError) {
- var errorMessage =
- chrome.runtime.lastError && chrome.runtime.lastError.message;
- console.error('notifications.update: UPDATED=' + wasUpdated +
- ', ERROR=' + errorMessage);
- }
- });
- } catch (error) {
- console.error('Error in notifications.update: ' + error);
- }
- }
-
- notificationsData[card.notificationId] = {
- actionUrls: card.actionUrls,
- version: card.version
- };
-}
-
-/**
* Parses JSON response from the notification server, show notifications and
* schedule next update.
* @param {string} response Server response.
@@ -317,9 +257,9 @@ function parseAndShowNotificationCards(response, callback) {
chrome.notifications.getAll(function(notifications) {
console.log('parseAndShowNotificationCards-getAll ' +
JSON.stringify(notifications));
- // TODO(vadimt): Figure out what to do when notifications are disabled for
- // our extension.
- notifications = notifications || {};
+ // TODO(vadimt): Figure out what to do when notifications are disabled for
rgustafson 2013/07/19 23:37:12 Why was this un-tabbed? It should be on the level
vadimt 2013/07/22 19:22:52 Done. I probably need to see my doctor.
+ // our extension.
+ notifications = notifications || {};
// Build a set of non-expired recent dismissals. It will be used for
// client-side filtering of cards.
@@ -351,9 +291,7 @@ function parseAndShowNotificationCards(response, callback) {
notificationId);
if (!(notificationId in updatedNotifications)) {
console.log('parseAndShowNotificationCards-delete ' + notificationId);
- chrome.notifications.clear(
- notificationId,
- function() {});
+ cardSet.clear(notificationId);
}
}
@@ -367,8 +305,10 @@ function parseAndShowNotificationCards(response, callback) {
var notificationData = items.notificationsData[card.notificationId];
var previousVersion = notifications[card.notificationId] &&
notificationData &&
- notificationData.previousVersion;
- showNotification(card, newNotificationsData, previousVersion);
+ notificationData.cardCreateInfo &&
+ notificationData.cardCreateInfo.version;
+ newNotificationsData[card.notificationId] =
+ cardSet.update(card, previousVersion);
}
}
@@ -641,9 +581,7 @@ function onNotificationClosed(notificationId, byUser) {
// Deleting the notification in case it was re-added while this task was
// scheduled, waiting for execution.
- chrome.notifications.clear(
- notificationId,
- function() {});
+ cardSet.clear(notificationId);
tasks.debugSetStepName('onNotificationClosed-get-pendingDismissals');
storage.get('pendingDismissals', function(items) {

Powered by Google App Engine
This is Rietveld 408576698