Bug 1420819 - run MediaCache::Flush() off the main thread. r=bechen,gerald

MozReview-Commit-ID: 4QR1TvORZlz

--HG--
extra : rebase_source : 1451c437c6daf80b15b6f23552900e2ef2467324
extra : intermediate-source : 3a0bdc29f6c70ac2a1479dbc7f10ebbd52a68456
extra : source : da25c3537d9b4665dff55f615467bcb62e5dde56
This commit is contained in:
JW Wang 2017-11-27 15:04:21 +08:00
Родитель 2b2a874b47
Коммит 57ea5cf9d9
1 изменённых файлов: 16 добавлений и 5 удалений

Просмотреть файл

@ -427,6 +427,8 @@ protected:
// end
void Truncate();
void FlushInternal(AutoLock&);
// There is at most one file-backed media cache.
// It is owned by all MediaCacheStreams that use it.
// This is a raw pointer set by GetMediaCache(), and reset by ~MediaCache(),
@ -695,13 +697,10 @@ MediaCacheStream::BlockList::NotifyBlockSwapped(int32_t aBlockIndex1,
}
void
MediaCache::Flush()
MediaCache::FlushInternal(AutoLock& aLock)
{
NS_ASSERTION(NS_IsMainThread(), "Only call on main thread");
AutoLock lock(mMonitor);
for (uint32_t blockIndex = 0; blockIndex < mIndex.Length(); ++blockIndex) {
FreeBlock(lock, blockIndex);
FreeBlock(aLock, blockIndex);
}
// Truncate index array.
@ -711,6 +710,18 @@ MediaCache::Flush()
mBlockCache->Flush();
}
void
MediaCache::Flush()
{
MOZ_ASSERT(NS_IsMainThread());
nsCOMPtr<nsIRunnable> r = NS_NewRunnableFunction(
"MediaCache::Flush", [self = RefPtr<MediaCache>(this)]() {
AutoLock lock(self->mMonitor);
self->FlushInternal(lock);
});
sThread->Dispatch(r.forget());
}
void
MediaCache::CloseStreamsForPrivateBrowsing()
{