Bug 1395802. P3 - ensure mChannelStatistics.AddBytes() to happen on the main thread. draft
authorJW Wang <jwwang@mozilla.com>
Fri, 01 Sep 2017 14:28:06 +0800
changeset 660057 6fa91ade351fcd520a21147d35bfb223a0b50047
parent 660056 f1da397c3c9aec4008a5a8a2ab381b87ea07edeb
child 660058 4cfc0a9c2b4c514e772600cd94d0cc63e1fc275c
push id78285
push userjwwang@mozilla.com
push dateWed, 06 Sep 2017 15:49:42 +0000
bugs1395802
milestone57.0a1
Bug 1395802. P3 - ensure mChannelStatistics.AddBytes() to happen on the main thread. MozReview-Commit-ID: CbDl9mWZDFs
dom/media/MediaResource.cpp
--- 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;