diff --git a/dom/workers/WorkerPrivate.cpp b/dom/workers/WorkerPrivate.cpp index f5556c8f23fe..7ab14d666968 100644 --- a/dom/workers/WorkerPrivate.cpp +++ b/dom/workers/WorkerPrivate.cpp @@ -964,9 +964,7 @@ public: NS_IMPL_ISUPPORTS_INHERITED0(TopLevelWorkerFinishedRunnable, Runnable) -template -class WorkerPrivateParent::EventTarget final - : public nsISerialEventTarget +class WorkerPrivate::EventTarget final : public nsISerialEventTarget { // This mutex protects mWorkerPrivate and must be acquired *before* the // WorkerPrivate's mutex whenever they must both be held. @@ -977,14 +975,14 @@ class WorkerPrivateParent::EventTarget final public: explicit EventTarget(WorkerPrivate* aWorkerPrivate) - : mMutex("WorkerPrivateParent::EventTarget::mMutex"), + : mMutex("WorkerPrivate::EventTarget::mMutex"), mWorkerPrivate(aWorkerPrivate), mWeakNestedEventTarget(nullptr) { MOZ_ASSERT(aWorkerPrivate); } EventTarget(WorkerPrivate* aWorkerPrivate, nsIEventTarget* aNestedEventTarget) - : mMutex("WorkerPrivateParent::EventTarget::mMutex"), + : mMutex("WorkerPrivate::EventTarget::mMutex"), mWorkerPrivate(aWorkerPrivate), mWeakNestedEventTarget(aNestedEventTarget), mNestedEventTarget(aNestedEventTarget) { @@ -1652,23 +1650,20 @@ WorkerPrivateParent::Traverse(nsCycleCollectionTraversalCallback& aCb) } } -template nsresult -WorkerPrivateParent::DispatchPrivate(already_AddRefed aRunnable, - nsIEventTarget* aSyncLoopTarget) +WorkerPrivate::DispatchPrivate(already_AddRefed aRunnable, + nsIEventTarget* aSyncLoopTarget) { // May be called on any thread! RefPtr runnable(aRunnable); - WorkerPrivate* self = ParentAsWorkerPrivate(); - { MutexAutoLock lock(mMutex); - MOZ_ASSERT_IF(aSyncLoopTarget, self->mThread); + MOZ_ASSERT_IF(aSyncLoopTarget, mThread); - if (!self->mThread) { - if (ParentStatus() == Pending || self->mStatus == Pending) { + if (!mThread) { + if (ParentStatus() == Pending || mStatus == Pending) { mPreStartRunnables.AppendElement(runnable); return NS_OK; } @@ -1678,7 +1673,7 @@ WorkerPrivateParent::DispatchPrivate(already_AddRefed a return NS_ERROR_UNEXPECTED; } - if (self->mStatus == Dead || + if (mStatus == Dead || (!aSyncLoopTarget && ParentStatus() > Running)) { NS_WARNING("A runnable was posted to a worker that is already shutting " "down!"); @@ -1689,7 +1684,7 @@ WorkerPrivateParent::DispatchPrivate(already_AddRefed a if (aSyncLoopTarget) { rv = aSyncLoopTarget->Dispatch(runnable.forget(), NS_DISPATCH_NORMAL); } else { - rv = self->mThread->DispatchAnyThread(WorkerThreadFriendKey(), runnable.forget()); + rv = mThread->DispatchAnyThread(WorkerThreadFriendKey(), runnable.forget()); } if (NS_WARN_IF(NS_FAILED(rv))) { @@ -1729,6 +1724,14 @@ WorkerPrivateParent::DisableDebugger() } } +template +nsresult +WorkerPrivateParent::Dispatch(already_AddRefed aRunnable) +{ + WorkerPrivate* self = ParentAsWorkerPrivate(); + return self->DispatchPrivate(Move(aRunnable), nullptr); +} + template nsresult WorkerPrivateParent::DispatchControlRunnable( @@ -5354,14 +5357,10 @@ WorkerPrivate::GetPerformanceStorage() NS_IMPL_ISUPPORTS_INHERITED0(ExternalRunnableWrapper, WorkerRunnable) -template -NS_IMPL_ADDREF(WorkerPrivateParent::EventTarget) +NS_IMPL_ADDREF(WorkerPrivate::EventTarget) +NS_IMPL_RELEASE(WorkerPrivate::EventTarget) -template -NS_IMPL_RELEASE(WorkerPrivateParent::EventTarget) - -template -NS_INTERFACE_MAP_BEGIN(WorkerPrivateParent::EventTarget) +NS_INTERFACE_MAP_BEGIN(WorkerPrivate::EventTarget) NS_INTERFACE_MAP_ENTRY(nsISerialEventTarget) NS_INTERFACE_MAP_ENTRY(nsIEventTarget) NS_INTERFACE_MAP_ENTRY(nsISupports) @@ -5376,19 +5375,17 @@ NS_INTERFACE_MAP_BEGIN(WorkerPrivateParent::EventTarget) #endif NS_INTERFACE_MAP_END -template NS_IMETHODIMP -WorkerPrivateParent:: -EventTarget::DispatchFromScript(nsIRunnable* aRunnable, uint32_t aFlags) +WorkerPrivate::EventTarget::DispatchFromScript(nsIRunnable* aRunnable, + uint32_t aFlags) { nsCOMPtr event(aRunnable); return Dispatch(event.forget(), aFlags); } -template NS_IMETHODIMP -WorkerPrivateParent:: -EventTarget::Dispatch(already_AddRefed aRunnable, uint32_t aFlags) +WorkerPrivate::EventTarget::Dispatch(already_AddRefed aRunnable, + uint32_t aFlags) { // May be called on any thread! nsCOMPtr event(aRunnable); @@ -5421,18 +5418,16 @@ EventTarget::Dispatch(already_AddRefed aRunnable, uint32_t aFlags) return NS_OK; } -template NS_IMETHODIMP -WorkerPrivateParent:: -EventTarget::DelayedDispatch(already_AddRefed, uint32_t) +WorkerPrivate::EventTarget::DelayedDispatch(already_AddRefed, + uint32_t) + { return NS_ERROR_NOT_IMPLEMENTED; } -template NS_IMETHODIMP -WorkerPrivateParent:: -EventTarget::IsOnCurrentThread(bool* aIsOnCurrentThread) +WorkerPrivate::EventTarget::IsOnCurrentThread(bool* aIsOnCurrentThread) { // May be called on any thread! @@ -5449,10 +5444,8 @@ EventTarget::IsOnCurrentThread(bool* aIsOnCurrentThread) return NS_OK; } -template NS_IMETHODIMP_(bool) -WorkerPrivateParent:: -EventTarget::IsOnCurrentThreadInfallible() +WorkerPrivate::EventTarget::IsOnCurrentThreadInfallible() { // May be called on any thread! diff --git a/dom/workers/WorkerPrivate.h b/dom/workers/WorkerPrivate.h index c82e8e586ce8..abcc18b0a4de 100644 --- a/dom/workers/WorkerPrivate.h +++ b/dom/workers/WorkerPrivate.h @@ -104,9 +104,6 @@ template class WorkerPrivateParent { protected: - class EventTarget; - friend class EventTarget; - typedef mozilla::ipc::PrincipalInfo PrincipalInfo; public: @@ -220,9 +217,6 @@ private: return NotifyPrivate(Terminating); } - nsresult - DispatchPrivate(already_AddRefed aRunnable, nsIEventTarget* aSyncLoopTarget); - public: NS_INLINE_DECL_REFCOUNTING(WorkerPrivateParent) @@ -245,10 +239,7 @@ public: } nsresult - Dispatch(already_AddRefed aRunnable) - { - return DispatchPrivate(Move(aRunnable), nullptr); - } + Dispatch(already_AddRefed aRunnable); nsresult DispatchControlRunnable(already_AddRefed aWorkerControlRunnable); @@ -875,6 +866,8 @@ public: class WorkerPrivate : public WorkerPrivateParent { + class EventTarget; + friend class EventTarget; friend class mozilla::dom::WorkerHolder; friend class WorkerPrivateParent; typedef WorkerPrivateParent ParentType; @@ -1400,6 +1393,10 @@ private: const nsACString& aServiceWorkerScope, WorkerLoadInfo& aLoadInfo); + nsresult + DispatchPrivate(already_AddRefed aRunnable, + nsIEventTarget* aSyncLoopTarget); + bool MayContinueRunning() {