Bug 1395802. P3 - ensure mChannelStatistics.AddBytes() to happen on the main thread.
MozReview-Commit-ID: CbDl9mWZDFs
--- a/dom/media/MediaResource.cpp
+++ b/dom/media/MediaResource.cpp
@@ -490,22 +490,24 @@ ChannelMediaResource::CopySegmentToCache
closure->mPrincipal, aFromSegment, aCount, aWriteCount);
}
nsresult
ChannelMediaResource::OnDataAvailable(nsIRequest* aRequest,
nsIInputStream* aStream,
uint32_t aCount)
{
+ // This might happen off the main thread.
NS_ASSERTION(mChannel.get() == aRequest, "Wrong channel!");
- {
- MutexAutoLock lock(mLock);
- mChannelStatistics.AddBytes(aCount);
- }
+ RefPtr<ChannelMediaResource> self = this;
+ nsCOMPtr<nsIRunnable> r = NS_NewRunnableFunction(
+ "ChannelMediaResource::OnDataAvailable",
+ [self, aCount]() { self->mChannelStatistics.AddBytes(aCount); });
+ mCallback->AbstractMainThread()->Dispatch(r.forget());
CopySegmentClosure closure;
nsIScriptSecurityManager* secMan = nsContentUtils::GetSecurityManager();
if (secMan && mChannel) {
secMan->GetChannelResultPrincipal(mChannel, getter_AddRefs(closure.mPrincipal));
}
closure.mResource = this;