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 593024 a275e44391cb01245e5dcbbd4a76ee6d41ae63bb
parent 593023 cb68fd5a14f589053a90d1f5264e2e49b9dab8a8
child 593025 f6b8a2b1e245edf5c60641ca919e6b0cebde66dc
push id63579
push usergsquelart@mozilla.com
push dateTue, 13 Jun 2017 05:16:04 +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
@@ -426,17 +426,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),
@@ -2055,18 +2054,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();
 }
@@ -2480,36 +2480,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;