Bug 1371882 - MediaCacheStream::mInitialized is redundant, mMediaCache is non-null after initialization - r=cpearce
MozReview-Commit-ID: 6VIPMLmzuEP
--- 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;