<!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>[205207] trunk/Source/WebKit2</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/205207">205207</a></dd>
<dt>Author</dt> <dd>andersca@apple.com</dd>
<dt>Date</dt> <dd>2016-08-30 15:59:12 -0700 (Tue, 30 Aug 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>Add Connection::sendWithReply
https://bugs.webkit.org/show_bug.cgi?id=161399

Reviewed by Tim Horton.

Connection::sendWithReply makes it easy to send a message and process its reply asynchronously on a given WorkQueue or RunLoop.
The reply handler is guaranteed to be called. If the reply is successfully received, it will consist of an std::tuple with the arguments,
otherwise it will be called with Nullopt.

* Platform/IPC/Connection.cpp:
(IPC::Connection::invalidate):
Go through all reply handlers and dispatch them with a null Decoder.

(IPC::Connection::sendMessageWithReply):
Add the reply handler to the m_replyHandlers hash map, and send the message.

(IPC::Connection::processIncomingSyncReply):
Check if the incoming reply has an entry in m_replyHandlers. If it does, dispatch its handler using the given dispatcher.

(IPC::Connection::connectionDidClose):
Go through all reply handlers and dispatch them with a null Decoder.

* Platform/IPC/Connection.h:
(IPC::Connection::sendWithReply):
Encode the message (we use the sync message ID infrastructure for this), then call sendMessageWithReply with a reply handler that
decodes the reply and calls the real reply handler.

* Platform/IPC/HandleMessage.h:
Forward declare Connection.

* UIProcess/Databases/DatabaseProcessProxy.h:
* UIProcess/Network/NetworkProcessProxy.h:
Forward declare WebsiteData.

* UIProcess/WebProcessProxy.cpp:
(WebKit::WebProcessProxy::~WebProcessProxy):
(WebKit::WebProcessProxy::processWillShutDown):
Remove m_pendingFetchWebsiteDataCallbacks.

(WebKit::WebProcessProxy::fetchWebsiteData):
Use Connection::sendWithReply.

(WebKit::WebProcessProxy::didFetchWebsiteData): Deleted.

* UIProcess/WebProcessProxy.h:
Remove members.

* UIProcess/WebProcessProxy.messages.in:
Remove DidFetchWebsiteData.

* WebProcess/WebProcess.cpp:
(WebKit::WebProcess::fetchWebsiteData):
* WebProcess/WebProcess.h:
* WebProcess/WebProcess.messages.in:
Update the FetchWebsiteData message to have a reply parameter.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2PlatformIPCConnectioncpp">trunk/Source/WebKit2/Platform/IPC/Connection.cpp</a></li>
<li><a href="#trunkSourceWebKit2PlatformIPCConnectionh">trunk/Source/WebKit2/Platform/IPC/Connection.h</a></li>
<li><a href="#trunkSourceWebKit2PlatformIPCHandleMessageh">trunk/Source/WebKit2/Platform/IPC/HandleMessage.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessDatabasesDatabaseProcessProxyh">trunk/Source/WebKit2/UIProcess/Databases/DatabaseProcessProxy.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessNetworkNetworkProcessProxyh">trunk/Source/WebKit2/UIProcess/Network/NetworkProcessProxy.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessWebProcessProxycpp">trunk/Source/WebKit2/UIProcess/WebProcessProxy.cpp</a></li>
<li><a href="#trunkSourceWebKit2UIProcessWebProcessProxyh">trunk/Source/WebKit2/UIProcess/WebProcessProxy.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessWebProcessProxymessagesin">trunk/Source/WebKit2/UIProcess/WebProcessProxy.messages.in</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebProcesscpp">trunk/Source/WebKit2/WebProcess/WebProcess.cpp</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebProcessh">trunk/Source/WebKit2/WebProcess/WebProcess.h</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebProcessmessagesin">trunk/Source/WebKit2/WebProcess/WebProcess.messages.in</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (205206 => 205207)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2016-08-30 22:54:41 UTC (rev 205206)
+++ trunk/Source/WebKit2/ChangeLog        2016-08-30 22:59:12 UTC (rev 205207)
</span><span class="lines">@@ -1,3 +1,61 @@
</span><ins>+2016-08-30  Anders Carlsson  &lt;andersca@apple.com&gt;
+
+        Add Connection::sendWithReply
+        https://bugs.webkit.org/show_bug.cgi?id=161399
+
+        Reviewed by Tim Horton.
+
+        Connection::sendWithReply makes it easy to send a message and process its reply asynchronously on a given WorkQueue or RunLoop.
+        The reply handler is guaranteed to be called. If the reply is successfully received, it will consist of an std::tuple with the arguments,
+        otherwise it will be called with Nullopt.
+
+        * Platform/IPC/Connection.cpp:
+        (IPC::Connection::invalidate):
+        Go through all reply handlers and dispatch them with a null Decoder.
+
+        (IPC::Connection::sendMessageWithReply):
+        Add the reply handler to the m_replyHandlers hash map, and send the message.
+
+        (IPC::Connection::processIncomingSyncReply):
+        Check if the incoming reply has an entry in m_replyHandlers. If it does, dispatch its handler using the given dispatcher.
+
+        (IPC::Connection::connectionDidClose):
+        Go through all reply handlers and dispatch them with a null Decoder.
+
+        * Platform/IPC/Connection.h:
+        (IPC::Connection::sendWithReply):
+        Encode the message (we use the sync message ID infrastructure for this), then call sendMessageWithReply with a reply handler that
+        decodes the reply and calls the real reply handler.
+
+        * Platform/IPC/HandleMessage.h:
+        Forward declare Connection.
+
+        * UIProcess/Databases/DatabaseProcessProxy.h:
+        * UIProcess/Network/NetworkProcessProxy.h:
+        Forward declare WebsiteData.
+
+        * UIProcess/WebProcessProxy.cpp:
+        (WebKit::WebProcessProxy::~WebProcessProxy):
+        (WebKit::WebProcessProxy::processWillShutDown):
+        Remove m_pendingFetchWebsiteDataCallbacks.
+
+        (WebKit::WebProcessProxy::fetchWebsiteData):
+        Use Connection::sendWithReply.
+
+        (WebKit::WebProcessProxy::didFetchWebsiteData): Deleted.
+
+        * UIProcess/WebProcessProxy.h:
+        Remove members.
+
+        * UIProcess/WebProcessProxy.messages.in:
+        Remove DidFetchWebsiteData.
+
+        * WebProcess/WebProcess.cpp:
+        (WebKit::WebProcess::fetchWebsiteData):
+        * WebProcess/WebProcess.h:
+        * WebProcess/WebProcess.messages.in:
+        Update the FetchWebsiteData message to have a reply parameter.
+
</ins><span class="cx"> 2016-08-30  Brady Eidson  &lt;beidson@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Fix runtime error caused by missing export after https://bugs.webkit.org/show_bug.cgi?id=160846
</span></span></pre></div>
<a id="trunkSourceWebKit2PlatformIPCConnectioncpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/Platform/IPC/Connection.cpp (205206 => 205207)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/Platform/IPC/Connection.cpp        2016-08-30 22:54:41 UTC (rev 205206)
+++ trunk/Source/WebKit2/Platform/IPC/Connection.cpp        2016-08-30 22:59:12 UTC (rev 205207)
</span><span class="lines">@@ -36,6 +36,11 @@
</span><span class="cx"> 
</span><span class="cx"> namespace IPC {
</span><span class="cx"> 
</span><ins>+struct Connection::ReplyHandler {
+    RefPtr&lt;FunctionDispatcher&gt; dispatcher;
+    Function&lt;void (std::unique_ptr&lt;Decoder&gt;)&gt; handler;
+};
+
</ins><span class="cx"> struct Connection::WaitForMessageState {
</span><span class="cx">     WaitForMessageState(StringReference messageReceiverName, StringReference messageName, uint64_t destinationID, OptionSet&lt;WaitForOption&gt; waitForOptions)
</span><span class="cx">         : messageReceiverName(messageReceiverName)
</span><span class="lines">@@ -324,6 +329,17 @@
</span><span class="cx">     
</span><span class="cx">     m_isValid = false;
</span><span class="cx"> 
</span><ins>+    {
+        std::lock_guard&lt;Lock&gt; lock(m_replyHandlersLock);
+        for (auto&amp; replyHandler : m_replyHandlers.values()) {
+            replyHandler.dispatcher-&gt;dispatch([handler = WTFMove(replyHandler.handler)] {
+                handler(nullptr);
+            });
+        }
+
+        m_replyHandlers.clear();
+    }
+
</ins><span class="cx">     m_connectionQueue-&gt;dispatch([protectedThis = makeRef(*this)]() mutable {
</span><span class="cx">         protectedThis-&gt;platformInvalidate();
</span><span class="cx">     });
</span><span class="lines">@@ -379,6 +395,25 @@
</span><span class="cx">     return true;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void Connection::sendMessageWithReply(uint64_t requestID, std::unique_ptr&lt;Encoder&gt; encoder, FunctionDispatcher&amp; replyDispatcher, Function&lt;void (std::unique_ptr&lt;Decoder&gt;)&gt;&amp;&amp; replyHandler)
+{
+    {
+        std::lock_guard&lt;Lock&gt; lock(m_replyHandlersLock);
+
+        if (!isValid()) {
+            replyDispatcher.dispatch([replyHandler = WTFMove(replyHandler)] {
+                replyHandler(nullptr);
+            });
+            return;
+        }
+
+        ASSERT(!m_replyHandlers.contains(requestID));
+        m_replyHandlers.set(requestID, ReplyHandler { &amp;replyDispatcher, WTFMove(replyHandler) });
+    }
+
+    sendMessage(WTFMove(encoder), { });
+}
+
</ins><span class="cx"> bool Connection::sendSyncReply(std::unique_ptr&lt;Encoder&gt; encoder)
</span><span class="cx"> {
</span><span class="cx">     return sendMessage(WTFMove(encoder), { });
</span><span class="lines">@@ -557,28 +592,46 @@
</span><span class="cx"> 
</span><span class="cx"> void Connection::processIncomingSyncReply(std::unique_ptr&lt;Decoder&gt; decoder)
</span><span class="cx"> {
</span><del>-    LockHolder locker(m_syncReplyStateMutex);
</del><ins>+    {
+        LockHolder locker(m_syncReplyStateMutex);
</ins><span class="cx"> 
</span><del>-    // Go through the stack of sync requests that have pending replies and see which one
-    // this reply is for.
-    for (size_t i = m_pendingSyncReplies.size(); i &gt; 0; --i) {
-        PendingSyncReply&amp; pendingSyncReply = m_pendingSyncReplies[i - 1];
</del><ins>+        // Go through the stack of sync requests that have pending replies and see which one
+        // this reply is for.
+        for (size_t i = m_pendingSyncReplies.size(); i &gt; 0; --i) {
+            PendingSyncReply&amp; pendingSyncReply = m_pendingSyncReplies[i - 1];
</ins><span class="cx"> 
</span><del>-        if (pendingSyncReply.syncRequestID != decoder-&gt;destinationID())
-            continue;
</del><ins>+            if (pendingSyncReply.syncRequestID != decoder-&gt;destinationID())
+                continue;
</ins><span class="cx"> 
</span><del>-        ASSERT(!pendingSyncReply.replyDecoder);
</del><ins>+            ASSERT(!pendingSyncReply.replyDecoder);
</ins><span class="cx"> 
</span><del>-        pendingSyncReply.replyDecoder = WTFMove(decoder);
-        pendingSyncReply.didReceiveReply = true;
</del><ins>+            pendingSyncReply.replyDecoder = WTFMove(decoder);
+            pendingSyncReply.didReceiveReply = true;
</ins><span class="cx"> 
</span><del>-        // We got a reply to the last send message, wake up the client run loop so it can be processed.
-        if (i == m_pendingSyncReplies.size())
-            SyncMessageState::singleton().wakeUpClientRunLoop();
</del><ins>+            // We got a reply to the last send message, wake up the client run loop so it can be processed.
+            if (i == m_pendingSyncReplies.size())
+                SyncMessageState::singleton().wakeUpClientRunLoop();
</ins><span class="cx"> 
</span><del>-        return;
</del><ins>+            return;
+        }
</ins><span class="cx">     }
</span><span class="cx"> 
</span><ins>+    {
+        LockHolder locker(m_replyHandlersLock);
+
+        auto replyHandler = m_replyHandlers.take(decoder-&gt;destinationID());
+        if (replyHandler.dispatcher) {
+            replyHandler.dispatcher-&gt;dispatch([protectedThis = makeRef(*this), handler = WTFMove(replyHandler.handler), decoder = WTFMove(decoder)] () mutable {
+                if (!protectedThis-&gt;isValid()) {
+                    handler(nullptr);
+                    return;
+                }
+
+                handler(WTFMove(decoder));
+            });
+        }
+    }
+
</ins><span class="cx">     // If we get here, it means we got a reply for a message that wasn't in the sync request stack or map.
</span><span class="cx">     // This can happen if the send timed out, so it's fine to ignore.
</span><span class="cx"> }
</span><span class="lines">@@ -703,6 +756,17 @@
</span><span class="cx">     platformInvalidate();
</span><span class="cx"> 
</span><span class="cx">     {
</span><ins>+        LockHolder locker(m_replyHandlersLock);
+        for (auto&amp; replyHandler : m_replyHandlers.values()) {
+            replyHandler.dispatcher-&gt;dispatch([handler = WTFMove(replyHandler.handler)] {
+                handler(nullptr);
+            });
+        }
+
+        m_replyHandlers.clear();
+    }
+
+    {
</ins><span class="cx">         LockHolder locker(m_syncReplyStateMutex);
</span><span class="cx"> 
</span><span class="cx">         ASSERT(m_shouldWaitForSyncReplies);
</span></span></pre></div>
<a id="trunkSourceWebKit2PlatformIPCConnectionh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/Platform/IPC/Connection.h (205206 => 205207)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/Platform/IPC/Connection.h        2016-08-30 22:54:41 UTC (rev 205206)
+++ trunk/Source/WebKit2/Platform/IPC/Connection.h        2016-08-30 22:59:12 UTC (rev 205207)
</span><span class="lines">@@ -29,6 +29,7 @@
</span><span class="cx"> 
</span><span class="cx"> #include &quot;Decoder.h&quot;
</span><span class="cx"> #include &quot;Encoder.h&quot;
</span><ins>+#include &quot;HandleMessage.h&quot;
</ins><span class="cx"> #include &quot;MessageReceiver.h&quot;
</span><span class="cx"> #include &lt;atomic&gt;
</span><span class="cx"> #include &lt;wtf/Condition.h&gt;
</span><span class="lines">@@ -164,11 +165,13 @@
</span><span class="cx">     void postConnectionDidCloseOnConnectionWorkQueue();
</span><span class="cx"> 
</span><span class="cx">     template&lt;typename T&gt; bool send(T&amp;&amp; message, uint64_t destinationID, OptionSet&lt;SendOption&gt; sendOptions = { });
</span><ins>+    template&lt;typename T&gt; void sendWithReply(T&amp;&amp; message, uint64_t destinationID, FunctionDispatcher&amp; replyDispatcher, Function&lt;void (Optional&lt;typename CodingType&lt;typename T::Reply&gt;::Type&gt;)&gt;&amp;&amp; replyHandler);
</ins><span class="cx">     template&lt;typename T&gt; bool sendSync(T&amp;&amp; message, typename T::Reply&amp;&amp; reply, uint64_t destinationID, std::chrono::milliseconds timeout = std::chrono::milliseconds::max(), OptionSet&lt;SendSyncOption&gt; sendSyncOptions = { });
</span><span class="cx">     template&lt;typename T&gt; bool waitForAndDispatchImmediately(uint64_t destinationID, std::chrono::milliseconds timeout, OptionSet&lt;WaitForOption&gt; waitForOptions = { });
</span><span class="cx"> 
</span><ins>+    bool sendMessage(std::unique_ptr&lt;Encoder&gt;, OptionSet&lt;SendOption&gt; sendOptions);
+    void sendMessageWithReply(uint64_t requestID, std::unique_ptr&lt;Encoder&gt;, FunctionDispatcher&amp; replyDispatcher, Function&lt;void (std::unique_ptr&lt;Decoder&gt;)&gt;&amp;&amp; replyHandler);
</ins><span class="cx">     std::unique_ptr&lt;Encoder&gt; createSyncMessageEncoder(StringReference messageReceiverName, StringReference messageName, uint64_t destinationID, uint64_t&amp; syncRequestID);
</span><del>-    bool sendMessage(std::unique_ptr&lt;Encoder&gt;, OptionSet&lt;SendOption&gt; sendOptions);
</del><span class="cx">     std::unique_ptr&lt;Decoder&gt; sendSyncMessage(uint64_t syncRequestID, std::unique_ptr&lt;Encoder&gt;, std::chrono::milliseconds timeout, OptionSet&lt;SendSyncOption&gt; sendSyncOptions);
</span><span class="cx">     bool sendSyncReply(std::unique_ptr&lt;Encoder&gt;);
</span><span class="cx"> 
</span><span class="lines">@@ -270,6 +273,11 @@
</span><span class="cx">     Condition m_waitForMessageCondition;
</span><span class="cx">     Lock m_waitForMessageMutex;
</span><span class="cx"> 
</span><ins>+    struct ReplyHandler;
+
+    Lock m_replyHandlersLock;
+    HashMap&lt;uint64_t, ReplyHandler&gt; m_replyHandlers;
+
</ins><span class="cx">     struct WaitForMessageState;
</span><span class="cx">     WaitForMessageState* m_waitingForMessage;
</span><span class="cx"> 
</span><span class="lines">@@ -325,7 +333,8 @@
</span><span class="cx"> #endif
</span><span class="cx"> };
</span><span class="cx"> 
</span><del>-template&lt;typename T&gt; bool Connection::send(T&amp;&amp; message, uint64_t destinationID, OptionSet&lt;SendOption&gt; sendOptions)
</del><ins>+template&lt;typename T&gt;
+bool Connection::send(T&amp;&amp; message, uint64_t destinationID, OptionSet&lt;SendOption&gt; sendOptions)
</ins><span class="cx"> {
</span><span class="cx">     COMPILE_ASSERT(!T::isSync, AsyncMessageExpected);
</span><span class="cx"> 
</span><span class="lines">@@ -335,6 +344,27 @@
</span><span class="cx">     return sendMessage(WTFMove(encoder), sendOptions);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+template&lt;typename T&gt;
+void Connection::sendWithReply(T&amp;&amp; message, uint64_t destinationID, FunctionDispatcher&amp; replyDispatcher, Function&lt;void (Optional&lt;typename CodingType&lt;typename T::Reply&gt;::Type&gt;)&gt;&amp;&amp; replyHandler)
+{
+    uint64_t requestID = 0;
+    std::unique_ptr&lt;Encoder&gt; encoder = createSyncMessageEncoder(T::receiverName(), T::name(), destinationID, requestID);
+
+    encoder-&gt;encode(message.arguments());
+
+    sendMessageWithReply(requestID, WTFMove(encoder), replyDispatcher, [replyHandler = WTFMove(replyHandler)](std::unique_ptr&lt;Decoder&gt; decoder) {
+        if (decoder) {
+            typename CodingType&lt;typename T::Reply&gt;::Type reply;
+            if (decoder-&gt;decode(reply)) {
+                replyHandler(WTFMove(reply));
+                return;
+            }
+        }
+
+        replyHandler(Nullopt);
+    });
+}
+
</ins><span class="cx"> template&lt;typename T&gt; bool Connection::sendSync(T&amp;&amp; message, typename T::Reply&amp;&amp; reply, uint64_t destinationID, std::chrono::milliseconds timeout, OptionSet&lt;SendSyncOption&gt; sendSyncOptions)
</span><span class="cx"> {
</span><span class="cx">     COMPILE_ASSERT(T::isSync, SyncMessageExpected);
</span></span></pre></div>
<a id="trunkSourceWebKit2PlatformIPCHandleMessageh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/Platform/IPC/HandleMessage.h (205206 => 205207)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/Platform/IPC/HandleMessage.h        2016-08-30 22:54:41 UTC (rev 205206)
+++ trunk/Source/WebKit2/Platform/IPC/HandleMessage.h        2016-08-30 22:59:12 UTC (rev 205207)
</span><span class="lines">@@ -5,6 +5,8 @@
</span><span class="cx"> 
</span><span class="cx"> namespace IPC {
</span><span class="cx"> 
</span><ins>+class Connection;
+
</ins><span class="cx"> // Dispatch functions with no reply arguments.
</span><span class="cx"> 
</span><span class="cx"> template &lt;typename C, typename MF, typename ArgsTuple, size_t... ArgsIndex&gt;
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessDatabasesDatabaseProcessProxyh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/Databases/DatabaseProcessProxy.h (205206 => 205207)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/Databases/DatabaseProcessProxy.h        2016-08-30 22:54:41 UTC (rev 205206)
+++ trunk/Source/WebKit2/UIProcess/Databases/DatabaseProcessProxy.h        2016-08-30 22:59:12 UTC (rev 205207)
</span><span class="lines">@@ -43,6 +43,7 @@
</span><span class="cx"> 
</span><span class="cx"> class WebProcessPool;
</span><span class="cx"> enum class WebsiteDataType;
</span><ins>+struct WebsiteData;
</ins><span class="cx"> 
</span><span class="cx"> class DatabaseProcessProxy : public ChildProcessProxy {
</span><span class="cx"> public:
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessNetworkNetworkProcessProxyh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/Network/NetworkProcessProxy.h (205206 => 205207)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/Network/NetworkProcessProxy.h        2016-08-30 22:54:41 UTC (rev 205206)
+++ trunk/Source/WebKit2/UIProcess/Network/NetworkProcessProxy.h        2016-08-30 22:59:12 UTC (rev 205207)
</span><span class="lines">@@ -51,6 +51,7 @@
</span><span class="cx"> enum class WebsiteDataFetchOption;
</span><span class="cx"> enum class WebsiteDataType;
</span><span class="cx"> struct NetworkProcessCreationParameters;
</span><ins>+struct WebsiteData;
</ins><span class="cx"> 
</span><span class="cx"> class NetworkProcessProxy : public ChildProcessProxy, private ProcessThrottlerClient {
</span><span class="cx"> public:
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessWebProcessProxycpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/WebProcessProxy.cpp (205206 => 205207)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/WebProcessProxy.cpp        2016-08-30 22:54:41 UTC (rev 205206)
+++ trunk/Source/WebKit2/UIProcess/WebProcessProxy.cpp        2016-08-30 22:59:12 UTC (rev 205207)
</span><span class="lines">@@ -115,7 +115,6 @@
</span><span class="cx"> 
</span><span class="cx"> WebProcessProxy::~WebProcessProxy()
</span><span class="cx"> {
</span><del>-    ASSERT(m_pendingFetchWebsiteDataCallbacks.isEmpty());
</del><span class="cx">     ASSERT(m_pendingDeleteWebsiteDataCallbacks.isEmpty());
</span><span class="cx">     ASSERT(m_pendingDeleteWebsiteDataForOriginsCallbacks.isEmpty());
</span><span class="cx">     ASSERT(m_pageURLRetainCountMap.isEmpty());
</span><span class="lines">@@ -164,10 +163,6 @@
</span><span class="cx"> {
</span><span class="cx">     ASSERT_UNUSED(connection, this-&gt;connection() == &amp;connection);
</span><span class="cx"> 
</span><del>-    for (const auto&amp; callback : m_pendingFetchWebsiteDataCallbacks.values())
-        callback(WebsiteData());
-    m_pendingFetchWebsiteDataCallbacks.clear();
-
</del><span class="cx">     for (const auto&amp; callback : m_pendingDeleteWebsiteDataCallbacks.values())
</span><span class="cx">         callback();
</span><span class="cx">     m_pendingDeleteWebsiteDataCallbacks.clear();
</span><span class="lines">@@ -706,12 +701,6 @@
</span><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void WebProcessProxy::didFetchWebsiteData(uint64_t callbackID, const WebsiteData&amp; websiteData)
-{
-    auto callback = m_pendingFetchWebsiteDataCallbacks.take(callbackID);
-    callback(websiteData);
-}
-
</del><span class="cx"> void WebProcessProxy::didDeleteWebsiteData(uint64_t callbackID)
</span><span class="cx"> {
</span><span class="cx">     auto callback = m_pendingDeleteWebsiteDataCallbacks.take(callbackID);
</span><span class="lines">@@ -747,20 +736,22 @@
</span><span class="cx">         page-&gt;viewStateDidChange(ViewState::IsVisuallyIdle);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void WebProcessProxy::fetchWebsiteData(SessionID sessionID, OptionSet&lt;WebsiteDataType&gt; dataTypes, std::function&lt;void (WebsiteData)&gt; completionHandler)
</del><ins>+void WebProcessProxy::fetchWebsiteData(SessionID sessionID, OptionSet&lt;WebsiteDataType&gt; dataTypes, Function&lt;void (WebsiteData)&gt; completionHandler)
</ins><span class="cx"> {
</span><span class="cx">     ASSERT(canSendMessage());
</span><span class="cx"> 
</span><del>-    uint64_t callbackID = generateCallbackID();
</del><span class="cx">     auto token = throttler().backgroundActivityToken();
</span><span class="cx">     RELEASE_LOG_IF(sessionID.isAlwaysOnLoggingAllowed(), &quot;%p - WebProcessProxy is taking a background assertion because the Web process is fetching Website data&quot;, this);
</span><span class="cx"> 
</span><del>-    m_pendingFetchWebsiteDataCallbacks.add(callbackID, [this, token, completionHandler, sessionID](WebsiteData websiteData) {
-        completionHandler(WTFMove(websiteData));
</del><ins>+    connection()-&gt;sendWithReply(Messages::WebProcess::FetchWebsiteData(sessionID, dataTypes), 0, RunLoop::main(), [this, token, completionHandler = WTFMove(completionHandler), sessionID](auto reply) {
+        if (!reply) {
+            completionHandler(WebsiteData { });
+            return;
+        }
+
+        completionHandler(WTFMove(std::get&lt;0&gt;(*reply)));
</ins><span class="cx">         RELEASE_LOG_IF(sessionID.isAlwaysOnLoggingAllowed(), &quot;%p - WebProcessProxy is releasing a background assertion because the Web process is done fetching Website data&quot;, this);
</span><span class="cx">     });
</span><del>-
-    send(Messages::WebProcess::FetchWebsiteData(sessionID, dataTypes, callbackID), 0);
</del><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void WebProcessProxy::deleteWebsiteData(SessionID sessionID, OptionSet&lt;WebsiteDataType&gt; dataTypes, std::chrono::system_clock::time_point modifiedSince, std::function&lt;void ()&gt; completionHandler)
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessWebProcessProxyh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/WebProcessProxy.h (205206 => 205207)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/WebProcessProxy.h        2016-08-30 22:54:41 UTC (rev 205206)
+++ trunk/Source/WebKit2/UIProcess/WebProcessProxy.h        2016-08-30 22:59:12 UTC (rev 205207)
</span><span class="lines">@@ -62,7 +62,8 @@
</span><span class="cx"> class WebProcessPool;
</span><span class="cx"> enum class WebsiteDataType;
</span><span class="cx"> struct WebNavigationDataStore;
</span><del>-    
</del><ins>+struct WebsiteData;
+
</ins><span class="cx"> class WebProcessProxy : public ChildProcessProxy, ResponsivenessTimer::Client, private ProcessThrottlerClient {
</span><span class="cx"> public:
</span><span class="cx">     typedef HashMap&lt;uint64_t, RefPtr&lt;WebBackForwardListItem&gt;&gt; WebBackForwardListItemMap;
</span><span class="lines">@@ -118,7 +119,7 @@
</span><span class="cx">     void didSaveToPageCache();
</span><span class="cx">     void releasePageCache();
</span><span class="cx"> 
</span><del>-    void fetchWebsiteData(WebCore::SessionID, OptionSet&lt;WebsiteDataType&gt;, std::function&lt;void (WebsiteData)&gt; completionHandler);
</del><ins>+    void fetchWebsiteData(WebCore::SessionID, OptionSet&lt;WebsiteDataType&gt;, Function&lt;void (WebsiteData)&gt; completionHandler);
</ins><span class="cx">     void deleteWebsiteData(WebCore::SessionID, OptionSet&lt;WebsiteDataType&gt;, std::chrono::system_clock::time_point modifiedSince, std::function&lt;void ()&gt; completionHandler);
</span><span class="cx">     void deleteWebsiteDataForOrigins(WebCore::SessionID, OptionSet&lt;WebsiteDataType&gt;, const Vector&lt;RefPtr&lt;WebCore::SecurityOrigin&gt;&gt;&amp; origins, std::function&lt;void ()&gt; completionHandler);
</span><span class="cx"> 
</span><span class="lines">@@ -169,7 +170,6 @@
</span><span class="cx"> 
</span><span class="cx">     void shouldTerminate(bool&amp; shouldTerminate);
</span><span class="cx"> 
</span><del>-    void didFetchWebsiteData(uint64_t callbackID, const WebsiteData&amp;);
</del><span class="cx">     void didDeleteWebsiteData(uint64_t callbackID);
</span><span class="cx">     void didDeleteWebsiteDataForOrigins(uint64_t callbackID);
</span><span class="cx"> 
</span><span class="lines">@@ -238,7 +238,6 @@
</span><span class="cx"> 
</span><span class="cx">     CustomProtocolManagerProxy m_customProtocolManagerProxy;
</span><span class="cx"> 
</span><del>-    HashMap&lt;uint64_t, std::function&lt;void (WebsiteData)&gt;&gt; m_pendingFetchWebsiteDataCallbacks;
</del><span class="cx">     HashMap&lt;uint64_t, std::function&lt;void ()&gt;&gt; m_pendingDeleteWebsiteDataCallbacks;
</span><span class="cx">     HashMap&lt;uint64_t, std::function&lt;void ()&gt;&gt; m_pendingDeleteWebsiteDataForOriginsCallbacks;
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessWebProcessProxymessagesin"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/WebProcessProxy.messages.in (205206 => 205207)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/WebProcessProxy.messages.in        2016-08-30 22:54:41 UTC (rev 205206)
+++ trunk/Source/WebKit2/UIProcess/WebProcessProxy.messages.in        2016-08-30 22:59:12 UTC (rev 205207)
</span><span class="lines">@@ -31,7 +31,6 @@
</span><span class="cx">     EnableSuddenTermination()
</span><span class="cx">     DisableSuddenTermination()
</span><span class="cx"> 
</span><del>-    DidFetchWebsiteData(uint64_t callbackID, struct WebKit::WebsiteData websiteData)
</del><span class="cx">     DidDeleteWebsiteData(uint64_t callbackID)
</span><span class="cx">     DidDeleteWebsiteDataForOrigins(uint64_t callbackID)
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebProcesscpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebProcess.cpp (205206 => 205207)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebProcess.cpp        2016-08-30 22:54:41 UTC (rev 205206)
+++ trunk/Source/WebKit2/WebProcess/WebProcess.cpp        2016-08-30 22:59:12 UTC (rev 205207)
</span><span class="lines">@@ -1199,16 +1199,12 @@
</span><span class="cx">     PageCache::singleton().pruneToSizeNow(0, PruningReason::MemoryPressure);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void WebProcess::fetchWebsiteData(SessionID sessionID, OptionSet&lt;WebsiteDataType&gt; websiteDataTypes, uint64_t callbackID)
</del><ins>+void WebProcess::fetchWebsiteData(WebCore::SessionID sessionID, OptionSet&lt;WebsiteDataType&gt; websiteDataTypes, WebsiteData&amp; websiteData)
</ins><span class="cx"> {
</span><del>-    WebsiteData websiteData;
-
</del><span class="cx">     if (websiteDataTypes.contains(WebsiteDataType::MemoryCache)) {
</span><span class="cx">         for (auto&amp; origin : MemoryCache::singleton().originsWithCache(sessionID))
</span><span class="cx">             websiteData.entries.append(WebsiteData::Entry { origin, WebsiteDataType::MemoryCache, 0 });
</span><span class="cx">     }
</span><del>-
-    parentProcessConnection()-&gt;send(Messages::WebProcessProxy::DidFetchWebsiteData(callbackID, websiteData), 0);
</del><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void WebProcess::deleteWebsiteData(SessionID sessionID, OptionSet&lt;WebsiteDataType&gt; websiteDataTypes, std::chrono::system_clock::time_point modifiedSince, uint64_t callbackID)
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebProcessh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebProcess.h (205206 => 205207)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebProcess.h        2016-08-30 22:54:41 UTC (rev 205206)
+++ trunk/Source/WebKit2/WebProcess/WebProcess.h        2016-08-30 22:59:12 UTC (rev 205207)
</span><span class="lines">@@ -73,6 +73,7 @@
</span><span class="cx"> namespace WebKit {
</span><span class="cx"> 
</span><span class="cx"> class EventDispatcher;
</span><ins>+class GamepadData;
</ins><span class="cx"> class InjectedBundle;
</span><span class="cx"> class NetworkProcessConnection;
</span><span class="cx"> class ObjCObjectGraph;
</span><span class="lines">@@ -86,11 +87,11 @@
</span><span class="cx"> class WebPageGroupProxy;
</span><span class="cx"> class WebProcessSupplement;
</span><span class="cx"> enum class WebsiteDataType;
</span><del>-class GamepadData;
</del><span class="cx"> struct WebPageCreationParameters;
</span><span class="cx"> struct WebPageGroupData;
</span><span class="cx"> struct WebPreferencesStore;
</span><span class="cx"> struct WebProcessCreationParameters;
</span><ins>+struct WebsiteData;
</ins><span class="cx"> 
</span><span class="cx"> #if ENABLE(DATABASE_PROCESS)
</span><span class="cx"> class WebToDatabaseProcessConnection;
</span><span class="lines">@@ -286,7 +287,7 @@
</span><span class="cx"> 
</span><span class="cx">     void releasePageCache();
</span><span class="cx"> 
</span><del>-    void fetchWebsiteData(WebCore::SessionID, OptionSet&lt;WebsiteDataType&gt;, uint64_t callbackID);
</del><ins>+    void fetchWebsiteData(WebCore::SessionID, OptionSet&lt;WebsiteDataType&gt;, WebsiteData&amp;);
</ins><span class="cx">     void deleteWebsiteData(WebCore::SessionID, OptionSet&lt;WebsiteDataType&gt;, std::chrono::system_clock::time_point modifiedSince, uint64_t callbackID);
</span><span class="cx">     void deleteWebsiteDataForOrigins(WebCore::SessionID, OptionSet&lt;WebsiteDataType&gt;, const Vector&lt;WebCore::SecurityOriginData&gt;&amp; origins, uint64_t callbackID);
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebProcessmessagesin"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebProcess.messages.in (205206 => 205207)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebProcess.messages.in        2016-08-30 22:54:41 UTC (rev 205206)
+++ trunk/Source/WebKit2/WebProcess/WebProcess.messages.in        2016-08-30 22:59:12 UTC (rev 205207)
</span><span class="lines">@@ -76,7 +76,7 @@
</span><span class="cx"> 
</span><span class="cx">     ReleasePageCache()
</span><span class="cx"> 
</span><del>-    FetchWebsiteData(WebCore::SessionID sessionID, OptionSet&lt;WebKit::WebsiteDataType&gt; websiteDataTypes, uint64_t callbackID)
</del><ins>+    FetchWebsiteData(WebCore::SessionID sessionID, OptionSet&lt;WebKit::WebsiteDataType&gt; websiteDataTypes) -&gt; (struct WebKit::WebsiteData websiteData)
</ins><span class="cx">     DeleteWebsiteData(WebCore::SessionID sessionID, OptionSet&lt;WebKit::WebsiteDataType&gt; websiteDataTypes, std::chrono::system_clock::time_point modifiedSince, uint64_t callbackID)
</span><span class="cx">     DeleteWebsiteDataForOrigins(WebCore::SessionID sessionID, OptionSet&lt;WebKit::WebsiteDataType&gt; websiteDataTypes, Vector&lt;WebCore::SecurityOriginData&gt; origins, uint64_t callbackID)
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>