Bug 1336345. Part 2 - some code cleanup. r=gerald
authorJW Wang <jwwang@mozilla.com>
Fri, 03 Feb 2017 15:16:50 +0800
changeset 479893 d729059d550a71caa819d9dd69470bd5cc669fed
parent 479892 370b66055c098a255d1d6a061b357f932ed70b5f
child 479894 2ccbbb9aabf6217f41140dd10e302f42594bc367
push id44393
push userVYV03354@nifty.ne.jp
push dateTue, 07 Feb 2017 13:53:48 +0000
reviewersgerald
bugs1336345
milestone54.0a1
Bug 1336345. Part 2 - some code cleanup. r=gerald MozReview-Commit-ID: 1XHkvz4aWxB
dom/media/MediaShutdownManager.cpp
dom/media/MediaShutdownManager.h
--- a/dom/media/MediaShutdownManager.cpp
+++ b/dom/media/MediaShutdownManager.cpp
@@ -14,18 +14,16 @@
 namespace mozilla {
 
 extern LazyLogModule gMediaDecoderLog;
 #define DECODER_LOG(type, msg) MOZ_LOG(gMediaDecoderLog, type, msg)
 
 NS_IMPL_ISUPPORTS(MediaShutdownManager, nsIAsyncShutdownBlocker)
 
 MediaShutdownManager::MediaShutdownManager()
-  : mIsObservingShutdown(false)
-  , mIsDoingXPCOMShutDown(false)
 {
   MOZ_ASSERT(NS_IsMainThread());
 }
 
 MediaShutdownManager::~MediaShutdownManager()
 {
   MOZ_ASSERT(NS_IsMainThread());
 }
@@ -83,46 +81,16 @@ MediaShutdownManager::InitStatics()
     auto buf = new char[CAPACITY];
     snprintf(buf, CAPACITY, "Failed to add shutdown blocker! rv=%x", uint32_t(rv));
     MOZ_CRASH_ANNOTATE(buf);
     MOZ_REALLY_CRASH();
   }
 }
 
 void
-MediaShutdownManager::EnsureCorrectShutdownObserverState()
-{
-  bool needShutdownObserver = mDecoders.Count() > 0;
-  if (needShutdownObserver != mIsObservingShutdown) {
-    mIsObservingShutdown = needShutdownObserver;
-    if (mIsObservingShutdown) {
-      nsresult rv = GetShutdownBarrier()->AddBlocker(
-        this, NS_LITERAL_STRING(__FILE__), __LINE__,
-        NS_LITERAL_STRING("MediaShutdownManager shutdown"));
-      if (NS_FAILED(rv)) {
-        // Leak the buffer on the heap to make sure that it lives long enough,
-        // as MOZ_CRASH_ANNOTATE expects the pointer passed to it to live to
-        // the end of the program.
-        const size_t CAPACITY = 256;
-        auto buf = new char[CAPACITY];
-        snprintf(buf, CAPACITY, "Failed to add shutdown blocker! rv=%x", uint32_t(rv));
-        MOZ_CRASH_ANNOTATE(buf);
-        MOZ_REALLY_CRASH();
-      }
-    } else {
-      GetShutdownBarrier()->RemoveBlocker(this);
-      // Clear our singleton reference. This will probably delete
-      // this instance, so don't deref |this| clearing sInstance.
-      sInstance = nullptr;
-      DECODER_LOG(LogLevel::Debug, ("MediaShutdownManager::BlockShutdown() end."));
-    }
-  }
-}
-
-void
 MediaShutdownManager::RemoveBlocker()
 {
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_ASSERT(mIsDoingXPCOMShutDown);
   MOZ_ASSERT(mDecoders.Count() == 0);
   GetShutdownBarrier()->RemoveBlocker(this);
   // Clear our singleton reference. This will probably delete
   // this instance, so don't deref |this| clearing sInstance.
--- a/dom/media/MediaShutdownManager.h
+++ b/dom/media/MediaShutdownManager.h
@@ -70,28 +70,21 @@ public:
   void Unregister(MediaDecoder* aDecoder);
 
 private:
 
   MediaShutdownManager();
   virtual ~MediaShutdownManager();
   void RemoveBlocker();
 
-  // Ensures we have a shutdown listener if we need one, and removes the
-  // listener and destroys the singleton if we don't.
-  void EnsureCorrectShutdownObserverState();
-
   static StaticRefPtr<MediaShutdownManager> sInstance;
 
   // References to the MediaDecoder. The decoders unregister themselves
   // in their Shutdown() method, so we'll drop the reference naturally when
   // we're shutting down (in the non xpcom-shutdown case).
   nsTHashtable<nsRefPtrHashKey<MediaDecoder>> mDecoders;
 
-  // True if we have an XPCOM shutdown observer.
-  bool mIsObservingShutdown;
-
-  bool mIsDoingXPCOMShutDown;
+  bool mIsDoingXPCOMShutDown = false;
 };
 
 } // namespace mozilla
 
 #endif