Bug 795887 - Document sleep and process suspend notifications. r=roc
authorBrian R. Bondy <netzen@gmail.com>
Fri, 09 Nov 2012 10:34:10 -0500
changeset 112917 6e70f8b8b025672fac43d24efa38277ed023e867
parent 112916 98e22583895a02249604a89ab5120c092e7d4cd3
child 112918 479a7ef74ae040ad13d0d7bcbd8759c7e6ea9c15
push id23840
push userryanvm@gmail.com
push dateSat, 10 Nov 2012 12:26:58 +0000
treeherdermozilla-central@ea5c4c1b0edf [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs795887
milestone19.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 795887 - Document sleep and process suspend notifications. r=roc
widget/cocoa/nsToolkit.mm
widget/nsIWidget.h
widget/windows/nsWindow.cpp
--- a/widget/cocoa/nsToolkit.mm
+++ b/widget/cocoa/nsToolkit.mm
@@ -71,32 +71,32 @@ nsToolkit::PostSleepWakeNotification(con
 static void ToolkitSleepWakeCallback(void *refCon, io_service_t service, natural_t messageType, void * messageArgument)
 {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
 
   switch (messageType)
   {
     case kIOMessageSystemWillSleep:
       // System is going to sleep now.
-      nsToolkit::PostSleepWakeNotification("sleep_notification");
+      nsToolkit::PostSleepWakeNotification(NS_WIDGET_SLEEP_OBSERVER_TOPIC);
       ::IOAllowPowerChange(gRootPort, (long)messageArgument);
       break;
       
     case kIOMessageCanSystemSleep:
       // In this case, the computer has been idle for several minutes
       // and will sleep soon so you must either allow or cancel
       // this notification. Important: if you don’t respond, there will
       // be a 30-second timeout before the computer sleeps.
       // In Mozilla's case, we always allow sleep.
       ::IOAllowPowerChange(gRootPort,(long)messageArgument);
       break;
       
     case kIOMessageSystemHasPoweredOn:
       // Handle wakeup.
-      nsToolkit::PostSleepWakeNotification("wake_notification");
+      nsToolkit::PostSleepWakeNotification(NS_WIDGET_WAKE_OBSERVER_TOPIC);
       break;
   }
 
   NS_OBJC_END_TRY_ABORT_BLOCK;
 }
 
 nsresult
 nsToolkit::RegisterForSleepWakeNotifcations()
--- a/widget/nsIWidget.h
+++ b/widget/nsIWidget.h
@@ -156,16 +156,39 @@ enum nsCursor {   ///(normal cursor,    
 
 enum nsTopLevelWidgetZPlacement { // for PlaceBehind()
   eZPlacementBottom = 0,  // bottom of the window stack
   eZPlacementBelow,       // just below another widget
   eZPlacementTop          // top of the window stack
 };
 
 /**
+ * Before the OS goes to sleep, this topic is notified.
+ */
+#define NS_WIDGET_SLEEP_OBSERVER_TOPIC "sleep_notification"
+
+/**
+ * After the OS wakes up, this topic is notified.
+ */
+#define NS_WIDGET_WAKE_OBSERVER_TOPIC "wake_notification"
+
+/**
+ * Before the OS suspends the current process, this topic is notified.  Some
+ * OS will kill processes that are suspended instead of resuming them.
+ * For that reason this topic may be useful to safely close down resources.
+ */
+#define NS_WIDGET_SUSPEND_PROCESS_OBSERVER_TOPIC "suspend_process_notification"
+
+/**
+ * After the current process resumes from being suspended, this topic is
+ * notified.
+ */
+#define NS_WIDGET_RESUME_PROCESS_OBSERVER_TOPIC "resume_process_notification"
+
+/**
  * Preference for receiving IME updates
  *
  * If mWantUpdates is true, PuppetWidget will forward
  * nsIWidget::OnIMETextChange and nsIWidget::OnIMESelectionChange to the chrome
  * process. This incurs overhead from observers and IPDL. If the IME
  * implementation on a particular platform doesn't care about OnIMETextChange
  * and OnIMESelectionChange from content processes, they should set
  * mWantUpdates to false to avoid these overheads.
--- a/widget/windows/nsWindow.cpp
+++ b/widget/windows/nsWindow.cpp
@@ -5544,17 +5544,18 @@ void nsWindow::PostSleepWakeNotification
     return;
 
   gIsSleepMode = aIsSleepMode;
 
   nsCOMPtr<nsIObserverService> observerService =
     mozilla::services::GetObserverService();
   if (observerService)
     observerService->NotifyObservers(nullptr,
-      aIsSleepMode ? "sleep_notification" : "wake_notification", nullptr);
+      aIsSleepMode ? NS_WIDGET_SLEEP_OBSERVER_TOPIC :
+                     NS_WIDGET_WAKE_OBSERVER_TOPIC, nullptr);
 }
 
 // RemoveNextCharMessage() should be called by WM_KEYDOWN or WM_SYSKEYDOWM
 // message handler.  If there is no WM_(SYS)CHAR message for it, this
 // method does nothing.
 // NOTE: WM_(SYS)CHAR message is posted by TranslateMessage() API which is
 // called in message loop.  So, WM_(SYS)KEYDOWN message should have
 // WM_(SYS)CHAR message in the queue if the keydown event causes character