From dde81db3d7fa0162758cfb40cf2e8f0ccc067f95 Mon Sep 17 00:00:00 2001 From: Jean-Yves Avenard Date: Wed, 13 May 2020 00:12:19 +0000 Subject: [PATCH] Bug 1592488 - P9. Make a DOMCacheThread an AbstractThread. r=baku This is a step towards bug 1119864. However, at this stage we only need the cache thread to support direct task dispatch so that we can have IPDL MozPromise acting in a similar fashion to JS promise. Differential Revision: https://phabricator.services.mozilla.com/D74637 --- dom/cache/Manager.cpp | 23 ++++++++++------------- dom/cache/Manager.h | 7 ++++--- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/dom/cache/Manager.cpp b/dom/cache/Manager.cpp index e0ff761a1883..f98439d28dcb 100644 --- a/dom/cache/Manager.cpp +++ b/dom/cache/Manager.cpp @@ -6,6 +6,7 @@ #include "mozilla/dom/cache/Manager.h" +#include "mozilla/AbstractThread.h" #include "mozilla/AutoRestore.h" #include "mozilla/Mutex.h" #include "mozilla/StaticMutex.h" @@ -25,7 +26,7 @@ #include "nsIInputStream.h" #include "nsID.h" #include "nsIFile.h" -#include "nsIThread.h" +#include "nsISerialEventTarget.h" #include "nsThreadUtils.h" #include "nsTObserverArray.h" #include "QuotaClientImpl.h" @@ -251,8 +252,11 @@ class Manager::Factory { return Err(rv); } - ref = MakeSafeRefPtr(aManagerId.clonePtr(), ioThread, - ConstructorGuard{}); + ref = MakeSafeRefPtr( + aManagerId.clonePtr(), + AbstractThread::CreateXPCOMThreadWrapper( + ioThread, false /* aRequireTailDispatch */), + ConstructorGuard{}); // There may be an old manager for this origin in the process of // cleaning up. We need to tell the new manager about this so @@ -1887,7 +1891,8 @@ void Manager::ExecutePutAll( pinnedContext->Dispatch(action); } -Manager::Manager(SafeRefPtr aManagerId, nsIThread* aIOThread, +Manager::Manager(SafeRefPtr aManagerId, + already_AddRefed aIOThread, const ConstructorGuard&) : mManagerId(std::move(aManagerId)), mIOThread(aIOThread), @@ -1902,14 +1907,6 @@ Manager::~Manager() { NS_ASSERT_OWNINGTHREAD(Manager); MOZ_DIAGNOSTIC_ASSERT(mState == Closing); MOZ_DIAGNOSTIC_ASSERT(!mContext); - - nsCOMPtr ioThread; - mIOThread.swap(ioThread); - - // Don't spin the event loop in the destructor waiting for the thread to - // shutdown. Defer this to the main thread, instead. - MOZ_ALWAYS_SUCCEEDS(NS_DispatchToMainThread(NewRunnableMethod( - "nsIThread::AsyncShutdown", ioThread, &nsIThread::AsyncShutdown))); } void Manager::Init(Maybe aOldManager) { @@ -1920,7 +1917,7 @@ void Manager::Init(Maybe aOldManager) { // Context goes away. RefPtr setupAction = new SetupAction(); SafeRefPtr ref = Context::Create( - SafeRefPtrFromThis(), mIOThread->SerialEventTarget(), setupAction, + SafeRefPtrFromThis(), mIOThread, setupAction, aOldManager ? SomeRef(*aOldManager->mContext) : Nothing()); mContext = ref.unsafeGetRawPtr(); } diff --git a/dom/cache/Manager.h b/dom/cache/Manager.h index 14f39a74faab..4212d2c61714 100644 --- a/dom/cache/Manager.h +++ b/dom/cache/Manager.h @@ -16,7 +16,7 @@ #include "nsTArray.h" class nsIInputStream; -class nsIThread; +class nsISerialEventTarget; namespace mozilla { @@ -213,7 +213,7 @@ class Manager final : public SafeRefCounted { void MaybeAllowContextToClose(); SafeRefPtr mManagerId; - nsCOMPtr mIOThread; + nsCOMPtr mIOThread; // Weak reference cleared by RemoveContext() in Context destructor. Context* MOZ_NON_OWNING_REF mContext; @@ -270,7 +270,8 @@ class Manager final : public SafeRefCounted { struct ConstructorGuard {}; public: - Manager(SafeRefPtr aManagerId, nsIThread* aIOThread, + Manager(SafeRefPtr aManagerId, + already_AddRefed aIOThread, const ConstructorGuard&); ~Manager();