<!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>[182610] 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/182610">182610</a></dd>
<dt>Author</dt> <dd>commit-queue@webkit.org</dd>
<dt>Date</dt> <dd>2015-04-09 15:37:19 -0700 (Thu, 09 Apr 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>Track IconDatabase retain counts for WebContent processes. Balance retain/releases for processes that terminate before successfully doing it themselves.
https://bugs.webkit.org/show_bug.cgi?id=143517.

Patch by Gordon Sheridan &lt;gordon_sheridan@apple.com&gt; on 2015-04-09
Reviewed by Brady Eidson.

* UIProcess/WebIconDatabase.messages.in:
Move RetainIconForPageURL and ReleaseIconForPageURL messages to WebProcessProxy so they can be associated with the appropriate web process.

* UIProcess/WebProcessProxy.cpp:
(WebKit::WebProcessProxy::connectionDidClose):
Call releaseRemainingIconsForPageURLs() to balance retains/releases for this process.

(WebKit::WebProcessProxy::retainIconForPageURL):
Track retain counts for page URLs and call through to WebIconDatabase.

(WebKit::WebProcessProxy::releaseIconForPageURL):
Ditto.

(WebKit::WebProcessProxy::releaseRemainingIconsForPageURLs):
Call releaseIconForPageURL() once for each outstanding retain count, for each page URL.

* UIProcess/WebProcessProxy.h:
Declare methods for retainIconForPageURL(), releaseIconForPageURL(), and releaseRemainingIconsForPageURLs().
Declare hash map to track number of retains per page URL.

* UIProcess/WebProcessProxy.messages.in:
Moved RetainIconForPageURL and ReleaseIconForPageURL messages here from WebIconDatabase.

* WebProcess/IconDatabase/WebIconDatabaseProxy.cpp:
(WebKit::WebIconDatabaseProxy::retainIconForPageURL):
Modify the receiver of the message to be WebProcessProxy.

(WebKit::WebIconDatabaseProxy::releaseIconForPageURL):
Ditto.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2UIProcessWebIconDatabasemessagesin">trunk/Source/WebKit2/UIProcess/WebIconDatabase.messages.in</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="#trunkSourceWebKit2WebProcessIconDatabaseWebIconDatabaseProxycpp">trunk/Source/WebKit2/WebProcess/IconDatabase/WebIconDatabaseProxy.cpp</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (182609 => 182610)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2015-04-09 22:36:56 UTC (rev 182609)
+++ trunk/Source/WebKit2/ChangeLog        2015-04-09 22:37:19 UTC (rev 182610)
</span><span class="lines">@@ -1,3 +1,40 @@
</span><ins>+2015-04-09  Gordon Sheridan  &lt;gordon_sheridan@apple.com&gt;
+
+        Track IconDatabase retain counts for WebContent processes. Balance retain/releases for processes that terminate before successfully doing it themselves.
+        https://bugs.webkit.org/show_bug.cgi?id=143517.
+
+        Reviewed by Brady Eidson.
+
+        * UIProcess/WebIconDatabase.messages.in:
+        Move RetainIconForPageURL and ReleaseIconForPageURL messages to WebProcessProxy so they can be associated with the appropriate web process.
+
+        * UIProcess/WebProcessProxy.cpp:
+        (WebKit::WebProcessProxy::connectionDidClose):
+        Call releaseRemainingIconsForPageURLs() to balance retains/releases for this process.
+
+        (WebKit::WebProcessProxy::retainIconForPageURL):
+        Track retain counts for page URLs and call through to WebIconDatabase.
+
+        (WebKit::WebProcessProxy::releaseIconForPageURL):
+        Ditto.
+
+        (WebKit::WebProcessProxy::releaseRemainingIconsForPageURLs):
+        Call releaseIconForPageURL() once for each outstanding retain count, for each page URL.
+
+        * UIProcess/WebProcessProxy.h:
+        Declare methods for retainIconForPageURL(), releaseIconForPageURL(), and releaseRemainingIconsForPageURLs().
+        Declare hash map to track number of retains per page URL.
+
+        * UIProcess/WebProcessProxy.messages.in:
+        Moved RetainIconForPageURL and ReleaseIconForPageURL messages here from WebIconDatabase.
+
+        * WebProcess/IconDatabase/WebIconDatabaseProxy.cpp:
+        (WebKit::WebIconDatabaseProxy::retainIconForPageURL):
+        Modify the receiver of the message to be WebProcessProxy.
+
+        (WebKit::WebIconDatabaseProxy::releaseIconForPageURL):
+        Ditto.
+
</ins><span class="cx"> 2015-04-09  Chris Dumez  &lt;cdumez@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [WK2] Regression(r182194): The NetworkProcess is calling the wrong memory pressure handler before suspending
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessWebIconDatabasemessagesin"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/WebIconDatabase.messages.in (182609 => 182610)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/WebIconDatabase.messages.in        2015-04-09 22:36:56 UTC (rev 182609)
+++ trunk/Source/WebKit2/UIProcess/WebIconDatabase.messages.in        2015-04-09 22:37:19 UTC (rev 182610)
</span><span class="lines">@@ -21,8 +21,6 @@
</span><span class="cx"> # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
</span><span class="cx"> 
</span><span class="cx"> messages -&gt; WebIconDatabase {
</span><del>-    RetainIconForPageURL(String pageURL)
-    ReleaseIconForPageURL(String pageURL)
</del><span class="cx">     SetIconURLForPageURL(String iconURL, String pageURL)
</span><span class="cx">     SetIconDataForIconURL(IPC::DataReference iconData, String iconURL)
</span><span class="cx">     
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessWebProcessProxycpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/WebProcessProxy.cpp (182609 => 182610)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/WebProcessProxy.cpp        2015-04-09 22:36:56 UTC (rev 182609)
+++ trunk/Source/WebKit2/UIProcess/WebProcessProxy.cpp        2015-04-09 22:37:19 UTC (rev 182610)
</span><span class="lines">@@ -38,6 +38,7 @@
</span><span class="cx"> #include &quot;TextCheckerState.h&quot;
</span><span class="cx"> #include &quot;UserData.h&quot;
</span><span class="cx"> #include &quot;WebBackForwardListItem.h&quot;
</span><ins>+#include &quot;WebIconDatabase.h&quot;
</ins><span class="cx"> #include &quot;WebInspectorProxy.h&quot;
</span><span class="cx"> #include &quot;WebNavigationDataStore.h&quot;
</span><span class="cx"> #include &quot;WebNotificationManagerProxy.h&quot;
</span><span class="lines">@@ -117,6 +118,7 @@
</span><span class="cx">     ASSERT(m_pendingFetchWebsiteDataCallbacks.isEmpty());
</span><span class="cx">     ASSERT(m_pendingDeleteWebsiteDataCallbacks.isEmpty());
</span><span class="cx">     ASSERT(m_pendingDeleteWebsiteDataForOriginsCallbacks.isEmpty());
</span><ins>+    ASSERT(m_pageURLRetainCountMap.isEmpty());
</ins><span class="cx"> 
</span><span class="cx">     if (m_webConnection)
</span><span class="cx">         m_webConnection-&gt;invalidate();
</span><span class="lines">@@ -163,6 +165,8 @@
</span><span class="cx"> 
</span><span class="cx">     for (auto&amp; page : m_pageMap.values())
</span><span class="cx">         page-&gt;connectionDidClose(connection);
</span><ins>+
+    releaseRemainingIconsForPageURLs();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void WebProcessProxy::disconnect()
</span><span class="lines">@@ -433,6 +437,53 @@
</span><span class="cx"> }
</span><span class="cx"> #endif // ENABLE(DATABASE_PROCESS)
</span><span class="cx"> 
</span><ins>+void WebProcessProxy::retainIconForPageURL(const String&amp; pageURL)
+{
+    WebIconDatabase* iconDatabase = processPool().iconDatabase();
+    if (!iconDatabase || pageURL.isEmpty())
+        return;
+
+    // Track retain counts so we can release them if the WebProcess terminates early.
+    auto result = m_pageURLRetainCountMap.add(pageURL, 1);
+    if (!result.isNewEntry)
+        ++result.iterator-&gt;value;
+
+    iconDatabase-&gt;retainIconForPageURL(pageURL);
+}
+
+void WebProcessProxy::releaseIconForPageURL(const String&amp; pageURL)
+{
+    WebIconDatabase* iconDatabase = processPool().iconDatabase();
+    if (!iconDatabase || pageURL.isEmpty())
+        return;
+
+    // Track retain counts so we can release them if the WebProcess terminates early.
+    auto result = m_pageURLRetainCountMap.find(pageURL);
+    if (result == m_pageURLRetainCountMap.end())
+        return;
+
+    --result-&gt;value;
+    if (!result-&gt;value)
+        m_pageURLRetainCountMap.remove(result);
+
+    iconDatabase-&gt;releaseIconForPageURL(pageURL);
+}
+
+void WebProcessProxy::releaseRemainingIconsForPageURLs()
+{
+    WebIconDatabase* iconDatabase = processPool().iconDatabase();
+    if (!iconDatabase)
+        return;
+
+    for (auto iter : m_pageURLRetainCountMap) {
+        uint64_t count = iter.value;
+        for (uint64_t i = 0; i &lt; count; ++i)
+            iconDatabase-&gt;releaseIconForPageURL(iter.key);
+    }
+
+    m_pageURLRetainCountMap.clear();
+}
+
</ins><span class="cx"> void WebProcessProxy::didReceiveMessage(IPC::Connection&amp; connection, IPC::MessageDecoder&amp; decoder)
</span><span class="cx"> {
</span><span class="cx">     if (dispatchMessage(connection, decoder))
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessWebProcessProxyh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/WebProcessProxy.h (182609 => 182610)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/WebProcessProxy.h        2015-04-09 22:36:56 UTC (rev 182609)
+++ trunk/Source/WebKit2/UIProcess/WebProcessProxy.h        2015-04-09 22:37:19 UTC (rev 182610)
</span><span class="lines">@@ -190,6 +190,10 @@
</span><span class="cx">     void getDatabaseProcessConnection(PassRefPtr&lt;Messages::WebProcessProxy::GetDatabaseProcessConnection::DelayedReply&gt;);
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><ins>+    void retainIconForPageURL(const String&amp; pageURL);
+    void releaseIconForPageURL(const String&amp; pageURL);
+    void releaseRemainingIconsForPageURLs();
+
</ins><span class="cx">     // IPC::Connection::Client
</span><span class="cx">     friend class WebConnectionToWebProcess;
</span><span class="cx">     virtual void didReceiveMessage(IPC::Connection&amp;, IPC::MessageDecoder&amp;) override;
</span><span class="lines">@@ -243,6 +247,8 @@
</span><span class="cx"> #if PLATFORM(IOS) &amp;&amp; ENABLE(NETWORK_PROCESS)
</span><span class="cx">     ProcessThrottler::ForegroundActivityToken m_tokenForNetworkProcess;
</span><span class="cx"> #endif
</span><ins>+
+    HashMap&lt;String, uint64_t&gt; m_pageURLRetainCountMap;
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> } // namespace WebKit
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessWebProcessProxymessagesin"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/WebProcessProxy.messages.in (182609 => 182610)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/WebProcessProxy.messages.in        2015-04-09 22:36:56 UTC (rev 182609)
+++ trunk/Source/WebKit2/UIProcess/WebProcessProxy.messages.in        2015-04-09 22:37:19 UTC (rev 182610)
</span><span class="lines">@@ -48,4 +48,7 @@
</span><span class="cx">     DidCancelProcessSuspension()
</span><span class="cx"> 
</span><span class="cx">     SetIsHoldingLockedFiles(bool isHoldingLockedFiles)
</span><ins>+
+    RetainIconForPageURL(String pageURL)
+    ReleaseIconForPageURL(String pageURL)
</ins><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessIconDatabaseWebIconDatabaseProxycpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/IconDatabase/WebIconDatabaseProxy.cpp (182609 => 182610)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/IconDatabase/WebIconDatabaseProxy.cpp        2015-04-09 22:36:56 UTC (rev 182609)
+++ trunk/Source/WebKit2/WebProcess/IconDatabase/WebIconDatabaseProxy.cpp        2015-04-09 22:37:19 UTC (rev 182610)
</span><span class="lines">@@ -30,6 +30,7 @@
</span><span class="cx"> #include &quot;WebIconDatabaseMessages.h&quot;
</span><span class="cx"> #include &quot;WebIconDatabaseProxyMessages.h&quot;
</span><span class="cx"> #include &quot;WebProcess.h&quot;
</span><ins>+#include &quot;WebProcessProxyMessages.h&quot;
</ins><span class="cx"> #include &lt;WebCore/SharedBuffer.h&gt;
</span><span class="cx"> #include &lt;wtf/text/WTFString.h&gt;
</span><span class="cx"> 
</span><span class="lines">@@ -64,12 +65,12 @@
</span><span class="cx"> 
</span><span class="cx"> void WebIconDatabaseProxy::retainIconForPageURL(const String&amp; pageURL)
</span><span class="cx"> {
</span><del>-    m_process-&gt;parentProcessConnection()-&gt;send(Messages::WebIconDatabase::RetainIconForPageURL(pageURL), 0);
</del><ins>+    m_process-&gt;parentProcessConnection()-&gt;send(Messages::WebProcessProxy::RetainIconForPageURL(pageURL), 0);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void WebIconDatabaseProxy::releaseIconForPageURL(const String&amp; pageURL)
</span><span class="cx"> {
</span><del>-    m_process-&gt;parentProcessConnection()-&gt;send(Messages::WebIconDatabase::ReleaseIconForPageURL(pageURL), 0);
</del><ins>+    m_process-&gt;parentProcessConnection()-&gt;send(Messages::WebProcessProxy::ReleaseIconForPageURL(pageURL), 0);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> Image* WebIconDatabaseProxy::synchronousIconForPageURL(const String&amp; pageURL, const IntSize&amp; /*size*/)
</span></span></pre>
</div>
</div>

</body>
</html>