Bug 1373888 - part3 : rename the topic of the wake lock. draft
authorAlastor Wu <alwu@mozilla.com>
Fri, 18 Aug 2017 15:21:34 +0800
changeset 648683 1e47b87b510360db8825f50d9ed1f8e9680aac5f
parent 648668 28b7d0560d0fdf5fef5960d0ecbe4909983f0945
child 648684 48fd72a340ff05d2566aaf2048eb31549074d5a2
child 649644 681c87716dc2f5ecd9f299905b606cc90059b4dd
push id74855
push useralwu@mozilla.com
push dateFri, 18 Aug 2017 07:32:34 +0000
bugs1373888
milestone57.0a1
Bug 1373888 - part3 : rename the topic of the wake lock. For knowing the wake lock usage more clearly, we should use more specific topic name. In OSX, you can use "$ pmset -g assertions" to check all the wakelock. In Windows, using "$ powser -energy" to generate the energy report. MozReview-Commit-ID: rAXnkxTvLc
dom/html/HTMLMediaElement.cpp
dom/html/HTMLVideoElement.cpp
widget/cocoa/nsAppShell.mm
widget/gtk/WakeLockListener.cpp
widget/windows/nsAppShell.cpp
--- a/dom/html/HTMLMediaElement.cpp
+++ b/dom/html/HTMLMediaElement.cpp
@@ -4185,17 +4185,17 @@ void
 HTMLMediaElement::WakeLockCreate()
 {
   if (!mWakeLock) {
     RefPtr<power::PowerManagerService> pmService =
       power::PowerManagerService::GetInstance();
     NS_ENSURE_TRUE_VOID(pmService);
 
     ErrorResult rv;
-    mWakeLock = pmService->NewWakeLock(NS_LITERAL_STRING("cpu"),
+    mWakeLock = pmService->NewWakeLock(NS_LITERAL_STRING("audio-playing"),
                                        OwnerDoc()->GetInnerWindow(),
                                        rv);
   }
 }
 
 void
 HTMLMediaElement::WakeLockRelease()
 {
--- a/dom/html/HTMLVideoElement.cpp
+++ b/dom/html/HTMLVideoElement.cpp
@@ -327,17 +327,17 @@ HTMLVideoElement::UpdateScreenWakeLock()
   }
 
   if (!mScreenWakeLock && !mPaused && !hidden && HasVideo()) {
     RefPtr<power::PowerManagerService> pmService =
       power::PowerManagerService::GetInstance();
     NS_ENSURE_TRUE_VOID(pmService);
 
     ErrorResult rv;
-    mScreenWakeLock = pmService->NewWakeLock(NS_LITERAL_STRING("screen"),
+    mScreenWakeLock = pmService->NewWakeLock(NS_LITERAL_STRING("video-playing"),
                                              OwnerDoc()->GetInnerWindow(),
                                              rv);
   }
 }
 
 void
 HTMLVideoElement::Init()
 {
--- a/widget/cocoa/nsAppShell.mm
+++ b/widget/cocoa/nsAppShell.mm
@@ -55,17 +55,19 @@ public:
   NS_DECL_ISUPPORTS;
 
 private:
   ~MacWakeLockListener() {}
 
   IOPMAssertionID mAssertionID = kIOPMNullAssertionID;
 
   NS_IMETHOD Callback(const nsAString& aTopic, const nsAString& aState) override {
-    if (!aTopic.EqualsASCII("screen")) {
+    if (!aTopic.EqualsASCII("screen") &&
+        !aTopic.EqualsASCII("audio-playing") &&
+        !aTopic.EqualsASCII("video-playing")) {
       return NS_OK;
     }
     // 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")) {
       // Prevent screen saver.
       CFStringRef cf_topic =
         ::CFStringCreateWithCharacters(kCFAllocatorDefault,
--- a/widget/gtk/WakeLockListener.cpp
+++ b/widget/gtk/WakeLockListener.cpp
@@ -338,17 +338,19 @@ WakeLockListener::Shutdown()
 
 nsresult
 WakeLockListener::Callback(const nsAString& topic, const nsAString& state)
 {
   if (!mConnection) {
     return NS_ERROR_FAILURE;
   }
 
-  if(!topic.Equals(NS_LITERAL_STRING("screen")))
+  if(!topic.Equals(NS_LITERAL_STRING("screen")) &&
+     !topic.Equals(NS_LITERAL_STRING("audio-playing")) &&
+     !topic.Equals(NS_LITERAL_STRING("video-playing")))
     return NS_OK;
 
   WakeLockTopic* topicLock = mTopics.Get(topic);
   if (!topicLock) {
     topicLock = new WakeLockTopic(topic, mConnection);
     mTopics.Put(topic, topicLock);
   }
 
--- a/widget/windows/nsAppShell.cpp
+++ b/widget/windows/nsAppShell.cpp
@@ -46,17 +46,19 @@ class WinWakeLockListener final : public
 {
 public:
   NS_DECL_ISUPPORTS;
 
 private:
   ~WinWakeLockListener() {}
 
   NS_IMETHOD Callback(const nsAString& aTopic, const nsAString& aState) {
-    if (!aTopic.EqualsASCII("screen")) {
+    if (!aTopic.EqualsASCII("screen") &&
+        !aTopic.EqualsASCII("audio-playing") &&
+        !aTopic.EqualsASCII("video-playing")) {
       return NS_OK;
     }
     // 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")) {
       WAKE_LOCK_LOG("WinWakeLock: Blocking screen saver");
       // Prevent the display turning off and block the screen saver.
       SetThreadExecutionState(ES_DISPLAY_REQUIRED|ES_CONTINUOUS);