Bug 1336345. Part 2 - some code cleanup. draft
authorJW Wang <jwwang@mozilla.com>
Fri, 03 Feb 2017 15:16:50 +0800
changeset 479148 410cc275cf00bfb3f217e4e058437b5dab8fa226
parent 479147 e7a08656b5578ef62922024fa1821d9fe99b205c
child 544597 4eefd4bf8686dd6950f78d7de5166e6503f55d5c
push id44158
push userjwwang@mozilla.com
push dateMon, 06 Feb 2017 02:30:28 +0000
bugs1336345
milestone54.0a1
Bug 1336345. Part 2 - some code cleanup. 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());
 }
@@ -78,46 +76,16 @@ MediaShutdownManager::InitStatics()
       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