Bug 1300658 P5 Make service worker APIs use the MainThreadTaskQueue. r=baku

This commit is contained in:
Ben Kelly 2016-09-12 12:32:21 -07:00
Родитель c66b226166
Коммит 9b3174b58d
7 изменённых файлов: 36 добавлений и 23 удалений

Просмотреть файл

@ -231,7 +231,7 @@ ServiceWorkerClient::PostMessage(JSContext* aCx, JS::Handle<JS::Value> aMessage,
return;
}
aRv = NS_DispatchToMainThread(runnable);
aRv = workerPrivate->DispatchToMainThread(runnable.forget());
if (NS_WARN_IF(aRv.Failed())) {
return;
}

Просмотреть файл

@ -675,7 +675,7 @@ ServiceWorkerClients::Get(const nsAString& aClientId, ErrorResult& aRv)
RefPtr<GetRunnable> r =
new GetRunnable(promiseProxy, aClientId);
MOZ_ALWAYS_SUCCEEDS(NS_DispatchToMainThread(r));
MOZ_ALWAYS_SUCCEEDS(workerPrivate->DispatchToMainThread(r.forget()));
return promise.forget();
}
@ -711,7 +711,7 @@ ServiceWorkerClients::MatchAll(const ClientQueryOptions& aOptions,
new MatchAllRunnable(promiseProxy,
NS_ConvertUTF16toUTF8(scope),
aOptions.mIncludeUncontrolled);
MOZ_ALWAYS_SUCCEEDS(NS_DispatchToMainThread(r));
MOZ_ALWAYS_SUCCEEDS(workerPrivate->DispatchToMainThread(r.forget()));
return promise.forget();
}
@ -752,7 +752,7 @@ ServiceWorkerClients::OpenWindow(const nsAString& aUrl,
RefPtr<OpenWindowRunnable> r = new OpenWindowRunnable(promiseProxy,
aUrl, scope);
MOZ_ALWAYS_SUCCEEDS(NS_DispatchToMainThread(r));
MOZ_ALWAYS_SUCCEEDS(workerPrivate->DispatchToMainThread(r.forget()));
return promise.forget();
}
@ -781,6 +781,6 @@ ServiceWorkerClients::Claim(ErrorResult& aRv)
RefPtr<ClaimRunnable> runnable =
new ClaimRunnable(promiseProxy, NS_ConvertUTF16toUTF8(scope));
MOZ_ALWAYS_SUCCEEDS(NS_DispatchToMainThread(runnable));
MOZ_ALWAYS_SUCCEEDS(workerPrivate->DispatchToMainThread(runnable.forget()));
return promise.forget();
}

Просмотреть файл

@ -394,7 +394,13 @@ void RespondWithCopyComplete(void* aClosure, nsresult aStatus)
data->mScriptSpec,
data->mResponseURLSpec);
}
MOZ_ALWAYS_SUCCEEDS(NS_DispatchToMainThread(event));
// 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()));
}
}
namespace {
@ -724,7 +730,13 @@ RespondWithHandler::CancelRequest(nsresult aStatus)
{
nsCOMPtr<nsIRunnable> runnable =
new CancelChannelRunnable(mInterceptedChannel, mRegistration, aStatus);
NS_DispatchToMainThread(runnable);
// 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()));
}
mRequestWasHandled = true;
}
@ -857,8 +869,8 @@ public:
mColumn = column;
}
MOZ_ALWAYS_SUCCEEDS(
NS_DispatchToMainThread(NewRunnableMethod(this, &WaitUntilHandler::ReportOnMainThread)));
MOZ_ALWAYS_SUCCEEDS(mWorkerPrivate->DispatchToMainThread(
NewRunnableMethod(this, &WaitUntilHandler::ReportOnMainThread)));
}
void

Просмотреть файл

@ -212,7 +212,7 @@ private:
mDone = true;
#endif
mCallback->SetResult(aResult);
MOZ_ALWAYS_SUCCEEDS(NS_DispatchToMainThread(mCallback));
MOZ_ALWAYS_SUCCEEDS(mWorkerPrivate->DispatchToMainThread(mCallback));
}
};
@ -495,7 +495,7 @@ public:
{
nsCOMPtr<nsIRunnable> runnable =
new RegistrationUpdateRunnable(mRegistration, true /* time check */);
NS_DispatchToMainThread(runnable.forget());
aWorkerPrivate->DispatchToMainThread(runnable.forget());
ExtendableEventWorkerRunnable::PostRun(aCx, aWorkerPrivate, aRunResult);
}
@ -535,7 +535,7 @@ public:
Cancel() override
{
mCallback->SetResult(false);
MOZ_ALWAYS_SUCCEEDS(NS_DispatchToMainThread(mCallback));
MOZ_ALWAYS_SUCCEEDS(mWorkerPrivate->DispatchToMainThread(mCallback));
return WorkerRunnable::Cancel();
}
@ -631,7 +631,7 @@ public:
mDone = true;
mCallback->SetResult(aResult);
nsresult rv = NS_DispatchToMainThread(mCallback);
nsresult rv = mWorkerPrivate->DispatchToMainThread(mCallback);
if (NS_WARN_IF(NS_FAILED(rv))) {
NS_RUNTIMEABORT("Failed to dispatch life cycle event handler.");
}
@ -762,6 +762,7 @@ public:
void Report(uint16_t aReason = nsIPushErrorReporter::DELIVERY_INTERNAL_ERROR)
{
WorkerPrivate* workerPrivate = mWorkerPrivate;
mWorkerPrivate->AssertIsOnWorkerThread();
mWorkerPrivate = nullptr;
@ -773,7 +774,7 @@ public:
NewRunnableMethod<uint16_t>(this,
&PushErrorReporter::ReportOnMainThread, aReason);
MOZ_ALWAYS_TRUE(NS_SUCCEEDED(
NS_DispatchToMainThread(runnable.forget())));
workerPrivate->DispatchToMainThread(runnable.forget())));
}
void ReportOnMainThread(uint16_t aReason)
@ -1420,7 +1421,7 @@ public:
Cancel() override
{
nsCOMPtr<nsIRunnable> runnable = new ResumeRequest(mInterceptedChannel);
if (NS_FAILED(NS_DispatchToMainThread(runnable))) {
if (NS_FAILED(mWorkerPrivate->DispatchToMainThread(runnable))) {
NS_WARNING("Failed to resume channel on FetchEventRunnable::Cancel()!\n");
}
WorkerRunnable::Cancel();
@ -1534,7 +1535,7 @@ private:
NS_ERROR_INTERCEPTION_FAILED);
}
MOZ_ALWAYS_SUCCEEDS(NS_DispatchToMainThread(runnable));
MOZ_ALWAYS_SUCCEEDS(mWorkerPrivate->DispatchToMainThread(runnable.forget()));
}
RefPtr<Promise> waitUntilPromise = event->GetPromise();

Просмотреть файл

@ -1110,7 +1110,7 @@ ServiceWorkerRegistrationWorkerThread::Update(ErrorResult& aRv)
}
RefPtr<UpdateRunnable> r = new UpdateRunnable(proxy, mScope);
MOZ_ALWAYS_SUCCEEDS(NS_DispatchToMainThread(r));
MOZ_ALWAYS_SUCCEEDS(worker->DispatchToMainThread(r.forget()));
return promise.forget();
}
@ -1142,7 +1142,7 @@ ServiceWorkerRegistrationWorkerThread::Unregister(ErrorResult& aRv)
}
RefPtr<StartUnregisterRunnable> r = new StartUnregisterRunnable(proxy, mScope);
MOZ_ALWAYS_SUCCEEDS(NS_DispatchToMainThread(r));
MOZ_ALWAYS_SUCCEEDS(worker->DispatchToMainThread(r.forget()));
return promise.forget();
}
@ -1180,7 +1180,7 @@ ServiceWorkerRegistrationWorkerThread::InitListener()
RefPtr<StartListeningRunnable> r =
new StartListeningRunnable(mListener);
MOZ_ALWAYS_SUCCEEDS(NS_DispatchToMainThread(r));
MOZ_ALWAYS_SUCCEEDS(worker->DispatchToMainThread(r.forget()));
}
class AsyncStopListeningRunnable final : public Runnable
@ -1238,7 +1238,7 @@ ServiceWorkerRegistrationWorkerThread::ReleaseListener(Reason aReason)
if (aReason == RegistrationIsGoingAway) {
RefPtr<AsyncStopListeningRunnable> r =
new AsyncStopListeningRunnable(mListener);
MOZ_ALWAYS_SUCCEEDS(NS_DispatchToMainThread(r));
MOZ_ALWAYS_SUCCEEDS(mWorkerPrivate->DispatchToMainThread(r.forget()));
} else if (aReason == WorkerIsGoingAway) {
RefPtr<SyncStopListeningRunnable> r =
new SyncStopListeningRunnable(mWorkerPrivate, mListener);

Просмотреть файл

@ -183,7 +183,7 @@ ServiceWorkerWindowClient::Focus(ErrorResult& aRv) const
if (promiseProxy) {
RefPtr<ClientFocusRunnable> r = new ClientFocusRunnable(mWindowId,
promiseProxy);
MOZ_ALWAYS_SUCCEEDS(NS_DispatchToMainThread(r));
MOZ_ALWAYS_SUCCEEDS(workerPrivate->DispatchToMainThread(r.forget()));
} else {
promise->MaybeReject(NS_ERROR_DOM_ABORT_ERR);
}
@ -516,7 +516,7 @@ ServiceWorkerWindowClient::Navigate(const nsAString& aUrl, ErrorResult& aRv)
if (promiseProxy) {
RefPtr<ClientNavigateRunnable> r =
new ClientNavigateRunnable(mWindowId, aUrl, promiseProxy);
MOZ_ALWAYS_SUCCEEDS(NS_DispatchToMainThread(r));
MOZ_ALWAYS_SUCCEEDS(workerPrivate->DispatchToMainThread(r.forget()));
} else {
promise->MaybeReject(NS_ERROR_DOM_ABORT_ERR);
}

Просмотреть файл

@ -697,7 +697,7 @@ ServiceWorkerGlobalScope::SkipWaiting(ErrorResult& aRv)
new WorkerScopeSkipWaitingRunnable(promiseProxy,
NS_ConvertUTF16toUTF8(mScope));
MOZ_ALWAYS_SUCCEEDS(NS_DispatchToMainThread(runnable));
MOZ_ALWAYS_SUCCEEDS(mWorkerPrivate->DispatchToMainThread(runnable.forget()));
return promise.forget();
}