Bug 1411504. P5 - handle CacheClientNotifySuspendedStatusChanged/QueueSuspendedStatusUpdate off the main thread. draft
authorJW Wang <jwwang@mozilla.com>
Tue, 24 Oct 2017 10:00:23 +0800
changeset 686107 6f0074c1cc158e4dea0d06af65d48b7fbb9a1bbd
parent 686106 7ca7d23fe3c7bba124556333b328e42b78414b93
child 686108 85e27e6f7299f407938752cd240aa0594756d2d3
child 687248 5c5b610efb91b2446dbaf45a328d28bbea5fcd03
push id86100
push userjwwang@mozilla.com
push dateWed, 25 Oct 2017 13:23:40 +0000
bugs1411504
milestone58.0a1
Bug 1411504. P5 - handle CacheClientNotifySuspendedStatusChanged/QueueSuspendedStatusUpdate off the main thread. MozReview-Commit-ID: 7Wc1tvd3S6x
dom/media/ChannelMediaResource.cpp
dom/media/MediaCache.cpp
--- a/dom/media/ChannelMediaResource.cpp
+++ b/dom/media/ChannelMediaResource.cpp
@@ -843,18 +843,21 @@ ChannelMediaResource::UpdatePrincipal()
     secMan->GetChannelResultPrincipal(mChannel, getter_AddRefs(principal));
     mCacheStream.UpdatePrincipal(principal);
   }
 }
 
 void
 ChannelMediaResource::CacheClientNotifySuspendedStatusChanged()
 {
-  NS_ASSERTION(NS_IsMainThread(), "Don't call on non-main thread");
-  mCallback->NotifySuspendedStatusChanged(IsSuspendedByCache());
+  mCallback->AbstractMainThread()->Dispatch(NewRunnableMethod<bool>(
+    "MediaResourceCallback::NotifySuspendedStatusChanged",
+    mCallback.get(),
+    &MediaResourceCallback::NotifySuspendedStatusChanged,
+    IsSuspendedByCache()));
 }
 
 nsresult
 ChannelMediaResource::Seek(int64_t aOffset, bool aResume)
 {
   MOZ_ASSERT(NS_IsMainThread());
   LOG("Seek requested for aOffset [%" PRId64 "]", aOffset);
 
--- a/dom/media/MediaCache.cpp
+++ b/dom/media/MediaCache.cpp
@@ -1567,17 +1567,17 @@ MediaCache::QueueUpdate()
   // don't leak a runnable in that case.
   nsCOMPtr<nsIRunnable> event = new UpdateEvent(this);
   SystemGroup::Dispatch(TaskCategory::Other, event.forget());
 }
 
 void
 MediaCache::QueueSuspendedStatusUpdate(int64_t aResourceID)
 {
-  NS_ASSERTION(NS_IsMainThread(), "Only call on main thread");
+  mReentrantMonitor.AssertCurrentThreadIn();
   if (!mSuspendedStatusToNotify.Contains(aResourceID)) {
     mSuspendedStatusToNotify.AppendElement(aResourceID);
   }
 }
 
 #ifdef DEBUG_VERIFY_CACHE
 void
 MediaCache::Verify()
@@ -2184,22 +2184,23 @@ void
 MediaCacheStream::Close()
 {
   NS_ASSERTION(NS_IsMainThread(), "Only call on main thread");
 
   if (!mMediaCache || mClosed) {
     return;
   }
 
+  ReentrantMonitorAutoEnter mon(mMediaCache->GetReentrantMonitor());
+
   // Closing a stream will change the return value of
   // MediaCacheStream::AreAllStreamsForResourceSuspended as well as
   // ChannelMediaResource::IsSuspendedByCache. Let's notify it.
   mMediaCache->QueueSuspendedStatusUpdate(mResourceID);
 
-  ReentrantMonitorAutoEnter mon(mMediaCache->GetReentrantMonitor());
   mClosed = true;
   mMediaCache->ReleaseStreamBlocks(this);
   // Wake up any blocked readers
   mon.NotifyAll();
 
   // Queue an Update since we may have created more free space. Don't do
   // it from CloseInternal since that gets called by Update() itself
   // sometimes, and we try to not to queue updates from Update().