Diff
Modified: trunk/Source/WebCore/ChangeLog (225716 => 225717)
--- trunk/Source/WebCore/ChangeLog 2017-12-09 01:05:58 UTC (rev 225716)
+++ trunk/Source/WebCore/ChangeLog 2017-12-09 03:03:06 UTC (rev 225717)
@@ -1,3 +1,29 @@
+2017-12-08 Brady Eidson <beid...@apple.com>
+
+ Delay some service worker operations until after the database import completes.
+ https://bugs.webkit.org/show_bug.cgi?id=180573
+
+ Reviewed by Chris Dumez.
+
+ No new tests (Not testable yet).
+
+ Right after the storage process launches it starts importing registration records.
+ During this time, a lot of the decisions we make regarding registrations, fetch, etc.
+ are invalid, as they rely on those in-memory records being in place.
+
+ This patch delays certain things until after the initial origin table import is complete.
+
+ * workers/service/server/RegistrationStore.cpp:
+ (WebCore::RegistrationStore::databaseOpenedAndRecordsImported):
+
+ * workers/service/server/SWOriginStore.h:
+
+ * workers/service/server/SWServer.cpp:
+ (WebCore::SWServer::registrationStoreImportComplete): Tell the origin store the initial
+ import was completed.
+ (WebCore::SWServer::addRegistrationFromStore):
+ * workers/service/server/SWServer.h:
+
2017-12-08 Youenn Fablet <you...@apple.com>
Service Worker should use a correct user agent
Modified: trunk/Source/WebCore/workers/service/server/RegistrationStore.cpp (225716 => 225717)
--- trunk/Source/WebCore/workers/service/server/RegistrationStore.cpp 2017-12-09 01:05:58 UTC (rev 225716)
+++ trunk/Source/WebCore/workers/service/server/RegistrationStore.cpp 2017-12-09 03:03:06 UTC (rev 225717)
@@ -100,12 +100,12 @@
void RegistrationStore::databaseFailedToOpen()
{
- // FIXME: Handle error in some appropriate manner.
+ m_server.registrationStoreImportComplete();
}
void RegistrationStore::databaseOpenedAndRecordsImported()
{
- // FIXME: Once we actually do the imports, conclude the importing phase here.
+ m_server.registrationStoreImportComplete();
}
} // namespace WebCore
Modified: trunk/Source/WebCore/workers/service/server/SWOriginStore.h (225716 => 225717)
--- trunk/Source/WebCore/workers/service/server/SWOriginStore.h 2017-12-09 01:05:58 UTC (rev 225716)
+++ trunk/Source/WebCore/workers/service/server/SWOriginStore.h 2017-12-09 03:03:06 UTC (rev 225717)
@@ -45,6 +45,8 @@
void clear(const SecurityOrigin&);
void clearAll();
+ virtual void importComplete() = 0;
+
private:
virtual void addToStore(const SecurityOrigin&) = 0;
virtual void removeFromStore(const SecurityOrigin&) = 0;
Modified: trunk/Source/WebCore/workers/service/server/SWServer.cpp (225716 => 225717)
--- trunk/Source/WebCore/workers/service/server/SWServer.cpp 2017-12-09 01:05:58 UTC (rev 225716)
+++ trunk/Source/WebCore/workers/service/server/SWServer.cpp 2017-12-09 03:03:06 UTC (rev 225717)
@@ -98,8 +98,16 @@
return m_registrations.get(registrationKey);
}
+void SWServer::registrationStoreImportComplete()
+{
+ m_originStore->importComplete();
+}
+
void SWServer::addRegistrationFromStore(ServiceWorkerContextData&& data)
{
+ // Pages should not have been able to make a new registration to this key while the import was still taking place.
+ ASSERT(!m_registrations.contains(data.registration.key));
+
addRegistration(std::make_unique<SWServerRegistration>(*this, data.registration.key, data.registration.updateViaCache, data.registration.scopeURL, data.scriptURL));
tryInstallContextData(WTFMove(data));
}
Modified: trunk/Source/WebCore/workers/service/server/SWServer.h (225716 => 225717)
--- trunk/Source/WebCore/workers/service/server/SWServer.h 2017-12-09 01:05:58 UTC (rev 225716)
+++ trunk/Source/WebCore/workers/service/server/SWServer.h 2017-12-09 03:03:06 UTC (rev 225717)
@@ -169,6 +169,7 @@
void resolveRegistrationReadyRequests(SWServerRegistration&);
void addRegistrationFromStore(ServiceWorkerContextData&&);
+ void registrationStoreImportComplete();
private:
void registerConnection(Connection&);
Modified: trunk/Source/WebKit/ChangeLog (225716 => 225717)
--- trunk/Source/WebKit/ChangeLog 2017-12-09 01:05:58 UTC (rev 225716)
+++ trunk/Source/WebKit/ChangeLog 2017-12-09 03:03:06 UTC (rev 225717)
@@ -1,3 +1,37 @@
+2017-12-08 Brady Eidson <beid...@apple.com>
+
+ Delay some service worker operations until after the database import completes.
+ https://bugs.webkit.org/show_bug.cgi?id=180573
+
+ Reviewed by Chris Dumez.
+
+ * StorageProcess/ServiceWorker/WebSWOriginStore.cpp:
+ (WebKit::WebSWOriginStore::importComplete): Tell the Origin Table on all connects that
+ the import is complete.
+ (WebKit::WebSWOriginStore::registerSWServerConnection):
+ * StorageProcess/ServiceWorker/WebSWOriginStore.h:
+
+ * WebProcess/Storage/WebSWClientConnection.cpp:
+ (WebKit::WebSWClientConnection::mayHaveServiceWorkerRegisteredForOrigin const):
+ (WebKit::WebSWClientConnection::setSWOriginTableIsImported): Run deferred tasks!
+ (WebKit::WebSWClientConnection::matchRegistration): If the import isn't complete yet, delay
+ the match registration task until later.
+ (WebKit::WebSWClientConnection::runOrDelayTask): Either send the message now or save off
+ the task to wait until the import is complete.
+ (WebKit::WebSWClientConnection::getRegistrations): If the import isn't complete yet, delay
+ the get registrations task until later.
+ (WebKit::WebSWClientConnection::initializeSWOriginTableAsEmpty): Deleted.
+ * WebProcess/Storage/WebSWClientConnection.h:
+ * WebProcess/Storage/WebSWClientConnection.messages.in:
+
+ * WebProcess/Storage/WebSWOriginTable.cpp:
+ (WebKit::WebSWOriginTable::setSharedMemory):
+ * WebProcess/Storage/WebSWOriginTable.h:
+ (WebKit::WebSWOriginTable::isImported const):
+ (WebKit::WebSWOriginTable::setIsImported):
+ (WebKit::WebSWOriginTable::isInitialized const): Deleted.
+ (WebKit::WebSWOriginTable::initializeAsEmpty): Deleted.
+
2017-12-08 Youenn Fablet <you...@apple.com>
Service Worker should use a correct user agent
Modified: trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWOriginStore.cpp (225716 => 225717)
--- trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWOriginStore.cpp 2017-12-09 01:05:58 UTC (rev 225716)
+++ trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWOriginStore.cpp 2017-12-09 03:03:06 UTC (rev 225717)
@@ -58,16 +58,22 @@
m_store.clear();
}
+void WebSWOriginStore::importComplete()
+{
+ m_isImported = true;
+ for (auto* connection : m_webSWServerConnections)
+ connection->send(Messages::WebSWClientConnection::SetSWOriginTableIsImported());
+}
+
void WebSWOriginStore::registerSWServerConnection(WebSWServerConnection& connection)
{
m_webSWServerConnections.add(&connection);
- if (m_store.isEmpty()) {
- connection.send(Messages::WebSWClientConnection::InitializeSWOriginTableAsEmpty());
- return;
- }
+ if (!m_store.isEmpty())
+ sendStoreHandle(connection);
- sendStoreHandle(connection);
+ if (m_isImported)
+ connection.send(Messages::WebSWClientConnection::SetSWOriginTableIsImported());
}
void WebSWOriginStore::unregisterSWServerConnection(WebSWServerConnection& connection)
Modified: trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWOriginStore.h (225716 => 225717)
--- trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWOriginStore.h 2017-12-09 01:05:58 UTC (rev 225716)
+++ trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWOriginStore.h 2017-12-09 03:03:06 UTC (rev 225717)
@@ -45,6 +45,7 @@
void registerSWServerConnection(WebSWServerConnection&);
void unregisterSWServerConnection(WebSWServerConnection&);
+ void importComplete() final;
private:
void sendStoreHandle(WebSWServerConnection&);
@@ -57,6 +58,7 @@
void didInvalidateSharedMemory() final;
SharedStringHashStore m_store;
+ bool m_isImported { false };
HashSet<WebSWServerConnection*> m_webSWServerConnections;
};
Modified: trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.cpp (225716 => 225717)
--- trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.cpp 2017-12-09 01:05:58 UTC (rev 225716)
+++ trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.cpp 2017-12-09 03:03:06 UTC (rev 225717)
@@ -109,7 +109,7 @@
bool WebSWClientConnection::mayHaveServiceWorkerRegisteredForOrigin(const SecurityOrigin& origin) const
{
- if (!m_swOriginTable->isInitialized())
+ if (!m_swOriginTable->isImported())
return true;
return m_swOriginTable->contains(origin);
@@ -120,9 +120,11 @@
m_swOriginTable->setSharedMemory(handle);
}
-void WebSWClientConnection::initializeSWOriginTableAsEmpty()
+void WebSWClientConnection::setSWOriginTableIsImported()
{
- m_swOriginTable->initializeAsEmpty();
+ m_swOriginTable->setIsImported();
+ while (!m_tasksPendingOriginImport.isEmpty())
+ m_tasksPendingOriginImport.takeFirst()();
}
void WebSWClientConnection::didMatchRegistration(uint64_t matchingRequest, std::optional<ServiceWorkerRegistrationData>&& result)
@@ -150,11 +152,21 @@
return;
}
- uint64_t callbackID = ++m_previousCallbackIdentifier;
- m_ongoingMatchRegistrationTasks.add(callbackID, WTFMove(callback));
- send(Messages::WebSWServerConnection::MatchRegistration(callbackID, SecurityOriginData::fromSecurityOrigin(topOrigin), clientURL));
+ runOrDelayTaskForImport([this, callback = WTFMove(callback), topOrigin = SecurityOriginData::fromSecurityOrigin(topOrigin), clientURL]() mutable {
+ uint64_t callbackID = ++m_previousCallbackIdentifier;
+ m_ongoingMatchRegistrationTasks.add(callbackID, WTFMove(callback));
+ send(Messages::WebSWServerConnection::MatchRegistration(callbackID, topOrigin, clientURL));
+ });
}
+void WebSWClientConnection::runOrDelayTaskForImport(WTF::Function<void()>&& task)
+{
+ if (m_swOriginTable->isImported())
+ task();
+ else
+ m_tasksPendingOriginImport.append(WTFMove(task));
+}
+
void WebSWClientConnection::whenRegistrationReady(const SecurityOrigin& topOrigin, const URL& clientURL, WhenRegistrationReadyCallback&& callback)
{
uint64_t callbackID = ++m_previousCallbackIdentifier;
@@ -178,9 +190,11 @@
return;
}
- uint64_t callbackID = ++m_previousCallbackIdentifier;
- m_ongoingGetRegistrationsTasks.add(callbackID, WTFMove(callback));
- send(Messages::WebSWServerConnection::GetRegistrations(callbackID, SecurityOriginData::fromSecurityOrigin(topOrigin), clientURL));
+ runOrDelayTaskForImport([this, callback = WTFMove(callback), topOrigin = SecurityOriginData::fromSecurityOrigin(topOrigin), clientURL]() mutable {
+ uint64_t callbackID = ++m_previousCallbackIdentifier;
+ m_ongoingGetRegistrationsTasks.add(callbackID, WTFMove(callback));
+ send(Messages::WebSWServerConnection::GetRegistrations(callbackID, topOrigin, clientURL));
+ });
}
void WebSWClientConnection::startFetch(const ResourceLoader& loader, uint64_t identifier)
Modified: trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.h (225716 => 225717)
--- trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.h 2017-12-09 01:05:58 UTC (rev 225716)
+++ trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.h 2017-12-09 03:03:06 UTC (rev 225717)
@@ -90,11 +90,13 @@
void scheduleStorageJob(const WebCore::ServiceWorkerJobData&);
+ void runOrDelayTaskForImport(WTF::Function<void()>&& task);
+
IPC::Connection* messageSenderConnection() final { return m_connection.ptr(); }
uint64_t messageSenderDestinationID() final { return m_identifier.toUInt64(); }
void setSWOriginTableSharedMemory(const SharedMemory::Handle&);
- void initializeSWOriginTableAsEmpty();
+ void setSWOriginTableIsImported();
PAL::SessionID m_sessionID;
WebCore::SWServerConnectionIdentifier m_identifier;
@@ -106,6 +108,7 @@
HashMap<uint64_t, RegistrationCallback> m_ongoingMatchRegistrationTasks;
HashMap<uint64_t, GetRegistrationsCallback> m_ongoingGetRegistrationsTasks;
HashMap<uint64_t, WhenRegistrationReadyCallback> m_ongoingRegistrationReadyTasks;
+ Deque<WTF::Function<void()>> m_tasksPendingOriginImport;
}; // class WebSWServerConnection
Modified: trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.messages.in (225716 => 225717)
--- trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.messages.in 2017-12-09 01:05:58 UTC (rev 225716)
+++ trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.messages.in 2017-12-09 03:03:06 UTC (rev 225717)
@@ -33,7 +33,7 @@
FireUpdateFoundEvent(WebCore::ServiceWorkerRegistrationIdentifier identifier)
NotifyClientsOfControllerChange(HashSet<WebCore::DocumentIdentifier> contextIdentifiers, struct WebCore::ServiceWorkerData newController)
- InitializeSWOriginTableAsEmpty()
+ SetSWOriginTableIsImported()
SetSWOriginTableSharedMemory(WebKit::SharedMemory::Handle handle)
PostMessageToServiceWorkerClient(WebCore::DocumentIdentifier destinationContextIdentifier, IPC::DataReference message, struct WebCore::ServiceWorkerData source, String sourceOrigin)
Modified: trunk/Source/WebKit/WebProcess/Storage/WebSWOriginTable.cpp (225716 => 225717)
--- trunk/Source/WebKit/WebProcess/Storage/WebSWOriginTable.cpp 2017-12-09 01:05:58 UTC (rev 225716)
+++ trunk/Source/WebKit/WebProcess/Storage/WebSWOriginTable.cpp 2017-12-09 03:03:06 UTC (rev 225717)
@@ -44,8 +44,6 @@
void WebSWOriginTable::setSharedMemory(const SharedMemory::Handle& handle)
{
- m_isInitialized = true;
-
auto sharedMemory = SharedMemory::map(handle, SharedMemory::Protection::ReadOnly);
if (!sharedMemory)
return;
Modified: trunk/Source/WebKit/WebProcess/Storage/WebSWOriginTable.h (225716 => 225717)
--- trunk/Source/WebKit/WebProcess/Storage/WebSWOriginTable.h 2017-12-09 01:05:58 UTC (rev 225716)
+++ trunk/Source/WebKit/WebProcess/Storage/WebSWOriginTable.h 2017-12-09 03:03:06 UTC (rev 225717)
@@ -40,14 +40,14 @@
public:
WebSWOriginTable() = default;
- bool isInitialized() const { return m_isInitialized; }
+ bool isImported() const { return m_isImported; }
+ void setIsImported() { m_isImported = true; }
bool contains(const WebCore::SecurityOrigin&) const;
void setSharedMemory(const SharedMemory::Handle&);
- void initializeAsEmpty() { m_isInitialized = true; }
private:
SharedStringHashTableReadOnly m_serviceWorkerOriginTable;
- bool m_isInitialized { false };
+ bool m_isImported { false };
};
} // namespace WebKit