<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[224553] trunk</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/224553">224553</a></dd>
<dt>Author</dt> <dd>beidson@apple.com</dd>
<dt>Date</dt> <dd>2017-11-07 15:06:55 -0800 (Tue, 07 Nov 2017)</dd>
</dl>

<h3>Log Message</h3>
<pre>Implement "UpdateWorkerState" and use it
https://bugs.webkit.org/show_bug.cgi?id=179318

Reviewed by Chris Dumez.

LayoutTests/imported/w3c:

* web-platform-tests/service-workers/service-worker/update.https-expected.txt:

Source/WebCore:

No new tests (Existing tests and changes there-to).

* workers/service/ServiceWorker.cpp:
(WebCore::ServiceWorker::allWorkers):
(WebCore::ServiceWorker::mutableAllWorkers):
(WebCore::ServiceWorker::ServiceWorker):
(WebCore::ServiceWorker::~ServiceWorker):
(WebCore::ServiceWorker::updateWorkerState):
(WebCore::ServiceWorker::setState): Deleted.
* workers/service/ServiceWorker.h:

* workers/service/ServiceWorkerContainer.cpp:
(WebCore::ServiceWorkerContainer::updateRegistrationState):
(WebCore::ServiceWorkerContainer::jobResolvedWithRegistration):
* workers/service/ServiceWorkerContainer.h:

* workers/service/ServiceWorkerRegistration.cpp:
(WebCore::ServiceWorkerRegistration::ServiceWorkerRegistration):
(WebCore::ServiceWorkerRegistration::~ServiceWorkerRegistration):
(WebCore::ServiceWorkerRegistration::updateStateFromServer):

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

* workers/service/ServiceWorkerRegistrationKey.cpp:
(WebCore::ServiceWorkerRegistrationKey::loggingString const):
* workers/service/ServiceWorkerRegistrationKey.h:

* workers/service/ServiceWorkerTypes.h:

* workers/service/context/SWContextManager.cpp:
(WebCore::SWContextManager::registerServiceWorkerThreadForInstall):
(WebCore::SWContextManager::registerServiceWorkerThreadForUpdate): Deleted.
* workers/service/context/SWContextManager.h:

* workers/service/server/SWClientConnection.cpp:
(WebCore::SWClientConnection::updateRegistrationState):
(WebCore::SWClientConnection::updateWorkerState):
* workers/service/server/SWClientConnection.h:

* workers/service/server/SWServer.cpp:
(WebCore::SWServer::updateWorker):
* workers/service/server/SWServer.h:
(WebCore::SWServer::workerByID const):

* workers/service/server/SWServerJobQueue.cpp:
(WebCore::SWServerJobQueue::scriptFetchFinished):
(WebCore::SWServerJobQueue::scriptContextStarted):
(WebCore::SWServerJobQueue::install):
(WebCore::SWServerJobQueue::tryClearRegistration):

* workers/service/server/SWServerRegistration.cpp:
(WebCore::SWServerRegistration::updateRegistrationState):
(WebCore::SWServerRegistration::updateWorkerState):
(WebCore::SWServerRegistration::data const):
* workers/service/server/SWServerRegistration.h:
(WebCore::SWServerRegistration::setActiveServiceWorkerIdentifier): Deleted.

* workers/service/server/SWServerWorker.h:
(WebCore::SWServerWorker::state const):
(WebCore::SWServerWorker::setState):

Source/WebKit:

* Scripts/webkit/messages.py:
(headers_for_type):
* Shared/WebCoreArgumentCoders.h:

       * StorageProcess/ServiceWorker/WebSWServerConnection.cpp:
(WebKit::WebSWServerConnection::updateWorkerStateInClient):
(WebKit::WebSWServerConnection::installServiceWorkerContext):
(WebKit::WebSWServerConnection::setContextConnection):
(WebKit::WebSWServerConnection::updateServiceWorkerContext): Deleted.
* StorageProcess/ServiceWorker/WebSWServerConnection.h:

* WebProcess/Storage/WebSWClientConnection.messages.in:

* WebProcess/Storage/WebSWContextManagerConnection.cpp:
(WebKit::WebSWContextManagerConnection::installServiceWorker):
(WebKit::WebSWContextManagerConnection::updateServiceWorker): Deleted.
* WebProcess/Storage/WebSWContextManagerConnection.h:
* WebProcess/Storage/WebSWContextManagerConnection.messages.in:

Source/WTF:

* wtf/ObjectIdentifier.h:
(WTF::ObjectIdentifier::loggingString const):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsimportedw3cChangeLog">trunk/LayoutTests/imported/w3c/ChangeLog</a></li>
<li><a href="#trunkLayoutTestsimportedw3cwebplatformtestsserviceworkersserviceworkerupdatehttpsexpectedtxt">trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/update.https-expected.txt</a></li>
<li><a href="#trunkSourceWTFChangeLog">trunk/Source/WTF/ChangeLog</a></li>
<li><a href="#trunkSourceWTFwtfObjectIdentifierh">trunk/Source/WTF/wtf/ObjectIdentifier.h</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreworkersserviceServiceWorkercpp">trunk/Source/WebCore/workers/service/ServiceWorker.cpp</a></li>
<li><a href="#trunkSourceWebCoreworkersserviceServiceWorkerh">trunk/Source/WebCore/workers/service/ServiceWorker.h</a></li>
<li><a href="#trunkSourceWebCoreworkersserviceServiceWorkerContainercpp">trunk/Source/WebCore/workers/service/ServiceWorkerContainer.cpp</a></li>
<li><a href="#trunkSourceWebCoreworkersserviceServiceWorkerContainerh">trunk/Source/WebCore/workers/service/ServiceWorkerContainer.h</a></li>
<li><a href="#trunkSourceWebCoreworkersserviceServiceWorkerRegistrationcpp">trunk/Source/WebCore/workers/service/ServiceWorkerRegistration.cpp</a></li>
<li><a href="#trunkSourceWebCoreworkersserviceServiceWorkerRegistrationDatacpp">trunk/Source/WebCore/workers/service/ServiceWorkerRegistrationData.cpp</a></li>
<li><a href="#trunkSourceWebCoreworkersserviceServiceWorkerRegistrationDatah">trunk/Source/WebCore/workers/service/ServiceWorkerRegistrationData.h</a></li>
<li><a href="#trunkSourceWebCoreworkersserviceServiceWorkerRegistrationKeycpp">trunk/Source/WebCore/workers/service/ServiceWorkerRegistrationKey.cpp</a></li>
<li><a href="#trunkSourceWebCoreworkersserviceServiceWorkerRegistrationKeyh">trunk/Source/WebCore/workers/service/ServiceWorkerRegistrationKey.h</a></li>
<li><a href="#trunkSourceWebCoreworkersserviceServiceWorkerTypesh">trunk/Source/WebCore/workers/service/ServiceWorkerTypes.h</a></li>
<li><a href="#trunkSourceWebCoreworkersservicecontextSWContextManagercpp">trunk/Source/WebCore/workers/service/context/SWContextManager.cpp</a></li>
<li><a href="#trunkSourceWebCoreworkersservicecontextSWContextManagerh">trunk/Source/WebCore/workers/service/context/SWContextManager.h</a></li>
<li><a href="#trunkSourceWebCoreworkersserviceserverSWClientConnectioncpp">trunk/Source/WebCore/workers/service/server/SWClientConnection.cpp</a></li>
<li><a href="#trunkSourceWebCoreworkersserviceserverSWClientConnectionh">trunk/Source/WebCore/workers/service/server/SWClientConnection.h</a></li>
<li><a href="#trunkSourceWebCoreworkersserviceserverSWServercpp">trunk/Source/WebCore/workers/service/server/SWServer.cpp</a></li>
<li><a href="#trunkSourceWebCoreworkersserviceserverSWServerh">trunk/Source/WebCore/workers/service/server/SWServer.h</a></li>
<li><a href="#trunkSourceWebCoreworkersserviceserverSWServerJobQueuecpp">trunk/Source/WebCore/workers/service/server/SWServerJobQueue.cpp</a></li>
<li><a href="#trunkSourceWebCoreworkersserviceserverSWServerRegistrationcpp">trunk/Source/WebCore/workers/service/server/SWServerRegistration.cpp</a></li>
<li><a href="#trunkSourceWebCoreworkersserviceserverSWServerRegistrationh">trunk/Source/WebCore/workers/service/server/SWServerRegistration.h</a></li>
<li><a href="#trunkSourceWebCoreworkersserviceserverSWServerWorkerh">trunk/Source/WebCore/workers/service/server/SWServerWorker.h</a></li>
<li><a href="#trunkSourceWebKitChangeLog">trunk/Source/WebKit/ChangeLog</a></li>
<li><a href="#trunkSourceWebKitScriptswebkitmessagespy">trunk/Source/WebKit/Scripts/webkit/messages.py</a></li>
<li><a href="#trunkSourceWebKitSharedWebCoreArgumentCodersh">trunk/Source/WebKit/Shared/WebCoreArgumentCoders.h</a></li>
<li><a href="#trunkSourceWebKitStorageProcessServiceWorkerWebSWServerConnectioncpp">trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.cpp</a></li>
<li><a href="#trunkSourceWebKitStorageProcessServiceWorkerWebSWServerConnectionh">trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.h</a></li>
<li><a href="#trunkSourceWebKitWebProcessStorageWebSWClientConnectionmessagesin">trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.messages.in</a></li>
<li><a href="#trunkSourceWebKitWebProcessStorageWebSWContextManagerConnectioncpp">trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.cpp</a></li>
<li><a href="#trunkSourceWebKitWebProcessStorageWebSWContextManagerConnectionh">trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.h</a></li>
<li><a href="#trunkSourceWebKitWebProcessStorageWebSWContextManagerConnectionmessagesin">trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.messages.in</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsimportedw3cChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/imported/w3c/ChangeLog (224552 => 224553)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/imported/w3c/ChangeLog 2017-11-07 23:04:34 UTC (rev 224552)
+++ trunk/LayoutTests/imported/w3c/ChangeLog    2017-11-07 23:06:55 UTC (rev 224553)
</span><span class="lines">@@ -1,3 +1,12 @@
</span><ins>+2017-11-07  Brady Eidson  <beidson@apple.com>
+
+        Implement "UpdateWorkerState" and use it
+        https://bugs.webkit.org/show_bug.cgi?id=179318
+
+        Reviewed by Chris Dumez.
+
+        * web-platform-tests/service-workers/service-worker/update.https-expected.txt:
+
</ins><span class="cx"> 2017-11-07  Maciej Stachowiak  <mjs@apple.com>
</span><span class="cx"> 
</span><span class="cx">         Update WPT encoding test suite to the latest version.
</span></span></pre></div>
<a id="trunkLayoutTestsimportedw3cwebplatformtestsserviceworkersserviceworkerupdatehttpsexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/update.https-expected.txt (224552 => 224553)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/update.https-expected.txt       2017-11-07 23:04:34 UTC (rev 224552)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/update.https-expected.txt  2017-11-07 23:06:55 UTC (rev 224553)
</span><span class="lines">@@ -1,3 +1,3 @@
</span><span class="cx"> 
</span><del>-FAIL Update a registration. promise_test: Unhandled rejection with value: object "TypeError: Cannot update a null/nonexistent service worker registration"
</del><ins>+FAIL Update a registration. assert_unreached: update() should reject. Reached unreachable code
</ins><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWTFChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/ChangeLog (224552 => 224553)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/ChangeLog       2017-11-07 23:04:34 UTC (rev 224552)
+++ trunk/Source/WTF/ChangeLog  2017-11-07 23:06:55 UTC (rev 224553)
</span><span class="lines">@@ -1,3 +1,13 @@
</span><ins>+2017-11-07  Brady Eidson  <beidson@apple.com>
+
+        Implement "UpdateWorkerState" and use it
+        https://bugs.webkit.org/show_bug.cgi?id=179318
+
+        Reviewed by Chris Dumez.
+
+        * wtf/ObjectIdentifier.h:
+        (WTF::ObjectIdentifier::loggingString const):
+
</ins><span class="cx"> 2017-11-07  Michael Saboff  <msaboff@apple.com>
</span><span class="cx"> 
</span><span class="cx">         Add SPI function pointers qualifiers for CPU(ARM64E)
</span></span></pre></div>
<a id="trunkSourceWTFwtfObjectIdentifierh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/wtf/ObjectIdentifier.h (224552 => 224553)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/wtf/ObjectIdentifier.h  2017-11-07 23:04:34 UTC (rev 224552)
+++ trunk/Source/WTF/wtf/ObjectIdentifier.h     2017-11-07 23:06:55 UTC (rev 224553)
</span><span class="lines">@@ -26,6 +26,7 @@
</span><span class="cx"> #pragma once
</span><span class="cx"> 
</span><span class="cx"> #include <wtf/HashTraits.h>
</span><ins>+#include <wtf/text/WTFString.h>
</ins><span class="cx"> 
</span><span class="cx"> namespace WTF {
</span><span class="cx"> 
</span><span class="lines">@@ -60,6 +61,13 @@
</span><span class="cx">     {
</span><span class="cx">         return m_identifier != other.m_identifier;
</span><span class="cx">     }
</span><ins>+    
+#ifndef NDEBUG
+    String loggingString() const
+    {
+        return String::number(m_identifier);
+    }
+#endif
</ins><span class="cx"> 
</span><span class="cx"> private:
</span><span class="cx">     template<typename U> friend ObjectIdentifier<U> makeObjectIdentifier(uint64_t);
</span></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (224552 => 224553)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog   2017-11-07 23:04:34 UTC (rev 224552)
+++ trunk/Source/WebCore/ChangeLog      2017-11-07 23:06:55 UTC (rev 224553)
</span><span class="lines">@@ -1,3 +1,75 @@
</span><ins>+2017-11-07  Brady Eidson  <beidson@apple.com>
+
+        Implement "UpdateWorkerState" and use it
+        https://bugs.webkit.org/show_bug.cgi?id=179318
+
+        Reviewed by Chris Dumez.
+
+        No new tests (Existing tests and changes there-to).
+
+        * workers/service/ServiceWorker.cpp:
+        (WebCore::ServiceWorker::allWorkers):
+        (WebCore::ServiceWorker::mutableAllWorkers):
+        (WebCore::ServiceWorker::ServiceWorker):
+        (WebCore::ServiceWorker::~ServiceWorker):
+        (WebCore::ServiceWorker::updateWorkerState):
+        (WebCore::ServiceWorker::setState): Deleted.
+        * workers/service/ServiceWorker.h:
+
+        * workers/service/ServiceWorkerContainer.cpp:
+        (WebCore::ServiceWorkerContainer::updateRegistrationState):
+        (WebCore::ServiceWorkerContainer::jobResolvedWithRegistration):
+        * workers/service/ServiceWorkerContainer.h:
+
+        * workers/service/ServiceWorkerRegistration.cpp:
+        (WebCore::ServiceWorkerRegistration::ServiceWorkerRegistration):
+        (WebCore::ServiceWorkerRegistration::~ServiceWorkerRegistration):
+        (WebCore::ServiceWorkerRegistration::updateStateFromServer):
+
+        * workers/service/ServiceWorkerRegistrationData.cpp:
+        (WebCore::ServiceWorkerRegistrationData::isolatedCopy const):
+        * workers/service/ServiceWorkerRegistrationData.h:
+        (WebCore::ServiceWorkerRegistrationData::encode const):
+        (WebCore::ServiceWorkerRegistrationData::decode):
+
+        * workers/service/ServiceWorkerRegistrationKey.cpp:
+        (WebCore::ServiceWorkerRegistrationKey::loggingString const):
+        * workers/service/ServiceWorkerRegistrationKey.h:
+
+        * workers/service/ServiceWorkerTypes.h:
+
+        * workers/service/context/SWContextManager.cpp:
+        (WebCore::SWContextManager::registerServiceWorkerThreadForInstall):
+        (WebCore::SWContextManager::registerServiceWorkerThreadForUpdate): Deleted.
+        * workers/service/context/SWContextManager.h:
+
+        * workers/service/server/SWClientConnection.cpp:
+        (WebCore::SWClientConnection::updateRegistrationState):
+        (WebCore::SWClientConnection::updateWorkerState):
+        * workers/service/server/SWClientConnection.h:
+
+        * workers/service/server/SWServer.cpp:
+        (WebCore::SWServer::updateWorker):
+        * workers/service/server/SWServer.h:
+        (WebCore::SWServer::workerByID const):
+
+        * workers/service/server/SWServerJobQueue.cpp:
+        (WebCore::SWServerJobQueue::scriptFetchFinished):
+        (WebCore::SWServerJobQueue::scriptContextStarted):
+        (WebCore::SWServerJobQueue::install):
+        (WebCore::SWServerJobQueue::tryClearRegistration):
+
+        * workers/service/server/SWServerRegistration.cpp:
+        (WebCore::SWServerRegistration::updateRegistrationState):
+        (WebCore::SWServerRegistration::updateWorkerState):
+        (WebCore::SWServerRegistration::data const):
+        * workers/service/server/SWServerRegistration.h:
+        (WebCore::SWServerRegistration::setActiveServiceWorkerIdentifier): Deleted.
+
+        * workers/service/server/SWServerWorker.h:
+        (WebCore::SWServerWorker::state const):
+        (WebCore::SWServerWorker::setState):
+
</ins><span class="cx"> 2017-11-07  Zalan Bujtas  <zalan@apple.com>
</span><span class="cx"> 
</span><span class="cx">         [LayoutState cleanup] Remove explicit LayoutStateMaintainer::pop calls.
</span></span></pre></div>
<a id="trunkSourceWebCoreworkersserviceServiceWorkercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/workers/service/ServiceWorker.cpp (224552 => 224553)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/workers/service/ServiceWorker.cpp   2017-11-07 23:04:34 UTC (rev 224552)
+++ trunk/Source/WebCore/workers/service/ServiceWorker.cpp      2017-11-07 23:06:55 UTC (rev 224553)
</span><span class="lines">@@ -35,20 +35,55 @@
</span><span class="cx"> #include "SerializedScriptValue.h"
</span><span class="cx"> #include "ServiceWorkerProvider.h"
</span><span class="cx"> #include <runtime/JSCJSValueInlines.h>
</span><ins>+#include <wtf/NeverDestroyed.h>
</ins><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="cx"> 
</span><ins>+const HashMap<ServiceWorkerIdentifier, HashSet<ServiceWorker*>>& ServiceWorker::allWorkers()
+{
+    return mutableAllWorkers();
+}
+
+HashMap<ServiceWorkerIdentifier, HashSet<ServiceWorker*>>& ServiceWorker::mutableAllWorkers()
+{
+    // FIXME: Once we support service workers from workers, this will need to change.
+    RELEASE_ASSERT(isMainThread());
+    
+    static NeverDestroyed<HashMap<ServiceWorkerIdentifier, HashSet<ServiceWorker*>>> allWorkersMap;
+    return allWorkersMap;
+}
+
</ins><span class="cx"> ServiceWorker::ServiceWorker(ScriptExecutionContext& context, ServiceWorkerIdentifier identifier, const URL& scriptURL)
</span><span class="cx">     : ContextDestructionObserver(&context)
</span><span class="cx">     , m_identifier(identifier)
</span><span class="cx">     , m_scriptURL(scriptURL)
</span><span class="cx"> {
</span><ins>+    auto result = mutableAllWorkers().ensure(identifier, [] {
+        return HashSet<ServiceWorker*>();
+    });
+    result.iterator->value.add(this);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-void ServiceWorker::setState(State state)
</del><ins>+ServiceWorker::~ServiceWorker()
</ins><span class="cx"> {
</span><ins>+    auto iterator = mutableAllWorkers().find(m_identifier);
+
+    ASSERT(iterator->value.contains(this));
+    iterator->value.remove(this);
+
+    if (iterator->value.isEmpty())
+        mutableAllWorkers().remove(iterator);
+}
+
+void ServiceWorker::updateWorkerState(State state, ShouldFireStateChangeEvent shouldFire)
+{
+    // FIXME: Once we support service workers from workers, this might need to change.
+    RELEASE_ASSERT(isMainThread());
+
</ins><span class="cx">     m_state = state;
</span><del>-    dispatchEvent(Event::create(eventNames().statechangeEvent, false, false));
</del><ins>+    
+    if (shouldFire == FireStateChangeEvent)
+        dispatchEvent(Event::create(eventNames().statechangeEvent, false, false));
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> ExceptionOr<void> ServiceWorker::postMessage(ScriptExecutionContext& context, JSC::JSValue messageValue, Vector<JSC::Strong<JSC::JSObject>>&& transfer)
</span></span></pre></div>
<a id="trunkSourceWebCoreworkersserviceServiceWorkerh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/workers/service/ServiceWorker.h (224552 => 224553)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/workers/service/ServiceWorker.h     2017-11-07 23:04:34 UTC (rev 224552)
+++ trunk/Source/WebCore/workers/service/ServiceWorker.h        2017-11-07 23:06:55 UTC (rev 224553)
</span><span class="lines">@@ -30,6 +30,7 @@
</span><span class="cx"> #include "ContextDestructionObserver.h"
</span><span class="cx"> #include "EventTarget.h"
</span><span class="cx"> #include "ServiceWorkerIdentifier.h"
</span><ins>+#include "ServiceWorkerTypes.h"
</ins><span class="cx"> #include "URL.h"
</span><span class="cx"> #include <heap/Strong.h>
</span><span class="cx"> #include <wtf/RefCounted.h>
</span><span class="lines">@@ -49,20 +50,18 @@
</span><span class="cx">         return adoptRef(*new ServiceWorker(context, identifier, scriptURL));
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    virtual ~ServiceWorker() = default;
</del><ins>+    virtual ~ServiceWorker();
</ins><span class="cx"> 
</span><del>-    enum class State {
-        Installing,
-        Installed,
-        Activating,
-        Activated,
-        Redundant,
-    };
-
</del><span class="cx">     const URL& scriptURL() const { return m_scriptURL; }
</span><span class="cx"> 
</span><ins>+    using State = ServiceWorkerState;
</ins><span class="cx">     State state() const { return m_state; }
</span><del>-    void setState(State);
</del><ins>+    
+    enum ShouldFireStateChangeEvent {
+        FireStateChangeEvent,
+        DoNotFireStateChangeEvent,
+    };
+    void updateWorkerState(State, ShouldFireStateChangeEvent = FireStateChangeEvent);
</ins><span class="cx"> 
</span><span class="cx">     ExceptionOr<void> postMessage(ScriptExecutionContext&, JSC::JSValue message, Vector<JSC::Strong<JSC::JSObject>>&&);
</span><span class="cx"> 
</span><span class="lines">@@ -71,8 +70,11 @@
</span><span class="cx">     using RefCounted::ref;
</span><span class="cx">     using RefCounted::deref;
</span><span class="cx"> 
</span><ins>+    static const HashMap<ServiceWorkerIdentifier, HashSet<ServiceWorker*>>& allWorkers();
+
</ins><span class="cx"> private:
</span><span class="cx">     ServiceWorker(ScriptExecutionContext&, ServiceWorkerIdentifier, const URL& scriptURL);
</span><ins>+    static HashMap<ServiceWorkerIdentifier, HashSet<ServiceWorker*>>& mutableAllWorkers();
</ins><span class="cx"> 
</span><span class="cx">     virtual EventTargetInterface eventTargetInterface() const;
</span><span class="cx">     virtual ScriptExecutionContext* scriptExecutionContext() const;
</span></span></pre></div>
<a id="trunkSourceWebCoreworkersserviceServiceWorkerContainercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/workers/service/ServiceWorkerContainer.cpp (224552 => 224553)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/workers/service/ServiceWorkerContainer.cpp  2017-11-07 23:04:34 UTC (rev 224552)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerContainer.cpp     2017-11-07 23:06:55 UTC (rev 224553)
</span><span class="lines">@@ -241,7 +241,7 @@
</span><span class="cx">     });
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void ServiceWorkerContainer::updateRegistration(const ServiceWorkerRegistrationKey& key, ServiceWorkerRegistrationState state, const std::optional<ServiceWorkerIdentifier>& serviceWorkerIdentifier)
</del><ins>+void ServiceWorkerContainer::updateRegistrationState(const ServiceWorkerRegistrationKey& key, ServiceWorkerRegistrationState state, const std::optional<ServiceWorkerIdentifier>& serviceWorkerIdentifier)
</ins><span class="cx"> {
</span><span class="cx">     if (auto* registration = m_registrations.get(key))
</span><span class="cx">         registration->updateStateFromServer(state, serviceWorkerIdentifier);
</span><span class="lines">@@ -299,17 +299,17 @@
</span><span class="cx">                 return;
</span><span class="cx">             registration->setInstallingWorker(nullptr);
</span><span class="cx">             registration->setWaitingWorker(serviceWorker.copyRef());
</span><del>-            serviceWorker->setState(ServiceWorker::State::Installed);
</del><ins>+            serviceWorker->updateWorkerState(ServiceWorker::State::Installed);
</ins><span class="cx">             callOnMainThread([container = WTFMove(container), registration = WTFMove(registration), serviceWorker = WTFMove(serviceWorker)] () mutable {
</span><span class="cx">                 if (container->isStopped())
</span><span class="cx">                     return;
</span><span class="cx">                 registration->setWaitingWorker(nullptr);
</span><span class="cx">                 registration->setActiveWorker(serviceWorker.copyRef());
</span><del>-                serviceWorker->setState(ServiceWorker::State::Activating);
</del><ins>+                serviceWorker->updateWorkerState(ServiceWorker::State::Activating);
</ins><span class="cx">                 callOnMainThread([container = WTFMove(container), serviceWorker = WTFMove(serviceWorker)] () mutable {
</span><span class="cx">                     if (container->isStopped())
</span><span class="cx">                         return;
</span><del>-                    serviceWorker->setState(ServiceWorker::State::Activated);
</del><ins>+                    serviceWorker->updateWorkerState(ServiceWorker::State::Activated);
</ins><span class="cx">                 });
</span><span class="cx">             });
</span><span class="cx">         });
</span><span class="lines">@@ -346,20 +346,31 @@
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     // FIXME: Implement proper selection of service workers.
</span><del>-    auto* activeServiceWorker = context->activeServiceWorker();
-    ASSERT(data.activeServiceWorkerIdentifier);
-    if (!activeServiceWorker || activeServiceWorker->identifier() != *data.activeServiceWorkerIdentifier) {
-        context->setActiveServiceWorker(ServiceWorker::create(*context, *data.activeServiceWorkerIdentifier, data.scriptURL));
-        activeServiceWorker = context->activeServiceWorker();
</del><ins>+    auto* installingServiceWorker = context->activeServiceWorker();
+    ASSERT(data.installingServiceWorkerIdentifier);
+    if (!installingServiceWorker || installingServiceWorker->identifier() != *data.installingServiceWorkerIdentifier) {
+        context->setActiveServiceWorker(ServiceWorker::create(*context, *data.installingServiceWorkerIdentifier, data.scriptURL));
+        installingServiceWorker = context->activeServiceWorker();
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     RefPtr<ServiceWorkerRegistration> registration = m_registrations.get(data.key);
</span><del>-    if (!registration)
</del><ins>+    if (!registration) {
+        // Currently the only registrations that can be created for the first time here should be Installing.
+        ASSERT(data.installingServiceWorkerIdentifier);
+        auto installingIdentifier = *data.installingServiceWorkerIdentifier;
+        
</ins><span class="cx">         registration = ServiceWorkerRegistration::create(*context, *this, WTFMove(data));
</span><ins>+        registration->updateStateFromServer(ServiceWorkerRegistrationState::Installing, installingIdentifier);
+        ASSERT(registration->installing());
</ins><span class="cx"> 
</span><del>-    activeServiceWorker->setState(ServiceWorker::State::Installing);
-    registration->setInstallingWorker(activeServiceWorker);
</del><ins>+        installingServiceWorker = registration->installing();
+    }
</ins><span class="cx"> 
</span><ins>+    installingServiceWorker->updateWorkerState(ServiceWorkerState::Installing, ServiceWorker::DoNotFireStateChangeEvent);
+    registration->setInstallingWorker(installingServiceWorker);
+
+    LOG(ServiceWorker, "Container %p resolved job with registration %p", this, registration.get());
+
</ins><span class="cx">     job.promise().resolve<IDLInterface<ServiceWorkerRegistration>>(*registration);
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreworkersserviceServiceWorkerContainerh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/workers/service/ServiceWorkerContainer.h (224552 => 224553)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/workers/service/ServiceWorkerContainer.h    2017-11-07 23:04:34 UTC (rev 224552)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerContainer.h       2017-11-07 23:06:55 UTC (rev 224553)
</span><span class="lines">@@ -65,7 +65,7 @@
</span><span class="cx">     void updateRegistration(const URL& scopeURL, const URL& scriptURL, WorkerType, Ref<DeferredPromise>&&);
</span><span class="cx"> 
</span><span class="cx">     void getRegistration(const String& clientURL, Ref<DeferredPromise>&&);
</span><del>-    void updateRegistration(const ServiceWorkerRegistrationKey&, ServiceWorkerRegistrationState, const std::optional<ServiceWorkerIdentifier>&);
</del><ins>+    void updateRegistrationState(const ServiceWorkerRegistrationKey&, ServiceWorkerRegistrationState, const std::optional<ServiceWorkerIdentifier>&);
</ins><span class="cx">     void fireUpdateFoundEvent(const ServiceWorkerRegistrationKey&);
</span><span class="cx">     void firePostInstallEvents(const ServiceWorkerRegistrationKey&);
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreworkersserviceServiceWorkerRegistrationcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/workers/service/ServiceWorkerRegistration.cpp (224552 => 224553)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/workers/service/ServiceWorkerRegistration.cpp       2017-11-07 23:04:34 UTC (rev 224552)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerRegistration.cpp  2017-11-07 23:06:55 UTC (rev 224553)
</span><span class="lines">@@ -29,6 +29,7 @@
</span><span class="cx"> #if ENABLE(SERVICE_WORKER)
</span><span class="cx"> #include "DOMWindow.h"
</span><span class="cx"> #include "Document.h"
</span><ins>+#include "Logging.h"
</ins><span class="cx"> #include "ServiceWorker.h"
</span><span class="cx"> #include "ServiceWorkerContainer.h"
</span><span class="cx"> #include "ServiceWorkerTypes.h"
</span><span class="lines">@@ -41,6 +42,7 @@
</span><span class="cx">     , m_registrationData(WTFMove(registrationData))
</span><span class="cx">     , m_container(WTFMove(container))
</span><span class="cx"> {
</span><ins>+    LOG(ServiceWorker, "Creating registration %p for registration key %s", this, m_registrationData.key.loggingString().utf8().data());
</ins><span class="cx">     suspendIfNeeded();
</span><span class="cx">     m_container->addRegistration(*this);
</span><span class="cx"> }
</span><span class="lines">@@ -47,6 +49,8 @@
</span><span class="cx"> 
</span><span class="cx"> ServiceWorkerRegistration::~ServiceWorkerRegistration()
</span><span class="cx"> {
</span><ins>+    LOG(ServiceWorker, "Deleting registration %p for registration key %s", this, m_registrationData.key.loggingString().utf8().data());
+
</ins><span class="cx">     m_container->removeRegistration(*this);
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -145,9 +149,25 @@
</span><span class="cx"> 
</span><span class="cx"> void ServiceWorkerRegistration::updateStateFromServer(ServiceWorkerRegistrationState state, std::optional<ServiceWorkerIdentifier> serviceWorkerIdentifier)
</span><span class="cx"> {
</span><del>-    // FIXME: Implement here along with "Update Worker State" algorithm
-    UNUSED_PARAM(state);
-    UNUSED_PARAM(serviceWorkerIdentifier);
</del><ins>+    auto* context = scriptExecutionContext();
+    if (!context)
+        return;
+
+    RefPtr<ServiceWorker> worker;
+    if (serviceWorkerIdentifier)
+        worker = ServiceWorker::create(*context, *serviceWorkerIdentifier, m_registrationData.scriptURL);
+
+    switch (state) {
+    case ServiceWorkerRegistrationState::Installing:
+        m_installingWorker = WTFMove(worker);
+        break;
+    case ServiceWorkerRegistrationState::Waiting:
+        m_waitingWorker = WTFMove(worker);
+        break;
+    case ServiceWorkerRegistrationState::Active:
+        m_activeWorker = WTFMove(worker);
+        break;
+    }
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> EventTargetInterface ServiceWorkerRegistration::eventTargetInterface() const
</span></span></pre></div>
<a id="trunkSourceWebCoreworkersserviceServiceWorkerRegistrationDatacpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/workers/service/ServiceWorkerRegistrationData.cpp (224552 => 224553)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/workers/service/ServiceWorkerRegistrationData.cpp   2017-11-07 23:04:34 UTC (rev 224552)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerRegistrationData.cpp      2017-11-07 23:06:55 UTC (rev 224553)
</span><span class="lines">@@ -35,10 +35,12 @@
</span><span class="cx">     return {
</span><span class="cx">         key.isolatedCopy(),
</span><span class="cx">         identifier,
</span><del>-        activeServiceWorkerIdentifier,
</del><span class="cx">         scopeURL.isolatedCopy(),
</span><span class="cx">         scriptURL.isolatedCopy(),
</span><del>-        updateViaCache
</del><ins>+        updateViaCache,
+        installingServiceWorkerIdentifier,
+        waitingServiceWorkerIdentifier,
+        activeServiceWorkerIdentifier,
</ins><span class="cx">     };
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreworkersserviceServiceWorkerRegistrationDatah"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/workers/service/ServiceWorkerRegistrationData.h (224552 => 224553)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/workers/service/ServiceWorkerRegistrationData.h     2017-11-07 23:04:34 UTC (rev 224552)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerRegistrationData.h        2017-11-07 23:06:55 UTC (rev 224553)
</span><span class="lines">@@ -37,11 +37,14 @@
</span><span class="cx"> struct ServiceWorkerRegistrationData {
</span><span class="cx">     ServiceWorkerRegistrationKey key;
</span><span class="cx">     uint64_t identifier;
</span><del>-    std::optional<ServiceWorkerIdentifier> activeServiceWorkerIdentifier; // FIXME: This should not be part of registrationData.
</del><span class="cx">     URL scopeURL;
</span><span class="cx">     URL scriptURL;
</span><span class="cx">     ServiceWorkerUpdateViaCache updateViaCache;
</span><span class="cx"> 
</span><ins>+    std::optional<ServiceWorkerIdentifier> installingServiceWorkerIdentifier;
+    std::optional<ServiceWorkerIdentifier> waitingServiceWorkerIdentifier;
+    std::optional<ServiceWorkerIdentifier> activeServiceWorkerIdentifier;
+
</ins><span class="cx">     ServiceWorkerRegistrationData isolatedCopy() const;
</span><span class="cx"> 
</span><span class="cx">     template<class Encoder> void encode(Encoder&) const;
</span><span class="lines">@@ -52,7 +55,7 @@
</span><span class="cx"> template<class Encoder>
</span><span class="cx"> void ServiceWorkerRegistrationData::encode(Encoder& encoder) const
</span><span class="cx"> {
</span><del>-    encoder << key << identifier << activeServiceWorkerIdentifier << scopeURL << scriptURL << updateViaCache;
</del><ins>+    encoder << key << identifier << scopeURL << scriptURL << updateViaCache << installingServiceWorkerIdentifier << waitingServiceWorkerIdentifier << activeServiceWorkerIdentifier;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> template<class Decoder>
</span><span class="lines">@@ -68,12 +71,6 @@
</span><span class="cx">     if (!identifier)
</span><span class="cx">         return std::nullopt;
</span><span class="cx"> 
</span><del>-
-    std::optional<std::optional<ServiceWorkerIdentifier>> activeServiceWorkerIdentifier;
-    decoder >> activeServiceWorkerIdentifier;
-    if (!activeServiceWorkerIdentifier)
-        return std::nullopt;
-
</del><span class="cx">     std::optional<URL> scopeURL;
</span><span class="cx">     decoder >> scopeURL;
</span><span class="cx">     if (!scopeURL)
</span><span class="lines">@@ -89,7 +86,22 @@
</span><span class="cx">     if (!updateViaCache)
</span><span class="cx">         return std::nullopt;
</span><span class="cx"> 
</span><del>-    return { { WTFMove(*key), WTFMove(*identifier), WTFMove(*activeServiceWorkerIdentifier), WTFMove(*scopeURL), WTFMove(*scriptURL), WTFMove(*updateViaCache) } };
</del><ins>+    std::optional<std::optional<ServiceWorkerIdentifier>> installingServiceWorkerIdentifier;
+    decoder >> installingServiceWorkerIdentifier;
+    if (!installingServiceWorkerIdentifier)
+        return std::nullopt;
+
+    std::optional<std::optional<ServiceWorkerIdentifier>> waitingServiceWorkerIdentifier;
+    decoder >> waitingServiceWorkerIdentifier;
+    if (!waitingServiceWorkerIdentifier)
+        return std::nullopt;
+
+    std::optional<std::optional<ServiceWorkerIdentifier>> activeServiceWorkerIdentifier;
+    decoder >> activeServiceWorkerIdentifier;
+    if (!activeServiceWorkerIdentifier)
+        return std::nullopt;
+
+    return { { WTFMove(*key), WTFMove(*identifier), WTFMove(*scopeURL), WTFMove(*scriptURL), WTFMove(*updateViaCache), WTFMove(*installingServiceWorkerIdentifier), WTFMove(*waitingServiceWorkerIdentifier), WTFMove(*activeServiceWorkerIdentifier) } };
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> } // namespace WTF
</span></span></pre></div>
<a id="trunkSourceWebCoreworkersserviceServiceWorkerRegistrationKeycpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/workers/service/ServiceWorkerRegistrationKey.cpp (224552 => 224553)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/workers/service/ServiceWorkerRegistrationKey.cpp    2017-11-07 23:04:34 UTC (rev 224552)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerRegistrationKey.cpp       2017-11-07 23:06:55 UTC (rev 224553)
</span><span class="lines">@@ -76,6 +76,13 @@
</span><span class="cx">     return clientURL.string().startsWith(m_scope);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+#ifndef NDEBUG
+String ServiceWorkerRegistrationKey::loggingString() const
+{
+    return makeString(m_topOrigin.debugString(), "-", m_clientCreationURL.string(), "-", m_scope.string());
+}
+#endif
+
</ins><span class="cx"> } // namespace WebCore
</span><span class="cx"> 
</span><span class="cx"> #endif // ENABLE(SERVICE_WORKER)
</span></span></pre></div>
<a id="trunkSourceWebCoreworkersserviceServiceWorkerRegistrationKeyh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/workers/service/ServiceWorkerRegistrationKey.h (224552 => 224553)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/workers/service/ServiceWorkerRegistrationKey.h      2017-11-07 23:04:34 UTC (rev 224552)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerRegistrationKey.h 2017-11-07 23:06:55 UTC (rev 224553)
</span><span class="lines">@@ -53,6 +53,10 @@
</span><span class="cx">     template<class Encoder> void encode(Encoder&) const;
</span><span class="cx">     template<class Decoder> static std::optional<ServiceWorkerRegistrationKey> decode(Decoder&);
</span><span class="cx"> 
</span><ins>+#ifndef NDEBUG
+    String loggingString() const;
+#endif
+
</ins><span class="cx"> private:
</span><span class="cx">     URL m_clientCreationURL;
</span><span class="cx">     SecurityOriginData m_topOrigin;
</span></span></pre></div>
<a id="trunkSourceWebCoreworkersserviceServiceWorkerTypesh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/workers/service/ServiceWorkerTypes.h (224552 => 224553)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/workers/service/ServiceWorkerTypes.h        2017-11-07 23:04:34 UTC (rev 224552)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerTypes.h   2017-11-07 23:06:55 UTC (rev 224553)
</span><span class="lines">@@ -35,6 +35,14 @@
</span><span class="cx">     Active = 2,
</span><span class="cx"> };
</span><span class="cx"> 
</span><ins>+enum class ServiceWorkerState {
+    Installing,
+    Installed,
+    Activating,
+    Activated,
+    Redundant,
+};
+
</ins><span class="cx"> } // namespace WebCore
</span><span class="cx"> 
</span><span class="cx"> #endif // ENABLE(SERVICE_WORKER)
</span></span></pre></div>
<a id="trunkSourceWebCoreworkersservicecontextSWContextManagercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/workers/service/context/SWContextManager.cpp (224552 => 224553)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/workers/service/context/SWContextManager.cpp        2017-11-07 23:04:34 UTC (rev 224552)
+++ trunk/Source/WebCore/workers/service/context/SWContextManager.cpp   2017-11-07 23:06:55 UTC (rev 224553)
</span><span class="lines">@@ -47,7 +47,7 @@
</span><span class="cx">     return m_connection.get();
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void SWContextManager::registerServiceWorkerThreadForUpdate(Ref<ServiceWorkerThreadProxy>&& serviceWorkerThreadProxy)
</del><ins>+void SWContextManager::registerServiceWorkerThreadForInstall(Ref<ServiceWorkerThreadProxy>&& serviceWorkerThreadProxy)
</ins><span class="cx"> {
</span><span class="cx">     auto serviceWorkerIdentifier = serviceWorkerThreadProxy->identifier();
</span><span class="cx">     auto* threadProxy = serviceWorkerThreadProxy.ptr();
</span></span></pre></div>
<a id="trunkSourceWebCoreworkersservicecontextSWContextManagerh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/workers/service/context/SWContextManager.h (224552 => 224553)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/workers/service/context/SWContextManager.h  2017-11-07 23:04:34 UTC (rev 224552)
+++ trunk/Source/WebCore/workers/service/context/SWContextManager.h     2017-11-07 23:06:55 UTC (rev 224553)
</span><span class="lines">@@ -53,10 +53,11 @@
</span><span class="cx">     WEBCORE_EXPORT void setConnection(std::unique_ptr<Connection>&&);
</span><span class="cx">     WEBCORE_EXPORT Connection* connection() const;
</span><span class="cx"> 
</span><del>-    WEBCORE_EXPORT void registerServiceWorkerThreadForUpdate(Ref<ServiceWorkerThreadProxy>&&);
</del><ins>+    WEBCORE_EXPORT void registerServiceWorkerThreadForInstall(Ref<ServiceWorkerThreadProxy>&&);
</ins><span class="cx">     WEBCORE_EXPORT ServiceWorkerThreadProxy* serviceWorkerThreadProxy(ServiceWorkerIdentifier) const;
</span><span class="cx">     WEBCORE_EXPORT void postMessageToServiceWorkerGlobalScope(ServiceWorkerIdentifier destination, Ref<SerializedScriptValue>&& message, const ServiceWorkerClientIdentifier& sourceIdentifier, const String& sourceOrigin);
</span><span class="cx">     WEBCORE_EXPORT void fireInstallEvent(ServiceWorkerIdentifier);
</span><ins>+
</ins><span class="cx"> private:
</span><span class="cx">     SWContextManager() = default;
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreworkersserviceserverSWClientConnectioncpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/workers/service/server/SWClientConnection.cpp (224552 => 224553)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/workers/service/server/SWClientConnection.cpp       2017-11-07 23:04:34 UTC (rev 224552)
+++ trunk/Source/WebCore/workers/service/server/SWClientConnection.cpp  2017-11-07 23:06:55 UTC (rev 224553)
</span><span class="lines">@@ -150,10 +150,18 @@
</span><span class="cx"> void SWClientConnection::updateRegistrationState(const ServiceWorkerRegistrationKey& key, ServiceWorkerRegistrationState state, std::optional<ServiceWorkerIdentifier> serviceWorkerIdentifier)
</span><span class="cx"> {
</span><span class="cx">     forEachContainer([&](ServiceWorkerContainer& container) {
</span><del>-        container.updateRegistration(key, state, serviceWorkerIdentifier);
</del><ins>+        container.updateRegistrationState(key, state, serviceWorkerIdentifier);
</ins><span class="cx">     });
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void SWClientConnection::updateWorkerState(ServiceWorkerIdentifier worker, ServiceWorkerState state)
+{
+    const auto& matchingWorkers = ServiceWorker::allWorkers().get(worker);
+    
+    for (auto* worker : matchingWorkers)
+        worker->updateWorkerState(state);
+}
+
</ins><span class="cx"> void SWClientConnection::fireUpdateFoundEvent(const ServiceWorkerRegistrationKey& key)
</span><span class="cx"> {
</span><span class="cx">     forEachContainer([&](ServiceWorkerContainer& container) {
</span></span></pre></div>
<a id="trunkSourceWebCoreworkersserviceserverSWClientConnectionh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/workers/service/server/SWClientConnection.h (224552 => 224553)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/workers/service/server/SWClientConnection.h 2017-11-07 23:04:34 UTC (rev 224552)
+++ trunk/Source/WebCore/workers/service/server/SWClientConnection.h    2017-11-07 23:06:55 UTC (rev 224553)
</span><span class="lines">@@ -40,6 +40,7 @@
</span><span class="cx"> class ServiceWorkerRegistration;
</span><span class="cx"> class SharedBuffer;
</span><span class="cx"> enum class ServiceWorkerRegistrationState;
</span><ins>+enum class ServiceWorkerState;
</ins><span class="cx"> struct ExceptionData;
</span><span class="cx"> struct ServiceWorkerFetchResult;
</span><span class="cx"> struct ServiceWorkerRegistrationData;
</span><span class="lines">@@ -68,6 +69,7 @@
</span><span class="cx">     WEBCORE_EXPORT void startScriptFetchForServer(uint64_t jobIdentifier);
</span><span class="cx">     WEBCORE_EXPORT void postMessageToServiceWorkerClient(uint64_t destinationScriptExecutionContextIdentifier, Ref<SerializedScriptValue>&& message, ServiceWorkerIdentifier source, const String& sourceOrigin);
</span><span class="cx">     WEBCORE_EXPORT void updateRegistrationState(const ServiceWorkerRegistrationKey&, ServiceWorkerRegistrationState, std::optional<ServiceWorkerIdentifier>);
</span><ins>+    WEBCORE_EXPORT void updateWorkerState(ServiceWorkerIdentifier, ServiceWorkerState);
</ins><span class="cx">     WEBCORE_EXPORT void fireUpdateFoundEvent(const ServiceWorkerRegistrationKey&);
</span><span class="cx">     WEBCORE_EXPORT void firePostInstallEvents(const ServiceWorkerRegistrationKey&);
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreworkersserviceserverSWServercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/workers/service/server/SWServer.cpp (224552 => 224553)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/workers/service/server/SWServer.cpp 2017-11-07 23:04:34 UTC (rev 224552)
+++ trunk/Source/WebCore/workers/service/server/SWServer.cpp    2017-11-07 23:06:55 UTC (rev 224553)
</span><span class="lines">@@ -262,12 +262,12 @@
</span><span class="cx"> Ref<SWServerWorker> SWServer::updateWorker(Connection& connection, const ServiceWorkerRegistrationKey& registrationKey, const URL& url, const String& script, WorkerType type)
</span><span class="cx"> {
</span><span class="cx">     auto serviceWorkerIdentifier = generateServiceWorkerIdentifier();
</span><del>-    
</del><ins>+
</ins><span class="cx">     auto result = m_workersByID.add(serviceWorkerIdentifier, SWServerWorker::create(registrationKey, url, script, type, serviceWorkerIdentifier));
</span><span class="cx">     ASSERT(result.isNewEntry);
</span><ins>+
+    connection.installServiceWorkerContext({ registrationKey, serviceWorkerIdentifier, script, url });
</ins><span class="cx">     
</span><del>-    connection.updateServiceWorkerContext({ registrationKey, serviceWorkerIdentifier, script, url });
-    
</del><span class="cx">     return result.iterator->value.get();
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreworkersserviceserverSWServerh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/workers/service/server/SWServer.h (224552 => 224553)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/workers/service/server/SWServer.h   2017-11-07 23:04:34 UTC (rev 224552)
+++ trunk/Source/WebCore/workers/service/server/SWServer.h      2017-11-07 23:06:55 UTC (rev 224553)
</span><span class="lines">@@ -27,6 +27,7 @@
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(SERVICE_WORKER)
</span><span class="cx"> 
</span><ins>+#include "SWServerWorker.h"
</ins><span class="cx"> #include "ServiceWorkerIdentifier.h"
</span><span class="cx"> #include "ServiceWorkerJob.h"
</span><span class="cx"> #include "ServiceWorkerRegistrationData.h"
</span><span class="lines">@@ -44,8 +45,8 @@
</span><span class="cx"> 
</span><span class="cx"> class SWServerJobQueue;
</span><span class="cx"> class SWServerRegistration;
</span><del>-class SWServerWorker;
</del><span class="cx"> enum class ServiceWorkerRegistrationState;
</span><ins>+enum class ServiceWorkerState;
</ins><span class="cx"> struct ExceptionData;
</span><span class="cx"> struct ServiceWorkerContextData;
</span><span class="cx"> struct ServiceWorkerFetchResult;
</span><span class="lines">@@ -65,6 +66,7 @@
</span><span class="cx"> 
</span><span class="cx">         // Messages to the client WebProcess
</span><span class="cx">         virtual void updateRegistrationStateInClient(const ServiceWorkerRegistrationKey&, ServiceWorkerRegistrationState, std::optional<ServiceWorkerIdentifier>) = 0;
</span><ins>+        virtual void updateWorkerStateInClient(ServiceWorkerIdentifier, ServiceWorkerState) = 0;
</ins><span class="cx">         virtual void fireUpdateFoundEvent(const ServiceWorkerRegistrationKey&) = 0;
</span><span class="cx">         virtual void firePostInstallEvents(const ServiceWorkerRegistrationKey&) = 0;
</span><span class="cx"> 
</span><span class="lines">@@ -85,7 +87,7 @@
</span><span class="cx">         virtual void startScriptFetchInClient(uint64_t jobIdentifier) = 0;
</span><span class="cx"> 
</span><span class="cx">         // Messages to the SW host WebProcess
</span><del>-        virtual void updateServiceWorkerContext(const ServiceWorkerContextData&) = 0;
</del><ins>+        virtual void installServiceWorkerContext(const ServiceWorkerContextData&) = 0;
</ins><span class="cx">         virtual void fireInstallEvent(ServiceWorkerIdentifier) = 0;
</span><span class="cx"> 
</span><span class="cx">         SWServer& m_server;
</span><span class="lines">@@ -111,6 +113,7 @@
</span><span class="cx"> 
</span><span class="cx">     Ref<SWServerWorker> updateWorker(Connection&, const ServiceWorkerRegistrationKey&, const URL&, const String& script, WorkerType);
</span><span class="cx">     void fireInstallEvent(Connection&, ServiceWorkerIdentifier);
</span><ins>+    SWServerWorker* workerByID(ServiceWorkerIdentifier identifier) const { return m_workersByID.get(identifier); }
</ins><span class="cx">     
</span><span class="cx">     Connection* getConnection(uint64_t identifier) { return m_connections.get(identifier); }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreworkersserviceserverSWServerJobQueuecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/workers/service/server/SWServerJobQueue.cpp (224552 => 224553)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/workers/service/server/SWServerJobQueue.cpp 2017-11-07 23:04:34 UTC (rev 224552)
+++ trunk/Source/WebCore/workers/service/server/SWServerJobQueue.cpp    2017-11-07 23:06:55 UTC (rev 224553)
</span><span class="lines">@@ -73,21 +73,12 @@
</span><span class="cx">         return;
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    // If newestWorker is not null, newestWorker's script url equals job's script url with the exclude fragments
</del><ins>+    // FIXME: If newestWorker is not null, newestWorker's script url equals job's script url with the exclude fragments
</ins><span class="cx">     // flag set, and script's source text is a byte-for-byte match with newestWorker's script resource's source
</span><span class="cx">     // text, then:
</span><del>-    if (newestWorker && equalIgnoringFragmentIdentifier(newestWorker->scriptURL(), job.scriptURL) && result.script == newestWorker->script()) {
-        // FIXME: if script is a classic script, and script's module record's [[ECMAScriptCode]] is a byte-for-byte
-        // match with newestWorker's script resource's module record's [[ECMAScriptCode]] otherwise.
</del><ins>+    // - Invoke Resolve Job Promise with job and registration.
+    // - Invoke Finish Job with job and abort these steps.
</ins><span class="cx"> 
</span><del>-        // Invoke Resolve Job Promise with job and registration.
-        m_server.resolveRegistrationJob(job, registration->data());
-
-        // Invoke Finish Job with job and abort these steps.
-        finishCurrentJob();
-        return;
-    }
-
</del><span class="cx">     // FIXME: Support the proper worker type (classic vs module)
</span><span class="cx">     m_server.updateWorker(connection, m_registrationKey, job.scriptURL, result.script, WorkerType::Classic);
</span><span class="cx"> }
</span><span class="lines">@@ -113,14 +104,20 @@
</span><span class="cx"> {
</span><span class="cx">     auto* registration = m_server.getRegistration(m_registrationKey);
</span><span class="cx">     ASSERT(registration);
</span><del>-    registration->setActiveServiceWorkerIdentifier(identifier);
</del><span class="cx"> 
</span><span class="cx">     install(*registration, connection, identifier);
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> // https://w3c.github.io/ServiceWorker/#install
</span><del>-void SWServerJobQueue::install(SWServerRegistration& registration, SWServer::Connection& connection, ServiceWorkerIdentifier serviceWorkerIdentifier)
</del><ins>+void SWServerJobQueue::install(SWServerRegistration& registration, SWServer::Connection& connection, ServiceWorkerIdentifier installingWorker)
</ins><span class="cx"> {
</span><ins>+    // The Install algorithm should never be invoked with a null worker.
+    auto* worker = m_server.workerByID(installingWorker);
+    RELEASE_ASSERT(worker);
+
+    registration.updateRegistrationState(ServiceWorkerRegistrationState::Installing, worker);
+    registration.updateWorkerState(*worker, ServiceWorkerState::Installing);
+
</ins><span class="cx">     // Invoke Resolve Job Promise with job and registration.
</span><span class="cx">     m_server.resolveRegistrationJob(firstJob(), registration.data());
</span><span class="cx"> 
</span><span class="lines">@@ -130,7 +127,7 @@
</span><span class="cx">     registration.fireUpdateFoundEvent(firstJob().connectionIdentifier());
</span><span class="cx"> 
</span><span class="cx">     // Queue a task to fire the InstallEvent.
</span><del>-    m_server.fireInstallEvent(connection, serviceWorkerIdentifier);
</del><ins>+    m_server.fireInstallEvent(connection, installingWorker);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> // https://w3c.github.io/ServiceWorker/#install
</span><span class="lines">@@ -250,9 +247,9 @@
</span><span class="cx"> {
</span><span class="cx">     // FIXME: Make sure that the registration has no service worker client.
</span><span class="cx"> 
</span><del>-    // FIXME: The specification has more complex logic here.
-    if (!registration.getNewestWorker())
-        clearRegistration(registration);
</del><ins>+    // FIXME: The specification has more complex logic here. We currently clear registrations
+    // too aggressively.
+    clearRegistration(registration);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> // https://w3c.github.io/ServiceWorker/#clear-registration
</span></span></pre></div>
<a id="trunkSourceWebCoreworkersserviceserverSWServerRegistrationcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/workers/service/server/SWServerRegistration.cpp (224552 => 224553)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/workers/service/server/SWServerRegistration.cpp     2017-11-07 23:04:34 UTC (rev 224552)
+++ trunk/Source/WebCore/workers/service/server/SWServerRegistration.cpp        2017-11-07 23:06:55 UTC (rev 224553)
</span><span class="lines">@@ -61,6 +61,8 @@
</span><span class="cx"> 
</span><span class="cx"> void SWServerRegistration::updateRegistrationState(ServiceWorkerRegistrationState state, SWServerWorker* worker)
</span><span class="cx"> {
</span><ins>+    LOG(ServiceWorker, "(%p) Updating registration state to %i with worker %p", this, (int)state, worker);
+    
</ins><span class="cx">     switch (state) {
</span><span class="cx">     case ServiceWorkerRegistrationState::Installing:
</span><span class="cx">         m_installingWorker = worker;
</span><span class="lines">@@ -83,6 +85,18 @@
</span><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void SWServerRegistration::updateWorkerState(SWServerWorker& worker, ServiceWorkerState state)
+{
+    LOG(ServiceWorker, "Updating worker %p state to %i (%p)", &worker, (int)state, this);
+
+    worker.setState(state);
+
+    for (auto& connectionIdentifierWithClients : m_clientRegistrationsByConnection.keys()) {
+        if (auto* connection = m_server.getConnection(connectionIdentifierWithClients))
+            connection->updateWorkerStateInClient(worker.identifier(), state);
+    }
+}
+
</ins><span class="cx"> void SWServerRegistration::fireUpdateFoundEvent(uint64_t connectionIdentifier)
</span><span class="cx"> {
</span><span class="cx">     // No matter what, we send the event to the connection that scheduled the job. The client registration
</span><span class="lines">@@ -115,7 +129,19 @@
</span><span class="cx"> 
</span><span class="cx"> ServiceWorkerRegistrationData SWServerRegistration::data() const
</span><span class="cx"> {
</span><del>-    return { m_registrationKey, identifier(), m_activeServiceWorkerIdentifier, m_scopeURL, m_scriptURL, m_updateViaCache };
</del><ins>+    std::optional<ServiceWorkerIdentifier> installingID;
+    if (m_installingWorker)
+        installingID = m_installingWorker->identifier();
+
+    std::optional<ServiceWorkerIdentifier> waitingID;
+    if (m_waitingWorker)
+        waitingID = m_waitingWorker->identifier();
+
+    std::optional<ServiceWorkerIdentifier> activeID;
+    if (m_activeWorker)
+        activeID = m_activeWorker->identifier();
+
+    return { m_registrationKey, identifier(), m_scopeURL, m_scriptURL, m_updateViaCache, installingID, waitingID, activeID };
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void SWServerRegistration::addClientServiceWorkerRegistration(uint64_t connectionIdentifier, uint64_t clientRegistrationIdentifier)
</span></span></pre></div>
<a id="trunkSourceWebCoreworkersserviceserverSWServerRegistrationh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/workers/service/server/SWServerRegistration.h (224552 => 224553)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/workers/service/server/SWServerRegistration.h       2017-11-07 23:04:34 UTC (rev 224552)
+++ trunk/Source/WebCore/workers/service/server/SWServerRegistration.h  2017-11-07 23:06:55 UTC (rev 224553)
</span><span class="lines">@@ -36,6 +36,7 @@
</span><span class="cx"> class SWServer;
</span><span class="cx"> class SWServerWorker;
</span><span class="cx"> enum class ServiceWorkerRegistrationState;
</span><ins>+enum class ServiceWorkerState;
</ins><span class="cx"> struct ExceptionData;
</span><span class="cx"> struct ServiceWorkerFetchResult;
</span><span class="cx"> 
</span><span class="lines">@@ -55,9 +56,8 @@
</span><span class="cx">     void setLastUpdateTime(double time) { m_lastUpdateTime = time; }
</span><span class="cx">     ServiceWorkerUpdateViaCache updateViaCache() const { return m_updateViaCache; }
</span><span class="cx"> 
</span><del>-    void setActiveServiceWorkerIdentifier(ServiceWorkerIdentifier identifier) { m_activeServiceWorkerIdentifier = identifier; }
-
</del><span class="cx">     void updateRegistrationState(ServiceWorkerRegistrationState, SWServerWorker*);
</span><ins>+    void updateWorkerState(SWServerWorker&, ServiceWorkerState);
</ins><span class="cx">     void fireUpdateFoundEvent(uint64_t connectionIdentifier);
</span><span class="cx">     void firePostInstallEvents(uint64_t connectionIdentifier);
</span><span class="cx"> 
</span><span class="lines">@@ -75,8 +75,6 @@
</span><span class="cx">     RefPtr<SWServerWorker> m_waitingWorker;
</span><span class="cx">     RefPtr<SWServerWorker> m_activeWorker;
</span><span class="cx"> 
</span><del>-    std::optional<ServiceWorkerIdentifier> m_activeServiceWorkerIdentifier;
-
</del><span class="cx">     double m_lastUpdateTime { 0 };
</span><span class="cx">     
</span><span class="cx">     HashMap<uint64_t, std::unique_ptr<HashSet<uint64_t>>> m_clientRegistrationsByConnection;
</span></span></pre></div>
<a id="trunkSourceWebCoreworkersserviceserverSWServerWorkerh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/workers/service/server/SWServerWorker.h (224552 => 224553)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/workers/service/server/SWServerWorker.h     2017-11-07 23:04:34 UTC (rev 224552)
+++ trunk/Source/WebCore/workers/service/server/SWServerWorker.h        2017-11-07 23:06:55 UTC (rev 224553)
</span><span class="lines">@@ -29,6 +29,7 @@
</span><span class="cx"> 
</span><span class="cx"> #include "ServiceWorkerIdentifier.h"
</span><span class="cx"> #include "ServiceWorkerRegistrationKey.h"
</span><ins>+#include "ServiceWorkerTypes.h"
</ins><span class="cx"> #include "URL.h"
</span><span class="cx"> #include <wtf/ThreadSafeRefCounted.h>
</span><span class="cx"> 
</span><span class="lines">@@ -49,8 +50,12 @@
</span><span class="cx">     const URL& scriptURL() const { return m_scriptURL; }
</span><span class="cx">     const String& script() const { return m_script; }
</span><span class="cx">     WorkerType type() const { return m_type; }
</span><ins>+
</ins><span class="cx">     ServiceWorkerIdentifier identifier() const { return m_identifier; }
</span><del>-    
</del><ins>+
+    ServiceWorkerState state() const { return m_state; }
+    void setState(ServiceWorkerState state) { m_state = state; }
+
</ins><span class="cx"> private:
</span><span class="cx">     SWServerWorker(const ServiceWorkerRegistrationKey&, const URL&, const String& script, WorkerType, ServiceWorkerIdentifier);
</span><span class="cx"> 
</span><span class="lines">@@ -59,6 +64,8 @@
</span><span class="cx">     String m_script;
</span><span class="cx">     ServiceWorkerIdentifier m_identifier;
</span><span class="cx">     WorkerType m_type;
</span><ins>+    
+    ServiceWorkerState m_state { ServiceWorkerState::Redundant };
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> } // namespace WebCore
</span></span></pre></div>
<a id="trunkSourceWebKitChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/ChangeLog (224552 => 224553)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/ChangeLog    2017-11-07 23:04:34 UTC (rev 224552)
+++ trunk/Source/WebKit/ChangeLog       2017-11-07 23:06:55 UTC (rev 224553)
</span><span class="lines">@@ -1,3 +1,29 @@
</span><ins>+2017-11-07  Brady Eidson  <beidson@apple.com>
+
+        Implement "UpdateWorkerState" and use it
+        https://bugs.webkit.org/show_bug.cgi?id=179318
+
+        Reviewed by Chris Dumez.
+
+        * Scripts/webkit/messages.py:
+        (headers_for_type):
+        * Shared/WebCoreArgumentCoders.h:

+       * StorageProcess/ServiceWorker/WebSWServerConnection.cpp:
+        (WebKit::WebSWServerConnection::updateWorkerStateInClient):
+        (WebKit::WebSWServerConnection::installServiceWorkerContext):
+        (WebKit::WebSWServerConnection::setContextConnection):
+        (WebKit::WebSWServerConnection::updateServiceWorkerContext): Deleted.
+        * StorageProcess/ServiceWorker/WebSWServerConnection.h:
+
+        * WebProcess/Storage/WebSWClientConnection.messages.in:
+
+        * WebProcess/Storage/WebSWContextManagerConnection.cpp:
+        (WebKit::WebSWContextManagerConnection::installServiceWorker):
+        (WebKit::WebSWContextManagerConnection::updateServiceWorker): Deleted.
+        * WebProcess/Storage/WebSWContextManagerConnection.h:
+        * WebProcess/Storage/WebSWContextManagerConnection.messages.in:
+
</ins><span class="cx"> 2017-11-07  Commit Queue  <commit-queue@webkit.org>
</span><span class="cx"> 
</span><span class="cx">         Unreviewed, rolling out r224512 and r224521.
</span></span></pre></div>
<a id="trunkSourceWebKitScriptswebkitmessagespy"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/Scripts/webkit/messages.py (224552 => 224553)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/Scripts/webkit/messages.py   2017-11-07 23:04:34 UTC (rev 224552)
+++ trunk/Source/WebKit/Scripts/webkit/messages.py      2017-11-07 23:06:55 UTC (rev 224553)
</span><span class="lines">@@ -373,6 +373,7 @@
</span><span class="cx">         'WebCore::PolicyAction': ['<WebCore/FrameLoaderTypes.h>'],
</span><span class="cx">         'WebCore::RecentSearch': ['<WebCore/SearchPopupMenu.h>'],
</span><span class="cx">         'WebCore::ServiceWorkerRegistrationState': ['<WebCore/ServiceWorkerTypes.h>'],
</span><ins>+        'WebCore::ServiceWorkerState': ['<WebCore/ServiceWorkerTypes.h>'],
</ins><span class="cx">         'WebCore::ShippingContactUpdate': ['<WebCore/ApplePaySessionPaymentRequest.h>'],
</span><span class="cx">         'WebCore::ShippingMethodUpdate': ['<WebCore/ApplePaySessionPaymentRequest.h>'],
</span><span class="cx">         'WebCore::ShouldSample': ['<WebCore/DiagnosticLoggingClient.h>'],
</span></span></pre></div>
<a id="trunkSourceWebKitSharedWebCoreArgumentCodersh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/Shared/WebCoreArgumentCoders.h (224552 => 224553)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/Shared/WebCoreArgumentCoders.h       2017-11-07 23:04:34 UTC (rev 224552)
+++ trunk/Source/WebKit/Shared/WebCoreArgumentCoders.h  2017-11-07 23:06:55 UTC (rev 224553)
</span><span class="lines">@@ -815,6 +815,17 @@
</span><span class="cx">         WebCore::ServiceWorkerRegistrationState::Active
</span><span class="cx">     >;
</span><span class="cx"> };
</span><ins>+    
+template <> struct EnumTraits<WebCore::ServiceWorkerState> {
+    using values = EnumValues<
+        WebCore::ServiceWorkerState,
+        WebCore::ServiceWorkerState::Installing,
+        WebCore::ServiceWorkerState::Installed,
+        WebCore::ServiceWorkerState::Activating,
+        WebCore::ServiceWorkerState::Activated,
+        WebCore::ServiceWorkerState::Redundant
+    >;
+};
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> } // namespace WTF
</span></span></pre></div>
<a id="trunkSourceWebKitStorageProcessServiceWorkerWebSWServerConnectioncpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.cpp (224552 => 224553)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.cpp       2017-11-07 23:04:34 UTC (rev 224552)
+++ trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.cpp  2017-11-07 23:06:55 UTC (rev 224553)
</span><span class="lines">@@ -111,9 +111,14 @@
</span><span class="cx">     send(Messages::WebSWClientConnection::FirePostInstallEvents(key));
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void WebSWServerConnection::updateServiceWorkerContext(const ServiceWorkerContextData& data)
</del><ins>+void WebSWServerConnection::updateWorkerStateInClient(ServiceWorkerIdentifier worker, ServiceWorkerState state)
</ins><span class="cx"> {
</span><del>-    if (sendToContextProcess(Messages::WebSWContextManagerConnection::UpdateServiceWorker(identifier(), data)))
</del><ins>+    send(Messages::WebSWClientConnection::UpdateWorkerState(worker, state));
+}
+
+void WebSWServerConnection::installServiceWorkerContext(const ServiceWorkerContextData& data)
+{
+    if (sendToContextProcess(Messages::WebSWContextManagerConnection::InstallServiceWorker(identifier(), data)))
</ins><span class="cx">         return;
</span><span class="cx"> 
</span><span class="cx">     m_pendingContextDatas.append(data);
</span><span class="lines">@@ -188,7 +193,7 @@
</span><span class="cx"> 
</span><span class="cx">     // We can now start any pending service worker updates.
</span><span class="cx">     for (auto& pendingContextData : m_pendingContextDatas)
</span><del>-        updateServiceWorkerContext(pendingContextData);
</del><ins>+        installServiceWorkerContext(pendingContextData);
</ins><span class="cx">     
</span><span class="cx">     m_pendingContextDatas.clear();
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebKitStorageProcessServiceWorkerWebSWServerConnectionh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.h (224552 => 224553)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.h 2017-11-07 23:04:34 UTC (rev 224552)
+++ trunk/Source/WebKit/StorageProcess/ServiceWorker/WebSWServerConnection.h    2017-11-07 23:06:55 UTC (rev 224553)
</span><span class="lines">@@ -66,6 +66,7 @@
</span><span class="cx">     void resolveUnregistrationJobInClient(uint64_t jobIdentifier, const WebCore::ServiceWorkerRegistrationKey&, bool unregistrationResult) final;
</span><span class="cx">     void startScriptFetchInClient(uint64_t jobIdentifier) final;
</span><span class="cx">     void updateRegistrationStateInClient(const WebCore::ServiceWorkerRegistrationKey&, WebCore::ServiceWorkerRegistrationState, std::optional<WebCore::ServiceWorkerIdentifier>) final;
</span><ins>+    void updateWorkerStateInClient(WebCore::ServiceWorkerIdentifier, WebCore::ServiceWorkerState) final;
</ins><span class="cx">     void fireUpdateFoundEvent(const WebCore::ServiceWorkerRegistrationKey&) final;
</span><span class="cx">     void firePostInstallEvents(const WebCore::ServiceWorkerRegistrationKey&) final;
</span><span class="cx"> 
</span><span class="lines">@@ -76,7 +77,7 @@
</span><span class="cx">     void matchRegistration(uint64_t registrationMatchRequestIdentifier, const WebCore::SecurityOriginData&, const WebCore::URL& clientURL);
</span><span class="cx"> 
</span><span class="cx">     // Messages to the SW context WebProcess
</span><del>-    void updateServiceWorkerContext(const WebCore::ServiceWorkerContextData&) final;
</del><ins>+    void installServiceWorkerContext(const WebCore::ServiceWorkerContextData&) final;
</ins><span class="cx">     void fireInstallEvent(WebCore::ServiceWorkerIdentifier) final;
</span><span class="cx"> 
</span><span class="cx">     IPC::Connection* messageSenderConnection() final { return m_contentConnection.ptr(); }
</span></span></pre></div>
<a id="trunkSourceWebKitWebProcessStorageWebSWClientConnectionmessagesin"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.messages.in (224552 => 224553)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.messages.in 2017-11-07 23:04:34 UTC (rev 224552)
+++ trunk/Source/WebKit/WebProcess/Storage/WebSWClientConnection.messages.in    2017-11-07 23:06:55 UTC (rev 224553)
</span><span class="lines">@@ -29,6 +29,7 @@
</span><span class="cx">     UnregistrationJobResolvedInServer(uint64_t identifier, bool unregistrationResult)
</span><span class="cx">     StartScriptFetchForServer(uint64_t jobIdentifier)
</span><span class="cx">     UpdateRegistrationState(WebCore::ServiceWorkerRegistrationKey key, enum WebCore::ServiceWorkerRegistrationState state, std::optional<WebCore::ServiceWorkerIdentifier> serviceWorkerIdentifier)
</span><ins>+    UpdateWorkerState(WebCore::ServiceWorkerIdentifier serviceWorkerIdentifier, enum WebCore::ServiceWorkerState state)
</ins><span class="cx">     FireUpdateFoundEvent(WebCore::ServiceWorkerRegistrationKey key)
</span><span class="cx">     FirePostInstallEvents(WebCore::ServiceWorkerRegistrationKey key)
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKitWebProcessStorageWebSWContextManagerConnectioncpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.cpp (224552 => 224553)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.cpp 2017-11-07 23:04:34 UTC (rev 224552)
+++ trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.cpp    2017-11-07 23:06:55 UTC (rev 224553)
</span><span class="lines">@@ -95,7 +95,7 @@
</span><span class="cx">     RuntimeEnabledFeatures::sharedFeatures().setFetchAPIEnabled(store.getBoolValueForKey(WebPreferencesKey::fetchAPIEnabledKey()));
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void WebSWContextManagerConnection::updateServiceWorker(uint64_t serverConnectionIdentifier, const ServiceWorkerContextData& data)
</del><ins>+void WebSWContextManagerConnection::installServiceWorker(uint64_t serverConnectionIdentifier, const ServiceWorkerContextData& data)
</ins><span class="cx"> {
</span><span class="cx">     // FIXME: Provide a sensical session ID.
</span><span class="cx">     auto sessionID = PAL::SessionID::defaultSessionID();
</span><span class="lines">@@ -114,7 +114,7 @@
</span><span class="cx">     pageConfiguration.loaderClientForMainFrame = frameLoaderClient.release();
</span><span class="cx"> 
</span><span class="cx">     auto serviceWorkerThreadProxy = ServiceWorkerThreadProxy::create(WTFMove(pageConfiguration), serverConnectionIdentifier, data, sessionID, WebProcess::singleton().cacheStorageProvider());
</span><del>-    SWContextManager::singleton().registerServiceWorkerThreadForUpdate(WTFMove(serviceWorkerThreadProxy));
</del><ins>+    SWContextManager::singleton().registerServiceWorkerThreadForInstall(WTFMove(serviceWorkerThreadProxy));
</ins><span class="cx"> 
</span><span class="cx">     LOG(ServiceWorker, "Context process PID: %i created worker thread\n", getpid());
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebKitWebProcessStorageWebSWContextManagerConnectionh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.h (224552 => 224553)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.h   2017-11-07 23:04:34 UTC (rev 224552)
+++ trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.h      2017-11-07 23:06:55 UTC (rev 224553)
</span><span class="lines">@@ -56,7 +56,7 @@
</span><span class="cx"> 
</span><span class="cx">     // IPC messages.
</span><span class="cx">     void serviceWorkerStartedWithMessage(WebCore::ServiceWorkerIdentifier, const String& exceptionMessage) final;
</span><del>-    void updateServiceWorker(uint64_t serverConnectionIdentifier, const WebCore::ServiceWorkerContextData&);
</del><ins>+    void installServiceWorker(uint64_t serverConnectionIdentifier, const WebCore::ServiceWorkerContextData&);
</ins><span class="cx">     void startFetch(uint64_t serverConnectionIdentifier, uint64_t fetchIdentifier, std::optional<WebCore::ServiceWorkerIdentifier>, WebCore::ResourceRequest&&, WebCore::FetchOptions&&);
</span><span class="cx">     void postMessageToServiceWorkerGlobalScope(WebCore::ServiceWorkerIdentifier destinationIdentifier, const IPC::DataReference& message, const WebCore::ServiceWorkerClientIdentifier& sourceIdentifier, const String& sourceOrigin);
</span><span class="cx">     void fireInstallEvent(uint64_t serverConnectionIdentifier, WebCore::ServiceWorkerIdentifier);
</span></span></pre></div>
<a id="trunkSourceWebKitWebProcessStorageWebSWContextManagerConnectionmessagesin"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.messages.in (224552 => 224553)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.messages.in 2017-11-07 23:04:34 UTC (rev 224552)
+++ trunk/Source/WebKit/WebProcess/Storage/WebSWContextManagerConnection.messages.in    2017-11-07 23:06:55 UTC (rev 224553)
</span><span class="lines">@@ -23,7 +23,7 @@
</span><span class="cx"> #if ENABLE(SERVICE_WORKER)
</span><span class="cx"> 
</span><span class="cx"> messages -> WebSWContextManagerConnection {
</span><del>-    UpdateServiceWorker(uint64_t serverConnectionIdentifier, struct WebCore::ServiceWorkerContextData contextData)
</del><ins>+    InstallServiceWorker(uint64_t serverConnectionIdentifier, struct WebCore::ServiceWorkerContextData contextData)
</ins><span class="cx">     StartFetch(uint64_t serverConnectionIdentifier, uint64_t fetchIdentifier, std::optional<WebCore::ServiceWorkerIdentifier> serviceWorkerIdentifier, WebCore::ResourceRequest request, struct WebCore::FetchOptions options)
</span><span class="cx">     PostMessageToServiceWorkerGlobalScope(WebCore::ServiceWorkerIdentifier destinationIdentifier, IPC::DataReference message, struct WebCore::ServiceWorkerClientIdentifier sourceIdentifier, String sourceOrigin)
</span><span class="cx">     FireInstallEvent(uint64_t serverConnectionIdentifier, WebCore::ServiceWorkerIdentifier identifier)
</span></span></pre>
</div>
</div>

</body>
</html>