<!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>[205183] 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/205183">205183</a></dd>
<dt>Author</dt> <dd>andersca@apple.com</dd>
<dt>Date</dt> <dd>2016-08-30 09:35:48 -0700 (Tue, 30 Aug 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>Stop using m_client to indicate whether an IPC::Connection is valid
https://bugs.webkit.org/show_bug.cgi?id=161362

Reviewed by Andreas Kling.

Instead, add an std::atomic&lt;bool&gt; so we can reliably check the state from other threads.

* Platform/IPC/Connection.cpp:
(IPC::Connection::Connection):
(IPC::Connection::invalidate):
(IPC::Connection::connectionDidClose):
(IPC::Connection::dispatchSyncMessage):
(IPC::Connection::dispatchDidReceiveInvalidMessage):
(IPC::Connection::dispatchMessage):
* Platform/IPC/Connection.h:
(IPC::Connection::client):
(IPC::Connection::isValid):
(IPC::Connection::waitForAndDispatchImmediately):
* UIProcess/WebGeolocationManagerProxy.cpp:
(WebKit::WebGeolocationManagerProxy::startUpdating):
(WebKit::WebGeolocationManagerProxy::stopUpdating):
(WebKit::WebGeolocationManagerProxy::setEnableHighAccuracy):</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="#trunkSourceWebKit2UIProcessWebGeolocationManagerProxycpp">trunk/Source/WebKit2/UIProcess/WebGeolocationManagerProxy.cpp</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (205182 => 205183)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2016-08-30 16:34:01 UTC (rev 205182)
+++ trunk/Source/WebKit2/ChangeLog        2016-08-30 16:35:48 UTC (rev 205183)
</span><span class="lines">@@ -1,3 +1,28 @@
</span><ins>+2016-08-29  Anders Carlsson  &lt;andersca@apple.com&gt;
+
+        Stop using m_client to indicate whether an IPC::Connection is valid
+        https://bugs.webkit.org/show_bug.cgi?id=161362
+
+        Reviewed by Andreas Kling.
+
+        Instead, add an std::atomic&lt;bool&gt; so we can reliably check the state from other threads.
+
+        * Platform/IPC/Connection.cpp:
+        (IPC::Connection::Connection):
+        (IPC::Connection::invalidate):
+        (IPC::Connection::connectionDidClose):
+        (IPC::Connection::dispatchSyncMessage):
+        (IPC::Connection::dispatchDidReceiveInvalidMessage):
+        (IPC::Connection::dispatchMessage):
+        * Platform/IPC/Connection.h:
+        (IPC::Connection::client):
+        (IPC::Connection::isValid):
+        (IPC::Connection::waitForAndDispatchImmediately):
+        * UIProcess/WebGeolocationManagerProxy.cpp:
+        (WebKit::WebGeolocationManagerProxy::startUpdating):
+        (WebKit::WebGeolocationManagerProxy::stopUpdating):
+        (WebKit::WebGeolocationManagerProxy::setEnableHighAccuracy):
+
</ins><span class="cx"> 2016-08-30  Carlos Garcia Campos  &lt;cgarcia@igalia.com&gt;
</span><span class="cx"> 
</span><span class="cx">         REGRESSION(r194846): [GTK] UI process crash visiting sites protected with HTTP auth when using GTK+ &lt; 3.14
</span></span></pre></div>
<a id="trunkSourceWebKit2PlatformIPCConnectioncpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/Platform/IPC/Connection.cpp (205182 => 205183)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/Platform/IPC/Connection.cpp        2016-08-30 16:34:01 UTC (rev 205182)
+++ trunk/Source/WebKit2/Platform/IPC/Connection.cpp        2016-08-30 16:35:48 UTC (rev 205183)
</span><span class="lines">@@ -214,7 +214,7 @@
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> Connection::Connection(Identifier identifier, bool isServer, Client&amp; client)
</span><del>-    : m_client(&amp;client)
</del><ins>+    : m_client(client)
</ins><span class="cx">     , m_isServer(isServer)
</span><span class="cx">     , m_syncRequestID(0)
</span><span class="cx">     , m_onlySendMessagesAsDispatchWhenWaitingForSyncReplyWhenProcessingSuchAMessage(false)
</span><span class="lines">@@ -315,12 +315,14 @@
</span><span class="cx"> 
</span><span class="cx"> void Connection::invalidate()
</span><span class="cx"> {
</span><ins>+    ASSERT(RunLoop::isMain());
+
</ins><span class="cx">     if (!isValid()) {
</span><span class="cx">         // Someone already called invalidate().
</span><span class="cx">         return;
</span><span class="cx">     }
</span><span class="cx">     
</span><del>-    m_client = nullptr;
</del><ins>+    m_isValid = false;
</ins><span class="cx"> 
</span><span class="cx">     m_connectionQueue-&gt;dispatch([protectedThis = makeRef(*this)]() mutable {
</span><span class="cx">         protectedThis-&gt;platformInvalidate();
</span><span class="lines">@@ -722,17 +724,15 @@
</span><span class="cx"> 
</span><span class="cx">     RunLoop::main().dispatch([protectedThis = makeRef(*this)]() mutable {
</span><span class="cx">         // If the connection has been explicitly invalidated before dispatchConnectionDidClose was called,
</span><del>-        // then the client will be null here.
-        if (!protectedThis-&gt;m_client)
</del><ins>+        // then the the connection will be invalid here.
+        if (!protectedThis-&gt;isValid())
</ins><span class="cx">             return;
</span><span class="cx"> 
</span><del>-        // Because we define a connection as being &quot;valid&quot; based on wheter it has a null client, we null out
-        // the client before calling didClose here. Otherwise, sendSync will try to send a message to the connection and
-        // will then wait indefinitely for a reply.
-        Client* client = protectedThis-&gt;m_client;
-        protectedThis-&gt;m_client = nullptr;
</del><ins>+        // Set m_isValid to false before calling didClose, otherwise, sendSync will try to send a message
+        // to the connection and will then wait indefinitely for a reply.
+        protectedThis-&gt;m_isValid = false;
</ins><span class="cx"> 
</span><del>-        client-&gt;didClose(protectedThis.get());
</del><ins>+        protectedThis-&gt;m_client.didClose(protectedThis.get());
</ins><span class="cx">     });
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -786,7 +786,7 @@
</span><span class="cx">         SyncMessageState::singleton().dispatchMessages(nullptr);
</span><span class="cx">     } else {
</span><span class="cx">         // Hand off both the decoder and encoder to the client.
</span><del>-        m_client-&gt;didReceiveSyncMessage(*this, decoder, replyEncoder);
</del><ins>+        m_client.didReceiveSyncMessage(*this, decoder, replyEncoder);
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     // FIXME: If the message was invalid, we should send back a SyncMessageError.
</span><span class="lines">@@ -800,10 +800,10 @@
</span><span class="cx"> {
</span><span class="cx">     ASSERT(RunLoop::isMain());
</span><span class="cx"> 
</span><del>-    if (!m_client)
</del><ins>+    if (!isValid())
</ins><span class="cx">         return;
</span><span class="cx"> 
</span><del>-    m_client-&gt;didReceiveInvalidMessage(*this, StringReference(messageReceiverNameString.data(), messageReceiverNameString.length()), StringReference(messageNameString.data(), messageNameString.length()));
</del><ins>+    m_client.didReceiveInvalidMessage(*this, StringReference(messageReceiverNameString.data(), messageReceiverNameString.length()), StringReference(messageNameString.data(), messageNameString.length()));
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void Connection::didFailToSendSyncMessage()
</span><span class="lines">@@ -828,17 +828,17 @@
</span><span class="cx"> 
</span><span class="cx"> void Connection::dispatchMessage(Decoder&amp; decoder)
</span><span class="cx"> {
</span><del>-    m_client-&gt;didReceiveMessage(*this, decoder);
</del><ins>+    m_client.didReceiveMessage(*this, decoder);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void Connection::dispatchMessage(std::unique_ptr&lt;Decoder&gt; message)
</span><span class="cx"> {
</span><del>-    if (!m_client)
</del><ins>+    if (!isValid())
</ins><span class="cx">         return;
</span><span class="cx"> 
</span><span class="cx">     if (message-&gt;shouldUseFullySynchronousModeForTesting()) {
</span><span class="cx">         if (!m_fullySynchronousModeIsAllowedForTesting) {
</span><del>-            m_client-&gt;didReceiveInvalidMessage(*this, message-&gt;messageReceiverName(), message-&gt;messageName());
</del><ins>+            m_client.didReceiveInvalidMessage(*this, message-&gt;messageReceiverName(), message-&gt;messageName());
</ins><span class="cx">             return;
</span><span class="cx">         }
</span><span class="cx">         m_inDispatchMessageMarkedToUseFullySynchronousModeForTesting++;
</span><span class="lines">@@ -868,8 +868,8 @@
</span><span class="cx">     if (message-&gt;shouldUseFullySynchronousModeForTesting())
</span><span class="cx">         m_inDispatchMessageMarkedToUseFullySynchronousModeForTesting--;
</span><span class="cx"> 
</span><del>-    if (m_didReceiveInvalidMessage &amp;&amp; m_client)
-        m_client-&gt;didReceiveInvalidMessage(*this, message-&gt;messageReceiverName(), message-&gt;messageName());
</del><ins>+    if (m_didReceiveInvalidMessage &amp;&amp; isValid())
+        m_client.didReceiveInvalidMessage(*this, message-&gt;messageReceiverName(), message-&gt;messageName());
</ins><span class="cx"> 
</span><span class="cx">     m_didReceiveInvalidMessage = oldDidReceiveInvalidMessage;
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebKit2PlatformIPCConnectionh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/Platform/IPC/Connection.h (205182 => 205183)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/Platform/IPC/Connection.h        2016-08-30 16:34:01 UTC (rev 205182)
+++ trunk/Source/WebKit2/Platform/IPC/Connection.h        2016-08-30 16:35:48 UTC (rev 205183)
</span><span class="lines">@@ -137,7 +137,7 @@
</span><span class="cx">     static Ref&lt;Connection&gt; createClientConnection(Identifier, Client&amp;);
</span><span class="cx">     ~Connection();
</span><span class="cx"> 
</span><del>-    Client* client() const { return m_client; }
</del><ins>+    Client&amp; client() const { return m_client; }
</ins><span class="cx"> 
</span><span class="cx"> #if PLATFORM(MAC) &amp;&amp; __MAC_OS_X_VERSION_MIN_REQUIRED &lt;= 101000
</span><span class="cx">     void setShouldCloseConnectionOnMachExceptions();
</span><span class="lines">@@ -186,7 +186,7 @@
</span><span class="cx">     void terminateSoon(double intervalInSeconds);
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><del>-    bool isValid() const { return m_client; }
</del><ins>+    bool isValid() const { return m_isValid; }
</ins><span class="cx"> 
</span><span class="cx"> #if HAVE(QOS_CLASSES)
</span><span class="cx">     void setShouldBoostMainThreadOnSyncMessage(bool b) { m_shouldBoostMainThreadOnSyncMessage = b; }
</span><span class="lines">@@ -237,8 +237,9 @@
</span><span class="cx"> 
</span><span class="cx">     std::chrono::milliseconds timeoutRespectingIgnoreTimeoutsForTesting(std::chrono::milliseconds) const;
</span><span class="cx">     
</span><del>-    Client* m_client;
</del><ins>+    Client&amp; m_client;
</ins><span class="cx">     bool m_isServer;
</span><ins>+    std::atomic&lt;bool&gt; m_isValid { true };
</ins><span class="cx">     std::atomic&lt;uint64_t&gt; m_syncRequestID;
</span><span class="cx"> 
</span><span class="cx">     bool m_onlySendMessagesAsDispatchWhenWaitingForSyncReplyWhenProcessingSuchAMessage;
</span><span class="lines">@@ -365,7 +366,7 @@
</span><span class="cx">         return false;
</span><span class="cx"> 
</span><span class="cx">     ASSERT(decoder-&gt;destinationID() == destinationID);
</span><del>-    m_client-&gt;didReceiveMessage(*this, *decoder);
</del><ins>+    m_client.didReceiveMessage(*this, *decoder);
</ins><span class="cx">     return true;
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessWebGeolocationManagerProxycpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/WebGeolocationManagerProxy.cpp (205182 => 205183)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/WebGeolocationManagerProxy.cpp        2016-08-30 16:34:01 UTC (rev 205182)
+++ trunk/Source/WebKit2/UIProcess/WebGeolocationManagerProxy.cpp        2016-08-30 16:35:48 UTC (rev 205183)
</span><span class="lines">@@ -106,7 +106,7 @@
</span><span class="cx"> void WebGeolocationManagerProxy::startUpdating(IPC::Connection&amp; connection)
</span><span class="cx"> {
</span><span class="cx">     bool wasUpdating = isUpdating();
</span><del>-    m_updateRequesters.add(connection.client());
</del><ins>+    m_updateRequesters.add(&amp;connection.client());
</ins><span class="cx">     if (!wasUpdating) {
</span><span class="cx">         m_provider.setEnableHighAccuracy(this, isHighAccuracyEnabled());
</span><span class="cx">         m_provider.startUpdating(this);
</span><span class="lines">@@ -115,7 +115,7 @@
</span><span class="cx"> 
</span><span class="cx"> void WebGeolocationManagerProxy::stopUpdating(IPC::Connection&amp; connection)
</span><span class="cx"> {
</span><del>-    removeRequester(connection.client());
</del><ins>+    removeRequester(&amp;connection.client());
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void WebGeolocationManagerProxy::removeRequester(const IPC::Connection::Client* client)
</span><span class="lines">@@ -140,9 +140,9 @@
</span><span class="cx">     bool highAccuracyWasEnabled = isHighAccuracyEnabled();
</span><span class="cx"> 
</span><span class="cx">     if (enabled)
</span><del>-        m_highAccuracyRequesters.add(connection.client());
</del><ins>+        m_highAccuracyRequesters.add(&amp;connection.client());
</ins><span class="cx">     else
</span><del>-        m_highAccuracyRequesters.remove(connection.client());
</del><ins>+        m_highAccuracyRequesters.remove(&amp;connection.client());
</ins><span class="cx"> 
</span><span class="cx">     bool highAccuracyShouldBeEnabled = isHighAccuracyEnabled();
</span><span class="cx">     if (isUpdating() &amp;&amp; highAccuracyWasEnabled != highAccuracyShouldBeEnabled)
</span></span></pre>
</div>
</div>

</body>
</html>