Bug 1791761 - Add support for nsISerialEventTarget and nsIDirectTaskDispatcher to RemoteLazyInputStreamThread; r=dom-storage-reviewers,jesup

Differential Revision: https://phabricator.services.mozilla.com/D157818
This commit is contained in:
Jan Varga 2022-10-28 11:24:57 +00:00
parent 173881e7e3
commit 09461e0f96
2 changed files with 47 additions and 2 deletions

View File

@ -47,7 +47,8 @@ class ThreadInitializeRunnable final : public Runnable {
} // namespace
NS_IMPL_ISUPPORTS(RemoteLazyInputStreamThread, nsIObserver, nsIEventTarget)
NS_IMPL_ISUPPORTS(RemoteLazyInputStreamThread, nsIObserver, nsIEventTarget,
nsISerialEventTarget, nsIDirectTaskDispatcher)
bool RLISThreadIsInOrBeyondShutdown() {
// ShutdownPhase::XPCOMShutdownThreads matches
@ -182,6 +183,46 @@ RemoteLazyInputStreamThread::UnregisterShutdownTask(nsITargetShutdownTask*) {
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
RemoteLazyInputStreamThread::DispatchDirectTask(
already_AddRefed<nsIRunnable> aRunnable) {
nsCOMPtr<nsIRunnable> runnable(aRunnable);
StaticMutexAutoLock lock(gRemoteLazyThreadMutex);
nsCOMPtr<nsIDirectTaskDispatcher> dispatcher = do_QueryInterface(mThread);
if (dispatcher) {
return dispatcher->DispatchDirectTask(runnable.forget());
}
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP RemoteLazyInputStreamThread::DrainDirectTasks() {
StaticMutexAutoLock lock(gRemoteLazyThreadMutex);
nsCOMPtr<nsIDirectTaskDispatcher> dispatcher = do_QueryInterface(mThread);
if (dispatcher) {
return dispatcher->DrainDirectTasks();
}
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP RemoteLazyInputStreamThread::HaveDirectTasks(bool* aValue) {
StaticMutexAutoLock lock(gRemoteLazyThreadMutex);
nsCOMPtr<nsIDirectTaskDispatcher> dispatcher = do_QueryInterface(mThread);
if (dispatcher) {
return dispatcher->HaveDirectTasks(aValue);
}
return NS_ERROR_FAILURE;
}
bool IsOnDOMFileThread() {
MOZ_ASSERT(!RLISThreadIsInOrBeyondShutdown());

View File

@ -18,12 +18,16 @@ namespace mozilla {
class RemoteLazyInputStreamChild;
// XXX Rename this class since it's used by LSNG too.
class RemoteLazyInputStreamThread final : public nsIObserver,
public nsIEventTarget {
public nsISerialEventTarget,
public nsIDirectTaskDispatcher {
public:
NS_DECL_THREADSAFE_ISUPPORTS
NS_DECL_NSIOBSERVER
NS_DECL_NSIEVENTTARGET
NS_DECL_NSISERIALEVENTTARGET
NS_DECL_NSIDIRECTTASKDISPATCHER
static RemoteLazyInputStreamThread* Get();