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

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

Issue 1079163004: Now component extension (v1): unregister from GCM on startup (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Unregister before clearing storage Created 5 years, 8 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 e24f70b499b482ea73d0a51204315cb4d34bcb2f..2db2d1e6f8c2b094265dcf2992fdc4e7edba8f56 100644
--- a/chrome/browser/resources/google_now/background.js
+++ b/chrome/browser/resources/google_now/background.js
@@ -202,6 +202,7 @@ var tasks = buildTaskManager(areTasksConflicting);
// Add error processing to API calls.
wrapper.instrumentChromeApiFunction('gcm.onMessage.addListener', 0);
wrapper.instrumentChromeApiFunction('gcm.register', 1);
+wrapper.instrumentChromeApiFunction('gcm.unregister', 0);
wrapper.instrumentChromeApiFunction('metricsPrivate.getVariationParams', 1);
wrapper.instrumentChromeApiFunction('notifications.clear', 1);
wrapper.instrumentChromeApiFunction('notifications.create', 2);
@@ -1027,7 +1028,8 @@ function stopPollingCards() {
*/
function initialize() {
recordEvent(GoogleNowEvent.EXTENSION_START);
- registerForGcm();
+ // TODO(skare): Reenable, after signin.
+ unregisterFromGcm();
onStateChange();
}
@@ -1311,6 +1313,24 @@ function getGcmRegistrationId() {
}
/**
+ * Unregisters from GCM if previously registered.
+ */
+function unregisterFromGcm() {
+ fillFromChromeLocalStorage({gcmRegistrationId: undefined})
+ .then(function(items) {
+ if (items.gcmRegistrationId) {
+ console.log('Unregistering from gcm.');
+ instrumented.gcm.unregister(function() {
+ if (!chrome.runtime.lastError) {
+ chrome.storage.local.remove(
+ ['gcmNotificationKey', 'gcmRegistrationId']);
+ }
+ });
+ }
+ });
+}
+
+/**
* Polls the optin state.
* Sometimes we get the response to the opted in result too soon during
* push messaging. We'll recheck the optin state a few times before giving up.
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698