| 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 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 } | 195 } |
| 196 | 196 |
| 197 return false; | 197 return false; |
| 198 } | 198 } |
| 199 | 199 |
| 200 var tasks = buildTaskManager(areTasksConflicting); | 200 var tasks = buildTaskManager(areTasksConflicting); |
| 201 | 201 |
| 202 // Add error processing to API calls. | 202 // Add error processing to API calls. |
| 203 wrapper.instrumentChromeApiFunction('gcm.onMessage.addListener', 0); | 203 wrapper.instrumentChromeApiFunction('gcm.onMessage.addListener', 0); |
| 204 wrapper.instrumentChromeApiFunction('gcm.register', 1); | 204 wrapper.instrumentChromeApiFunction('gcm.register', 1); |
| 205 wrapper.instrumentChromeApiFunction('gcm.unregister', 0); |
| 205 wrapper.instrumentChromeApiFunction('metricsPrivate.getVariationParams', 1); | 206 wrapper.instrumentChromeApiFunction('metricsPrivate.getVariationParams', 1); |
| 206 wrapper.instrumentChromeApiFunction('notifications.clear', 1); | 207 wrapper.instrumentChromeApiFunction('notifications.clear', 1); |
| 207 wrapper.instrumentChromeApiFunction('notifications.create', 2); | 208 wrapper.instrumentChromeApiFunction('notifications.create', 2); |
| 208 wrapper.instrumentChromeApiFunction('notifications.getPermissionLevel', 0); | 209 wrapper.instrumentChromeApiFunction('notifications.getPermissionLevel', 0); |
| 209 wrapper.instrumentChromeApiFunction('notifications.update', 2); | 210 wrapper.instrumentChromeApiFunction('notifications.update', 2); |
| 210 wrapper.instrumentChromeApiFunction('notifications.getAll', 0); | 211 wrapper.instrumentChromeApiFunction('notifications.getAll', 0); |
| 211 wrapper.instrumentChromeApiFunction( | 212 wrapper.instrumentChromeApiFunction( |
| 212 'notifications.onButtonClicked.addListener', 0); | 213 'notifications.onButtonClicked.addListener', 0); |
| 213 wrapper.instrumentChromeApiFunction('notifications.onClicked.addListener', 0); | 214 wrapper.instrumentChromeApiFunction('notifications.onClicked.addListener', 0); |
| 214 wrapper.instrumentChromeApiFunction('notifications.onClosed.addListener', 0); | 215 wrapper.instrumentChromeApiFunction('notifications.onClosed.addListener', 0); |
| (...skipping 805 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1020 // We don't clear localStorage since those values are still relevant | 1021 // We don't clear localStorage since those values are still relevant |
| 1021 // across Google Now start-stop events. | 1022 // across Google Now start-stop events. |
| 1022 chrome.storage.local.clear(); | 1023 chrome.storage.local.clear(); |
| 1023 } | 1024 } |
| 1024 | 1025 |
| 1025 /** | 1026 /** |
| 1026 * Initializes the event page on install or on browser startup. | 1027 * Initializes the event page on install or on browser startup. |
| 1027 */ | 1028 */ |
| 1028 function initialize() { | 1029 function initialize() { |
| 1029 recordEvent(GoogleNowEvent.EXTENSION_START); | 1030 recordEvent(GoogleNowEvent.EXTENSION_START); |
| 1030 registerForGcm(); | 1031 // TODO(skare): Reenable, after signin. |
| 1032 unregisterFromGcm(); |
| 1031 onStateChange(); | 1033 onStateChange(); |
| 1032 } | 1034 } |
| 1033 | 1035 |
| 1034 /** | 1036 /** |
| 1035 * Starts or stops the main pipeline for polling cards. | 1037 * Starts or stops the main pipeline for polling cards. |
| 1036 * @param {boolean} shouldPollCardsRequest true to start and | 1038 * @param {boolean} shouldPollCardsRequest true to start and |
| 1037 * false to stop polling cards. | 1039 * false to stop polling cards. |
| 1038 */ | 1040 */ |
| 1039 function setShouldPollCards(shouldPollCardsRequest) { | 1041 function setShouldPollCards(shouldPollCardsRequest) { |
| 1040 updateCardsAttempts.isRunning(function(currentValue) { | 1042 updateCardsAttempts.isRunning(function(currentValue) { |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1304 resolve(registrationId); | 1306 resolve(registrationId); |
| 1305 } else { | 1307 } else { |
| 1306 reject(); | 1308 reject(); |
| 1307 } | 1309 } |
| 1308 }); | 1310 }); |
| 1309 }); | 1311 }); |
| 1310 }); | 1312 }); |
| 1311 } | 1313 } |
| 1312 | 1314 |
| 1313 /** | 1315 /** |
| 1316 * Unregisters from GCM if previously registered. |
| 1317 */ |
| 1318 function unregisterFromGcm() { |
| 1319 fillFromChromeLocalStorage({gcmRegistrationId: undefined}) |
| 1320 .then(function(items) { |
| 1321 if (items.gcmRegistrationId) { |
| 1322 console.log('Unregistering from gcm.'); |
| 1323 instrumented.gcm.unregister(function() { |
| 1324 if (!chrome.runtime.lastError) { |
| 1325 chrome.storage.local.remove( |
| 1326 ['gcmNotificationKey', 'gcmRegistrationId']); |
| 1327 } |
| 1328 }); |
| 1329 } |
| 1330 }); |
| 1331 } |
| 1332 |
| 1333 /** |
| 1314 * Polls the optin state. | 1334 * Polls the optin state. |
| 1315 * Sometimes we get the response to the opted in result too soon during | 1335 * Sometimes we get the response to the opted in result too soon during |
| 1316 * push messaging. We'll recheck the optin state a few times before giving up. | 1336 * push messaging. We'll recheck the optin state a few times before giving up. |
| 1317 */ | 1337 */ |
| 1318 function pollOptedInWithRecheck() { | 1338 function pollOptedInWithRecheck() { |
| 1319 /** | 1339 /** |
| 1320 * Cleans up any state used to recheck the opt-in poll. | 1340 * Cleans up any state used to recheck the opt-in poll. |
| 1321 */ | 1341 */ |
| 1322 function clearPollingState() { | 1342 function clearPollingState() { |
| 1323 localStorage.removeItem('optedInCheckCount'); | 1343 localStorage.removeItem('optedInCheckCount'); |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1470 lastPollNowPayloads: items.lastPollNowPayloads, | 1490 lastPollNowPayloads: items.lastPollNowPayloads, |
| 1471 notificationGroups: items.notificationGroups | 1491 notificationGroups: items.notificationGroups |
| 1472 }); | 1492 }); |
| 1473 | 1493 |
| 1474 pollOptedInWithRecheck(); | 1494 pollOptedInWithRecheck(); |
| 1475 } | 1495 } |
| 1476 }); | 1496 }); |
| 1477 }); | 1497 }); |
| 1478 } | 1498 } |
| 1479 }); | 1499 }); |
| OLD | NEW |