<!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>[245164] trunk/Source/WebKit</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/245164">245164</a></dd>
<dt>Author</dt> <dd>achristensen@apple.com</dd>
<dt>Date</dt> <dd>2019-05-09 16:29:41 -0700 (Thu, 09 May 2019)</dd>
</dl>

<h3>Log Message</h3>
<pre>Unreviewed, rolling out most of <a href="http://trac.webkit.org/projects/webkit/changeset/245151">r245151</a>.

Caused assertions in High Sierra

Reverted most of changeset:

"Remove now-unnecessary Connection::sendMessageWithReply"
https://bugs.webkit.org/show_bug.cgi?id=197747
https://trac.webkit.org/changeset/245151</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebKitChangeLog">trunk/Source/WebKit/ChangeLog</a></li>
<li><a href="#trunkSourceWebKitPlatformIPCConnectioncpp">trunk/Source/WebKit/Platform/IPC/Connection.cpp</a></li>
<li><a href="#trunkSourceWebKitPlatformIPCConnectionh">trunk/Source/WebKit/Platform/IPC/Connection.h</a></li>
<li><a href="#trunkSourceWebKitSharedmacSecItemResponseDatah">trunk/Source/WebKit/Shared/mac/SecItemResponseData.h</a></li>
<li><a href="#trunkSourceWebKitSharedmacSecItemShimcpp">trunk/Source/WebKit/Shared/mac/SecItemShim.cpp</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebKitChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/ChangeLog (245163 => 245164)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/ChangeLog    2019-05-09 23:05:44 UTC (rev 245163)
+++ trunk/Source/WebKit/ChangeLog       2019-05-09 23:29:41 UTC (rev 245164)
</span><span class="lines">@@ -1,3 +1,15 @@
</span><ins>+2019-05-09  Alex Christensen  <achristensen@webkit.org>
+
+        Unreviewed, rolling out most of r245151.
+
+        Caused assertions in High Sierra
+
+        Reverted most of changeset:
+
+        "Remove now-unnecessary Connection::sendMessageWithReply"
+        https://bugs.webkit.org/show_bug.cgi?id=197747
+        https://trac.webkit.org/changeset/245151
+
</ins><span class="cx"> 2019-05-09  Daniel Bates  <dabates@apple.com>
</span><span class="cx"> 
</span><span class="cx">         [iOS] Lazily request keyboard on first hardware keydown when a non-editable element is focused
</span></span></pre></div>
<a id="trunkSourceWebKitPlatformIPCConnectioncpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/Platform/IPC/Connection.cpp (245163 => 245164)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/Platform/IPC/Connection.cpp  2019-05-09 23:05:44 UTC (rev 245163)
+++ trunk/Source/WebKit/Platform/IPC/Connection.cpp     2019-05-09 23:29:41 UTC (rev 245164)
</span><span class="lines">@@ -49,6 +49,11 @@
</span><span class="cx"> const size_t maxPendingIncomingMessagesKillingThreshold { 50000 };
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><ins>+struct Connection::ReplyHandler {
+    RefPtr<FunctionDispatcher> dispatcher;
+    Function<void (std::unique_ptr<Decoder>)> handler;
+};
+
</ins><span class="cx"> struct Connection::WaitForMessageState {
</span><span class="cx">     WaitForMessageState(StringReference messageReceiverName, StringReference messageName, uint64_t destinationID, OptionSet<WaitForOption> waitForOptions)
</span><span class="cx">         : messageReceiverName(messageReceiverName)
</span><span class="lines">@@ -366,6 +371,17 @@
</span><span class="cx">     
</span><span class="cx">     m_isValid = false;
</span><span class="cx"> 
</span><ins>+    {
+        std::lock_guard<Lock> lock(m_replyHandlersLock);
+        for (auto& replyHandler : m_replyHandlers.values()) {
+            replyHandler.dispatcher->dispatch([handler = WTFMove(replyHandler.handler)] {
+                handler(nullptr);
+            });
+        }
+
+        m_replyHandlers.clear();
+    }
+
</ins><span class="cx">     m_connectionQueue->dispatch([protectedThis = makeRef(*this)]() mutable {
</span><span class="cx">         protectedThis->platformInvalidate();
</span><span class="cx">     });
</span><span class="lines">@@ -421,6 +437,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<Encoder> encoder, FunctionDispatcher& replyDispatcher, Function<void (std::unique_ptr<Decoder>)>&& replyHandler)
+{
+    {
+        std::lock_guard<Lock> lock(m_replyHandlersLock);
+
+        if (!isValid()) {
+            replyDispatcher.dispatch([replyHandler = WTFMove(replyHandler)] {
+                replyHandler(nullptr);
+            });
+            return;
+        }
+
+        ASSERT(!m_replyHandlers.contains(requestID));
+        m_replyHandlers.set(requestID, ReplyHandler { &replyDispatcher, WTFMove(replyHandler) });
+    }
+
+    sendMessage(WTFMove(encoder), { });
+}
+
</ins><span class="cx"> bool Connection::sendSyncReply(std::unique_ptr<Encoder> encoder)
</span><span class="cx"> {
</span><span class="cx">     return sendMessage(WTFMove(encoder), { });
</span><span class="lines">@@ -623,6 +658,22 @@
</span><span class="cx">         }
</span><span class="cx">     }
</span><span class="cx"> 
</span><ins>+    {
+        LockHolder locker(m_replyHandlersLock);
+
+        auto replyHandler = m_replyHandlers.take(decoder->destinationID());
+        if (replyHandler.dispatcher) {
+            replyHandler.dispatcher->dispatch([protectedThis = makeRef(*this), handler = WTFMove(replyHandler.handler), decoder = WTFMove(decoder)] () mutable {
+                if (!protectedThis->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">@@ -757,6 +808,17 @@
</span><span class="cx">     platformInvalidate();
</span><span class="cx"> 
</span><span class="cx">     {
</span><ins>+        LockHolder locker(m_replyHandlersLock);
+        for (auto& replyHandler : m_replyHandlers.values()) {
+            replyHandler.dispatcher->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="trunkSourceWebKitPlatformIPCConnectionh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/Platform/IPC/Connection.h (245163 => 245164)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/Platform/IPC/Connection.h    2019-05-09 23:05:44 UTC (rev 245163)
+++ trunk/Source/WebKit/Platform/IPC/Connection.h       2019-05-09 23:29:41 UTC (rev 245164)
</span><span class="lines">@@ -179,10 +179,12 @@
</span><span class="cx"> 
</span><span class="cx">     template<typename T, typename C> void sendWithAsyncReply(T&& message, C&& completionHandler, uint64_t destinationID = 0);
</span><span class="cx">     template<typename T> bool send(T&& message, uint64_t destinationID, OptionSet<SendOption> sendOptions = { });
</span><ins>+    template<typename T> void sendWithReply(T&& message, uint64_t destinationID, FunctionDispatcher& replyDispatcher, Function<void(Optional<typename CodingType<typename T::Reply>::Type>)>&& replyHandler);
</ins><span class="cx">     template<typename T> bool sendSync(T&& message, typename T::Reply&& reply, uint64_t destinationID, Seconds timeout = Seconds::infinity(), OptionSet<SendSyncOption> sendSyncOptions = { });
</span><span class="cx">     template<typename T> bool waitForAndDispatchImmediately(uint64_t destinationID, Seconds timeout, OptionSet<WaitForOption> waitForOptions = { });
</span><span class="cx"> 
</span><span class="cx">     bool sendMessage(std::unique_ptr<Encoder>, OptionSet<SendOption> sendOptions);
</span><ins>+    void sendMessageWithReply(uint64_t requestID, std::unique_ptr<Encoder>, FunctionDispatcher& replyDispatcher, Function<void(std::unique_ptr<Decoder>)>&& replyHandler);
</ins><span class="cx">     std::unique_ptr<Encoder> createSyncMessageEncoder(StringReference messageReceiverName, StringReference messageName, uint64_t destinationID, uint64_t& syncRequestID);
</span><span class="cx">     std::unique_ptr<Decoder> sendSyncMessage(uint64_t syncRequestID, std::unique_ptr<Encoder>, Seconds timeout, OptionSet<SendSyncOption> sendSyncOptions);
</span><span class="cx">     bool sendSyncReply(std::unique_ptr<Encoder>);
</span><span class="lines">@@ -311,6 +313,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<uint64_t, ReplyHandler> m_replyHandlers;
+
</ins><span class="cx">     struct WaitForMessageState;
</span><span class="cx">     WaitForMessageState* m_waitingForMessage;
</span><span class="cx"> 
</span><span class="lines">@@ -427,6 +434,28 @@
</span><span class="cx">     });
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+template<typename T>
+void Connection::sendWithReply(T&& message, uint64_t destinationID, FunctionDispatcher& replyDispatcher, Function<void(Optional<typename CodingType<typename T::Reply>::Type>)>&& replyHandler)
+{
+    uint64_t requestID = 0;
+    std::unique_ptr<Encoder> encoder = createSyncMessageEncoder(T::receiverName(), T::name(), destinationID, requestID);
+
+    encoder->encode(message.arguments());
+
+    sendMessageWithReply(requestID, WTFMove(encoder), replyDispatcher, [replyHandler = WTFMove(replyHandler)](std::unique_ptr<Decoder> decoder) {
+        if (decoder) {
+            Optional<typename CodingType<typename T::Reply>::Type> reply;
+            *decoder >> reply;
+            if (reply) {
+                replyHandler(WTFMove(*reply));
+                return;
+            }
+        }
+
+        replyHandler(WTF::nullopt);
+    });
+}
+
</ins><span class="cx"> template<size_t i, typename A, typename B> struct TupleMover {
</span><span class="cx">     static void move(A&& a, B& b)
</span><span class="cx">     {
</span></span></pre></div>
<a id="trunkSourceWebKitSharedmacSecItemResponseDatah"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/Shared/mac/SecItemResponseData.h (245163 => 245164)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/Shared/mac/SecItemResponseData.h     2019-05-09 23:05:44 UTC (rev 245163)
+++ trunk/Source/WebKit/Shared/mac/SecItemResponseData.h        2019-05-09 23:29:41 UTC (rev 245164)
</span><span class="lines">@@ -36,7 +36,6 @@
</span><span class="cx">     
</span><span class="cx"> class SecItemResponseData {
</span><span class="cx"> public:
</span><del>-    SecItemResponseData() = default;
</del><span class="cx">     SecItemResponseData(OSStatus, RetainPtr<CFTypeRef>&& result);
</span><span class="cx"> 
</span><span class="cx">     void encode(IPC::Encoder&) const;
</span></span></pre></div>
<a id="trunkSourceWebKitSharedmacSecItemShimcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/Shared/mac/SecItemShim.cpp (245163 => 245164)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/Shared/mac/SecItemShim.cpp   2019-05-09 23:05:44 UTC (rev 245163)
+++ trunk/Source/WebKit/Shared/mac/SecItemShim.cpp      2019-05-09 23:29:41 UTC (rev 245164)
</span><span class="lines">@@ -64,16 +64,37 @@
</span><span class="cx">     return networkProcess.get();
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+static WorkQueue& workQueue()
+{
+    static WorkQueue* workQueue;
+    static dispatch_once_t onceToken;
+    dispatch_once(&onceToken, ^{
+        workQueue = &WorkQueue::create("com.apple.WebKit.SecItemShim").leakRef();
+
+    });
+
+    return *workQueue;
+}
+
</ins><span class="cx"> static Optional<SecItemResponseData> sendSecItemRequest(SecItemRequestData::Type requestType, CFDictionaryRef query, CFDictionaryRef attributesToMatch = 0)
</span><span class="cx"> {
</span><span class="cx">     if (!globalNetworkProcess())
</span><span class="cx">         return WTF::nullopt;
</span><span class="cx"> 
</span><del>-    SecItemResponseData response;
-    if (!globalNetworkProcess()->parentProcessConnection()->sendSync(Messages::SecItemShimProxy::SecItemRequest(SecItemRequestData(requestType, query, attributesToMatch)), Messages::SecItemShimProxy::SecItemRequest::Reply(response), 0))
-        return WTF::nullopt;
</del><ins>+    Optional<SecItemResponseData> response;
</ins><span class="cx"> 
</span><del>-    return WTFMove(response);
</del><ins>+    BinarySemaphore semaphore;
+
+    globalNetworkProcess()->parentProcessConnection()->sendWithReply(Messages::SecItemShimProxy::SecItemRequest(SecItemRequestData(requestType, query, attributesToMatch)), 0, workQueue(), [&response, &semaphore](auto reply) {
+        if (reply)
+            response = WTFMove(std::get<0>(*reply));
+
+        semaphore.signal();
+    });
+
+    semaphore.wait();
+
+    return response;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> static OSStatus webSecItemCopyMatching(CFDictionaryRef query, CFTypeRef* result)
</span></span></pre>
</div>
</div>

</body>
</html>