Bug 851368 - Remove SimplePush registrations on app uninstall. r=dougt
authorNikhil Marathe <nsm.nikhil@gmail.com>
Thu, 04 Apr 2013 13:42:35 -0700
changeset 127693 6af472638173db65947ece1be175b71387157c14
parent 127692 a451409c4d941740edf76b30b68bef5c293f980b
child 127694 a65a4e4b385d44b9b7c579515420fb6200f2ef56
push id25916
push usernsm.nikhil@gmail.com
push dateThu, 04 Apr 2013 21:43:55 +0000
treeherdermozilla-inbound@6af472638173 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdougt
bugs851368
milestone23.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 851368 - Remove SimplePush registrations on app uninstall. r=dougt
dom/push/src/PushService.js
--- a/dom/push/src/PushService.js
+++ b/dom/push/src/PushService.js
@@ -292,16 +292,17 @@ PushService.prototype = {
         if (!this._prefs.get("enabled"))
           return;
 
         Services.obs.addObserver(this, "final-ui-startup", false);
         Services.obs.addObserver(this, "profile-change-teardown", false);
         Services.obs.addObserver(this,
                                  "network-interface-state-changed",
                                  false);
+        Services.obs.addObserver(this, "webapps-uninstall", false);
         break;
       case "final-ui-startup":
         Services.obs.removeObserver(this, "final-ui-startup");
         this.init();
         break;
       case "profile-change-teardown":
         Services.obs.removeObserver(this, "profile-change-teardown");
         this._shutdown();
@@ -346,16 +347,44 @@ PushService.prototype = {
                 if (this._requestQueue[i].channelID == channelID)
                   this._requestQueue.splice(i, 1);
             }
           }
         }
         else if (aSubject == this._retryTimeoutTimer) {
           this._beginWSSetup();
         }
+        break;
+      case "webapps-uninstall":
+        debug("webapps-uninstall");
+        let appsService = Cc["@mozilla.org/AppsService;1"]
+                            .getService(Ci.nsIAppsService);
+        var app = appsService.getAppFromObserverMessage(aData);
+        if (!app) {
+          debug("webapps-uninstall: No app found " + aData.origin);
+          return;
+        }
+
+        this._db.getAllByManifestURL(app.manifestURL, function(records) {
+          debug("Got " + records.length);
+          for (var i = 0; i < records.length; i++) {
+            this._db.delete(records[i].channelID, null, function() {
+              debug("app uninstall: " + app.manifestURL + " Could not delete entry " + records[i].channelID);
+            });
+            // courtesy, but don't establish a connection
+            // just for it
+            if (this._ws) {
+              debug("Had a connection, so telling the server");
+              this._request("unregister", {channelID: records[i].channelID});
+            }
+          }
+        }.bind(this), function() {
+          debug("Error in getAllByManifestURL: url " + app.manifestURL);
+        });
+
     }
   },
 
   _prefs : new Preferences("services.push."),
 
   get _UAID() {
     return this._prefs.get("userAgentID");
   },