From 021d8073d522a2fdc76d5d2c11f8ca46633b97f5 Mon Sep 17 00:00:00 2001 From: Andrea Marchesini Date: Thu, 8 Feb 2018 09:33:33 +0100 Subject: [PATCH] Bug 1435263 - Get rid of WorkerPrivateParent template - part 8 - QueueRunnables, ParentWindowPauseDepth, r=bkelly --- dom/workers/WorkerPrivate.cpp | 30 ++++++++--------- dom/workers/WorkerPrivate.h | 61 ++++++++++++++++++----------------- 2 files changed, 44 insertions(+), 47 deletions(-) diff --git a/dom/workers/WorkerPrivate.cpp b/dom/workers/WorkerPrivate.cpp index 8adfbce28fed..65f6fb4cf9be 100644 --- a/dom/workers/WorkerPrivate.cpp +++ b/dom/workers/WorkerPrivate.cpp @@ -1551,8 +1551,7 @@ WorkerPrivateParent::WorkerPrivateParent( const nsACString& aServiceWorkerScope, WorkerLoadInfo& aLoadInfo) : mMutex("WorkerPrivateParent Mutex"), - mCondVar(mMutex, "WorkerPrivateParent CondVar"), - mParentWindowPausedDepth(0) + mCondVar(mMutex, "WorkerPrivateParent CondVar") { } @@ -1817,11 +1816,11 @@ WorkerPrivateParent::NotifyPrivate(WorkerStatus aStatus) return true; } - NS_ASSERTION(aStatus != Terminating || mQueuedRunnables.IsEmpty(), + NS_ASSERTION(aStatus != Terminating || self->mQueuedRunnables.IsEmpty(), "Shouldn't have anything queued!"); // Anything queued will be discarded. - mQueuedRunnables.Clear(); + self->mQueuedRunnables.Clear(); RefPtr runnable = new NotifyRunnable(ParentAsWorkerPrivate(), aStatus); @@ -1942,11 +1941,11 @@ WorkerPrivateParent::Thaw(nsPIDOMWindowInner* aWindow) // Execute queued runnables before waking up the worker, otherwise the worker // could post new messages before we run those that have been queued. - if (!IsParentWindowPaused() && !mQueuedRunnables.IsEmpty()) { + if (!self->IsParentWindowPaused() && !self->mQueuedRunnables.IsEmpty()) { MOZ_ASSERT(self->IsDedicatedWorker()); nsTArray> runnables; - mQueuedRunnables.SwapElements(runnables); + self->mQueuedRunnables.SwapElements(runnables); for (uint32_t index = 0; index < runnables.Length(); index++) { runnables[index]->Run(); @@ -1962,25 +1961,21 @@ WorkerPrivateParent::Thaw(nsPIDOMWindowInner* aWindow) return true; } -template void -WorkerPrivateParent::ParentWindowPaused() +WorkerPrivate::ParentWindowPaused() { AssertIsOnMainThread(); - WorkerPrivate* self = ParentAsWorkerPrivate(); - MOZ_ASSERT_IF(self->IsDedicatedWorker(), mParentWindowPausedDepth == 0); + MOZ_ASSERT_IF(IsDedicatedWorker(), mParentWindowPausedDepth == 0); mParentWindowPausedDepth += 1; } -template void -WorkerPrivateParent::ParentWindowResumed() +WorkerPrivate::ParentWindowResumed() { AssertIsOnMainThread(); - WorkerPrivate* self = ParentAsWorkerPrivate(); MOZ_ASSERT(mParentWindowPausedDepth > 0); - MOZ_ASSERT_IF(self->IsDedicatedWorker(), mParentWindowPausedDepth == 1); + MOZ_ASSERT_IF(IsDedicatedWorker(), mParentWindowPausedDepth == 1); mParentWindowPausedDepth -= 1; if (mParentWindowPausedDepth > 0) { return; @@ -1989,15 +1984,15 @@ WorkerPrivateParent::ParentWindowResumed() { MutexAutoLock lock(mMutex); - if (self->mParentStatus >= Terminating) { + if (mParentStatus >= Terminating) { return; } } // Execute queued runnables before waking up, otherwise the worker could post // new messages before we run those that have been queued. - if (!self->IsFrozen() && !mQueuedRunnables.IsEmpty()) { - MOZ_ASSERT(self->IsDedicatedWorker()); + if (!IsFrozen() && !mQueuedRunnables.IsEmpty()) { + MOZ_ASSERT(IsDedicatedWorker()); nsTArray> runnables; mQueuedRunnables.SwapElements(runnables); @@ -2725,6 +2720,7 @@ WorkerPrivate::WorkerPrivate(WorkerPrivate* aParent, WorkerEventTarget::Behavior::Hybrid)) , mErrorHandlerRecursionCount(0) , mNextTimeoutId(1) + , mParentWindowPausedDepth(0) , mParentStatus(Pending) , mStatus(Pending) , mFrozen(false) diff --git a/dom/workers/WorkerPrivate.h b/dom/workers/WorkerPrivate.h index ae6082917878..1bb6176b374b 100644 --- a/dom/workers/WorkerPrivate.h +++ b/dom/workers/WorkerPrivate.h @@ -131,17 +131,10 @@ protected: private: - // Only used for top level workers. - nsTArray> mQueuedRunnables; - // Only touched on the parent thread (currently this is always the main // thread as SharedWorkers are always top-level). nsTArray> mSharedWorkers; - // SharedWorkers may have multiple windows paused, so this must be - // a count instead of just a boolean. - uint32_t mParentWindowPausedDepth; - protected: WorkerPrivateParent(WorkerPrivate* aParent, const nsAString& aScriptURL, bool aIsChromeWorker, @@ -224,15 +217,6 @@ public: bool Thaw(nsPIDOMWindowInner* aWindow); - // When we debug a worker, we want to disconnect the window and the worker - // communication. This happens calling this method. - // Note: this method doesn't suspend the worker! Use Freeze/Thaw instead. - void - ParentWindowPaused(); - - void - ParentWindowResumed(); - bool Terminate() { @@ -283,20 +267,6 @@ public: void WorkerScriptLoaded(); - void - QueueRunnable(nsIRunnable* aRunnable) - { - AssertIsOnParentThread(); - mQueuedRunnables.AppendElement(aRunnable); - } - - bool - IsParentWindowPaused() const - { - AssertIsOnParentThread(); - return mParentWindowPausedDepth > 0; - } - nsresult SetPrincipalOnMainThread(nsIPrincipal* aPrincipal, nsILoadGroup* aLoadGroup); @@ -459,10 +429,18 @@ class WorkerPrivate : public WorkerPrivateParent RefPtr mPerformanceStorage; + // Only used for top level workers. + nsTArray> mQueuedRunnables; + JS::UniqueChars mDefaultLocale; // nulled during worker JSContext init TimeStamp mKillTime; uint32_t mErrorHandlerRecursionCount; uint32_t mNextTimeoutId; + + // SharedWorkers may have multiple windows paused, so this must be + // a count instead of just a boolean. + uint32_t mParentWindowPausedDepth; + WorkerStatus mParentStatus; WorkerStatus mStatus; UniquePtr mClientSource; @@ -1044,6 +1022,22 @@ public: return mParentFrozen; } + bool + IsParentWindowPaused() const + { + AssertIsOnParentThread(); + return mParentWindowPausedDepth > 0; + } + + // When we debug a worker, we want to disconnect the window and the worker + // communication. This happens calling this method. + // Note: this method doesn't suspend the worker! Use Freeze/Thaw instead. + void + ParentWindowPaused(); + + void + ParentWindowResumed(); + const nsString& ScriptURL() const { @@ -1393,6 +1387,13 @@ public: mLoadingWorkerScript = aLoadingWorkerScript; } + void + QueueRunnable(nsIRunnable* aRunnable) + { + AssertIsOnParentThread(); + mQueuedRunnables.AppendElement(aRunnable); + } + private: WorkerPrivate(WorkerPrivate* aParent, const nsAString& aScriptURL, bool aIsChromeWorker,