From ad30b9265193219b7050092aefb3dabc18a38faa Mon Sep 17 00:00:00 2001 From: wolfbeast Date: Sun, 16 Sep 2018 10:22:11 +0200 Subject: Stop using the MainThreadTaskQueue from service workers. --- dom/workers/ServiceWorkerClient.cpp | 2 +- dom/workers/ServiceWorkerClients.cpp | 8 ++++---- dom/workers/ServiceWorkerEvents.cpp | 20 ++++---------------- dom/workers/ServiceWorkerPrivate.cpp | 15 +++++++-------- dom/workers/ServiceWorkerRegistration.cpp | 8 ++++---- dom/workers/ServiceWorkerWindowClient.cpp | 4 ++-- dom/workers/WorkerScope.cpp | 2 +- 7 files changed, 23 insertions(+), 36 deletions(-) diff --git a/dom/workers/ServiceWorkerClient.cpp b/dom/workers/ServiceWorkerClient.cpp index 660512a5f..6ed3a6ea4 100644 --- a/dom/workers/ServiceWorkerClient.cpp +++ b/dom/workers/ServiceWorkerClient.cpp @@ -224,7 +224,7 @@ ServiceWorkerClient::PostMessage(JSContext* aCx, JS::Handle aMessage, return; } - aRv = workerPrivate->DispatchToMainThread(runnable.forget()); + aRv = NS_DispatchToMainThread(runnable); if (NS_WARN_IF(aRv.Failed())) { return; } diff --git a/dom/workers/ServiceWorkerClients.cpp b/dom/workers/ServiceWorkerClients.cpp index 11f864443..38f49e355 100644 --- a/dom/workers/ServiceWorkerClients.cpp +++ b/dom/workers/ServiceWorkerClients.cpp @@ -753,7 +753,7 @@ ServiceWorkerClients::Get(const nsAString& aClientId, ErrorResult& aRv) RefPtr r = new GetRunnable(promiseProxy, aClientId); - MOZ_ALWAYS_SUCCEEDS(workerPrivate->DispatchToMainThread(r.forget())); + MOZ_ALWAYS_SUCCEEDS(NS_DispatchToMainThread(r)); return promise.forget(); } @@ -789,7 +789,7 @@ ServiceWorkerClients::MatchAll(const ClientQueryOptions& aOptions, new MatchAllRunnable(promiseProxy, NS_ConvertUTF16toUTF8(scope), aOptions.mIncludeUncontrolled); - MOZ_ALWAYS_SUCCEEDS(workerPrivate->DispatchToMainThread(r.forget())); + MOZ_ALWAYS_SUCCEEDS(NS_DispatchToMainThread(r)); return promise.forget(); } @@ -830,7 +830,7 @@ ServiceWorkerClients::OpenWindow(const nsAString& aUrl, RefPtr r = new OpenWindowRunnable(promiseProxy, aUrl, scope); - MOZ_ALWAYS_SUCCEEDS(workerPrivate->DispatchToMainThread(r.forget())); + MOZ_ALWAYS_SUCCEEDS(NS_DispatchToMainThread(r)); return promise.forget(); } @@ -859,6 +859,6 @@ ServiceWorkerClients::Claim(ErrorResult& aRv) RefPtr runnable = new ClaimRunnable(promiseProxy, NS_ConvertUTF16toUTF8(scope)); - MOZ_ALWAYS_SUCCEEDS(workerPrivate->DispatchToMainThread(runnable.forget())); + MOZ_ALWAYS_SUCCEEDS(NS_DispatchToMainThread(runnable)); return promise.forget(); } diff --git a/dom/workers/ServiceWorkerEvents.cpp b/dom/workers/ServiceWorkerEvents.cpp index 1f79e2c92..8b375c635 100644 --- a/dom/workers/ServiceWorkerEvents.cpp +++ b/dom/workers/ServiceWorkerEvents.cpp @@ -400,13 +400,7 @@ void RespondWithCopyComplete(void* aClosure, nsresult aStatus) data->mScriptSpec, data->mResponseURLSpec); } - // In theory this can happen after the worker thread is terminated. - WorkerPrivate* worker = GetCurrentThreadWorkerPrivate(); - if (worker) { - MOZ_ALWAYS_SUCCEEDS(worker->DispatchToMainThread(event.forget())); - } else { - MOZ_ALWAYS_SUCCEEDS(NS_DispatchToMainThread(event.forget())); - } + MOZ_ALWAYS_SUCCEEDS(NS_DispatchToMainThread(event)); } namespace { @@ -734,13 +728,7 @@ RespondWithHandler::CancelRequest(nsresult aStatus) { nsCOMPtr runnable = new CancelChannelRunnable(mInterceptedChannel, mRegistration, aStatus); - // Note, this may run off the worker thread during worker termination. - WorkerPrivate* worker = GetCurrentThreadWorkerPrivate(); - if (worker) { - MOZ_ALWAYS_SUCCEEDS(worker->DispatchToMainThread(runnable.forget())); - } else { - MOZ_ALWAYS_SUCCEEDS(NS_DispatchToMainThread(runnable.forget())); - } + NS_DispatchToMainThread(runnable); mRequestWasHandled = true; } @@ -873,8 +861,8 @@ public: mColumn = column; } - MOZ_ALWAYS_SUCCEEDS(mWorkerPrivate->DispatchToMainThread( - NewRunnableMethod(this, &WaitUntilHandler::ReportOnMainThread))); + MOZ_ALWAYS_SUCCEEDS( + NS_DispatchToMainThread(NewRunnableMethod(this, &WaitUntilHandler::ReportOnMainThread))); } void diff --git a/dom/workers/ServiceWorkerPrivate.cpp b/dom/workers/ServiceWorkerPrivate.cpp index 24b2e11e6..23ae3b366 100644 --- a/dom/workers/ServiceWorkerPrivate.cpp +++ b/dom/workers/ServiceWorkerPrivate.cpp @@ -214,7 +214,7 @@ private: mDone = true; #endif mCallback->SetResult(aResult); - MOZ_ALWAYS_SUCCEEDS(mWorkerPrivate->DispatchToMainThread(mCallback)); + MOZ_ALWAYS_SUCCEEDS(NS_DispatchToMainThread(mCallback)); } }; @@ -500,7 +500,7 @@ public: if (mRegistration) { nsCOMPtr runnable = new RegistrationUpdateRunnable(mRegistration, true /* time check */); - aWorkerPrivate->DispatchToMainThread(runnable.forget()); + NS_DispatchToMainThread(runnable.forget()); } ExtendableEventWorkerRunnable::PostRun(aCx, aWorkerPrivate, aRunResult); @@ -541,7 +541,7 @@ public: Cancel() override { mCallback->SetResult(false); - MOZ_ALWAYS_SUCCEEDS(mWorkerPrivate->DispatchToMainThread(mCallback)); + MOZ_ALWAYS_SUCCEEDS(NS_DispatchToMainThread(mCallback)); return WorkerRunnable::Cancel(); } @@ -637,7 +637,7 @@ public: mDone = true; mCallback->SetResult(aResult); - nsresult rv = mWorkerPrivate->DispatchToMainThread(mCallback); + nsresult rv = NS_DispatchToMainThread(mCallback); if (NS_WARN_IF(NS_FAILED(rv))) { NS_RUNTIMEABORT("Failed to dispatch life cycle event handler."); } @@ -768,7 +768,6 @@ public: void Report(uint16_t aReason = nsIPushErrorReporter::DELIVERY_INTERNAL_ERROR) { - WorkerPrivate* workerPrivate = mWorkerPrivate; mWorkerPrivate->AssertIsOnWorkerThread(); mWorkerPrivate = nullptr; @@ -780,7 +779,7 @@ public: NewRunnableMethod(this, &PushErrorReporter::ReportOnMainThread, aReason); MOZ_ALWAYS_TRUE(NS_SUCCEEDED( - workerPrivate->DispatchToMainThread(runnable.forget()))); + NS_DispatchToMainThread(runnable.forget()))); } void ReportOnMainThread(uint16_t aReason) @@ -1434,7 +1433,7 @@ public: Cancel() override { nsCOMPtr runnable = new ResumeRequest(mInterceptedChannel); - if (NS_FAILED(mWorkerPrivate->DispatchToMainThread(runnable))) { + if (NS_FAILED(NS_DispatchToMainThread(runnable))) { NS_WARNING("Failed to resume channel on FetchEventRunnable::Cancel()!\n"); } WorkerRunnable::Cancel(); @@ -1554,7 +1553,7 @@ private: NS_ERROR_INTERCEPTION_FAILED); } - MOZ_ALWAYS_SUCCEEDS(mWorkerPrivate->DispatchToMainThread(runnable.forget())); + MOZ_ALWAYS_SUCCEEDS(NS_DispatchToMainThread(runnable)); } RefPtr waitUntilPromise = event->GetPromise(); diff --git a/dom/workers/ServiceWorkerRegistration.cpp b/dom/workers/ServiceWorkerRegistration.cpp index 451bd2be9..b3cda2c10 100644 --- a/dom/workers/ServiceWorkerRegistration.cpp +++ b/dom/workers/ServiceWorkerRegistration.cpp @@ -1107,7 +1107,7 @@ ServiceWorkerRegistrationWorkerThread::Update(ErrorResult& aRv) } RefPtr r = new UpdateRunnable(proxy, mScope); - MOZ_ALWAYS_SUCCEEDS(worker->DispatchToMainThread(r.forget())); + MOZ_ALWAYS_SUCCEEDS(NS_DispatchToMainThread(r)); return promise.forget(); } @@ -1139,7 +1139,7 @@ ServiceWorkerRegistrationWorkerThread::Unregister(ErrorResult& aRv) } RefPtr r = new StartUnregisterRunnable(proxy, mScope); - MOZ_ALWAYS_SUCCEEDS(worker->DispatchToMainThread(r.forget())); + MOZ_ALWAYS_SUCCEEDS(NS_DispatchToMainThread(r)); return promise.forget(); } @@ -1161,7 +1161,7 @@ ServiceWorkerRegistrationWorkerThread::InitListener() nsCOMPtr r = NewRunnableMethod(mListener, &WorkerListener::StartListeningForEvents); - MOZ_ALWAYS_SUCCEEDS(worker->DispatchToMainThread(r.forget())); + MOZ_ALWAYS_SUCCEEDS(NS_DispatchToMainThread(r)); } void @@ -1183,7 +1183,7 @@ ServiceWorkerRegistrationWorkerThread::ReleaseListener() nsCOMPtr r = NewRunnableMethod(mListener, &WorkerListener::StopListeningForEvents); - MOZ_ALWAYS_SUCCEEDS(mWorkerPrivate->DispatchToMainThread(r.forget())); + MOZ_ALWAYS_SUCCEEDS(NS_DispatchToMainThread(r)); mListener = nullptr; mWorkerPrivate = nullptr; diff --git a/dom/workers/ServiceWorkerWindowClient.cpp b/dom/workers/ServiceWorkerWindowClient.cpp index 2ce0603cf..bae747214 100644 --- a/dom/workers/ServiceWorkerWindowClient.cpp +++ b/dom/workers/ServiceWorkerWindowClient.cpp @@ -183,7 +183,7 @@ ServiceWorkerWindowClient::Focus(ErrorResult& aRv) const if (promiseProxy) { RefPtr r = new ClientFocusRunnable(mWindowId, promiseProxy); - MOZ_ALWAYS_SUCCEEDS(workerPrivate->DispatchToMainThread(r.forget())); + MOZ_ALWAYS_SUCCEEDS(NS_DispatchToMainThread(r)); } else { promise->MaybeReject(NS_ERROR_DOM_ABORT_ERR); } @@ -549,7 +549,7 @@ ServiceWorkerWindowClient::Navigate(const nsAString& aUrl, ErrorResult& aRv) if (promiseProxy) { RefPtr r = new ClientNavigateRunnable(mWindowId, aUrl, scope, promiseProxy); - MOZ_ALWAYS_SUCCEEDS(workerPrivate->DispatchToMainThread(r.forget())); + MOZ_ALWAYS_SUCCEEDS(NS_DispatchToMainThread(r)); } else { promise->MaybeReject(NS_ERROR_DOM_ABORT_ERR); } diff --git a/dom/workers/WorkerScope.cpp b/dom/workers/WorkerScope.cpp index 54252e53b..ace1a09fc 100644 --- a/dom/workers/WorkerScope.cpp +++ b/dom/workers/WorkerScope.cpp @@ -717,7 +717,7 @@ ServiceWorkerGlobalScope::SkipWaiting(ErrorResult& aRv) new WorkerScopeSkipWaitingRunnable(promiseProxy, NS_ConvertUTF16toUTF8(mScope)); - MOZ_ALWAYS_SUCCEEDS(mWorkerPrivate->DispatchToMainThread(runnable.forget())); + MOZ_ALWAYS_SUCCEEDS(NS_DispatchToMainThread(runnable)); return promise.forget(); } -- cgit v1.2.3