https://bugs.webkit.org/show_bug.cgi?id=180263
Reviewed by Youenn Fablet.
Get rid of microtask in ServiceWorkerContainer::jobResolvedWithRegistration(). It
is no longer needed and MicrotaskQueue::mainThreadQueue() is only safe to use from
the main thread, as its name suggest. ServiceWorkerContainer are also instantiated
in Service worker threads nowadays.
* workers/service/SWClientConnection.cpp:
(WebCore::SWClientConnection::registrationJobResolvedInServer):
* workers/service/ServiceWorkerContainer.cpp:
(WebCore::ServiceWorkerContainer::jobResolvedWithRegistration):
* workers/service/ServiceWorkerContainer.h:
* workers/service/ServiceWorkerJob.cpp:
(WebCore::ServiceWorkerJob::resolvedWithRegistration):
* workers/service/ServiceWorkerJob.h:
* workers/service/ServiceWorkerJobClient.h:
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@225415
268f45cc-cd09-0410-ab3c-
d52691b4dbfc
+2017-12-01 Chris Dumez <cdumez@apple.com>
+
+ Get rid of microtask in ServiceWorkerContainer::jobResolvedWithRegistration()
+ https://bugs.webkit.org/show_bug.cgi?id=180263
+
+ Reviewed by Youenn Fablet.
+
+ Get rid of microtask in ServiceWorkerContainer::jobResolvedWithRegistration(). It
+ is no longer needed and MicrotaskQueue::mainThreadQueue() is only safe to use from
+ the main thread, as its name suggest. ServiceWorkerContainer are also instantiated
+ in Service worker threads nowadays.
+
+ * workers/service/SWClientConnection.cpp:
+ (WebCore::SWClientConnection::registrationJobResolvedInServer):
+ * workers/service/ServiceWorkerContainer.cpp:
+ (WebCore::ServiceWorkerContainer::jobResolvedWithRegistration):
+ * workers/service/ServiceWorkerContainer.h:
+ * workers/service/ServiceWorkerJob.cpp:
+ (WebCore::ServiceWorkerJob::resolvedWithRegistration):
+ * workers/service/ServiceWorkerJob.h:
+ * workers/service/ServiceWorkerJobClient.h:
+
2017-12-01 Myles C. Maxfield <mmaxfield@apple.com>
Free FontFaceSets may include fonts that were never actually added to them
}
auto key = registrationData.key;
- job->resolvedWithRegistration(WTFMove(registrationData), [this, protectedThis = makeRef(*this), key, shouldNotifyWhenResolved] {
- if (shouldNotifyWhenResolved == ShouldNotifyWhenResolved::Yes)
- didResolveRegistrationPromise(key);
- });
+ job->resolvedWithRegistration(WTFMove(registrationData), shouldNotifyWhenResolved);
}
void SWClientConnection::unregistrationJobResolvedInServer(const ServiceWorkerJobDataIdentifier& jobDataIdentifier, bool unregistrationResult)
#include "JSDOMPromiseDeferred.h"
#include "JSServiceWorkerRegistration.h"
#include "Logging.h"
-#include "Microtasks.h"
#include "NavigatorBase.h"
#include "ResourceError.h"
#include "ScriptExecutionContext.h"
registration->scheduleTaskToFireUpdateFoundEvent();
}
-void ServiceWorkerContainer::jobResolvedWithRegistration(ServiceWorkerJob& job, ServiceWorkerRegistrationData&& data, WTF::Function<void()>&& promiseResolvedHandler)
+void ServiceWorkerContainer::jobResolvedWithRegistration(ServiceWorkerJob& job, ServiceWorkerRegistrationData&& data, ShouldNotifyWhenResolved shouldNotifyWhenResolved)
{
auto guard = WTF::makeScopeExit([this, &job] {
jobDidFinish(job);
});
+ WTF::Function<void()> notifyWhenResolvedIfNeeded = [] { };
+ if (shouldNotifyWhenResolved == ShouldNotifyWhenResolved::Yes) {
+ notifyWhenResolvedIfNeeded = [connection = m_swConnection, registrationKey = data.key.isolatedCopy()]() mutable {
+ callOnMainThread([connection = WTFMove(connection), registrationKey = WTFMove(registrationKey)] {
+ connection->didResolveRegistrationPromise(registrationKey);
+ });
+ };
+ }
+
if (isStopped()) {
- promiseResolvedHandler();
+ notifyWhenResolvedIfNeeded();
return;
}
- scriptExecutionContext()->postTask([this, protectedThis = makeRef(*this), job = makeRef(job), data = WTFMove(data), promiseResolvedHandler = WTFMove(promiseResolvedHandler)](ScriptExecutionContext& context) mutable {
+ scriptExecutionContext()->postTask([this, protectedThis = makeRef(*this), job = makeRef(job), data = WTFMove(data), notifyWhenResolvedIfNeeded = WTFMove(notifyWhenResolvedIfNeeded)](ScriptExecutionContext& context) mutable {
if (isStopped()) {
- promiseResolvedHandler();
+ notifyWhenResolvedIfNeeded();
return;
}
job->promise().resolve<IDLInterface<ServiceWorkerRegistration>>(WTFMove(registration));
- MicrotaskQueue::mainThreadQueue().append(std::make_unique<VoidMicrotask>([promiseResolvedHandler = WTFMove(promiseResolvedHandler)] {
- promiseResolvedHandler();
- }));
+ notifyWhenResolvedIfNeeded();
});
}
void scheduleJob(Ref<ServiceWorkerJob>&&);
void jobFailedWithException(ServiceWorkerJob&, const Exception&) final;
- void jobResolvedWithRegistration(ServiceWorkerJob&, ServiceWorkerRegistrationData&&, WTF::Function<void()>&& promiseResolvedHandler) final;
+ void jobResolvedWithRegistration(ServiceWorkerJob&, ServiceWorkerRegistrationData&&, ShouldNotifyWhenResolved) final;
void jobResolvedWithUnregistrationResult(ServiceWorkerJob&, bool unregistrationResult) final;
void startScriptFetchForJob(ServiceWorkerJob&) final;
void jobFinishedLoadingScript(ServiceWorkerJob&, const String&) final;
m_client->jobFailedWithException(*this, exception);
}
-void ServiceWorkerJob::resolvedWithRegistration(ServiceWorkerRegistrationData&& data, WTF::Function<void()>&& promiseResolvedHandler)
+void ServiceWorkerJob::resolvedWithRegistration(ServiceWorkerRegistrationData&& data, ShouldNotifyWhenResolved shouldNotifyWhenResolved)
{
ASSERT(currentThread() == m_creationThread);
ASSERT(!m_completed);
m_completed = true;
- m_client->jobResolvedWithRegistration(*this, WTFMove(data), WTFMove(promiseResolvedHandler));
+ m_client->jobResolvedWithRegistration(*this, WTFMove(data), shouldNotifyWhenResolved);
}
void ServiceWorkerJob::resolvedWithUnregistrationResult(bool unregistrationResult)
WEBCORE_EXPORT ~ServiceWorkerJob();
void failedWithException(const Exception&);
- void resolvedWithRegistration(ServiceWorkerRegistrationData&&, WTF::Function<void()>&& promiseResolvedHandler);
+ void resolvedWithRegistration(ServiceWorkerRegistrationData&&, ShouldNotifyWhenResolved);
void resolvedWithUnregistrationResult(bool);
void startScriptFetch();
virtual ~ServiceWorkerJobClient() = default;
virtual void jobFailedWithException(ServiceWorkerJob&, const Exception&) = 0;
- virtual void jobResolvedWithRegistration(ServiceWorkerJob&, ServiceWorkerRegistrationData&&, WTF::Function<void()>&& promiseResolvedHandler) = 0;
+ virtual void jobResolvedWithRegistration(ServiceWorkerJob&, ServiceWorkerRegistrationData&&, ShouldNotifyWhenResolved) = 0;
virtual void jobResolvedWithUnregistrationResult(ServiceWorkerJob&, bool unregistrationResult) = 0;
virtual void startScriptFetchForJob(ServiceWorkerJob&) = 0;
virtual void jobFinishedLoadingScript(ServiceWorkerJob&, const String&) = 0;