Bug 1394724. P4 - merge MediaCacheStream::Close() and CloseInternal(). draft
authorJW Wang <jwwang@mozilla.com>
Tue, 29 Aug 2017 16:46:42 +0800
changeset 656339 f4824bc31723ee2dc3bd0c2405aeee7b40680d54
parent 656338 6fe18257507f2f939fa24d03e69e1120ae1c0edb
child 729106 46b54a3b021f51a4199a7a5c4538f02075407aed
push id77176
push userjwwang@mozilla.com
push dateThu, 31 Aug 2017 02:42:53 +0000
bugs1394724
milestone57.0a1
Bug 1394724. P4 - merge MediaCacheStream::Close() and CloseInternal(). MozReview-Commit-ID: Fo43lKYPA0m
dom/media/MediaCache.cpp
dom/media/MediaCache.h
--- a/dom/media/MediaCache.cpp
+++ b/dom/media/MediaCache.cpp
@@ -2103,46 +2103,39 @@ MediaCacheStream::AreAllStreamsForResour
   return true;
 }
 
 void
 MediaCacheStream::Close()
 {
   NS_ASSERTION(NS_IsMainThread(), "Only call on main thread");
 
-  if (!mMediaCache) {
+  if (!mMediaCache || mClosed) {
     return;
   }
 
+  mClosed = true;
+
+  // Closing a stream will change the return value of
+  // MediaCacheStream::AreAllStreamsForResourceSuspended as well as
+  // ChannelMediaResource::IsSuspendedByCache. Let's notify it.
+  mMediaCache->QueueSuspendedStatusUpdate(mResourceID);
+
   ReentrantMonitorAutoEnter mon(mMediaCache->GetReentrantMonitor());
-  CloseInternal(mon);
+  mMediaCache->ReleaseStreamBlocks(this);
+  // Wake up any blocked readers
+  mon.NotifyAll();
+
   // Queue an Update since we may have created more free space. Don't do
   // it from CloseInternal since that gets called by Update() itself
   // sometimes, and we try to not to queue updates from Update().
   mMediaCache->QueueUpdate();
 }
 
 void
-MediaCacheStream::CloseInternal(ReentrantMonitorAutoEnter& aReentrantMonitor)
-{
-  NS_ASSERTION(NS_IsMainThread(), "Only call on main thread");
-
-  if (mClosed)
-    return;
-  mClosed = true;
-  // Closing a stream will change the return value of
-  // MediaCacheStream::AreAllStreamsForResourceSuspended as well as
-  // ChannelMediaResource::IsSuspendedByCache. Let's notify it.
-  mMediaCache->QueueSuspendedStatusUpdate(mResourceID);
-  mMediaCache->ReleaseStreamBlocks(this);
-  // Wake up any blocked readers
-  aReentrantMonitor.NotifyAll();
-}
-
-void
 MediaCacheStream::Pin()
 {
   ReentrantMonitorAutoEnter mon(mMediaCache->GetReentrantMonitor());
   ++mPinCount;
   // Queue an Update since we may no longer want to read more into the
   // cache, if this stream's block have become non-evictable
   mMediaCache->QueueUpdate();
 }
--- a/dom/media/MediaCache.h
+++ b/dom/media/MediaCache.h
@@ -420,22 +420,16 @@ private:
   // This method assumes that the cache monitor is held and can be called on
   // any thread.
   int64_t GetNextCachedDataInternal(int64_t aOffset);
   // Writes |mPartialBlock| to disk.
   // Used by |NotifyDataEnded| and |FlushPartialBlock|.
   // If |aNotifyAll| is true, this function will wake up readers who may be
   // waiting on the media cache monitor. Called on the main thread only.
   void FlushPartialBlockInternal(bool aNotify, ReentrantMonitorAutoEnter& aReentrantMonitor);
-  // A helper function to do the work of closing the stream. Assumes
-  // that the cache monitor is held. Main thread only.
-  // aReentrantMonitor is the nsAutoReentrantMonitor wrapper holding the cache monitor.
-  // This is used to NotifyAll to wake up threads that might be
-  // blocked on reading from this stream.
-  void CloseInternal(ReentrantMonitorAutoEnter& aReentrantMonitor);
   // Update mPrincipal given that data has been received from aPrincipal
   bool UpdatePrincipal(nsIPrincipal* aPrincipal);
 
   // Instance of MediaCache to use with this MediaCacheStream.
   RefPtr<MediaCache> mMediaCache;
 
   // These fields are main-thread-only.
   ChannelMediaResource*  mClient;