Bug 1373888 - part2 : remove the timer which was used for b2g. draft
authorAlastor Wu <alwu@mozilla.com>
Fri, 18 Aug 2017 14:10:11 +0800
changeset 648668 28b7d0560d0fdf5fef5960d0ecbe4909983f0945
parent 648667 3113ee31f98ac595b96faa0252882c3f37df95ea
child 648669 a0e49c8919212fa160c88aab7de597d63c64c9bd
child 648683 1e47b87b510360db8825f50d9ed1f8e9680aac5f
push id74847
push useralwu@mozilla.com
push dateFri, 18 Aug 2017 06:27:51 +0000
bugs1373888
milestone57.0a1
Bug 1373888 - part2 : remove the timer which was used for b2g. The timer was added for the b2g issue, now we can remove it. MozReview-Commit-ID: BNjIghImCzC
dom/html/HTMLMediaElement.cpp
dom/html/HTMLMediaElement.h
modules/libpref/init/all.js
--- a/dom/html/HTMLMediaElement.cpp
+++ b/dom/html/HTMLMediaElement.cpp
@@ -4161,64 +4161,29 @@ HTMLMediaElement::WakeLockBoolWrapper::o
     return *this;
   }
 
   mValue = val;
   UpdateWakeLock();
   return *this;
 }
 
-HTMLMediaElement::WakeLockBoolWrapper::~WakeLockBoolWrapper()
-{
-  if (mTimer) {
-    mTimer->Cancel();
-  }
-}
-
 void
 HTMLMediaElement::WakeLockBoolWrapper::UpdateWakeLock()
 {
   MOZ_ASSERT(NS_IsMainThread());
-
-  if (!mOuter) {
-    return;
-  }
+  MOZ_ASSERT(mOuter);
 
   bool playing = !mValue;
 
   if (playing) {
-    if (mTimer) {
-      mTimer->Cancel();
-      mTimer = nullptr;
-    }
     mOuter->WakeLockCreate();
-  } else if (!mTimer) {
-    // Don't release the wake lock immediately; instead, release it after a
-    // grace period.
-    int timeout = Preferences::GetInt("media.wakelock_timeout", 2000);
-    mTimer = do_CreateInstance("@mozilla.org/timer;1");
-    if (mTimer) {
-      mTimer->SetTarget(mOuter->MainThreadEventTarget());
-      mTimer->InitWithNamedFuncCallback(
-        TimerCallback,
-        this,
-        timeout,
-        nsITimer::TYPE_ONE_SHOT,
-        "dom::HTMLMediaElement::WakeLockBoolWrapper::UpdateWakeLock");
-    }
-  }
-}
-
-void
-HTMLMediaElement::WakeLockBoolWrapper::TimerCallback(nsITimer* aTimer,
-                                                     void* aClosure)
-{
-  WakeLockBoolWrapper* wakeLock = static_cast<WakeLockBoolWrapper*>(aClosure);
-  wakeLock->mOuter->WakeLockRelease();
-  wakeLock->mTimer = nullptr;
+  } else {
+    mOuter->WakeLockRelease();
+  }
 }
 
 void
 HTMLMediaElement::WakeLockCreate()
 {
   if (!mWakeLock) {
     RefPtr<power::PowerManagerService> pmService =
       power::PowerManagerService::GetInstance();
--- a/dom/html/HTMLMediaElement.h
+++ b/dom/html/HTMLMediaElement.h
@@ -818,34 +818,31 @@ protected:
 
   class WakeLockBoolWrapper {
   public:
     explicit WakeLockBoolWrapper(bool val = false)
       : mValue(val)
       , mOuter(nullptr)
     {}
 
-    ~WakeLockBoolWrapper();
+    ~WakeLockBoolWrapper() {};
 
     void SetOuter(HTMLMediaElement* outer) { mOuter = outer; }
 
     MOZ_IMPLICIT operator bool() const { return mValue; }
 
     WakeLockBoolWrapper& operator=(bool val);
 
     bool operator !() const { return !mValue; }
 
-    static void TimerCallback(nsITimer* aTimer, void* aClosure);
-
   private:
     void UpdateWakeLock();
 
     bool mValue;
     HTMLMediaElement* mOuter;
-    nsCOMPtr<nsITimer> mTimer;
   };
 
   // Holds references to the DOM wrappers for the MediaStreams that we're
   // writing to.
   struct OutputMediaStream {
     OutputMediaStream();
     ~OutputMediaStream();
 
--- a/modules/libpref/init/all.js
+++ b/modules/libpref/init/all.js
@@ -352,19 +352,16 @@ pref("media.throttle-factor", 2);
 // readahead_limit if the download is fast. This pref toggles the "and the
 // download is fast" check off, so that we can always throttle the download
 // once the readaheadd limit is reached even on a slow network.
 pref("media.throttle-regardless-of-download-rate", false);
 
 // Master HTML5 media volume scale.
 pref("media.volume_scale", "1.0");
 
-// Timeout for wakelock release
-pref("media.wakelock_timeout", 2000);
-
 // Whether we should play videos opened in a "video document", i.e. videos
 // opened as top-level documents, as opposed to inside a media element.
 pref("media.play-stand-alone", true);
 
 pref("media.hardware-video-decoding.enabled", true);
 pref("media.hardware-video-decoding.force-enabled", false);
 
 #ifdef MOZ_FMP4