<!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>[192807] 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/192807">192807</a></dd>
<dt>Author</dt> <dd>cdumez@apple.com</dd>
<dt>Date</dt> <dd>2015-11-30 11:06:15 -0800 (Mon, 30 Nov 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>[WK2][Cache] We should not speculatively revalidate transient resources
https://bugs.webkit.org/show_bug.cgi?id=151402
&lt;rdar://problem/23092196&gt;

Reviewed by Antti Koivisto.

We should not speculatively revalidate transient resources. This patch
adds a simple and conservative algorithm to detect that a subresource is
transient and then ignores those when doing the speculative revalidation.

The algorithm is question marks as transient all subresources that are
not common to the 2 last loads of a main resource.

This is not perfect as I see the number of non-speculative revalidations
going up to 11-12 from 9 in the context of the warm PLT. However, it is
best to be conservative at first and we can improve this later.

* NetworkProcess/cache/NetworkCache.cpp:
(WebKit::NetworkCache::Cache::retrieve):
* NetworkProcess/cache/NetworkCacheSpeculativeLoadManager.cpp:
(WebKit::NetworkCache::SpeculativeLoadManager::PendingFrameLoad::create):
(WebKit::NetworkCache::SpeculativeLoadManager::PendingFrameLoad::~PendingFrameLoad):
(WebKit::NetworkCache::SpeculativeLoadManager::PendingFrameLoad::registerSubresource):
(WebKit::NetworkCache::SpeculativeLoadManager::PendingFrameLoad::markLoadAsCompleted):
(WebKit::NetworkCache::SpeculativeLoadManager::PendingFrameLoad::setExistingSubresourcesEntry):
(WebKit::NetworkCache::SpeculativeLoadManager::PendingFrameLoad::PendingFrameLoad):
(WebKit::NetworkCache::SpeculativeLoadManager::PendingFrameLoad::saveToDiskIfReady):
(WebKit::NetworkCache::SpeculativeLoadManager::registerLoad):
(WebKit::NetworkCache::SpeculativeLoadManager::startSpeculativeRevalidation):
(WebKit::NetworkCache::SpeculativeLoadManager::retrieveSubresourcesEntry):
(WebKit::NetworkCache::SpeculativeLoadManager::retrieve): Deleted.
(WebKit::NetworkCache::SpeculativeLoadManager::revalidateEntry): Deleted.
* NetworkProcess/cache/NetworkCacheSpeculativeLoadManager.h:
* NetworkProcess/cache/NetworkCacheSubresourcesEntry.cpp:
(WebKit::NetworkCache::SubresourcesEntry::encodeAsStorageRecord):
(WebKit::NetworkCache::SubresourcesEntry::decodeStorageRecord):
(WebKit::NetworkCache::SubresourcesEntry::SubresourcesEntry):
(WebKit::NetworkCache::SubresourcesEntry::updateSubresourceKeys):
* NetworkProcess/cache/NetworkCacheSubresourcesEntry.h:
(WebKit::NetworkCache::SubresourcesEntry::SubresourceInfo::encode):
(WebKit::NetworkCache::SubresourcesEntry::SubresourceInfo::decode):
(WebKit::NetworkCache::SubresourcesEntry::SubresourceInfo::SubresourceInfo):
(WebKit::NetworkCache::SubresourcesEntry::subresources):</pre>

<h3>Modified Paths</h3>
<ul>
<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="#trunkSourceWebKit2NetworkProcesscacheNetworkCacheSpeculativeLoadManagercpp">trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheSpeculativeLoadManager.cpp</a></li>
<li><a href="#trunkSourceWebKit2NetworkProcesscacheNetworkCacheSpeculativeLoadManagerh">trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheSpeculativeLoadManager.h</a></li>
<li><a href="#trunkSourceWebKit2NetworkProcesscacheNetworkCacheSubresourcesEntrycpp">trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheSubresourcesEntry.cpp</a></li>
<li><a href="#trunkSourceWebKit2NetworkProcesscacheNetworkCacheSubresourcesEntryh">trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheSubresourcesEntry.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (192806 => 192807)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2015-11-30 19:05:05 UTC (rev 192806)
+++ trunk/Source/WebKit2/ChangeLog        2015-11-30 19:06:15 UTC (rev 192807)
</span><span class="lines">@@ -1,3 +1,49 @@
</span><ins>+2015-11-30  Chris Dumez  &lt;cdumez@apple.com&gt;
+
+        [WK2][Cache] We should not speculatively revalidate transient resources
+        https://bugs.webkit.org/show_bug.cgi?id=151402
+        &lt;rdar://problem/23092196&gt;
+
+        Reviewed by Antti Koivisto.
+
+        We should not speculatively revalidate transient resources. This patch
+        adds a simple and conservative algorithm to detect that a subresource is
+        transient and then ignores those when doing the speculative revalidation.
+
+        The algorithm is question marks as transient all subresources that are
+        not common to the 2 last loads of a main resource.
+
+        This is not perfect as I see the number of non-speculative revalidations
+        going up to 11-12 from 9 in the context of the warm PLT. However, it is
+        best to be conservative at first and we can improve this later.
+
+        * NetworkProcess/cache/NetworkCache.cpp:
+        (WebKit::NetworkCache::Cache::retrieve):
+        * NetworkProcess/cache/NetworkCacheSpeculativeLoadManager.cpp:
+        (WebKit::NetworkCache::SpeculativeLoadManager::PendingFrameLoad::create):
+        (WebKit::NetworkCache::SpeculativeLoadManager::PendingFrameLoad::~PendingFrameLoad):
+        (WebKit::NetworkCache::SpeculativeLoadManager::PendingFrameLoad::registerSubresource):
+        (WebKit::NetworkCache::SpeculativeLoadManager::PendingFrameLoad::markLoadAsCompleted):
+        (WebKit::NetworkCache::SpeculativeLoadManager::PendingFrameLoad::setExistingSubresourcesEntry):
+        (WebKit::NetworkCache::SpeculativeLoadManager::PendingFrameLoad::PendingFrameLoad):
+        (WebKit::NetworkCache::SpeculativeLoadManager::PendingFrameLoad::saveToDiskIfReady):
+        (WebKit::NetworkCache::SpeculativeLoadManager::registerLoad):
+        (WebKit::NetworkCache::SpeculativeLoadManager::startSpeculativeRevalidation):
+        (WebKit::NetworkCache::SpeculativeLoadManager::retrieveSubresourcesEntry):
+        (WebKit::NetworkCache::SpeculativeLoadManager::retrieve): Deleted.
+        (WebKit::NetworkCache::SpeculativeLoadManager::revalidateEntry): Deleted.
+        * NetworkProcess/cache/NetworkCacheSpeculativeLoadManager.h:
+        * NetworkProcess/cache/NetworkCacheSubresourcesEntry.cpp:
+        (WebKit::NetworkCache::SubresourcesEntry::encodeAsStorageRecord):
+        (WebKit::NetworkCache::SubresourcesEntry::decodeStorageRecord):
+        (WebKit::NetworkCache::SubresourcesEntry::SubresourcesEntry):
+        (WebKit::NetworkCache::SubresourcesEntry::updateSubresourceKeys):
+        * NetworkProcess/cache/NetworkCacheSubresourcesEntry.h:
+        (WebKit::NetworkCache::SubresourcesEntry::SubresourceInfo::encode):
+        (WebKit::NetworkCache::SubresourcesEntry::SubresourceInfo::decode):
+        (WebKit::NetworkCache::SubresourcesEntry::SubresourceInfo::SubresourceInfo):
+        (WebKit::NetworkCache::SubresourcesEntry::subresources):
+
</ins><span class="cx"> 2015-11-30  Brent Fulgham  &lt;bfulgham@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [Mac] Add font service permission to the sandbox profile
</span></span></pre></div>
<a id="trunkSourceWebKit2NetworkProcesscacheNetworkCachecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCache.cpp (192806 => 192807)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCache.cpp        2015-11-30 19:05:05 UTC (rev 192806)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCache.cpp        2015-11-30 19:06:15 UTC (rev 192807)
</span><span class="lines">@@ -356,12 +356,8 @@
</span><span class="cx">     Key storageKey = makeCacheKey(originalRequest);
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(NETWORK_CACHE_SPECULATIVE_REVALIDATION)
</span><del>-    if (m_speculativeLoadManager) {
</del><ins>+    if (m_speculativeLoadManager)
</ins><span class="cx">         m_speculativeLoadManager-&gt;registerLoad(frameID, originalRequest, storageKey);
</span><del>-        RunLoop::main().dispatch([this, originalRequest, frameID, storageKey] {
-            m_speculativeLoadManager-&gt;startSpeculativeRevalidation(originalRequest, frameID, storageKey);
-        });
-    }
</del><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx">     auto retrieveDecision = makeRetrieveDecision(originalRequest);
</span></span></pre></div>
<a id="trunkSourceWebKit2NetworkProcesscacheNetworkCacheSpeculativeLoadManagercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheSpeculativeLoadManager.cpp (192806 => 192807)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheSpeculativeLoadManager.cpp        2015-11-30 19:05:05 UTC (rev 192806)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheSpeculativeLoadManager.cpp        2015-11-30 19:06:15 UTC (rev 192807)
</span><span class="lines">@@ -34,6 +34,7 @@
</span><span class="cx"> #include &quot;NetworkCacheSubresourcesEntry.h&quot;
</span><span class="cx"> #include &lt;WebCore/HysteresisActivity.h&gt;
</span><span class="cx"> #include &lt;wtf/NeverDestroyed.h&gt;
</span><ins>+#include &lt;wtf/RefCounted.h&gt;
</ins><span class="cx"> #include &lt;wtf/RunLoop.h&gt;
</span><span class="cx"> 
</span><span class="cx"> namespace WebKit {
</span><span class="lines">@@ -109,52 +110,86 @@
</span><span class="cx">     std::function&lt;void()&gt; m_lifetimeReachedHandler;
</span><span class="cx"> };
</span><span class="cx"> 
</span><del>-class SpeculativeLoadManager::PendingFrameLoad {
-    WTF_MAKE_FAST_ALLOCATED;
</del><ins>+class SpeculativeLoadManager::PendingFrameLoad : public RefCounted&lt;PendingFrameLoad&gt; {
</ins><span class="cx"> public:
</span><del>-    PendingFrameLoad(const Key&amp; mainResourceKey, std::function&lt;void()&gt;&amp;&amp; completionHandler)
-        : m_mainResourceKey(mainResourceKey)
-        , m_completionHandler(WTF::move(completionHandler))
-        , m_loadHysteresisActivity([this](HysteresisState state) { if (state == HysteresisState::Stopped) m_completionHandler(); })
-    { }
</del><ins>+    static Ref&lt;PendingFrameLoad&gt; create(Storage&amp; storage, const Key&amp; mainResourceKey, std::function&lt;void()&gt;&amp;&amp; loadCompletionHandler)
+    {
+        return adoptRef(*new PendingFrameLoad(storage, mainResourceKey, WTF::move(loadCompletionHandler)));
+    }
</ins><span class="cx"> 
</span><ins>+    ~PendingFrameLoad()
+    {
+        ASSERT(m_didFinishLoad);
+        ASSERT(m_didRetrieveExistingEntry);
+    }
+
</ins><span class="cx">     void registerSubresource(const Key&amp; subresourceKey)
</span><span class="cx">     {
</span><span class="cx">         ASSERT(RunLoop::isMain());
</span><del>-        m_subresourceKeys.add(subresourceKey);
</del><ins>+        m_subresourceKeys.append(subresourceKey);
</ins><span class="cx">         m_loadHysteresisActivity.impulse();
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    Optional&lt;Storage::Record&gt; encodeAsSubresourcesRecord()
</del><ins>+    void markLoadAsCompleted()
</ins><span class="cx">     {
</span><span class="cx">         ASSERT(RunLoop::isMain());
</span><ins>+        if (m_didFinishLoad)
+            return;
+
+        m_didFinishLoad = true;
+        saveToDiskIfReady();
+        m_loadCompletionHandler();
+    }
+
+    void setExistingSubresourcesEntry(std::unique_ptr&lt;SubresourcesEntry&gt; entry)
+    {
+        ASSERT(!m_existingEntry);
+        ASSERT(!m_didRetrieveExistingEntry);
+
+        m_existingEntry = WTF::move(entry);
+        m_didRetrieveExistingEntry = true;
+        saveToDiskIfReady();
+    }
+
+private:
+    PendingFrameLoad(Storage&amp; storage, const Key&amp; mainResourceKey, std::function&lt;void()&gt;&amp;&amp; loadCompletionHandler)
+        : m_storage(storage)
+        , m_mainResourceKey(mainResourceKey)
+        , m_loadCompletionHandler(WTF::move(loadCompletionHandler))
+        , m_loadHysteresisActivity([this](HysteresisState state) { if (state == HysteresisState::Stopped) markLoadAsCompleted(); })
+    { }
+
+    void saveToDiskIfReady()
+    {
+        if (!m_didFinishLoad || !m_didRetrieveExistingEntry)
+            return;
+
</ins><span class="cx">         if (m_subresourceKeys.isEmpty())
</span><del>-            return { };
</del><ins>+            return;
</ins><span class="cx"> 
</span><del>-        auto subresourcesStorageKey = makeSubresourcesKey(m_mainResourceKey);
-        Vector&lt;Key&gt; subresourceKeys;
-        copyToVector(m_subresourceKeys, subresourceKeys);
-
</del><span class="cx"> #if !LOG_DISABLED
</span><span class="cx">         LOG(NetworkCacheSpeculativePreloading, &quot;(NetworkProcess) Saving to disk list of subresources for '%s':&quot;, m_mainResourceKey.identifier().utf8().data());
</span><del>-        for (auto&amp; subresourceKey : subresourceKeys)
</del><ins>+        for (auto&amp; subresourceKey : m_subresourceKeys)
</ins><span class="cx">             LOG(NetworkCacheSpeculativePreloading, &quot;(NetworkProcess) * Subresource: '%s'.&quot;, subresourceKey.identifier().utf8().data());
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><del>-        return SubresourcesEntry(WTF::move(subresourcesStorageKey), WTF::move(subresourceKeys)).encodeAsStorageRecord();
</del><ins>+        if (m_existingEntry) {
+            m_existingEntry-&gt;updateSubresourceKeys(m_subresourceKeys);
+            m_storage.store(m_existingEntry-&gt;encodeAsStorageRecord(), [](const Data&amp;) { });
+        } else {
+            SubresourcesEntry entry(makeSubresourcesKey(m_mainResourceKey), m_subresourceKeys);
+            m_storage.store(entry.encodeAsStorageRecord(), [](const Data&amp;) { });
+        }
</ins><span class="cx">     }
</span><span class="cx"> 
</span><del>-    void markAsCompleted()
-    {
-        ASSERT(RunLoop::isMain());
-        m_completionHandler();
-    }
-
-private:
</del><ins>+    Storage&amp; m_storage;
</ins><span class="cx">     Key m_mainResourceKey;
</span><del>-    HashSet&lt;Key&gt; m_subresourceKeys;
-    std::function&lt;void()&gt; m_completionHandler;
</del><ins>+    Vector&lt;Key&gt; m_subresourceKeys;
+    std::function&lt;void()&gt; m_loadCompletionHandler;
</ins><span class="cx">     HysteresisActivity m_loadHysteresisActivity;
</span><ins>+    std::unique_ptr&lt;SubresourcesEntry&gt; m_existingEntry;
+    bool m_didFinishLoad { false };
+    bool m_didRetrieveExistingEntry { false };
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> SpeculativeLoadManager::SpeculativeLoadManager(Storage&amp; storage)
</span><span class="lines">@@ -200,16 +235,24 @@
</span><span class="cx">     if (isMainResource) {
</span><span class="cx">         // Mark previous load in this frame as completed if necessary.
</span><span class="cx">         if (auto* pendingFrameLoad = m_pendingFrameLoads.get(frameID))
</span><del>-            pendingFrameLoad-&gt;markAsCompleted();
</del><ins>+            pendingFrameLoad-&gt;markLoadAsCompleted();
</ins><span class="cx"> 
</span><ins>+        ASSERT(!m_pendingFrameLoads.contains(frameID));
+
</ins><span class="cx">         // Start tracking loads in this frame.
</span><del>-        m_pendingFrameLoads.add(frameID, std::make_unique&lt;PendingFrameLoad&gt;(resourceKey, [this, frameID]() {
-            auto frameLoad = m_pendingFrameLoads.take(frameID);
-            auto optionalRecord = frameLoad-&gt;encodeAsSubresourcesRecord();
-            if (!optionalRecord)
-                return;
-            m_storage.store(optionalRecord.value(), [](const Data&amp;) { });
-        }));
</del><ins>+        RefPtr&lt;PendingFrameLoad&gt; pendingFrameLoad = PendingFrameLoad::create(m_storage, resourceKey, [this, frameID] {
+            bool wasRemoved = m_pendingFrameLoads.remove(frameID);
+            ASSERT_UNUSED(wasRemoved, wasRemoved);
+        });
+        m_pendingFrameLoads.add(frameID, pendingFrameLoad);
+
+        // Retrieve the subresources entry if it exists to start speculative revalidation and to update it.
+        retrieveSubresourcesEntry(resourceKey, [this, frameID, pendingFrameLoad](std::unique_ptr&lt;SubresourcesEntry&gt; entry) {
+            if (entry)
+                startSpeculativeRevalidation(frameID, *entry);
+
+            pendingFrameLoad-&gt;setExistingSubresourcesEntry(WTF::move(entry));
+        });
</ins><span class="cx">         return;
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="lines">@@ -306,24 +349,33 @@
</span><span class="cx">     });
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void SpeculativeLoadManager::startSpeculativeRevalidation(const ResourceRequest&amp; originalRequest, const GlobalFrameID&amp; frameID, const Key&amp; storageKey)
</del><ins>+void SpeculativeLoadManager::startSpeculativeRevalidation(const GlobalFrameID&amp; frameID, SubresourcesEntry&amp; entry)
</ins><span class="cx"> {
</span><del>-    if (originalRequest.requester() != ResourceRequest::Requester::Main)
-        return;
</del><ins>+    for (auto&amp; subresource : entry.subresources()) {
+        if (!subresource.value.isTransient)
+            preloadEntry(subresource.key, frameID);
+        else
+            LOG(NetworkCacheSpeculativePreloading, &quot;(NetworkProcess) Not preloading '%s' because it is marked as transient&quot;, subresource.key.identifier().utf8().data());
+    }
+}
</ins><span class="cx"> 
</span><ins>+void SpeculativeLoadManager::retrieveSubresourcesEntry(const Key&amp; storageKey, std::function&lt;void (std::unique_ptr&lt;SubresourcesEntry&gt;)&gt; completionHandler)
+{
+    ASSERT(storageKey.type() == &quot;resource&quot;);
</ins><span class="cx">     auto subresourcesStorageKey = makeSubresourcesKey(storageKey);
</span><del>-
-    m_storage.retrieve(subresourcesStorageKey, static_cast&lt;unsigned&gt;(ResourceLoadPriority::Medium), [this, frameID](std::unique_ptr&lt;Storage::Record&gt; record) {
-        if (!record)
</del><ins>+    m_storage.retrieve(subresourcesStorageKey, static_cast&lt;unsigned&gt;(ResourceLoadPriority::Medium), [completionHandler](std::unique_ptr&lt;Storage::Record&gt; record) {
+        if (!record) {
+            completionHandler(nullptr);
</ins><span class="cx">             return false;
</span><ins>+        }
</ins><span class="cx"> 
</span><span class="cx">         auto subresourcesEntry = SubresourcesEntry::decodeStorageRecord(*record);
</span><del>-        if (!subresourcesEntry)
</del><ins>+        if (!subresourcesEntry) {
+            completionHandler(nullptr);
</ins><span class="cx">             return false;
</span><ins>+        }
</ins><span class="cx"> 
</span><del>-        for (auto&amp; subresourceKey : subresourcesEntry-&gt;subresourceKeys())
-            preloadEntry(subresourceKey, frameID);
-
</del><ins>+        completionHandler(WTF::move(subresourcesEntry));
</ins><span class="cx">         return true;
</span><span class="cx">     });
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebKit2NetworkProcesscacheNetworkCacheSpeculativeLoadManagerh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheSpeculativeLoadManager.h (192806 => 192807)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheSpeculativeLoadManager.h        2015-11-30 19:05:05 UTC (rev 192806)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheSpeculativeLoadManager.h        2015-11-30 19:06:15 UTC (rev 192807)
</span><span class="lines">@@ -40,6 +40,7 @@
</span><span class="cx"> 
</span><span class="cx"> class Entry;
</span><span class="cx"> class SpeculativeLoad;
</span><ins>+class SubresourcesEntry;
</ins><span class="cx"> 
</span><span class="cx"> class SpeculativeLoadManager {
</span><span class="cx"> public:
</span><span class="lines">@@ -51,19 +52,19 @@
</span><span class="cx">     typedef std::function&lt;void (std::unique_ptr&lt;Entry&gt;)&gt; RetrieveCompletionHandler;
</span><span class="cx">     bool retrieve(const Key&amp; storageKey, const RetrieveCompletionHandler&amp;);
</span><span class="cx"> 
</span><del>-    void startSpeculativeRevalidation(const WebCore::ResourceRequest&amp;, const GlobalFrameID&amp;, const Key&amp; storageKey);
-
</del><span class="cx"> private:
</span><span class="cx">     void addPreloadedEntry(std::unique_ptr&lt;Entry&gt;);
</span><span class="cx">     void preloadEntry(const Key&amp;, const GlobalFrameID&amp;);
</span><span class="cx">     void retrieveEntryFromStorage(const Key&amp;, const RetrieveCompletionHandler&amp;);
</span><span class="cx">     void revalidateEntry(std::unique_ptr&lt;Entry&gt;, const GlobalFrameID&amp;);
</span><span class="cx">     bool satisfyPendingRequests(const Key&amp;, Entry*);
</span><ins>+    void retrieveSubresourcesEntry(const Key&amp; storageKey, std::function&lt;void (std::unique_ptr&lt;SubresourcesEntry&gt;)&gt;);
+    void startSpeculativeRevalidation(const GlobalFrameID&amp;, SubresourcesEntry&amp;);
</ins><span class="cx"> 
</span><span class="cx">     Storage&amp; m_storage;
</span><span class="cx"> 
</span><span class="cx">     class PendingFrameLoad;
</span><del>-    HashMap&lt;GlobalFrameID, std::unique_ptr&lt;PendingFrameLoad&gt;&gt; m_pendingFrameLoads;
</del><ins>+    HashMap&lt;GlobalFrameID, RefPtr&lt;PendingFrameLoad&gt;&gt; m_pendingFrameLoads;
</ins><span class="cx"> 
</span><span class="cx">     HashMap&lt;Key, std::unique_ptr&lt;SpeculativeLoad&gt;&gt; m_pendingPreloads;
</span><span class="cx">     HashMap&lt;Key, std::unique_ptr&lt;Vector&lt;RetrieveCompletionHandler&gt;&gt;&gt; m_pendingRetrieveRequests;
</span></span></pre></div>
<a id="trunkSourceWebKit2NetworkProcesscacheNetworkCacheSubresourcesEntrycpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheSubresourcesEntry.cpp (192806 => 192807)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheSubresourcesEntry.cpp        2015-11-30 19:05:05 UTC (rev 192806)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheSubresourcesEntry.cpp        2015-11-30 19:06:15 UTC (rev 192807)
</span><span class="lines">@@ -39,7 +39,7 @@
</span><span class="cx"> Storage::Record SubresourcesEntry::encodeAsStorageRecord() const
</span><span class="cx"> {
</span><span class="cx">     Encoder encoder;
</span><del>-    encoder &lt;&lt; m_subresourceKeys;
</del><ins>+    encoder &lt;&lt; m_subresources;
</ins><span class="cx"> 
</span><span class="cx">     encoder.encodeChecksum();
</span><span class="cx"> 
</span><span class="lines">@@ -51,7 +51,7 @@
</span><span class="cx">     auto entry = std::make_unique&lt;SubresourcesEntry&gt;(storageEntry);
</span><span class="cx"> 
</span><span class="cx">     Decoder decoder(storageEntry.header.data(), storageEntry.header.size());
</span><del>-    if (!decoder.decode(entry-&gt;m_subresourceKeys))
</del><ins>+    if (!decoder.decode(entry-&gt;m_subresources))
</ins><span class="cx">         return nullptr;
</span><span class="cx"> 
</span><span class="cx">     if (!decoder.verifyChecksum()) {
</span><span class="lines">@@ -69,14 +69,26 @@
</span><span class="cx">     ASSERT(m_key.type() == &quot;subresources&quot;);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-SubresourcesEntry::SubresourcesEntry(Key&amp;&amp; key, Vector&lt;Key&gt;&amp;&amp; subresourceKeys)
</del><ins>+SubresourcesEntry::SubresourcesEntry(Key&amp;&amp; key, const Vector&lt;Key&gt;&amp; subresourceKeys)
</ins><span class="cx">     : m_key(WTF::move(key))
</span><span class="cx">     , m_timeStamp(std::chrono::system_clock::now())
</span><del>-    , m_subresourceKeys(WTF::move(subresourceKeys))
</del><span class="cx"> {
</span><span class="cx">     ASSERT(m_key.type() == &quot;subresources&quot;);
</span><ins>+    for (auto&amp; key : subresourceKeys)
+        m_subresources.add(key, SubresourceInfo());
</ins><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void SubresourcesEntry::updateSubresourceKeys(const Vector&lt;Key&gt;&amp; subresourceKeys)
+{
+    auto oldSubresources = WTF::move(m_subresources);
+
+    // Mark keys that are common with last load as non-Transient.
+    for (auto&amp; key : subresourceKeys) {
+        bool isTransient = !oldSubresources.contains(key);
+        m_subresources.add(key, SubresourceInfo(isTransient));
+    }
+}
+
</ins><span class="cx"> } // namespace WebKit
</span><span class="cx"> } // namespace NetworkCache
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKit2NetworkProcesscacheNetworkCacheSubresourcesEntryh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheSubresourcesEntry.h (192806 => 192807)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheSubresourcesEntry.h        2015-11-30 19:05:05 UTC (rev 192806)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheSubresourcesEntry.h        2015-11-30 19:06:15 UTC (rev 192807)
</span><span class="lines">@@ -28,7 +28,10 @@
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(NETWORK_CACHE_SPECULATIVE_REVALIDATION)
</span><span class="cx"> 
</span><ins>+#include &quot;NetworkCacheDecoder.h&quot;
+#include &quot;NetworkCacheEncoder.h&quot;
</ins><span class="cx"> #include &quot;NetworkCacheStorage.h&quot;
</span><ins>+#include &lt;wtf/HashMap.h&gt;
</ins><span class="cx"> 
</span><span class="cx"> namespace WebKit {
</span><span class="cx"> namespace NetworkCache {
</span><span class="lines">@@ -36,7 +39,16 @@
</span><span class="cx"> class SubresourcesEntry {
</span><span class="cx">     WTF_MAKE_NONCOPYABLE(SubresourcesEntry); WTF_MAKE_FAST_ALLOCATED;
</span><span class="cx"> public:
</span><del>-    SubresourcesEntry(Key&amp;&amp;, Vector&lt;Key&gt;&amp;&amp; subresourceKeys);
</del><ins>+    struct SubresourceInfo {
+        void encode(Encoder&amp; encoder) const { encoder &lt;&lt; isTransient; }
+        static bool decode(Decoder&amp; decoder, SubresourceInfo&amp; info) { return decoder.decode(info.isTransient); }
+
+        SubresourceInfo() = default;
+        SubresourceInfo(bool isTransient) : isTransient(isTransient) { }
+
+        bool isTransient { false };
+    };
+    SubresourcesEntry(Key&amp;&amp;, const Vector&lt;Key&gt;&amp; subresourceKeys);
</ins><span class="cx">     explicit SubresourcesEntry(const Storage::Record&amp;);
</span><span class="cx"> 
</span><span class="cx">     Storage::Record encodeAsStorageRecord() const;
</span><span class="lines">@@ -44,12 +56,14 @@
</span><span class="cx"> 
</span><span class="cx">     const Key&amp; key() const { return m_key; }
</span><span class="cx">     std::chrono::system_clock::time_point timeStamp() const { return m_timeStamp; }
</span><del>-    const Vector&lt;Key&gt;&amp; subresourceKeys() const { return m_subresourceKeys; }
</del><ins>+    const HashMap&lt;Key, SubresourceInfo&gt;&amp; subresources() const { return m_subresources; }
</ins><span class="cx"> 
</span><ins>+    void updateSubresourceKeys(const Vector&lt;Key&gt;&amp;);
+
</ins><span class="cx"> private:
</span><span class="cx">     Key m_key;
</span><span class="cx">     std::chrono::system_clock::time_point m_timeStamp;
</span><del>-    Vector&lt;Key&gt; m_subresourceKeys;
</del><ins>+    HashMap&lt;Key, SubresourceInfo&gt; m_subresources;
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> } // namespace WebKit
</span></span></pre>
</div>
</div>

</body>
</html>