From 9241a14957ebd57091aeaa0c577a22af627728eb Mon Sep 17 00:00:00 2001 From: Andrea Marchesini Date: Thu, 8 Feb 2018 09:33:34 +0100 Subject: [PATCH] Bug 1435263 - Get rid of WorkerPrivateParent template - part 16 - Dispatch methods, r=bkelly --- dom/workers/WorkerPrivate.cpp | 59 +++++++++--------------------- dom/workers/WorkerPrivate.h | 69 +++++++++++++++++------------------ 2 files changed, 51 insertions(+), 77 deletions(-) diff --git a/dom/workers/WorkerPrivate.cpp b/dom/workers/WorkerPrivate.cpp index a0281283d454..0e9006db23df 100644 --- a/dom/workers/WorkerPrivate.cpp +++ b/dom/workers/WorkerPrivate.cpp @@ -1646,37 +1646,25 @@ WorkerPrivate::DisableDebugger() } } -template nsresult -WorkerPrivateParent::Dispatch(already_AddRefed aRunnable) -{ - WorkerPrivate* self = ParentAsWorkerPrivate(); - return self->DispatchPrivate(Move(aRunnable), nullptr); -} - -template -nsresult -WorkerPrivateParent::DispatchControlRunnable( - already_AddRefed aWorkerControlRunnable) +WorkerPrivate::DispatchControlRunnable(already_AddRefed aWorkerControlRunnable) { // May be called on any thread! RefPtr runnable(aWorkerControlRunnable); MOZ_ASSERT(runnable); - WorkerPrivate* self = ParentAsWorkerPrivate(); - { MutexAutoLock lock(mMutex); - if (self->mStatus == Dead) { + if (mStatus == Dead) { return NS_ERROR_UNEXPECTED; } // Transfer ownership to the control queue. - self->mControlQueue.Push(runnable.forget().take()); + mControlQueue.Push(runnable.forget().take()); - if (JSContext* cx = self->mJSContext) { - MOZ_ASSERT(self->mThread); + if (JSContext* cx = mJSContext) { + MOZ_ASSERT(mThread); JS_RequestInterruptCallback(cx); } @@ -1686,10 +1674,8 @@ WorkerPrivateParent::DispatchControlRunnable( return NS_OK; } -template nsresult -WorkerPrivateParent::DispatchDebuggerRunnable( - already_AddRefed aDebuggerRunnable) +WorkerPrivate::DispatchDebuggerRunnable(already_AddRefed aDebuggerRunnable) { // May be called on any thread! @@ -1697,19 +1683,17 @@ WorkerPrivateParent::DispatchDebuggerRunnable( MOZ_ASSERT(runnable); - WorkerPrivate* self = ParentAsWorkerPrivate(); - { MutexAutoLock lock(mMutex); - if (self->mStatus == Dead) { + if (mStatus == Dead) { NS_WARNING("A debugger runnable was posted to a worker that is already " "shutting down!"); return NS_ERROR_UNEXPECTED; } // Transfer ownership to the debugger queue. - self->mDebuggerQueue.Push(runnable.forget().take()); + mDebuggerQueue.Push(runnable.forget().take()); mCondVar.Notify(); } @@ -2573,47 +2557,40 @@ WorkerPrivate::FlushReportsToSharedWorkers(nsIConsoleReportCollector* aReporter) #ifdef DEBUG -template void -WorkerPrivateParent::AssertIsOnParentThread() const +WorkerPrivate::AssertIsOnParentThread() const { - WorkerPrivate* self = ParentAsWorkerPrivate(); - if (self->GetParent()) { - self->GetParent()->AssertIsOnWorkerThread(); - } - else { + if (GetParent()) { + GetParent()->AssertIsOnWorkerThread(); + } else { AssertIsOnMainThread(); } } -template void -WorkerPrivateParent::AssertInnerWindowIsCorrect() const +WorkerPrivate::AssertInnerWindowIsCorrect() const { AssertIsOnParentThread(); - WorkerPrivate* self = ParentAsWorkerPrivate(); // Only care about top level workers from windows. - if (self->mParent || !self->mLoadInfo.mWindow) { + if (mParent || !mLoadInfo.mWindow) { return; } AssertIsOnMainThread(); - nsPIDOMWindowOuter* outer = self->mLoadInfo.mWindow->GetOuterWindow(); - NS_ASSERTION(outer && outer->GetCurrentInnerWindow() == self->mLoadInfo.mWindow, + nsPIDOMWindowOuter* outer = mLoadInfo.mWindow->GetOuterWindow(); + NS_ASSERTION(outer && outer->GetCurrentInnerWindow() == mLoadInfo.mWindow, "Inner window no longer correct!"); } #endif #ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED -template bool -WorkerPrivateParent::PrincipalIsValid() const +WorkerPrivate::PrincipalIsValid() const { - WorkerPrivate* self = ParentAsWorkerPrivate(); - return self->mLoadInfo.PrincipalIsValid(); + return mLoadInfo.PrincipalIsValid(); } #endif diff --git a/dom/workers/WorkerPrivate.h b/dom/workers/WorkerPrivate.h index 90a95f0cd3fc..66753217996f 100644 --- a/dom/workers/WorkerPrivate.h +++ b/dom/workers/WorkerPrivate.h @@ -136,45 +136,9 @@ protected: virtual ~WorkerPrivateParent(); -private: - Derived* - ParentAsWorkerPrivate() const - { - return static_cast(const_cast(this)); - } - public: NS_INLINE_DECL_REFCOUNTING(WorkerPrivateParent) - nsresult - Dispatch(already_AddRefed aRunnable); - - nsresult - DispatchControlRunnable(already_AddRefed aWorkerControlRunnable); - - nsresult - DispatchDebuggerRunnable(already_AddRefed aDebuggerRunnable); - -#ifdef DEBUG - void - AssertIsOnParentThread() const; - - void - AssertInnerWindowIsCorrect() const; -#else - void - AssertIsOnParentThread() const - { } - - void - AssertInnerWindowIsCorrect() const - { } -#endif - -#ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED - bool - PrincipalIsValid() const; -#endif }; class WorkerPrivate : public WorkerPrivateParent @@ -1382,6 +1346,39 @@ public: void OfflineStatusChangeEvent(bool aIsOffline); + nsresult + Dispatch(already_AddRefed aRunnable) + { + return DispatchPrivate(Move(aRunnable), nullptr); + } + + nsresult + DispatchControlRunnable(already_AddRefed aWorkerControlRunnable); + + nsresult + DispatchDebuggerRunnable(already_AddRefed aDebuggerRunnable); + +#ifdef DEBUG + void + AssertIsOnParentThread() const; + + void + AssertInnerWindowIsCorrect() const; +#else + void + AssertIsOnParentThread() const + { } + + void + AssertInnerWindowIsCorrect() const + { } +#endif + +#ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED + bool + PrincipalIsValid() const; +#endif + private: WorkerPrivate(WorkerPrivate* aParent, const nsAString& aScriptURL, bool aIsChromeWorker,