Bug 180047 - Register Documents as ServiceWorker clients to the StorageProcess
Summary: Register Documents as ServiceWorker clients to the StorageProcess
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore Misc. (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: youenn fablet
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2017-11-27 11:21 PST by youenn fablet
Modified: 2017-12-01 13:07 PST (History)
10 users (show)

See Also:


Attachments
Patch (27.81 KB, patch)
2017-11-27 11:44 PST, youenn fablet
no flags Details | Formatted Diff | Diff
Patch (27.57 KB, patch)
2017-11-27 13:06 PST, youenn fablet
no flags Details | Formatted Diff | Diff
Patch (26.05 KB, patch)
2017-11-27 13:14 PST, youenn fablet
no flags Details | Formatted Diff | Diff
Patch (26.15 KB, patch)
2017-11-27 13:25 PST, youenn fablet
no flags Details | Formatted Diff | Diff
Archive of layout-test-results from ews100 for mac-elcapitan (303.86 KB, application/zip)
2017-11-27 13:58 PST, EWS Watchlist
no flags Details
Archive of layout-test-results from ews114 for mac-elcapitan (400.92 KB, application/zip)
2017-11-27 14:04 PST, EWS Watchlist
no flags Details
Archive of layout-test-results from ews126 for ios-simulator-wk2 (1.48 MB, application/zip)
2017-11-27 14:23 PST, EWS Watchlist
no flags Details
Archive of layout-test-results from ews106 for mac-elcapitan-wk2 (1.75 MB, application/zip)
2017-11-27 14:25 PST, EWS Watchlist
no flags Details
Patch (27.09 KB, patch)
2017-11-27 15:38 PST, youenn fablet
no flags Details | Formatted Diff | Diff
Patch (27.15 KB, patch)
2017-11-27 16:41 PST, youenn fablet
no flags Details | Formatted Diff | Diff
Patch (28.34 KB, patch)
2017-11-28 12:37 PST, youenn fablet
no flags Details | Formatted Diff | Diff
Patch for landing (28.08 KB, patch)
2017-11-28 17:18 PST, youenn fablet
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description youenn fablet 2017-11-27 11:21:25 PST
Storage Process needs to know potential ServiceWorker clients.
Any document which may interact with a service worker should be registered.
Comment 1 youenn fablet 2017-11-27 11:44:03 PST
Created attachment 327654 [details]
Patch
Comment 2 youenn fablet 2017-11-27 13:06:33 PST
Created attachment 327663 [details]
Patch
Comment 3 youenn fablet 2017-11-27 13:14:36 PST
Created attachment 327664 [details]
Patch
Comment 4 youenn fablet 2017-11-27 13:25:23 PST
Created attachment 327667 [details]
Patch
Comment 5 EWS Watchlist 2017-11-27 13:58:14 PST
Comment on attachment 327667 [details]
Patch

Attachment 327667 [details] did not pass mac-ews (mac):
Output: http://webkit-queues.webkit.org/results/5378744

Number of test failures exceeded the failure limit.
Comment 6 EWS Watchlist 2017-11-27 13:58:15 PST
Created attachment 327675 [details]
Archive of layout-test-results from ews100 for mac-elcapitan

The attached test failures were seen while running run-webkit-tests on the mac-ews.
Bot: ews100  Port: mac-elcapitan  Platform: Mac OS X 10.11.6
Comment 7 EWS Watchlist 2017-11-27 14:04:29 PST
Comment on attachment 327667 [details]
Patch

Attachment 327667 [details] did not pass mac-debug-ews (mac):
Output: http://webkit-queues.webkit.org/results/5378697

Number of test failures exceeded the failure limit.
Comment 8 EWS Watchlist 2017-11-27 14:04:30 PST
Created attachment 327677 [details]
Archive of layout-test-results from ews114 for mac-elcapitan

The attached test failures were seen while running run-webkit-tests on the mac-debug-ews.
Bot: ews114  Port: mac-elcapitan  Platform: Mac OS X 10.11.6
Comment 9 EWS Watchlist 2017-11-27 14:23:45 PST
Comment on attachment 327667 [details]
Patch

Attachment 327667 [details] did not pass ios-sim-ews (ios-simulator-wk2):
Output: http://webkit-queues.webkit.org/results/5378877

Number of test failures exceeded the failure limit.
Comment 10 EWS Watchlist 2017-11-27 14:23:46 PST
Created attachment 327680 [details]
Archive of layout-test-results from ews126 for ios-simulator-wk2

The attached test failures were seen while running run-webkit-tests on the ios-sim-ews.
Bot: ews126  Port: ios-simulator-wk2  Platform: Mac OS X 10.12.6
Comment 11 EWS Watchlist 2017-11-27 14:25:24 PST
Comment on attachment 327667 [details]
Patch

Attachment 327667 [details] did not pass mac-wk2-ews (mac-wk2):
Output: http://webkit-queues.webkit.org/results/5379142

Number of test failures exceeded the failure limit.
Comment 12 EWS Watchlist 2017-11-27 14:25:25 PST
Created attachment 327682 [details]
Archive of layout-test-results from ews106 for mac-elcapitan-wk2

The attached test failures were seen while running run-webkit-tests on the mac-wk2-ews.
Bot: ews106  Port: mac-elcapitan-wk2  Platform: Mac OS X 10.11.6
Comment 13 youenn fablet 2017-11-27 15:38:06 PST
Created attachment 327699 [details]
Patch
Comment 14 youenn fablet 2017-11-27 16:41:05 PST
Created attachment 327711 [details]
Patch
Comment 15 youenn fablet 2017-11-28 12:37:19 PST
Created attachment 327775 [details]
Patch
Comment 16 Chris Dumez 2017-11-28 14:50:50 PST
Comment on attachment 327775 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=327775&action=review

> Source/WebCore/ChangeLog:17
> +        Storing all clients in SWServer as a HasMap keyed by ClientOrigin.

typo: HasMap

> Source/WebCore/dom/Document.cpp:7589
> +void Document::setServiceWorkerConnection(SWClientConnection* serviceWorkerConnection)

This seems to be only called when a service worker starts controlling a document. This seems wrong no? In the current state, it seems identical to the "client using registration" concept which we already have.

> Source/WebCore/workers/service/ServiceWorkerClientIdentifier.h:40
> +    bool operator==(const ServiceWorkerClientIdentifier& identifier) const { return serverConnectionIdentifier == identifier.serverConnectionIdentifier &&  contextIdentifier == identifier.contextIdentifier; }

Darin told me we normally prefer when the operator is outside the class, not a member.

> Source/WebCore/workers/service/server/SWServer.cpp:502
> +    clients.removeFirstMatching([&] (const auto& item) {

Why aren't we using a HashSet?

> Source/WebCore/workers/service/server/SWServer.h:177
> +    HashMap<ClientOrigin, Vector<ClientInformation>> m_clients;

Why are clients stored like this and not on SWServiceWorker? Those are *service worker* clients, right? If so, shouldn't they be tried to a SWServiceWorker object instead of globally on the server?

> Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.h:99
> +    HashMap<WebCore::DocumentIdentifier, WebCore::ClientOrigin> m_clientOrigins;

Why do we need another copy of this map? This is basically the same map as on SWServer, no?
Comment 17 Chris Dumez 2017-11-28 15:10:16 PST
Basically, I expected something like:
HashSet<ServiceWorkerClientIdentifier> m_clients;

on SWServerWorker.

Any reason we cannot / should not do this?
Comment 18 youenn fablet 2017-11-28 15:10:44 PST
Comment on attachment 327775 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=327775&action=review

>> Source/WebCore/dom/Document.cpp:7589
>> +void Document::setServiceWorkerConnection(SWClientConnection* serviceWorkerConnection)
> 
> This seems to be only called when a service worker starts controlling a document. This seems wrong no? In the current state, it seems identical to the "client using registration" concept which we already have.

If service worker runtime flag is on, it will be called for every document in DocumentLoader::commitData.
This patch does the registration as a client just before selecting a service worker if there is one.

>> Source/WebCore/workers/service/ServiceWorkerClientIdentifier.h:40
>> +    bool operator==(const ServiceWorkerClientIdentifier& identifier) const { return serverConnectionIdentifier == identifier.serverConnectionIdentifier &&  contextIdentifier == identifier.contextIdentifier; }
> 
> Darin told me we normally prefer when the operator is outside the class, not a member.

Right.

>> Source/WebCore/workers/service/server/SWServer.cpp:502
>> +    clients.removeFirstMatching([&] (const auto& item) {
> 
> Why aren't we using a HashSet?

Was not too sure about it.
I picked a Vector since algos like Clients.matchAll are iterating through this list and are generating arrays of clients.
That said, matchAll is requiring some sorting at the end of the algorithm so maybe a HashSet would be better.

>> Source/WebCore/workers/service/server/SWServer.h:177
>> +    HashMap<ClientOrigin, Vector<ClientInformation>> m_clients;
> 
> Why are clients stored like this and not on SWServiceWorker? Those are *service worker* clients, right? If so, shouldn't they be tried to a SWServiceWorker object instead of globally on the server?

Not sure to follow here.
They are indeed service worker clients and any service worker from that ClientOrigin can talk to any of this client.

>> Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.h:99
>> +    HashMap<WebCore::DocumentIdentifier, WebCore::ClientOrigin> m_clientOrigins;
> 
> Why do we need another copy of this map? This is basically the same map as on SWServer, no?

This is a map specific to the clients of a WebProcess, SWServer map is global to all web processes.
m_clientOrigins for instance allows removing all clients of a given WebProcess if it crashes for instance.
Comment 19 Brady Eidson 2017-11-28 16:33:12 PST
Comment on attachment 327775 [details]
Patch

Little details pointed out by Chris aside, I think this is the necessary approach
Comment 20 Chris Dumez 2017-11-28 16:51:14 PST
(In reply to Brady Eidson from comment #19)
> Comment on attachment 327775 [details]
> Patch
> 
> Little details pointed out by Chris aside, I think this is the necessary
> approach

Yes, after discussing this offline with Youenn. My initial understanding was wrong and I am ok with this approach as well now.
Comment 21 youenn fablet 2017-11-28 17:18:09 PST
Created attachment 327807 [details]
Patch for landing
Comment 22 youenn fablet 2017-11-28 17:18:49 PST
I kept a vector instead of a HashSet for now.
I will revisit this when fully implementing Clients API.
Comment 23 WebKit Commit Bot 2017-11-28 17:50:07 PST
Comment on attachment 327807 [details]
Patch for landing

Clearing flags on attachment: 327807

Committed r225251: <https://trac.webkit.org/changeset/225251>
Comment 24 WebKit Commit Bot 2017-11-28 17:50:09 PST
All reviewed patches have been landed.  Closing bug.
Comment 25 Radar WebKit Bug Importer 2017-11-28 17:51:31 PST
<rdar://problem/35738152>
Comment 26 youenn fablet 2017-12-01 13:07:45 PST
(In reply to youenn fablet from comment #22)
> I kept a vector instead of a HashSet for now.
> I will revisit this when fully implementing Clients API.

Looking at it further, matched clients should be sorted by their creation order.
This creation order is now supported by Vector.
If we need a more explicit creation order, we should use a HashSet.