commit 72a7b93d81bf508b084609a67a8a53b1a955b34b
parent 77e124873b10cd76550bafca9d4f5839295143d9
Author: Artur Iunusov <aiunusov@mozilla.com>
Date: Fri, 21 Nov 2025 17:11:24 +0000
Bug 1990233 - WorkerPrivate: unify TimeoutManager Thaw()/Freeze() Resume()/Suspend() logic, r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D273409
Diffstat:
2 files changed, 67 insertions(+), 7 deletions(-)
diff --git a/dom/workers/WorkerPrivate.cpp b/dom/workers/WorkerPrivate.cpp
@@ -512,6 +512,19 @@ class FreezeRunnable final : public WorkerControlRunnable {
}
};
+class SuspendRunnable final : public WorkerControlRunnable {
+ public:
+ explicit SuspendRunnable(WorkerPrivate* aWorkerPrivate, bool aSuspend)
+ : WorkerControlRunnable("SuspendRunnable"), mSuspend{aSuspend} {}
+
+ private:
+ bool mSuspend = false;
+ virtual bool WorkerRun(JSContext* aCx,
+ WorkerPrivate* aWorkerPrivate) override {
+ return aWorkerPrivate->SuspendTimeoutManagerInternal(mSuspend);
+ }
+};
+
class ThawRunnable final : public WorkerControlRunnable {
public:
explicit ThawRunnable(WorkerPrivate* aWorkerPrivate)
@@ -2248,11 +2261,15 @@ void WorkerPrivate::ParentWindowPaused() {
MOZ_ALWAYS_SUCCEEDS(
mMainThreadDebuggeeEventTarget->SetIsPaused(!isCanceling));
}
+
+ SuspendTimeoutManager();
}
void WorkerPrivate::ParentWindowResumed() {
AssertIsOnMainThread();
+ ResumeTimeoutManager();
+
MOZ_ASSERT(mParentWindowPaused);
mParentWindowPaused = false;
@@ -4773,9 +4790,47 @@ bool WorkerPrivate::FreezeInternal() {
auto* timeoutManager =
data->mScope ? data->mScope->GetTimeoutManager() : nullptr;
if (timeoutManager) {
- timeoutManager->Suspend();
+ timeoutManager->Freeze();
+ }
+
+ return true;
+}
+
+bool WorkerPrivate::SuspendTimeoutManager() {
+ AssertIsOnParentThread();
+ RefPtr<SuspendRunnable> runnable = new SuspendRunnable(this, true);
+ runnable->Dispatch(this);
+ return true;
+}
+
+bool WorkerPrivate::ResumeTimeoutManager() {
+ AssertIsOnParentThread();
+ RefPtr<SuspendRunnable> runnable = new SuspendRunnable(this, false);
+ runnable->Dispatch(this);
+ return true;
+}
+
+bool WorkerPrivate::SuspendTimeoutManagerInternal(bool aSuspend) {
+ AssertIsOnWorkerThread();
+ auto data = mWorkerThreadAccessible.Access();
+
+ for (uint32_t index = 0; index < data->mChildWorkers.Length(); index++) {
+ if (aSuspend) {
+ data->mChildWorkers[index]->SuspendTimeoutManager();
+ } else {
+ data->mChildWorkers[index]->ResumeTimeoutManager();
+ }
}
+ auto* timeoutManager =
+ data->mScope ? data->mScope->GetTimeoutManager() : nullptr;
+ if (timeoutManager) {
+ if (aSuspend) {
+ timeoutManager->Suspend();
+ } else {
+ timeoutManager->Resume();
+ }
+ }
return true;
}
@@ -4793,6 +4848,11 @@ bool WorkerPrivate::ThawInternal() {
NS_ASSERTION(data->mFrozen, "Not yet frozen!");
// BindRemoteWorkerDebuggerChild();
+ auto* timeoutManager =
+ data->mScope ? data->mScope->GetTimeoutManager() : nullptr;
+ if (timeoutManager) {
+ timeoutManager->Thaw();
+ }
for (uint32_t index = 0; index < data->mChildWorkers.Length(); index++) {
data->mChildWorkers[index]->Thaw(nullptr);
@@ -4805,12 +4865,6 @@ bool WorkerPrivate::ThawInternal() {
data->mScope->MutableClientSourceRef().Thaw();
}
- auto* timeoutManager =
- data->mScope ? data->mScope->GetTimeoutManager() : nullptr;
- if (timeoutManager) {
- timeoutManager->Resume();
- }
-
return true;
}
diff --git a/dom/workers/WorkerPrivate.h b/dom/workers/WorkerPrivate.h
@@ -409,6 +409,12 @@ class WorkerPrivate final
bool FreezeInternal();
+ bool SuspendTimeoutManager();
+
+ bool ResumeTimeoutManager();
+
+ bool SuspendTimeoutManagerInternal(bool aSuspend);
+
bool ThawInternal();
void PropagateStorageAccessPermissionGrantedInternal();