Changeset 225486 in webkit
- Timestamp:
- Dec 4, 2017 12:35:05 PM (6 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r225485 r225486 1 2017-12-04 Youenn Fablet <youenn@apple.com> 2 3 Call "Terminate Service Worker" on all workers when all their clients are gone 4 https://bugs.webkit.org/show_bug.cgi?id=179552 5 6 Reviewed by Chris Dumez. 7 8 Tested manually. 9 10 When SWServer detects that there is no longer any client for a given client origin, 11 it iterates through the running workers to terminate them if they have the given client origin. 12 A timer of 60 seconds is used in case a user closes a tab or a window, and reopens one with the same origin shortly after. 13 14 * workers/service/server/SWServer.cpp: 15 (WebCore::SWServer::findClientByIdentifier): 16 (WebCore::SWServer::matchAll): 17 (WebCore::SWServer::registerServiceWorkerClient): 18 (WebCore::SWServer::unregisterServiceWorkerClient): 19 * workers/service/server/SWServer.h: 20 1 21 2017-12-04 Antti Koivisto <antti@apple.com> 2 22 -
trunk/Source/WebCore/workers/service/server/SWServer.cpp
r225457 r225486 53 53 } 54 54 55 static Seconds terminationDelay { 60_s }; 56 55 57 SWServer::Connection::Connection(SWServer& server) 56 58 : m_server(server) … … 323 325 return std::nullopt; 324 326 325 auto& clients = iterator->value ;327 auto& clients = iterator->value.clients; 326 328 auto position = clients.findMatching([&] (const auto& client) { 327 329 return clientIdentifier == client.identifier; … … 337 339 // FIXME: Support WindowClient additional properties. 338 340 339 auto clients = m_clients. get(worker.origin());341 auto clients = m_clients.find(worker.origin())->value.clients; 340 342 341 343 if (!options.includeUncontrolled) { … … 616 618 void SWServer::registerServiceWorkerClient(ClientOrigin&& clientOrigin, ServiceWorkerClientIdentifier identifier, ServiceWorkerClientData&& data) 617 619 { 618 m_clients.ensure(WTFMove(clientOrigin), [] { 619 return Vector<ServiceWorkerClientInformation> { }; 620 }).iterator->value.append(ServiceWorkerClientInformation { identifier, WTFMove(data) }); 620 auto& clientsData = m_clients.ensure(WTFMove(clientOrigin), [] { 621 return Clients { }; 622 }).iterator->value; 623 624 clientsData.clients.append(ServiceWorkerClientInformation { identifier, WTFMove(data) }); 625 if (clientsData.terminateServiceWorkersTimer) 626 clientsData.terminateServiceWorkersTimer = nullptr; 621 627 } 622 628 … … 626 632 ASSERT(iterator != m_clients.end()); 627 633 628 auto& clients = iterator->value ;634 auto& clients = iterator->value.clients; 629 635 clients.removeFirstMatching([&] (const auto& item) { 630 636 return identifier == item.identifier; 631 637 }); 632 if (clients.isEmpty()) { 633 // FIXME: We might want to terminate any clientOrigin related service worker. 634 m_clients.remove(iterator); 635 } 638 639 if (!clients.isEmpty() || m_runningOrTerminatingWorkers.isEmpty()) 640 return; 641 642 ASSERT(!iterator->value.terminateServiceWorkersTimer); 643 iterator->value.terminateServiceWorkersTimer = std::make_unique<Timer>([clientOrigin, this] { 644 for (auto& worker : m_runningOrTerminatingWorkers.values()) { 645 if (worker->origin() == clientOrigin) 646 terminateWorker(worker); 647 } 648 m_clients.remove(clientOrigin); 649 }); 650 iterator->value.terminateServiceWorkersTimer->startOneShot(terminationDelay); 636 651 } 637 652 -
trunk/Source/WebCore/workers/service/server/SWServer.h
r225452 r225486 60 60 struct ServiceWorkerFetchResult; 61 61 struct ServiceWorkerRegistrationData; 62 class Timer; 62 63 63 64 class SWServer { … … 185 186 HashMap<ServiceWorkerIdentifier, Ref<SWServerWorker>> m_runningOrTerminatingWorkers; 186 187 187 HashMap<ClientOrigin, Vector<ServiceWorkerClientInformation>> m_clients; 188 struct Clients { 189 Vector<ServiceWorkerClientInformation> clients; 190 std::unique_ptr<Timer> terminateServiceWorkersTimer; 191 }; 192 HashMap<ClientOrigin, Clients> m_clients; 188 193 HashMap<ServiceWorkerClientIdentifier, ServiceWorkerIdentifier> m_clientToControllingWorker; 189 194
Note: See TracChangeset
for help on using the changeset viewer.