Bug 1373888 - part8 : add log. draft
authorAlastor Wu <alwu@mozilla.com>
Tue, 29 Aug 2017 15:28:28 +0800
changeset 654757 fed0c1c5b224545a6451689836d23ef2a977add8
parent 654756 0cb777f01d296511fad45ee5ba5d8433b405b7da
child 728648 2250440aadedbbebe8ca90c8a847692995723d84
push id76666
push useralwu@mozilla.com
push dateTue, 29 Aug 2017 07:28:48 +0000
bugs1373888
milestone57.0a1
Bug 1373888 - part8 : add log. MozReview-Commit-ID: JyLXnA9J9Ic
widget/cocoa/nsAppShell.mm
--- a/widget/cocoa/nsAppShell.mm
+++ b/widget/cocoa/nsAppShell.mm
@@ -41,16 +41,19 @@
 #endif
 
 #include <IOKit/pwr_mgt/IOPMLib.h>
 #include "nsIDOMWakeLockListener.h"
 #include "nsIPowerManagerService.h"
 
 using namespace mozilla::widget;
 
+#define WAKE_LOCK_LOG(...) MOZ_LOG(gMacWakeLockLog, mozilla::LogLevel::Debug, (__VA_ARGS__))
+static mozilla::LazyLogModule gMacWakeLockLog("MacWakeLock");
+
 // A wake lock listener that disables screen saver when requested by
 // Gecko. For example when we're playing video in a foreground tab we
 // don't want the screen saver to turn on.
 
 class MacWakeLockListener final : public nsIDOMMozWakeLockListener {
 public:
   NS_DECL_ISUPPORTS;
 
@@ -65,55 +68,58 @@ private:
         !aTopic.EqualsASCII("audio-playing") &&
         !aTopic.EqualsASCII("video-playing")) {
       return NS_OK;
     }
 
     // we should still hold the lock for background audio.
     if (aTopic.EqualsASCII("audio-playing") &&
         aState.EqualsASCII("locked-background")) {
+      WAKE_LOCK_LOG("keep audio playing even in background");
       return NS_OK;
     }
 
     bool shouldKeepDisplayOn = aTopic.EqualsASCII("screen") ||
                                aTopic.EqualsASCII("video-playing");
     CFStringRef assertionType = shouldKeepDisplayOn ?
       kIOPMAssertionTypeNoDisplaySleep : kIOPMAssertionTypeNoIdleSleep;
     IOPMAssertionID& assertionId = shouldKeepDisplayOn ?
       mAssertionNoDisplaySleepID : mAssertionNoIdleSleepID;
 
     // Note the wake lock code ensures that we're not sent duplicate
     // "locked-foreground" notifications when multiple wake locks are held.
     if (aState.EqualsASCII("locked-foreground")) {
       if (assertionId != kIOPMNullAssertionID) {
+        WAKE_LOCK_LOG("already has a lock");
         return NS_OK;
       }
       // Prevent screen saver.
       CFStringRef cf_topic =
         ::CFStringCreateWithCharacters(kCFAllocatorDefault,
                                        reinterpret_cast<const UniChar*>
                                          (aTopic.Data()),
                                        aTopic.Length());
       IOReturn success =
         ::IOPMAssertionCreateWithName(assertionType,
                                       kIOPMAssertionLevelOn,
                                       cf_topic,
                                       &assertionId);
       CFRelease(cf_topic);
       if (success != kIOReturnSuccess) {
-        NS_WARNING("failed to disable screensaver");
+        WAKE_LOCK_LOG("failed to disable screensaver");
       }
+      WAKE_LOCK_LOG("create screensaver");
     } else {
       // Re-enable screen saver.
-      NS_WARNING("Releasing screensaver");
       if (assertionId != kIOPMNullAssertionID) {
         IOReturn result = ::IOPMAssertionRelease(assertionId);
         if (result != kIOReturnSuccess) {
-          NS_WARNING("failed to release screensaver");
+          WAKE_LOCK_LOG("failed to release screensaver");
         }
+        WAKE_LOCK_LOG("Release screensaver");
         assertionId = kIOPMNullAssertionID;
       }
     }
     return NS_OK;
   }
 }; // MacWakeLockListener
 
 // defined in nsCocoaWindow.mm