Bug 1395802. P3 - ensure mChannelStatistics.AddBytes() to happen on the main thread. r=cpearce
authorJW Wang <jwwang@mozilla.com>
Fri, 01 Sep 2017 14:28:06 +0800
changeset 428770 a70f47912fbe20ae0fdba26c0123c32b0356b439
parent 428769 8bfe3fa7b4f15d8fc4bd4598f51b36bbac6b22e3
child 428771 6469a2cb7df662afb23493b5566f99b6802fcb5a
push id7761
push userjlund@mozilla.com
push dateFri, 15 Sep 2017 00:19:52 +0000
treeherdermozilla-beta@c38455951db4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscpearce
bugs1395802
milestone57.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1395802. P3 - ensure mChannelStatistics.AddBytes() to happen on the main thread. r=cpearce 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;