Bug 1371882 - MediaCacheStream::mInitialized is redundant, mMediaCache is non-null after initialization - r=cpearce draft
authorGerald Squelart <gsquelart@mozilla.com>
Fri, 09 Jun 2017 13:48:06 +1200
changeset 595150 80df4e3bda168660812d420e26c6117c7ccc4b88
parent 595149 a4eaadb9c4bd40034e16a811878cf7663b6a66ce
child 595151 d83836ad127895197fba32cd69d282fe9b1c27df
push id64265
push usergsquelart@mozilla.com
push dateFri, 16 Jun 2017 03:37:56 +0000
reviewerscpearce
bugs1371882
milestone56.0a1
Bug 1371882 - MediaCacheStream::mInitialized is redundant, mMediaCache is non-null after initialization - r=cpearce MozReview-Commit-ID: 6VIPMLmzuEP
dom/media/MediaCache.cpp
dom/media/MediaCache.h
--- a/dom/media/MediaCache.cpp
+++ b/dom/media/MediaCache.cpp
@@ -436,17 +436,16 @@ MediaCacheFlusher::Observe(nsISupports *
   }
   return NS_OK;
 }
 
 MediaCacheStream::MediaCacheStream(ChannelMediaResource* aClient,
                                    bool aIsPrivateBrowsing)
   : mMediaCache(nullptr)
   , mClient(aClient)
-  , mInitialized(false)
   , mHasHadUpdate(false)
   , mClosed(false)
   , mDidNotifyDataEnded(false)
   , mResourceID(0)
   , mIsTransportSeekable(false)
   , mCacheSuspended(false)
   , mChannelEnded(false)
   , mChannelOffset(0)
@@ -2067,18 +2066,19 @@ MediaCacheStream::AreAllStreamsForResour
   return true;
 }
 
 void
 MediaCacheStream::Close()
 {
   NS_ASSERTION(NS_IsMainThread(), "Only call on main thread");
 
-  if (!mInitialized)
+  if (!mMediaCache) {
     return;
+  }
 
   ReentrantMonitorAutoEnter mon(mMediaCache->GetReentrantMonitor());
   CloseInternal(mon);
   // 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();
 }
@@ -2495,36 +2495,37 @@ MediaCacheStream::ReadFromCache(char* aB
   return NS_OK;
 }
 
 nsresult
 MediaCacheStream::Init()
 {
   NS_ASSERTION(NS_IsMainThread(), "Only call on main thread");
 
-  if (mInitialized)
+  if (mMediaCache) {
     return NS_OK;
+  }
 
   mMediaCache = MediaCache::GetMediaCache();
   if (!mMediaCache) {
     return NS_ERROR_FAILURE;
   }
   mMediaCache->OpenStream(this);
-  mInitialized = true;
   return NS_OK;
 }
 
 nsresult
 MediaCacheStream::InitAsClone(MediaCacheStream* aOriginal)
 {
   if (!aOriginal->IsAvailableForSharing())
     return NS_ERROR_FAILURE;
 
-  if (mInitialized)
+  if (mMediaCache) {
     return NS_OK;
+  }
 
   nsresult rv = Init();
   if (NS_FAILED(rv))
     return rv;
   mResourceID = aOriginal->mResourceID;
 
   // Grab cache blocks from aOriginal as readahead blocks for our stream
   ReentrantMonitorAutoEnter mon(mMediaCache->GetReentrantMonitor());
--- a/dom/media/MediaCache.h
+++ b/dom/media/MediaCache.h
@@ -439,18 +439,16 @@ private:
   bool UpdatePrincipal(nsIPrincipal* aPrincipal);
 
   // Instance of MediaCache to use with this MediaCacheStream.
   MediaCache* mMediaCache;
 
   // These fields are main-thread-only.
   ChannelMediaResource*  mClient;
   nsCOMPtr<nsIPrincipal> mPrincipal;
-  // Set to true when Init or InitAsClone has been called
-  bool                   mInitialized;
   // Set to true when MediaCache::Update() has finished while this stream
   // was present.
   bool                   mHasHadUpdate;
   // Set to true when the stream has been closed either explicitly or
   // due to an internal cache error
   bool                   mClosed;
   // True if CacheClientNotifyDataEnded has been called for this stream.
   bool                   mDidNotifyDataEnded;