Skip to content
Permalink
Browse files
Introduce ServerWorkerRegistration task queues.
https://bugs.webkit.org/show_bug.cgi?id=175851

Reviewed by Andy Estes.

Source/WebCore:

Test: http/tests/workers/service/registration-task-queue-scheduling-1.html

This change introduces:
- A task thread/queue owned by each SWServer object.
- The SWServerRegistration object, which is the in-server representation of a
  service worker registration scope.
- A registration job queue per SWServerRegistration object which actually runs the
  jobs as tasks on the owning SWServer's thread.

With that infrastructure in place, it moves the "register" job to something that is
scheduled and rejected asynchronously, as opposed to synchronously rejected.

The test verifies that two different registration scopes (localhost and 127.0.0.1)
can both spam the SWServer with registration requests, but neither of their queues
starve the other.

The rest of this change is a lot of support and plumbing for making the above happen.

* CMakeLists.txt:
* WebCore.xcodeproj/project.pbxproj:

* dom/ExceptionData.cpp:
(WebCore::ExceptionData::isolatedCopy const):
* dom/ExceptionData.h:

* workers/service/ServiceWorkerContainer.cpp:
(WebCore::ServiceWorkerContainer::addRegistration):
(WebCore::ServiceWorkerContainer::connectionIdentifier):
* workers/service/ServiceWorkerContainer.h:

* workers/service/ServiceWorkerJob.cpp:
(WebCore::ServiceWorkerJob::ServiceWorkerJob):
(WebCore::ServiceWorkerJob::data const): Deleted.
* workers/service/ServiceWorkerJob.h:
(WebCore::ServiceWorkerJob::create):
(WebCore::ServiceWorkerJob::data const):
(WebCore::ServiceWorkerJob::createRegisterJob): Deleted.

* workers/service/ServiceWorkerJobClient.h:

* workers/service/ServiceWorkerJobData.cpp:
(WebCore::ServiceWorkerJobData::ServiceWorkerJobData):
(WebCore::ServiceWorkerJobData::registrationKey const):
(WebCore::ServiceWorkerJobData::isolatedCopy const):
* workers/service/ServiceWorkerJobData.h:
(WebCore::ServiceWorkerJobData::jobIdentifier const):
(WebCore::ServiceWorkerJobData::connectionIdentifier const):
(WebCore::ServiceWorkerJobData::encode const):
(WebCore::ServiceWorkerJobData::decode):

* workers/service/ServiceWorkerRegistrationKey.cpp:
(WebCore::ServiceWorkerRegistrationKey::emptyKey):
(WebCore::ServiceWorkerRegistrationKey::hash const):
(WebCore::ServiceWorkerRegistrationKey::operator== const):
* workers/service/ServiceWorkerRegistrationKey.h:
(WTF::ServiceWorkerRegistrationKeyHash::hash):
(WTF::ServiceWorkerRegistrationKeyHash::equal):
(WTF::HashTraits<WebCore::ServiceWorkerRegistrationKey>::emptyValue):
(WTF::HashTraits<WebCore::ServiceWorkerRegistrationKey>::constructDeletedValue):
(WTF::HashTraits<WebCore::ServiceWorkerRegistrationKey>::isDeletedValue):

* workers/service/ServiceWorkerRegistrationOptions.cpp:
(WebCore::RegistrationOptions::isolatedCopy const):
* workers/service/ServiceWorkerRegistrationOptions.h:
(WebCore::RegistrationOptions::encode const):
(WebCore::RegistrationOptions::decode):

* workers/service/server/SWClientConnection.h:

* workers/service/server/SWServer.cpp:
(WebCore::SWServer::Connection::Connection):
(WebCore::SWServer::~SWServer):
(WebCore::SWServer::Connection::scheduleJobInServer):
(WebCore::SWServer::SWServer):
(WebCore::SWServer::scheduleJob):
(WebCore::SWServer::rejectJob):
(WebCore::SWServer::taskThreadEntryPoint):
(WebCore::SWServer::postTask):
(WebCore::SWServer::postTaskReply):
(WebCore::SWServer::handleTaskRepliesOnMainThread):
(WebCore::SWServer::registerConnection):
(WebCore::SWServer::unregisterConnection):
* workers/service/server/SWServer.h:
(WebCore::SWServer::Connection::identifier const):

* workers/service/server/SWServerRegistration.cpp: Added.
(WebCore::SWServerRegistration::SWServerRegistration):
(WebCore::SWServerRegistration::~SWServerRegistration):
(WebCore::SWServerRegistration::enqueueJob):
(WebCore::SWServerRegistration::startNextJob):
(WebCore::SWServerRegistration::performCurrentJob):
(WebCore::SWServerRegistration::rejectCurrentJob):
(WebCore::SWServerRegistration::finishCurrentJob):
* workers/service/server/SWServerRegistration.h:

Source/WebKit:

* StorageProcess/ServiceWorker/WebSWServerConnection.cpp:
(WebKit::WebSWServerConnection::WebSWServerConnection):
* StorageProcess/ServiceWorker/WebSWServerConnection.h:
(WebKit::WebSWServerConnection::identifier const): Deleted.

* WebProcess/Storage/WebSWClientConnection.h:
(WebKit::WebSWClientConnection::identifier const): Deleted.

LayoutTests:

* http/tests/workers/service/registration-task-queue-scheduling-1-expected.txt: Added.
* http/tests/workers/service/registration-task-queue-scheduling-1.html: Added.
* http/tests/workers/service/resources/registration-task-queue-scheduling-1-second-window.html: Added.
* http/tests/workers/service/resources/registration-task-queue-scheduling-1.js: Added.


Canonical link: https://commits.webkit.org/192646@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@221198 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
beidson committed Aug 25, 2017
1 parent 6fa653f commit 32ae1b6ac8af901ad01ba5e3cead082768dba875
Showing 30 changed files with 874 additions and 82 deletions.
@@ -1,3 +1,15 @@
2017-08-25 Brady Eidson <beidson@apple.com>

Introduce ServerWorkerRegistration task queues.
https://bugs.webkit.org/show_bug.cgi?id=175851

Reviewed by Andy Estes.

* http/tests/workers/service/registration-task-queue-scheduling-1-expected.txt: Added.
* http/tests/workers/service/registration-task-queue-scheduling-1.html: Added.
* http/tests/workers/service/resources/registration-task-queue-scheduling-1-second-window.html: Added.
* http/tests/workers/service/resources/registration-task-queue-scheduling-1.js: Added.

2017-07-25 Frederic Wang <fwang@igalia.com>

Add flag allow-modals to iframe sandbox
@@ -0,0 +1,2 @@
ALERT: Done

@@ -0,0 +1,9 @@
<html>
<head>
<script src="resources/sw-test-pre.js"></script>
</head>
<body>

<script src="resources/registration-task-queue-scheduling-1.js"></script>
</body>
</html>
@@ -0,0 +1,16 @@
<script>

if (!window.opener)
alert("This HTML file should not be opened directly")

for (var i = 0; i < 1000; ++i) {
navigator.serviceWorker.register("empty-worker.js", { })
.then(function(r) {
alert("Popup window resolved successfully (unexpected)")
opener.postMessage("done", "*");
}, function(e) {
opener.postMessage("responded", "*");
})
}

</script>
@@ -0,0 +1,60 @@
// This test makes sure that two different windows from two different domains who spam SW registrations get responses intertwined with each other
// as each registration should operate on its own task queue.

if (location.hostname != "127.0.0.1")
alert("This test must be initiated from the hostname 127.0.0.1");

window.onmessage = function(evt)
{
if (evt.data == "done") {
alert("Error in popup window");
finishSWTest();
} else if (evt.data == "responded") {
if (!window.popupTimestamp)
window.popupTimestamp = new Date();

responded();
} else {
alert("Unexpected event from popup window");
finishSWTest();
}
}

function responded()
{
if (!window.thisTimestamp) {
window.thisTimestamp = new Date();

if (window.popupTimestamp)
alert("Registrations in second window should not have responded before the first");

return;
}

if (!window.popupTimestamp)
return;

if (window.popupTimestamp < window.thisTimestamp)
alert("Popup should not have popped up before this main window");
else
alert("Done");

finishSWTest();
}

for (var i = 0; i < 1000; ++i) {
navigator.serviceWorker.register("resources/empty-worker.js", { })
.then(function(r) {
console.log("Original window resolved successfully (unexpected)")
done();
}, function(e) {
if (e+"" != "UnknownError: serviceWorker job scheduling is not yet implemented") {
alert("Unexpected error received from server");
finishSWTest();
}

responded();
})
}

otherWindow = window.open("http://localhost:8000/workers/service/resources/registration-task-queue-scheduling-1-second-window.html", "other");
@@ -1545,6 +1545,7 @@ set(WebCore_SOURCES
dom/EventNames.cpp
dom/EventPath.cpp
dom/EventTarget.cpp
dom/ExceptionData.cpp
dom/ExtensionStyleSheets.cpp
dom/FocusEvent.cpp
dom/GenericEventQueue.cpp
@@ -2990,12 +2991,15 @@ set(WebCore_SOURCES
workers/service/ServiceWorkerContainer.cpp
workers/service/ServiceWorkerGlobalScope.cpp
workers/service/ServiceWorkerJob.cpp
workers/service/ServiceWorkerJobData.cpp
workers/service/ServiceWorkerProvider.cpp
workers/service/ServiceWorkerRegistration.cpp
workers/service/ServiceWorkerRegistrationParameters.cpp
workers/service/ServiceWorkerRegistrationKey.cpp
workers/service/ServiceWorkerRegistrationOptions.cpp

workers/service/server/SWClientConnection.cpp
workers/service/server/SWServer.cpp
workers/service/server/SWServerRegistration.cpp

xml/DOMParser.cpp
xml/NativeXPathNSResolver.cpp
@@ -1,3 +1,105 @@
2017-08-25 Brady Eidson <beidson@apple.com>

Introduce ServerWorkerRegistration task queues.
https://bugs.webkit.org/show_bug.cgi?id=175851

Reviewed by Andy Estes.

Test: http/tests/workers/service/registration-task-queue-scheduling-1.html

This change introduces:
- A task thread/queue owned by each SWServer object.
- The SWServerRegistration object, which is the in-server representation of a
service worker registration scope.
- A registration job queue per SWServerRegistration object which actually runs the
jobs as tasks on the owning SWServer's thread.

With that infrastructure in place, it moves the "register" job to something that is
scheduled and rejected asynchronously, as opposed to synchronously rejected.

The test verifies that two different registration scopes (localhost and 127.0.0.1)
can both spam the SWServer with registration requests, but neither of their queues
starve the other.

The rest of this change is a lot of support and plumbing for making the above happen.

* CMakeLists.txt:
* WebCore.xcodeproj/project.pbxproj:

* dom/ExceptionData.cpp:
(WebCore::ExceptionData::isolatedCopy const):
* dom/ExceptionData.h:

* workers/service/ServiceWorkerContainer.cpp:
(WebCore::ServiceWorkerContainer::addRegistration):
(WebCore::ServiceWorkerContainer::connectionIdentifier):
* workers/service/ServiceWorkerContainer.h:

* workers/service/ServiceWorkerJob.cpp:
(WebCore::ServiceWorkerJob::ServiceWorkerJob):
(WebCore::ServiceWorkerJob::data const): Deleted.
* workers/service/ServiceWorkerJob.h:
(WebCore::ServiceWorkerJob::create):
(WebCore::ServiceWorkerJob::data const):
(WebCore::ServiceWorkerJob::createRegisterJob): Deleted.

* workers/service/ServiceWorkerJobClient.h:

* workers/service/ServiceWorkerJobData.cpp:
(WebCore::ServiceWorkerJobData::ServiceWorkerJobData):
(WebCore::ServiceWorkerJobData::registrationKey const):
(WebCore::ServiceWorkerJobData::isolatedCopy const):
* workers/service/ServiceWorkerJobData.h:
(WebCore::ServiceWorkerJobData::jobIdentifier const):
(WebCore::ServiceWorkerJobData::connectionIdentifier const):
(WebCore::ServiceWorkerJobData::encode const):
(WebCore::ServiceWorkerJobData::decode):

* workers/service/ServiceWorkerRegistrationKey.cpp:
(WebCore::ServiceWorkerRegistrationKey::emptyKey):
(WebCore::ServiceWorkerRegistrationKey::hash const):
(WebCore::ServiceWorkerRegistrationKey::operator== const):
* workers/service/ServiceWorkerRegistrationKey.h:
(WTF::ServiceWorkerRegistrationKeyHash::hash):
(WTF::ServiceWorkerRegistrationKeyHash::equal):
(WTF::HashTraits<WebCore::ServiceWorkerRegistrationKey>::emptyValue):
(WTF::HashTraits<WebCore::ServiceWorkerRegistrationKey>::constructDeletedValue):
(WTF::HashTraits<WebCore::ServiceWorkerRegistrationKey>::isDeletedValue):

* workers/service/ServiceWorkerRegistrationOptions.cpp:
(WebCore::RegistrationOptions::isolatedCopy const):
* workers/service/ServiceWorkerRegistrationOptions.h:
(WebCore::RegistrationOptions::encode const):
(WebCore::RegistrationOptions::decode):

* workers/service/server/SWClientConnection.h:

* workers/service/server/SWServer.cpp:
(WebCore::SWServer::Connection::Connection):
(WebCore::SWServer::~SWServer):
(WebCore::SWServer::Connection::scheduleJobInServer):
(WebCore::SWServer::SWServer):
(WebCore::SWServer::scheduleJob):
(WebCore::SWServer::rejectJob):
(WebCore::SWServer::taskThreadEntryPoint):
(WebCore::SWServer::postTask):
(WebCore::SWServer::postTaskReply):
(WebCore::SWServer::handleTaskRepliesOnMainThread):
(WebCore::SWServer::registerConnection):
(WebCore::SWServer::unregisterConnection):
* workers/service/server/SWServer.h:
(WebCore::SWServer::Connection::identifier const):

* workers/service/server/SWServerRegistration.cpp: Added.
(WebCore::SWServerRegistration::SWServerRegistration):
(WebCore::SWServerRegistration::~SWServerRegistration):
(WebCore::SWServerRegistration::enqueueJob):
(WebCore::SWServerRegistration::startNextJob):
(WebCore::SWServerRegistration::performCurrentJob):
(WebCore::SWServerRegistration::rejectCurrentJob):
(WebCore::SWServerRegistration::finishCurrentJob):
* workers/service/server/SWServerRegistration.h:

2017-08-25 Michael Catanzaro <mcatanzaro@igalia.com>

Unreviewed, add comment warning that some flags have been copied into Epiphany

0 comments on commit 32ae1b6

Please sign in to comment.