<!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>[184620] trunk/Source</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/184620">184620</a></dd>
<dt>Author</dt> <dd>carlosgc@webkit.org</dd>
<dt>Date</dt> <dd>2015-05-20 00:04:34 -0700 (Wed, 20 May 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>[SOUP] Network Cache: Implement ShareableResource for Soup and enable it for GTK platform
https://bugs.webkit.org/show_bug.cgi?id=144380

Reviewed by Antti Koivisto.

Source/WebCore:

Add a soup implementation of SharedBuffer::tryReplaceContentsWithPlatformBuffer().

Covered by http/tests/cache/disk-cache/ tests.

* loader/cache/CachedResource.cpp: Define
CachedResource::tryReplaceEncodedData() also for Soup.
* loader/cache/CachedResource.h: Ditto.
* platform/soup/SharedBufferSoup.cpp:
(WebCore::SharedBuffer::tryReplaceContentsWithPlatformBuffer):

Source/WebKit2:

It improves the network cache performance, by mmaping big
resources and sending only the file descriptor to the web process
instead of the actual file data. It needs some changes in
cross-platform code, because we can't use the same approach as
mac (it uses a platform specific implementation not available in
other platforms).

* NetworkProcess/cache/NetworkCache.cpp:
(WebKit::NetworkCache::Cache::store): Use
Data::tryCreateSharedMemory() to create the shared memory used by
the ShareableResource. Also add an ASSERT instead of checking the
shareable resource created is not nullptr, because the
ShareableResource::create() that receives a shared memory should
never return nullptr.
* NetworkProcess/cache/NetworkCacheData.h:
* NetworkProcess/cache/NetworkCacheDataCocoa.mm:
(WebKit::NetworkCache::Data::tryCreateSharedMemory):
* NetworkProcess/cache/NetworkCacheDataSoup.cpp:
(WebKit::NetworkCache::Data::tryCreateSharedMemory): Create a
SharedMemory object to wrap the mapped file, but keeping the ownership.
* NetworkProcess/cache/NetworkCacheEntry.cpp:
(WebKit::NetworkCache::Entry::initializeShareableResourceHandleFromStorageRecord):
Use Data::tryCreateSharedMemory() to create the shared memory used
bythe ShareableResource. Also add an ASSERT instead of checking
the shareable resource created is not nullptr, because the
ShareableResource::create() that receives a shared memory should
never return nullptr.
* Platform/SharedMemory.h:
* Platform/unix/SharedMemoryUnix.cpp:
(WebKit::SharedMemory::map): Use wrapMap() and initialize
m_isWrappingMap to false.
(WebKit::SharedMemory::wrapMap): Create a SharedMemory object for
the given map, without taking its ownership.
(WebKit::SharedMemory::~SharedMemory): Do not unmap and close the
file descriptor if m_isWrappingMap is true.
* Shared/ShareableResource.cpp:
(WebKit::createShareableResourceDeallocator):
(WebKit::ShareableResource::wrapInSharedBuffer): Create a SharedBuffer
wrapping the ShareableResource data.
(WebKit::ShareableResource::Handle::tryWrapInSharedBuffer): Create
a ShareableResource for the handle and create a SharedBuffer
wrapping it.
* Shared/ShareableResource.h:
* WebKit2Prefix.h: Enable ENABLE_SHAREABLE_RESOURCE for GTK.
* WebProcess/Network/WebResourceLoader.cpp:
(WebKit::WebResourceLoader::didReceiveResource): Get the CFData
from the SharedBuffer for QuickLook instead of wrapping the handle again.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreloadercacheCachedResourcecpp">trunk/Source/WebCore/loader/cache/CachedResource.cpp</a></li>
<li><a href="#trunkSourceWebCoreloadercacheCachedResourceh">trunk/Source/WebCore/loader/cache/CachedResource.h</a></li>
<li><a href="#trunkSourceWebCoreplatformsoupSharedBufferSoupcpp">trunk/Source/WebCore/platform/soup/SharedBufferSoup.cpp</a></li>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2NetworkProcesscacheNetworkCachecpp">trunk/Source/WebKit2/NetworkProcess/cache/NetworkCache.cpp</a></li>
<li><a href="#trunkSourceWebKit2NetworkProcesscacheNetworkCacheDatah">trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheData.h</a></li>
<li><a href="#trunkSourceWebKit2NetworkProcesscacheNetworkCacheDataCocoamm">trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheDataCocoa.mm</a></li>
<li><a href="#trunkSourceWebKit2NetworkProcesscacheNetworkCacheDataSoupcpp">trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheDataSoup.cpp</a></li>
<li><a href="#trunkSourceWebKit2NetworkProcesscacheNetworkCacheEntrycpp">trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheEntry.cpp</a></li>
<li><a href="#trunkSourceWebKit2PlatformSharedMemoryh">trunk/Source/WebKit2/Platform/SharedMemory.h</a></li>
<li><a href="#trunkSourceWebKit2PlatformunixSharedMemoryUnixcpp">trunk/Source/WebKit2/Platform/unix/SharedMemoryUnix.cpp</a></li>
<li><a href="#trunkSourceWebKit2SharedShareableResourcecpp">trunk/Source/WebKit2/Shared/ShareableResource.cpp</a></li>
<li><a href="#trunkSourceWebKit2SharedShareableResourceh">trunk/Source/WebKit2/Shared/ShareableResource.h</a></li>
<li><a href="#trunkSourceWebKit2WebKit2Prefixh">trunk/Source/WebKit2/WebKit2Prefix.h</a></li>
<li><a href="#trunkSourceWebKit2WebProcessNetworkWebResourceLoadercpp">trunk/Source/WebKit2/WebProcess/Network/WebResourceLoader.cpp</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (184619 => 184620)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2015-05-20 06:29:13 UTC (rev 184619)
+++ trunk/Source/WebCore/ChangeLog        2015-05-20 07:04:34 UTC (rev 184620)
</span><span class="lines">@@ -1,3 +1,20 @@
</span><ins>+2015-05-19  Carlos Garcia Campos  &lt;cgarcia@igalia.com&gt;
+
+        [SOUP] Network Cache: Implement ShareableResource for Soup and enable it for GTK platform
+        https://bugs.webkit.org/show_bug.cgi?id=144380
+
+        Reviewed by Antti Koivisto.
+
+        Add a soup implementation of SharedBuffer::tryReplaceContentsWithPlatformBuffer().
+
+        Covered by http/tests/cache/disk-cache/ tests.
+
+        * loader/cache/CachedResource.cpp: Define
+        CachedResource::tryReplaceEncodedData() also for Soup.
+        * loader/cache/CachedResource.h: Ditto.
+        * platform/soup/SharedBufferSoup.cpp:
+        (WebCore::SharedBuffer::tryReplaceContentsWithPlatformBuffer):
+
</ins><span class="cx"> 2015-05-17  Sam Weinig  &lt;sam@webkit.org&gt;
</span><span class="cx"> 
</span><span class="cx">         Organize event handlers a bit
</span></span></pre></div>
<a id="trunkSourceWebCoreloadercacheCachedResourcecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/loader/cache/CachedResource.cpp (184619 => 184620)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/loader/cache/CachedResource.cpp        2015-05-20 06:29:13 UTC (rev 184619)
+++ trunk/Source/WebCore/loader/cache/CachedResource.cpp        2015-05-20 07:04:34 UTC (rev 184620)
</span><span class="lines">@@ -773,7 +773,7 @@
</span><span class="cx">     m_resource.didAddClient(&amp;m_client);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-#if USE(FOUNDATION)
</del><ins>+#if USE(FOUNDATION) || USE(SOUP)
</ins><span class="cx"> 
</span><span class="cx"> void CachedResource::tryReplaceEncodedData(SharedBuffer&amp; newBuffer)
</span><span class="cx"> {
</span></span></pre></div>
<a id="trunkSourceWebCoreloadercacheCachedResourceh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/loader/cache/CachedResource.h (184619 => 184620)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/loader/cache/CachedResource.h        2015-05-20 06:29:13 UTC (rev 184619)
+++ trunk/Source/WebCore/loader/cache/CachedResource.h        2015-05-20 07:04:34 UTC (rev 184620)
</span><span class="lines">@@ -252,7 +252,7 @@
</span><span class="cx"> 
</span><span class="cx">     virtual bool canReuse(const ResourceRequest&amp;) const { return true; }
</span><span class="cx"> 
</span><del>-#if USE(FOUNDATION)
</del><ins>+#if USE(FOUNDATION) || USE(SOUP)
</ins><span class="cx">     WEBCORE_EXPORT void tryReplaceEncodedData(SharedBuffer&amp;);
</span><span class="cx"> #endif
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformsoupSharedBufferSoupcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/soup/SharedBufferSoup.cpp (184619 => 184620)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/soup/SharedBufferSoup.cpp        2015-05-20 06:29:13 UTC (rev 184619)
+++ trunk/Source/WebCore/platform/soup/SharedBufferSoup.cpp        2015-05-20 07:04:34 UTC (rev 184620)
</span><span class="lines">@@ -78,6 +78,16 @@
</span><span class="cx">     return false;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void SharedBuffer::tryReplaceContentsWithPlatformBuffer(SharedBuffer&amp; newContents)
+{
+    if (!newContents.hasPlatformData())
+        return;
+
+    clear();
+    // FIXME: Use GRefPtr instead of GUniquePtr for the SoupBuffer.
+    m_soupBuffer.swap(newContents.m_soupBuffer);
+}
+
</ins><span class="cx"> } // namespace WebCore
</span><span class="cx"> 
</span><span class="cx"> #endif
</span></span></pre></div>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (184619 => 184620)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2015-05-20 06:29:13 UTC (rev 184619)
+++ trunk/Source/WebKit2/ChangeLog        2015-05-20 07:04:34 UTC (rev 184620)
</span><span class="lines">@@ -1,5 +1,60 @@
</span><span class="cx"> 2015-05-19  Carlos Garcia Campos  &lt;cgarcia@igalia.com&gt;
</span><span class="cx"> 
</span><ins>+        [SOUP] Network Cache: Implement ShareableResource for Soup and enable it for GTK platform
+        https://bugs.webkit.org/show_bug.cgi?id=144380
+
+        Reviewed by Antti Koivisto.
+
+        It improves the network cache performance, by mmaping big
+        resources and sending only the file descriptor to the web process
+        instead of the actual file data. It needs some changes in
+        cross-platform code, because we can't use the same approach as
+        mac (it uses a platform specific implementation not available in
+        other platforms).
+
+        * NetworkProcess/cache/NetworkCache.cpp:
+        (WebKit::NetworkCache::Cache::store): Use
+        Data::tryCreateSharedMemory() to create the shared memory used by
+        the ShareableResource. Also add an ASSERT instead of checking the
+        shareable resource created is not nullptr, because the
+        ShareableResource::create() that receives a shared memory should
+        never return nullptr.
+        * NetworkProcess/cache/NetworkCacheData.h:
+        * NetworkProcess/cache/NetworkCacheDataCocoa.mm:
+        (WebKit::NetworkCache::Data::tryCreateSharedMemory):
+        * NetworkProcess/cache/NetworkCacheDataSoup.cpp:
+        (WebKit::NetworkCache::Data::tryCreateSharedMemory): Create a
+        SharedMemory object to wrap the mapped file, but keeping the ownership.
+        * NetworkProcess/cache/NetworkCacheEntry.cpp:
+        (WebKit::NetworkCache::Entry::initializeShareableResourceHandleFromStorageRecord):
+        Use Data::tryCreateSharedMemory() to create the shared memory used
+        bythe ShareableResource. Also add an ASSERT instead of checking
+        the shareable resource created is not nullptr, because the
+        ShareableResource::create() that receives a shared memory should
+        never return nullptr.
+        * Platform/SharedMemory.h:
+        * Platform/unix/SharedMemoryUnix.cpp:
+        (WebKit::SharedMemory::map): Use wrapMap() and initialize
+        m_isWrappingMap to false.
+        (WebKit::SharedMemory::wrapMap): Create a SharedMemory object for
+        the given map, without taking its ownership.
+        (WebKit::SharedMemory::~SharedMemory): Do not unmap and close the
+        file descriptor if m_isWrappingMap is true.
+        * Shared/ShareableResource.cpp:
+        (WebKit::createShareableResourceDeallocator):
+        (WebKit::ShareableResource::wrapInSharedBuffer): Create a SharedBuffer
+        wrapping the ShareableResource data.
+        (WebKit::ShareableResource::Handle::tryWrapInSharedBuffer): Create
+        a ShareableResource for the handle and create a SharedBuffer
+        wrapping it.
+        * Shared/ShareableResource.h:
+        * WebKit2Prefix.h: Enable ENABLE_SHAREABLE_RESOURCE for GTK.
+        * WebProcess/Network/WebResourceLoader.cpp:
+        (WebKit::WebResourceLoader::didReceiveResource): Get the CFData
+        from the SharedBuffer for QuickLook instead of wrapping the handle again.
+
+2015-05-19  Carlos Garcia Campos  &lt;cgarcia@igalia.com&gt;
+
</ins><span class="cx">         [SOUP] Network Cache: Disable network cache efficacy logging
</span><span class="cx">         https://bugs.webkit.org/show_bug.cgi?id=145172
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKit2NetworkProcesscacheNetworkCachecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCache.cpp (184619 => 184620)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCache.cpp        2015-05-20 06:29:13 UTC (rev 184619)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCache.cpp        2015-05-20 07:04:34 UTC (rev 184620)
</span><span class="lines">@@ -414,11 +414,10 @@
</span><span class="cx">     m_storage-&gt;store(record, [completionHandler](const Data&amp; bodyData) {
</span><span class="cx">         MappedBody mappedBody;
</span><span class="cx"> #if ENABLE(SHAREABLE_RESOURCE)
</span><del>-        if (bodyData.isMap()) {
-            RefPtr&lt;SharedMemory&gt; sharedMemory = SharedMemory::create(const_cast&lt;uint8_t*&gt;(bodyData.data()), bodyData.size(), SharedMemory::Protection::ReadOnly);
-            mappedBody.shareableResource = sharedMemory ? ShareableResource::create(WTF::move(sharedMemory), 0, bodyData.size()) : nullptr;
-            if (mappedBody.shareableResource)
-                mappedBody.shareableResource-&gt;createHandle(mappedBody.shareableResourceHandle);
</del><ins>+        if (RefPtr&lt;SharedMemory&gt; sharedMemory = bodyData.tryCreateSharedMemory()) {
+            mappedBody.shareableResource = ShareableResource::create(WTF::move(sharedMemory), 0, bodyData.size());
+            ASSERT(mappedBody.shareableResource);
+            mappedBody.shareableResource-&gt;createHandle(mappedBody.shareableResourceHandle);
</ins><span class="cx">         }
</span><span class="cx"> #endif
</span><span class="cx">         completionHandler(mappedBody);
</span></span></pre></div>
<a id="trunkSourceWebKit2NetworkProcesscacheNetworkCacheDatah"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheData.h (184619 => 184620)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheData.h        2015-05-20 06:29:13 UTC (rev 184619)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheData.h        2015-05-20 07:04:34 UTC (rev 184620)
</span><span class="lines">@@ -39,6 +39,9 @@
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> namespace WebKit {
</span><ins>+
+class SharedMemory;
+
</ins><span class="cx"> namespace NetworkCache {
</span><span class="cx"> 
</span><span class="cx"> #if PLATFORM(COCOA)
</span><span class="lines">@@ -119,6 +122,7 @@
</span><span class="cx">     const uint8_t* data() const;
</span><span class="cx">     size_t size() const { return m_size; }
</span><span class="cx">     bool isMap() const { return m_isMap; }
</span><ins>+    RefPtr&lt;SharedMemory&gt; tryCreateSharedMemory() const;
</ins><span class="cx"> 
</span><span class="cx">     Data subrange(size_t offset, size_t) const;
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKit2NetworkProcesscacheNetworkCacheDataCocoamm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheDataCocoa.mm (184619 => 184620)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheDataCocoa.mm        2015-05-20 06:29:13 UTC (rev 184619)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheDataCocoa.mm        2015-05-20 07:04:34 UTC (rev 184620)
</span><span class="lines">@@ -28,6 +28,7 @@
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(NETWORK_CACHE)
</span><span class="cx"> 
</span><ins>+#include &quot;SharedMemory.h&quot;
</ins><span class="cx"> #include &lt;dispatch/dispatch.h&gt;
</span><span class="cx"> #include &lt;sys/mman.h&gt;
</span><span class="cx"> #include &lt;sys/stat.h&gt;
</span><span class="lines">@@ -103,7 +104,13 @@
</span><span class="cx">     return { bodyMap, Data::Backing::Map };
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+RefPtr&lt;SharedMemory&gt; Data::tryCreateSharedMemory() const
+{
+    if (isNull() || !isMap())
+        return nullptr;
</ins><span class="cx"> 
</span><ins>+    return SharedMemory::create(const_cast&lt;uint8_t*&gt;(data()), m_size, SharedMemory::Protection::ReadOnly);
+}
</ins><span class="cx"> 
</span><span class="cx"> }
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebKit2NetworkProcesscacheNetworkCacheDataSoupcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheDataSoup.cpp (184619 => 184620)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheDataSoup.cpp        2015-05-20 06:29:13 UTC (rev 184619)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheDataSoup.cpp        2015-05-20 07:04:34 UTC (rev 184620)
</span><span class="lines">@@ -28,6 +28,7 @@
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(NETWORK_CACHE)
</span><span class="cx"> 
</span><ins>+#include &quot;SharedMemory.h&quot;
</ins><span class="cx"> #include &lt;fcntl.h&gt;
</span><span class="cx"> #include &lt;sys/mman.h&gt;
</span><span class="cx"> #include &lt;sys/stat.h&gt;
</span><span class="lines">@@ -127,7 +128,13 @@
</span><span class="cx">     return { WTF::move(buffer), fd };
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+RefPtr&lt;SharedMemory&gt; Data::tryCreateSharedMemory() const
+{
+    if (isNull() || !isMap())
+        return nullptr;
</ins><span class="cx"> 
</span><ins>+    return SharedMemory::wrapMap(const_cast&lt;char*&gt;(m_buffer-&gt;data), m_buffer-&gt;length, m_fileDescriptor);
+}
</ins><span class="cx"> 
</span><span class="cx"> } // namespace NetworkCache
</span><span class="cx"> } // namespace WebKit
</span></span></pre></div>
<a id="trunkSourceWebKit2NetworkProcesscacheNetworkCacheEntrycpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheEntry.cpp (184619 => 184620)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheEntry.cpp        2015-05-20 06:29:13 UTC (rev 184619)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheEntry.cpp        2015-05-20 07:04:34 UTC (rev 184620)
</span><span class="lines">@@ -104,12 +104,13 @@
</span><span class="cx"> #if ENABLE(SHAREABLE_RESOURCE)
</span><span class="cx"> void Entry::initializeShareableResourceHandleFromStorageRecord() const
</span><span class="cx"> {
</span><del>-    auto* data = m_sourceStorageRecord.body.data();
-    size_t size = m_sourceStorageRecord.body.size();
-    RefPtr&lt;SharedMemory&gt; sharedMemory = m_sourceStorageRecord.body.isMap() ? SharedMemory::create(const_cast&lt;uint8_t*&gt;(data), size, SharedMemory::Protection::ReadOnly) : nullptr;
-    RefPtr&lt;ShareableResource&gt; shareableResource = sharedMemory ? ShareableResource::create(sharedMemory.release(), 0, size) : nullptr;
-    if (shareableResource)
-        shareableResource-&gt;createHandle(m_shareableResourceHandle);
</del><ins>+    RefPtr&lt;SharedMemory&gt; sharedMemory = m_sourceStorageRecord.body.tryCreateSharedMemory();
+    if (!sharedMemory)
+        return;
+
+    RefPtr&lt;ShareableResource&gt; shareableResource = ShareableResource::create(sharedMemory.release(), 0, m_sourceStorageRecord.body.size());
+    ASSERT(shareableResource);
+    shareableResource-&gt;createHandle(m_shareableResourceHandle);
</ins><span class="cx"> }
</span><span class="cx"> #endif
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKit2PlatformSharedMemoryh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/Platform/SharedMemory.h (184619 => 184620)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/Platform/SharedMemory.h        2015-05-20 06:29:13 UTC (rev 184619)
+++ trunk/Source/WebKit2/Platform/SharedMemory.h        2015-05-20 07:04:34 UTC (rev 184620)
</span><span class="lines">@@ -85,6 +85,9 @@
</span><span class="cx">     static RefPtr&lt;SharedMemory&gt; allocate(size_t);
</span><span class="cx">     static RefPtr&lt;SharedMemory&gt; create(void*, size_t, Protection);
</span><span class="cx">     static RefPtr&lt;SharedMemory&gt; map(const Handle&amp;, Protection);
</span><ins>+#if USE(UNIX_DOMAIN_SOCKETS)
+    static RefPtr&lt;SharedMemory&gt; wrapMap(void*, size_t, int fileDescriptor);
+#endif
</ins><span class="cx"> 
</span><span class="cx">     ~SharedMemory();
</span><span class="cx"> 
</span><span class="lines">@@ -113,6 +116,7 @@
</span><span class="cx">     mach_port_t m_port;
</span><span class="cx"> #elif USE(UNIX_DOMAIN_SOCKETS)
</span><span class="cx">     int m_fileDescriptor;
</span><ins>+    bool m_isWrappingMap { false };
</ins><span class="cx"> #endif
</span><span class="cx"> };
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKit2PlatformunixSharedMemoryUnixcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/Platform/unix/SharedMemoryUnix.cpp (184619 => 184620)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/Platform/unix/SharedMemoryUnix.cpp        2015-05-20 06:29:13 UTC (rev 184619)
+++ trunk/Source/WebKit2/Platform/unix/SharedMemoryUnix.cpp        2015-05-20 07:04:34 UTC (rev 184620)
</span><span class="lines">@@ -156,17 +156,27 @@
</span><span class="cx">     if (data == MAP_FAILED)
</span><span class="cx">         return nullptr;
</span><span class="cx"> 
</span><ins>+    RefPtr&lt;SharedMemory&gt; instance = wrapMap(data, handle.m_attachment.size(), handle.m_attachment.releaseFileDescriptor());
+    instance-&gt;m_isWrappingMap = false;
+    return instance;
+}
+
+RefPtr&lt;SharedMemory&gt; SharedMemory::wrapMap(void* data, size_t size, int fileDescriptor)
+{
</ins><span class="cx">     RefPtr&lt;SharedMemory&gt; instance = adoptRef(new SharedMemory());
</span><span class="cx">     instance-&gt;m_data = data;
</span><del>-    instance-&gt;m_fileDescriptor = handle.m_attachment.releaseFileDescriptor();
-    instance-&gt;m_size = handle.m_attachment.size();
</del><ins>+    instance-&gt;m_size = size;
+    instance-&gt;m_fileDescriptor = fileDescriptor;
+    instance-&gt;m_isWrappingMap = true;
</ins><span class="cx">     return instance;
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> SharedMemory::~SharedMemory()
</span><span class="cx"> {
</span><del>-    munmap(m_data, m_size);
-    closeWithRetry(m_fileDescriptor);
</del><ins>+    if (!m_isWrappingMap) {
+        munmap(m_data, m_size);
+        closeWithRetry(m_fileDescriptor);
+    }
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> bool SharedMemory::createHandle(Handle&amp; handle, Protection)
</span></span></pre></div>
<a id="trunkSourceWebKit2SharedShareableResourcecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/Shared/ShareableResource.cpp (184619 => 184620)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/Shared/ShareableResource.cpp        2015-05-20 06:29:13 UTC (rev 184619)
+++ trunk/Source/WebKit2/Shared/ShareableResource.cpp        2015-05-20 07:04:34 UTC (rev 184620)
</span><span class="lines">@@ -57,6 +57,7 @@
</span><span class="cx">     return true;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+#if USE(CF)
</ins><span class="cx"> static void shareableResourceDeallocate(void *ptr, void *info)
</span><span class="cx"> {
</span><span class="cx">     (static_cast&lt;ShareableResource*&gt;(info))-&gt;deref(); // Balanced by ref() in createShareableResourceDeallocator()
</span><span class="lines">@@ -64,8 +65,6 @@
</span><span class="cx">     
</span><span class="cx"> static CFAllocatorRef createShareableResourceDeallocator(ShareableResource* resource)
</span><span class="cx"> {
</span><del>-    resource-&gt;ref(); // Balanced by deref in shareableResourceDeallocate()
-
</del><span class="cx">     CFAllocatorContext context = { 0,
</span><span class="cx">         resource,
</span><span class="cx">         NULL, // retain
</span><span class="lines">@@ -79,24 +78,35 @@
</span><span class="cx"> 
</span><span class="cx">     return CFAllocatorCreate(kCFAllocatorDefault, &amp;context);
</span><span class="cx"> }
</span><ins>+#endif
</ins><span class="cx"> 
</span><del>-RetainPtr&lt;CFDataRef&gt; ShareableResource::Handle::tryWrapInCFData() const
</del><ins>+PassRefPtr&lt;SharedBuffer&gt; ShareableResource::wrapInSharedBuffer()
</ins><span class="cx"> {
</span><ins>+    ref(); // Balanced by deref when SharedBuffer is deallocated.
+
+#if USE(CF)
+    RetainPtr&lt;CFAllocatorRef&gt; deallocator = adoptCF(createShareableResourceDeallocator(this));
+    RetainPtr&lt;CFDataRef&gt; cfData = adoptCF(CFDataCreateWithBytesNoCopy(kCFAllocatorDefault, reinterpret_cast&lt;const UInt8*&gt;(data()), static_cast&lt;CFIndex&gt;(size()), deallocator.get()));
+    return SharedBuffer::wrapCFData(cfData.get());
+#elif USE(SOUP)
+    return SharedBuffer::wrapSoupBuffer(soup_buffer_new_with_owner(data(), size(), this, [](void* data) { static_cast&lt;ShareableResource*&gt;(data)-&gt;deref(); }));
+#else
+    ASSERT_NOT_REACHED();
+    return nullptr;
+#endif
+}
+
+PassRefPtr&lt;SharedBuffer&gt; ShareableResource::Handle::tryWrapInSharedBuffer() const
+{
</ins><span class="cx">     RefPtr&lt;ShareableResource&gt; resource = ShareableResource::create(*this);
</span><span class="cx">     if (!resource) {
</span><span class="cx">         LOG_ERROR(&quot;Failed to recreate ShareableResource from handle.&quot;);
</span><del>-        return 0;
</del><ins>+        return nullptr;
</ins><span class="cx">     }
</span><span class="cx"> 
</span><del>-    RetainPtr&lt;CFAllocatorRef&gt; deallocator = adoptCF(createShareableResourceDeallocator(resource.get()));
-    return adoptCF(CFDataCreateWithBytesNoCopy(kCFAllocatorDefault, reinterpret_cast&lt;const UInt8*&gt;(resource-&gt;data()), static_cast&lt;CFIndex&gt;(resource-&gt;size()), deallocator.get()));
</del><ins>+    return resource-&gt;wrapInSharedBuffer();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-PassRefPtr&lt;SharedBuffer&gt; ShareableResource::Handle::tryWrapInSharedBuffer() const
-{
-    return SharedBuffer::wrapCFData(tryWrapInCFData().get());
-}
-    
</del><span class="cx"> PassRefPtr&lt;ShareableResource&gt; ShareableResource::create(PassRefPtr&lt;SharedMemory&gt; sharedMemory, unsigned offset, unsigned size)
</span><span class="cx"> {
</span><span class="cx">     return adoptRef(new ShareableResource(sharedMemory, offset, size));
</span></span></pre></div>
<a id="trunkSourceWebKit2SharedShareableResourceh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/Shared/ShareableResource.h (184619 => 184620)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/Shared/ShareableResource.h        2015-05-20 06:29:13 UTC (rev 184619)
+++ trunk/Source/WebKit2/Shared/ShareableResource.h        2015-05-20 07:04:34 UTC (rev 184620)
</span><span class="lines">@@ -56,9 +56,6 @@
</span><span class="cx">         void encode(IPC::ArgumentEncoder&amp;) const;
</span><span class="cx">         static bool decode(IPC::ArgumentDecoder&amp;, Handle&amp;);
</span><span class="cx"> 
</span><del>-#if USE(CF)
-        RetainPtr&lt;CFDataRef&gt; tryWrapInCFData() const;
-#endif
</del><span class="cx">         PassRefPtr&lt;WebCore::SharedBuffer&gt; tryWrapInSharedBuffer() const;
</span><span class="cx"> 
</span><span class="cx">     private:
</span><span class="lines">@@ -86,6 +83,7 @@
</span><span class="cx">     
</span><span class="cx"> private:
</span><span class="cx">     ShareableResource(PassRefPtr&lt;SharedMemory&gt;, unsigned offset, unsigned size);
</span><ins>+    PassRefPtr&lt;WebCore::SharedBuffer&gt; wrapInSharedBuffer();
</ins><span class="cx"> 
</span><span class="cx">     RefPtr&lt;SharedMemory&gt; m_sharedMemory;
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKit2WebKit2Prefixh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebKit2Prefix.h (184619 => 184620)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebKit2Prefix.h        2015-05-20 06:29:13 UTC (rev 184619)
+++ trunk/Source/WebKit2/WebKit2Prefix.h        2015-05-20 07:04:34 UTC (rev 184620)
</span><span class="lines">@@ -58,6 +58,7 @@
</span><span class="cx"> 
</span><span class="cx"> #if PLATFORM(GTK)
</span><span class="cx"> #define ENABLE_NETWORK_PROCESS 1
</span><ins>+#define ENABLE_SHAREABLE_RESOURCE 1
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> /* When C++ exceptions are disabled, the C++ library defines |try| and |catch|
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessNetworkWebResourceLoadercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/Network/WebResourceLoader.cpp (184619 => 184620)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/Network/WebResourceLoader.cpp        2015-05-20 06:29:13 UTC (rev 184619)
+++ trunk/Source/WebKit2/WebProcess/Network/WebResourceLoader.cpp        2015-05-20 07:04:34 UTC (rev 184620)
</span><span class="lines">@@ -180,11 +180,12 @@
</span><span class="cx"> {
</span><span class="cx">     LOG(Network, &quot;(WebProcess) WebResourceLoader::didReceiveResource for '%s'&quot;, m_coreLoader-&gt;url().string().utf8().data());
</span><span class="cx"> 
</span><ins>+    RefPtr&lt;SharedBuffer&gt; buffer = handle.tryWrapInSharedBuffer();
+
</ins><span class="cx"> #if USE(QUICK_LOOK)
</span><span class="cx">     if (QuickLookHandle* quickLookHandle = m_coreLoader-&gt;documentLoader()-&gt;quickLookHandle()) {
</span><del>-        RetainPtr&lt;CFDataRef&gt; cfBuffer = handle.tryWrapInCFData();
-        if (cfBuffer) {
-            if (quickLookHandle-&gt;didReceiveData(cfBuffer.get())) {
</del><ins>+        if (buffer) {
+            if (quickLookHandle-&gt;didReceiveData(buffer-&gt;existingCFData())) {
</ins><span class="cx">                 quickLookHandle-&gt;didFinishLoading();
</span><span class="cx">                 return;
</span><span class="cx">             }
</span><span class="lines">@@ -193,7 +194,6 @@
</span><span class="cx">     }
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><del>-    RefPtr&lt;SharedBuffer&gt; buffer = handle.tryWrapInSharedBuffer();
</del><span class="cx">     if (!buffer) {
</span><span class="cx">         LOG_ERROR(&quot;Unable to create buffer from ShareableResource sent from the network process.&quot;);
</span><span class="cx">         m_coreLoader-&gt;didFail(internalError(m_coreLoader-&gt;request().url()));
</span></span></pre>
</div>
</div>

</body>
</html>