Bug 1371882 - MediaCache::Flush reinitializes block cache instead of recreating it - r?cpearce
This saves from destruction&re-construction efforts, makes the flushing less
prone to first-initialization failures.
And it will allow moving the choice of block cache outside of MediaCache::Init.
MozReview-Commit-ID: 8vSunM3rRkL
--- a/dom/media/MediaCache.cpp
+++ b/dom/media/MediaCache.cpp
@@ -698,21 +698,22 @@ MediaCache::Flush()
{
NS_ASSERTION(NS_IsMainThread(), "Only call on main thread");
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
for (uint32_t blockIndex = 0; blockIndex < mIndex.Length(); ++blockIndex) {
FreeBlock(blockIndex);
}
- // Truncate file, close it, and reopen
+ // Truncate index array.
Truncate();
NS_ASSERTION(mIndex.Length() == 0, "Blocks leaked?");
- mBlockCache = nullptr;
- Init();
+ // Re-initialize block cache.
+ nsresult rv = mBlockCache->Init();
+ NS_ENSURE_SUCCESS_VOID(rv);
}
void
MediaCache::CloseStreamsForPrivateBrowsing()
{
MOZ_ASSERT(NS_IsMainThread());
for (MediaCacheStream* s : mStreams) {
if (s->mIsPrivateBrowsing) {