diff --git a/dom/media/gmp/GMPCrashHelper.cpp b/dom/media/gmp/GMPCrashHelper.cpp index fcf9c53abd4c..f46c4e833719 100644 --- a/dom/media/gmp/GMPCrashHelper.cpp +++ b/dom/media/gmp/GMPCrashHelper.cpp @@ -19,7 +19,9 @@ GMPCrashHelper::Destroy() delete this; } else { // Don't addref, as then we'd end up releasing after the detele runs! - NS_DispatchToMainThread(mozilla::NewNonOwningRunnableMethod(this, &GMPCrashHelper::Destroy)); + SystemGroup::Dispatch( + "GMPCrashHelper::Destroy", TaskCategory::Other, + NewNonOwningRunnableMethod(this, &GMPCrashHelper::Destroy)); } } diff --git a/dom/media/gmp/GMPParent.cpp b/dom/media/gmp/GMPParent.cpp index 3bfd2b155feb..54e78ad4da51 100644 --- a/dom/media/gmp/GMPParent.cpp +++ b/dom/media/gmp/GMPParent.cpp @@ -60,7 +60,7 @@ extern LogModule* GetGMPLog(); namespace gmp { -GMPParent::GMPParent() +GMPParent::GMPParent(AbstractThread* aMainThread) : mState(GMPStateNotLoaded) , mProcess(nullptr) , mDeleteProcessOnlyOnUnload(false) @@ -70,6 +70,7 @@ GMPParent::GMPParent() , mGMPContentChildCount(0) , mChildPid(0) , mHoldingSelfRef(false) + , mMainThread(aMainThread) { mPluginId = GeckoChildProcessHost::GetUniqueID(); LOGD("GMPParent ctor id=%u", mPluginId); @@ -302,7 +303,8 @@ GMPParent::Shutdown() class NotifyGMPShutdownTask : public Runnable { public: explicit NotifyGMPShutdownTask(const nsAString& aNodeId) - : mNodeId(aNodeId) + : Runnable("NotifyGMPShutdownTask") + , mNodeId(aNodeId) { } NS_IMETHOD Run() override { @@ -354,9 +356,9 @@ GMPParent::DeleteProcess() mProcess = nullptr; mState = GMPStateNotLoaded; - NS_DispatchToMainThread( - new NotifyGMPShutdownTask(NS_ConvertUTF8toUTF16(mNodeId)), - NS_DISPATCH_NORMAL); + nsCOMPtr r + = new NotifyGMPShutdownTask(NS_ConvertUTF8toUTF16(mNodeId)); + mMainThread->Dispatch(r.forget()); if (mHoldingSelfRef) { Release(); @@ -517,9 +519,9 @@ GMPParent::ActorDestroy(ActorDestroyReason aWhy) } // NotifyObservers is mainthread-only - NS_DispatchToMainThread(WrapRunnableNM(&GMPNotifyObservers, - mPluginId, mDisplayName, dumpID), - NS_DISPATCH_NORMAL); + nsCOMPtr r = WrapRunnableNM( + &GMPNotifyObservers, mPluginId, mDisplayName, dumpID); + mMainThread->Dispatch(r.forget()); } #endif // warn us off trying to close again @@ -728,8 +730,7 @@ GMPParent::ReadChromiumManifestFile(nsIFile* aFile) // DOM JSON parsing needs to run on the main thread. return InvokeAsync( - // Non DocGroup-version of AbstractThread::MainThread for the task in parent. - AbstractThread::MainThread(), this, __func__, + mMainThread, this, __func__, &GMPParent::ParseChromiumManifest, NS_ConvertUTF8toUTF16(json)); } diff --git a/dom/media/gmp/GMPParent.h b/dom/media/gmp/GMPParent.h index 091d26386f0b..9d9cbf758830 100644 --- a/dom/media/gmp/GMPParent.h +++ b/dom/media/gmp/GMPParent.h @@ -73,7 +73,7 @@ class GMPParent final : public PGMPParent public: NS_INLINE_DECL_THREADSAFE_REFCOUNTING(GMPParent) - GMPParent(); + explicit GMPParent(AbstractThread* aMainThread); RefPtr Init(GeckoMediaPluginServiceParent* aService, nsIFile* aPluginDir); nsresult CloneFrom(const GMPParent* aOther); @@ -228,6 +228,8 @@ private: #ifdef MOZ_CRASHREPORTER UniquePtr mCrashReporter; #endif + + const RefPtr mMainThread; }; } // namespace gmp diff --git a/dom/media/gmp/GMPService.cpp b/dom/media/gmp/GMPService.cpp index 9139b6d536d2..f3f4a059e257 100644 --- a/dom/media/gmp/GMPService.cpp +++ b/dom/media/gmp/GMPService.cpp @@ -79,12 +79,11 @@ public: if (NS_IsMainThread()) { service = GetOrCreateOnMainThread(); } else { - nsCOMPtr mainThread = do_GetMainThread(); - MOZ_ASSERT(mainThread); - RefPtr createHelper = new GMPServiceCreateHelper(); - mozilla::SyncRunnable::DispatchToThread(mainThread, createHelper, true); + mozilla::SyncRunnable::DispatchToThread( + SystemGroup::EventTargetFor(mozilla::TaskCategory::Other), + createHelper, true); service = createHelper->mService.forget(); } @@ -94,6 +93,7 @@ public: private: GMPServiceCreateHelper() + : Runnable("GMPServiceCreateHelper") { } diff --git a/dom/media/gmp/GMPServiceChild.cpp b/dom/media/gmp/GMPServiceChild.cpp index 8982bd449320..25c7e4b1f9f9 100644 --- a/dom/media/gmp/GMPServiceChild.cpp +++ b/dom/media/gmp/GMPServiceChild.cpp @@ -305,8 +305,9 @@ GeckoMediaPluginServiceChild::GetServiceChild() MozPromiseHolder* holder = mGetServiceChildPromises.AppendElement(); RefPtr promise = holder->Ensure(__func__); if (mGetServiceChildPromises.Length() == 1) { - NS_DispatchToMainThread(WrapRunnable(contentChild, - &dom::ContentChild::SendCreateGMPService)); + nsCOMPtr r = WrapRunnable( + contentChild, &dom::ContentChild::SendCreateGMPService); + SystemGroup::Dispatch("SendCreateGMPService", TaskCategory::Other, r.forget()); } return promise; } diff --git a/dom/media/gmp/GMPServiceParent.cpp b/dom/media/gmp/GMPServiceParent.cpp index 4f3b6d908855..f22e616ee3f5 100644 --- a/dom/media/gmp/GMPServiceParent.cpp +++ b/dom/media/gmp/GMPServiceParent.cpp @@ -94,6 +94,7 @@ GeckoMediaPluginServiceParent::GeckoMediaPluginServiceParent() , mInitPromiseMonitor("GeckoMediaPluginServiceParent::mInitPromiseMonitor") , mLoadPluginsFromDiskComplete(false) , mServiceUserCount(0) + , mMainThread(SystemGroup::AbstractMainThreadFor(TaskCategory::Other)) { MOZ_ASSERT(NS_IsMainThread()); mInitPromise.SetMonitor(&mInitPromiseMonitor); @@ -462,9 +463,10 @@ GeckoMediaPluginServiceParent::UnloadPlugins() plugin->CloseActive(true); } - nsCOMPtr task(NewRunnableMethod( - this, &GeckoMediaPluginServiceParent::NotifySyncShutdownComplete)); - NS_DispatchToMainThread(task); + nsCOMPtr task = NewRunnableMethod( + "GeckoMediaPluginServiceParent::NotifySyncShutdownComplete", + this, &GeckoMediaPluginServiceParent::NotifySyncShutdownComplete); + mMainThread->Dispatch(task.forget()); } void @@ -520,7 +522,8 @@ GeckoMediaPluginServiceParent::LoadFromEnvironment() class NotifyObserversTask final : public mozilla::Runnable { public: explicit NotifyObserversTask(const char* aTopic, nsString aData = EmptyString()) - : mTopic(aTopic) + : Runnable(aTopic) + , mTopic(aTopic) , mData(aData) {} NS_IMETHOD Run() override { @@ -553,9 +556,10 @@ void GeckoMediaPluginServiceParent::UpdateContentProcessGMPCapabilities() { if (!NS_IsMainThread()) { - nsCOMPtr task = - NewRunnableMethod(this, &GeckoMediaPluginServiceParent::UpdateContentProcessGMPCapabilities); - NS_DispatchToMainThread(task); + nsCOMPtr task = NewRunnableMethod( + "GeckoMediaPluginServiceParent::UpdateContentProcessGMPCapabilities", + this, &GeckoMediaPluginServiceParent::UpdateContentProcessGMPCapabilities); + mMainThread->Dispatch(task.forget()); return; } @@ -617,7 +621,7 @@ GeckoMediaPluginServiceParent::AsyncAddPluginDirectory(const nsAString& aDirecto thread, this, __func__, &GeckoMediaPluginServiceParent::AddOnGMPThread, dir) ->Then( - AbstractThread::MainThread(), // Non DocGroup-version for the task in parent. + mMainThread, __func__, [dir, self]() -> void { LOGD(("GeckoMediaPluginServiceParent::AsyncAddPluginDirectory %s succeeded", @@ -779,7 +783,7 @@ GeckoMediaPluginServiceParent::SelectPluginForAPI(const nsACString& aNodeId, } RefPtr -CreateGMPParent() +CreateGMPParent(AbstractThread* aMainThread) { #if defined(XP_LINUX) && defined(MOZ_GMP_SANDBOX) if (!SandboxInfo::Get().CanSandboxMedia()) { @@ -790,7 +794,7 @@ CreateGMPParent() NS_WARNING("Loading media plugin despite lack of sandboxing."); } #endif - return new GMPParent(); + return new GMPParent(aMainThread); } already_AddRefed @@ -798,7 +802,7 @@ GeckoMediaPluginServiceParent::ClonePlugin(const GMPParent* aOriginal) { MOZ_ASSERT(aOriginal); - RefPtr gmp = CreateGMPParent(); + RefPtr gmp = CreateGMPParent(mMainThread); nsresult rv = gmp ? gmp->CloneFrom(aOriginal) : NS_ERROR_NOT_AVAILABLE; if (NS_FAILED(rv)) { @@ -837,7 +841,7 @@ GeckoMediaPluginServiceParent::AddOnGMPThread(nsString aDirectory) return GenericPromise::CreateAndReject(NS_ERROR_FAILURE, __func__); } - RefPtr gmp = CreateGMPParent(); + RefPtr gmp = CreateGMPParent(mMainThread); if (!gmp) { NS_WARNING("Can't Create GMPParent"); return GenericPromise::CreateAndReject(NS_ERROR_FAILURE, __func__); @@ -920,9 +924,9 @@ GeckoMediaPluginServiceParent::RemoveOnGMPThread(const nsAString& aDirectory, } if (NS_SUCCEEDED(directory->Remove(true))) { mPluginsWaitingForDeletion.RemoveElement(aDirectory); - NS_DispatchToMainThread(new NotifyObserversTask("gmp-directory-deleted", - nsString(aDirectory)), - NS_DISPATCH_NORMAL); + nsCOMPtr task = new NotifyObserversTask( + "gmp-directory-deleted", nsString(aDirectory)); + mMainThread->Dispatch(task.forget()); } } } @@ -1537,7 +1541,9 @@ GeckoMediaPluginServiceParent::ClearRecentHistoryOnGMPThread(PRTime aSince) ClearNodeIdAndPlugin(filter); - NS_DispatchToMainThread(new NotifyObserversTask("gmp-clear-storage-complete"), NS_DISPATCH_NORMAL); + nsCOMPtr task + = new NotifyObserversTask("gmp-clear-storage-complete"); + mMainThread->Dispatch(task.forget()); } NS_IMETHODIMP @@ -1647,7 +1653,9 @@ GeckoMediaPluginServiceParent::ClearStorage() // Clear private-browsing storage. mTempGMPStorage.Clear(); - NS_DispatchToMainThread(new NotifyObserversTask("gmp-clear-storage-complete"), NS_DISPATCH_NORMAL); + nsCOMPtr task + = new NotifyObserversTask("gmp-clear-storage-complete"); + mMainThread->Dispatch(task.forget()); } already_AddRefed @@ -1664,9 +1672,10 @@ GeckoMediaPluginServiceParent::GetById(uint32_t aPluginId) GMPServiceParent::~GMPServiceParent() { - NS_DispatchToMainThread( - NewRunnableMethod(mService.get(), - &GeckoMediaPluginServiceParent::ServiceUserDestroyed)); + nsCOMPtr task = NewRunnableMethod( + "GeckoMediaPluginServiceParent::ServiceUserDestroyed", + mService.get(), &GeckoMediaPluginServiceParent::ServiceUserDestroyed); + mService->MainThread()->Dispatch(task.forget()); } mozilla::ipc::IPCResult diff --git a/dom/media/gmp/GMPServiceParent.h b/dom/media/gmp/GMPServiceParent.h index ea3ccf243656..35c3dc0b14d9 100644 --- a/dom/media/gmp/GMPServiceParent.h +++ b/dom/media/gmp/GMPServiceParent.h @@ -65,6 +65,8 @@ public: void UpdateContentProcessGMPCapabilities(); + AbstractThread* MainThread() const { return mMainThread; } + private: friend class GMPServiceParent; @@ -202,6 +204,8 @@ private: // Tracks how many users are running (on the GMP thread). Only when this count // drops to 0 can we safely shut down the thread. MainThreadOnly mServiceUserCount; + + const RefPtr mMainThread; }; nsresult ReadSalt(nsIFile* aPath, nsACString& aOutData);