Bug 1492095 - Replace use of XPCOM 'embedcomp/appstartup-notifier' after its removal in bug 1491741. r=philipp
authorGeoff Lankow <geoff@darktrojan.net>
Wed, 26 Sep 2018 20:20:38 +1200
changeset 33235 8b20130d8bb9b9e2e022644cd48df0eddd1b2cd3
parent 33234 6dfdc289650b385ba673e5887c29da3d2516f693
child 33236 e386db4f34bd5db42dcad676cb465b010b165299
push id387
push userclokep@gmail.com
push dateMon, 10 Dec 2018 21:30:47 +0000
reviewersphilipp
bugs1492095, 1491741
Bug 1492095 - Replace use of XPCOM 'embedcomp/appstartup-notifier' after its removal in bug 1491741. r=philipp
calendar/base/src/calAlarmMonitor.js
calendar/base/src/calAlarmService.js
calendar/base/src/calItemModule.js
calendar/base/src/calItemModule.manifest
--- a/calendar/base/src/calAlarmMonitor.js
+++ b/calendar/base/src/calAlarmMonitor.js
@@ -16,16 +16,19 @@ function peekAlarmWindow() {
  * set. This monitor is only used for DISPLAY type alarms.
  */
 function calAlarmMonitor() {
     this.wrappedJSObject = this;
     this.mAlarms = [];
 
     this.mSound = Components.classes["@mozilla.org/sound;1"]
                             .createInstance(Components.interfaces.nsISound);
+
+    Services.obs.addObserver(this, "alarm-service-startup");
+    Services.obs.addObserver(this, "alarm-service-shutdown");
 }
 
 var calAlarmMonitorClassID = Components.ID("{4b7ae030-ed79-11d9-8cd6-0800200c9a66}");
 var calAlarmMonitorInterfaces = [
     Components.interfaces.nsIObserver,
     Components.interfaces.calIAlarmServiceObserver
 ];
 calAlarmMonitor.prototype = {
--- a/calendar/base/src/calAlarmService.js
+++ b/calendar/base/src/calAlarmService.js
@@ -222,21 +222,20 @@ calAlarmService.prototype = {
         if (this.mStarted) {
             return;
         }
 
         Services.obs.addObserver(this, "profile-after-change");
         Services.obs.addObserver(this, "xpcom-shutdown");
         Services.obs.addObserver(this, "wake_notification");
 
-        /* Tell people that we're alive so they can start monitoring alarms.
-         */
-        let notifier = Components.classes["@mozilla.org/embedcomp/appstartup-notifier;1"]
-                                 .getService(Components.interfaces.nsIObserver);
-        notifier.observe(null, "alarm-service-startup", null);
+        // Make sure the alarm monitor is alive so it's observing the notification.
+        Cc["@mozilla.org/calendar/alarm-monitor;1"].getService(Ci.calIAlarmServiceObserver);
+        // Tell people that we're alive so they can start monitoring alarms.
+        Services.obs.notifyObservers(null, "alarm-service-startup");
 
         cal.getCalendarManager().addObserver(this.calendarManagerObserver);
 
         for (let calendar of cal.getCalendarManager().getCalendars({})) {
             this.observeCalendar(calendar);
         }
 
         /* set up a timer to update alarms every N hours */
@@ -276,20 +275,18 @@ calAlarmService.prototype = {
         this.mStarted = true;
     },
 
     shutdown: function() {
         if (!this.mStarted) {
             return;
         }
 
-        /* tell people that we're no longer running */
-        let notifier = Components.classes["@mozilla.org/embedcomp/appstartup-notifier;1"]
-                                 .getService(Components.interfaces.nsIObserver);
-        notifier.observe(null, "alarm-service-shutdown", null);
+        // Tell people that we're no longer running.
+        Services.obs.notifyObservers(null, "alarm-service-shutdown");
 
         if (this.mUpdateTimer) {
             this.mUpdateTimer.cancel();
             this.mUpdateTimer = null;
         }
 
         let calmgr = cal.getCalendarManager();
         calmgr.removeObserver(this.calendarManagerObserver);
--- a/calendar/base/src/calItemModule.js
+++ b/calendar/base/src/calItemModule.js
@@ -6,18 +6,18 @@ ChromeUtils.import("resource://gre/modul
 ChromeUtils.import("resource://gre/modules/Services.jsm");
 
 this.NSGetFactory = (cid) => {
     let scriptLoadOrder = [
         "resource://calendar/calendar-js/calItemBase.js",
         "resource://calendar/calendar-js/calCachedCalendar.js",
 
         "resource://calendar/calendar-js/calAlarm.js",
+        "resource://calendar/calendar-js/calAlarmMonitor.js",
         "resource://calendar/calendar-js/calAlarmService.js",
-        "resource://calendar/calendar-js/calAlarmMonitor.js",
         "resource://calendar/calendar-js/calAttendee.js",
         "resource://calendar/calendar-js/calAttachment.js",
         "resource://calendar/calendar-js/calCalendarManager.js",
         "resource://calendar/calendar-js/calCalendarSearchService.js",
         "resource://calendar/calendar-js/calDateTimeFormatter.js",
         "resource://calendar/calendar-js/calDeletedItems.js",
         "resource://calendar/calendar-js/calEvent.js",
         "resource://calendar/calendar-js/calFreeBusyService.js",
@@ -34,17 +34,17 @@ this.NSGetFactory = (cid) => {
         "resource://calendar/calendar-js/calWeekInfoService.js"
     ];
 
     for (let script of scriptLoadOrder) {
         Services.scriptloader.loadSubScript(script, this);
     }
 
     let components = [
-        calAlarm, calAlarmService, calAlarmMonitor, calAttendee, calAttachment, calCalendarManager,
+        calAlarm, calAlarmMonitor, calAlarmService, calAttendee, calAttachment, calCalendarManager,
         calCalendarSearchService, calDateTimeFormatter, calDeletedItems, calEvent, calFreeBusyService,
         calIcsParser, calIcsSerializer, calItipItem, calProtocolHandlerWebcal,
         calProtocolHandlerWebcals, calRecurrenceDate, calRecurrenceInfo, calRelation,
         calStartupService, calTransaction, calTransactionManager, calTodo, calWeekInfoService,
     ];
 
     this.NSGetFactory = XPCOMUtils.generateNSGetFactory(components);
     return this.NSGetFactory(cid);
--- a/calendar/base/src/calItemModule.manifest
+++ b/calendar/base/src/calItemModule.manifest
@@ -1,18 +1,16 @@
 component {b8db7c7f-c168-4e11-becb-f26c1c4f5f8f} calItemModule.js
 contract @mozilla.org/calendar/alarm;1 {b8db7c7f-c168-4e11-becb-f26c1c4f5f8f}
 
 component {7a9200dd-6a64-4fff-a798-c5802186e2cc} calItemModule.js
 contract @mozilla.org/calendar/alarm-service;1 {7a9200dd-6a64-4fff-a798-c5802186e2cc}
 
 component {4b7ae030-ed79-11d9-8cd6-0800200c9a66} calItemModule.js
 contract @mozilla.org/calendar/alarm-monitor;1 {4b7ae030-ed79-11d9-8cd6-0800200c9a66}
-category alarm-service-startup calendar-alarm-monitor service,@mozilla.org/calendar/alarm-monitor;1
-category alarm-service-shutdown calendar-alarm-monitor service,@mozilla.org/calendar/alarm-monitor;1
 
 component {5c8dcaa3-170c-4a73-8142-d531156f664d} calItemModule.js
 contract @mozilla.org/calendar/attendee;1 {5c8dcaa3-170c-4a73-8142-d531156f664d}
 
 component {5f76b352-ab75-4c2b-82c9-9206dbbf8571} calItemModule.js
 contract @mozilla.org/calendar/attachment;1 {5f76b352-ab75-4c2b-82c9-9206dbbf8571}
 
 component {f42585e7-e736-4600-985d-9624c1c51992} calItemModule.js