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

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

Issue 22647003: Remove chrome.* Function Instrumentation Inlining and Use a Separate Instrumented Object (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@SMLog
Patch Set: Quick Spacing Fix Created 7 years, 4 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 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 var MS_IN_SECOND = 1000; 7 var MS_IN_SECOND = 1000;
8 8
9 /** 9 /**
10 * Builds an object to manage notification card set. 10 * Builds an object to manage notification card set.
(...skipping 25 matching lines...) Expand all
36 * parameters for showing a Chrome notification. 36 * parameters for showing a Chrome notification.
37 */ 37 */
38 function showNotification(cardId, cardCreateInfo) { 38 function showNotification(cardId, cardCreateInfo) {
39 console.log('cardManager.showNotification ' + cardId + ' ' + 39 console.log('cardManager.showNotification ' + cardId + ' ' +
40 JSON.stringify(cardCreateInfo)); 40 JSON.stringify(cardCreateInfo));
41 41
42 if (cardCreateInfo.previousVersion !== cardCreateInfo.version) { 42 if (cardCreateInfo.previousVersion !== cardCreateInfo.version) {
43 try { 43 try {
44 // Delete a notification with the specified id if it already exists, and 44 // Delete a notification with the specified id if it already exists, and
45 // then create a notification. 45 // then create a notification.
46 chrome.notifications.create( 46 instrumented.notifications.create(
47 cardId, 47 cardId,
48 cardCreateInfo.notification, 48 cardCreateInfo.notification,
49 function(newNotificationId) { 49 function(newNotificationId) {
50 if (!newNotificationId || chrome.runtime.lastError) { 50 if (!newNotificationId || chrome.runtime.lastError) {
51 var errorMessage = chrome.runtime.lastError && 51 var errorMessage = chrome.runtime.lastError &&
52 chrome.runtime.lastError.message; 52 chrome.runtime.lastError.message;
53 console.error('notifications.create: ID=' + newNotificationId + 53 console.error('notifications.create: ID=' + newNotificationId +
54 ', ERROR=' + errorMessage); 54 ', ERROR=' + errorMessage);
55 return; 55 return;
56 } 56 }
57 57
58 scheduleHiding(cardId, cardCreateInfo.timeHide); 58 scheduleHiding(cardId, cardCreateInfo.timeHide);
59 }); 59 });
60 } catch (error) { 60 } catch (error) {
61 console.error('Error in notifications.create: ' + error); 61 console.error('Error in notifications.create: ' + error);
62 } 62 }
63 } else { 63 } else {
64 try { 64 try {
65 // Update existing notification. 65 // Update existing notification.
66 chrome.notifications.update( 66 instrumented.notifications.update(
67 cardId, 67 cardId,
68 cardCreateInfo.notification, 68 cardCreateInfo.notification,
69 function(wasUpdated) { 69 function(wasUpdated) {
70 if (!wasUpdated || chrome.runtime.lastError) { 70 if (!wasUpdated || chrome.runtime.lastError) {
71 var errorMessage = chrome.runtime.lastError && 71 var errorMessage = chrome.runtime.lastError &&
72 chrome.runtime.lastError.message; 72 chrome.runtime.lastError.message;
73 console.error('notifications.update: UPDATED=' + wasUpdated + 73 console.error('notifications.update: UPDATED=' + wasUpdated +
74 ', ERROR=' + errorMessage); 74 ', ERROR=' + errorMessage);
75 return; 75 return;
76 } 76 }
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 * @param {string} cardId Card ID. 140 * @param {string} cardId Card ID.
141 */ 141 */
142 function clear(cardId) { 142 function clear(cardId) {
143 console.log('cardManager.unregister ' + cardId); 143 console.log('cardManager.unregister ' + cardId);
144 144
145 chrome.notifications.clear(cardId, function() {}); 145 chrome.notifications.clear(cardId, function() {});
146 chrome.alarms.clear(cardShowPrefix + cardId); 146 chrome.alarms.clear(cardShowPrefix + cardId);
147 chrome.alarms.clear(cardHidePrefix + cardId); 147 chrome.alarms.clear(cardHidePrefix + cardId);
148 } 148 }
149 149
150 chrome.alarms.onAlarm.addListener(function(alarm) { 150 instrumented.alarms.onAlarm.addListener(function(alarm) {
151 console.log('cardManager.onAlarm ' + JSON.stringify(alarm)); 151 console.log('cardManager.onAlarm ' + JSON.stringify(alarm));
152 152
153 if (alarm.name.indexOf(cardShowPrefix) == 0) { 153 if (alarm.name.indexOf(cardShowPrefix) == 0) {
154 // Alarm to show the card. 154 // Alarm to show the card.
155 var cardId = alarm.name.substring(cardShowPrefix.length); 155 var cardId = alarm.name.substring(cardShowPrefix.length);
156 storage.get('notificationsData', function(items) { 156 instrumented.storage.local.get('notificationsData', function(items) {
157 items.notificationsData = items.notificationsData || {}; 157 items.notificationsData = items.notificationsData || {};
158 console.log('cardManager.onAlarm.get ' + JSON.stringify(items)); 158 console.log('cardManager.onAlarm.get ' + JSON.stringify(items));
159 var notificationData = items.notificationsData[cardId]; 159 var notificationData = items.notificationsData[cardId];
160 if (!notificationData) 160 if (!notificationData)
161 return; 161 return;
162 162
163 showNotification(cardId, notificationData.cardCreateInfo); 163 showNotification(cardId, notificationData.cardCreateInfo);
164 }); 164 });
165 } else if (alarm.name.indexOf(cardHidePrefix) == 0) { 165 } else if (alarm.name.indexOf(cardHidePrefix) == 0) {
166 // Alarm to hide the card. 166 // Alarm to hide the card.
167 var cardId = alarm.name.substring(cardHidePrefix.length); 167 var cardId = alarm.name.substring(cardHidePrefix.length);
168 chrome.notifications.clear(cardId, function() {}); 168 chrome.notifications.clear(cardId, function() {});
169 } 169 }
170 }); 170 });
171 171
172 return { 172 return {
173 update: update, 173 update: update,
174 clear: clear 174 clear: clear
175 }; 175 };
176 } 176 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698