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 087b2ac97912b99ca456bfc1bb2d45d74e1c8676..0d2fba1b49221bbb590548441dde796c24503879 100644 |
--- a/chrome/browser/resources/google_now/background.js |
+++ b/chrome/browser/resources/google_now/background.js |
@@ -189,6 +189,7 @@ function areTasksConflicting(newTaskName, scheduledTaskName) { |
var tasks = buildTaskManager(areTasksConflicting); |
// Add error processing to API calls. |
+wrapper.instrumentChromeApiFunction('gcm.onMessage.addListener', 0); |
wrapper.instrumentChromeApiFunction('metricsPrivate.getVariationParams', 1); |
wrapper.instrumentChromeApiFunction('notifications.clear', 1); |
wrapper.instrumentChromeApiFunction('notifications.create', 2); |
@@ -204,10 +205,9 @@ wrapper.instrumentChromeApiFunction( |
wrapper.instrumentChromeApiFunction( |
'notifications.onShowSettings.addListener', 0); |
wrapper.instrumentChromeApiFunction('permissions.contains', 1); |
-wrapper.instrumentChromeApiFunction('pushMessaging.onMessage.addListener', 0); |
-wrapper.instrumentChromeApiFunction('storage.onChanged.addListener', 0); |
wrapper.instrumentChromeApiFunction('runtime.onInstalled.addListener', 0); |
wrapper.instrumentChromeApiFunction('runtime.onStartup.addListener', 0); |
+wrapper.instrumentChromeApiFunction('storage.onChanged.addListener', 0); |
wrapper.instrumentChromeApiFunction('tabs.create', 1); |
var updateCardsAttempts = buildAttemptManager( |
@@ -1015,6 +1015,7 @@ function stopPollingCards() { |
*/ |
function initialize() { |
recordEvent(GoogleNowEvent.EXTENSION_START); |
+ registerForGcm(); |
onStateChange(); |
} |
@@ -1334,13 +1335,15 @@ instrumented.storage.onChanged.addListener(function(changes, areaName) { |
} |
}); |
-instrumented.pushMessaging.onMessage.addListener(function(message) { |
- // message.payload will be '' when the extension first starts. |
- // Each time after signing in, we'll get latest payload for all channels. |
- // So, we need to poll the server only when the payload is non-empty and has |
- // changed. |
- console.log('pushMessaging.onMessage ' + JSON.stringify(message)); |
- if (message.payload.indexOf('REQUEST_CARDS') == 0) { |
+instrumented.gcm.onMessage.addListener(function(message) { |
+ console.log('gcm.onMessage ' + JSON.stringify(message)); |
+ if (!message || !message.data) { |
+ return; |
+ } |
+ |
+ var payload = message.data.payload; |
+ var subchannel = message.data.subchannelId; |
robliao
2015/02/18 00:04:25
So we still need subchannel ID? I thought subchann
skare_
2015/02/19 16:48:10
made this 'tag' - I also don't think we'll need it
|
+ if (payload.indexOf('REQUEST_CARDS') == 0) { |
tasks.add(ON_PUSH_MESSAGE_START_TASK_NAME, function() { |
// Accept promise rejection on failure since it's safer to do nothing, |
// preventing polling the server when the payload really didn't change. |
@@ -1349,9 +1352,8 @@ instrumented.pushMessaging.onMessage.addListener(function(message) { |
/** @type {Object<string, StoredNotificationGroup>} */ |
notificationGroups: {} |
}, PromiseRejection.ALLOW).then(function(items) { |
- if (items.lastPollNowPayloads[message.subchannelId] != |
- message.payload) { |
- items.lastPollNowPayloads[message.subchannelId] = message.payload; |
+ if (items.lastPollNowPayloads[message.subchannelId] != payload) { |
robliao
2015/02/18 00:04:25
message.subchannelId -> subchannelId
Two more inst
skare_
2015/02/19 16:48:10
Done.
|
+ items.lastPollNowPayloads[message.subchannelId] = payload; |
items.notificationGroups['PUSH' + message.subchannelId] = { |
cards: [], |