Bug 841736 - Add observer and callback function to remove alarm API data on "webapps-clear-data" event. r=clian
authorSebastian Wong <swong15@illinois.edu>
Tue, 28 May 2013 13:29:02 -0400
changeset 144585 6a4bbef0f57239b1ab6c94188de810c5f33014c0
parent 144583 61ae64707ffba5bdf31a15bfd8078b90d3b39e22
child 144586 f063968fe9ad3b844a74af81ad2d00dd1372264f
push id2697
push userbbajaj@mozilla.com
push dateMon, 05 Aug 2013 18:49:53 +0000
treeherdermozilla-beta@dfec938c7b63 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersclian
bugs841736
milestone24.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 841736 - Add observer and callback function to remove alarm API data on "webapps-clear-data" event. r=clian
dom/alarm/AlarmService.jsm
--- a/dom/alarm/AlarmService.jsm
+++ b/dom/alarm/AlarmService.jsm
@@ -15,16 +15,20 @@ function debug(aStr) {
 const { classes: Cc, interfaces: Ci, utils: Cu, results: Cr } = Components;
 
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource://gre/modules/AlarmDB.jsm");
 
 this.EXPORTED_SYMBOLS = ["AlarmService"];
 
+XPCOMUtils.defineLazyGetter(this, "appsService", function() {
+  return Cc["@mozilla.org/AppsService;1"].getService(Ci.nsIAppsService);
+});
+
 XPCOMUtils.defineLazyServiceGetter(this, "ppmm",
                                    "@mozilla.org/parentprocessmessagemanager;1",
                                    "nsIMessageListenerManager");
 
 XPCOMUtils.defineLazyGetter(this, "messenger", function() {
   return Cc["@mozilla.org/system-message-internal;1"].getService(Ci.nsISystemMessagesInternal);
 });
 
@@ -44,16 +48,17 @@ let myGlobal = this;
  * using AlarmService.add() and AlarmService.remove(). Only Gecko code running
  * in the parent process should do this.
  */
 
 this.AlarmService = {
   init: function init() {
     debug("init()");
     Services.obs.addObserver(this, "profile-change-teardown", false);
+    Services.obs.addObserver(this, "webapps-clear-data",false);
 
     this._currentTimezoneOffset = (new Date()).getTimezoneOffset();
 
     let alarmHalService =
       this._alarmHalService = Cc["@mozilla.org/alarmHalService;1"]
                               .getService(Ci.nsIAlarmHalService);
 
     alarmHalService.setAlarmFiredCb(this._onAlarmFired.bind(this));
@@ -491,22 +496,40 @@ this.AlarmService = {
       }.bind(this)
     );
   },
 
   observe: function(aSubject, aTopic, aData) {
     switch (aTopic) {
       case "profile-change-teardown":
         this.uninit();
+        break;
+      case "webapps-clear-data":
+        let params =
+          aSubject.QueryInterface(Ci.mozIApplicationClearPrivateDataParams);
+        let manifestURL = appsService.getManifestURLByLocalId(params.appId);
+        this._db.getAll(
+          manifestURL,
+          function getAllSuccessCb(aAlarms) {
+            aAlarms.forEach(function removeAlarm(aAlarm) {
+              this.remove(aAlarm.id, manifestURL);
+            }, this);
+          }.bind(this),
+          function getAllErrorCb(aErrorMsg) {
+            throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
+          }
+        );
+        break;
     }
   },
 
   uninit: function uninit() {
     debug("uninit()");
     Services.obs.removeObserver(this, "profile-change-teardown");
+    Services.obs.removeObserver(this, "webapps-clear-data");
 
     this._messages.forEach(function(aMsgName) {
       ppmm.removeMessageListener(aMsgName, this);
     }.bind(this));
     ppmm = null;
 
     if (this._db) {
       this._db.close();