<!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
<rdar://problem/23092196>
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 <cdumez@apple.com>
+
+ [WK2][Cache] We should not speculatively revalidate transient resources
+ https://bugs.webkit.org/show_bug.cgi?id=151402
+ <rdar://problem/23092196>
+
+ 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 <bfulgham@apple.com>
</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->registerLoad(frameID, originalRequest, storageKey);
</span><del>- RunLoop::main().dispatch([this, originalRequest, frameID, storageKey] {
- m_speculativeLoadManager->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 "NetworkCacheSubresourcesEntry.h"
</span><span class="cx"> #include <WebCore/HysteresisActivity.h>
</span><span class="cx"> #include <wtf/NeverDestroyed.h>
</span><ins>+#include <wtf/RefCounted.h>
</ins><span class="cx"> #include <wtf/RunLoop.h>
</span><span class="cx">
</span><span class="cx"> namespace WebKit {
</span><span class="lines">@@ -109,52 +110,86 @@
</span><span class="cx"> std::function<void()> 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<PendingFrameLoad> {
</ins><span class="cx"> public:
</span><del>- PendingFrameLoad(const Key& mainResourceKey, std::function<void()>&& completionHandler)
- : m_mainResourceKey(mainResourceKey)
- , m_completionHandler(WTF::move(completionHandler))
- , m_loadHysteresisActivity([this](HysteresisState state) { if (state == HysteresisState::Stopped) m_completionHandler(); })
- { }
</del><ins>+ static Ref<PendingFrameLoad> create(Storage& storage, const Key& mainResourceKey, std::function<void()>&& 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& 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<Storage::Record> 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<SubresourcesEntry> entry)
+ {
+ ASSERT(!m_existingEntry);
+ ASSERT(!m_didRetrieveExistingEntry);
+
+ m_existingEntry = WTF::move(entry);
+ m_didRetrieveExistingEntry = true;
+ saveToDiskIfReady();
+ }
+
+private:
+ PendingFrameLoad(Storage& storage, const Key& mainResourceKey, std::function<void()>&& 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<Key> subresourceKeys;
- copyToVector(m_subresourceKeys, subresourceKeys);
-
</del><span class="cx"> #if !LOG_DISABLED
</span><span class="cx"> LOG(NetworkCacheSpeculativePreloading, "(NetworkProcess) Saving to disk list of subresources for '%s':", m_mainResourceKey.identifier().utf8().data());
</span><del>- for (auto& subresourceKey : subresourceKeys)
</del><ins>+ for (auto& subresourceKey : m_subresourceKeys)
</ins><span class="cx"> LOG(NetworkCacheSpeculativePreloading, "(NetworkProcess) * Subresource: '%s'.", 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->updateSubresourceKeys(m_subresourceKeys);
+ m_storage.store(m_existingEntry->encodeAsStorageRecord(), [](const Data&) { });
+ } else {
+ SubresourcesEntry entry(makeSubresourcesKey(m_mainResourceKey), m_subresourceKeys);
+ m_storage.store(entry.encodeAsStorageRecord(), [](const Data&) { });
+ }
</ins><span class="cx"> }
</span><span class="cx">
</span><del>- void markAsCompleted()
- {
- ASSERT(RunLoop::isMain());
- m_completionHandler();
- }
-
-private:
</del><ins>+ Storage& m_storage;
</ins><span class="cx"> Key m_mainResourceKey;
</span><del>- HashSet<Key> m_subresourceKeys;
- std::function<void()> m_completionHandler;
</del><ins>+ Vector<Key> m_subresourceKeys;
+ std::function<void()> m_loadCompletionHandler;
</ins><span class="cx"> HysteresisActivity m_loadHysteresisActivity;
</span><ins>+ std::unique_ptr<SubresourcesEntry> 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& 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->markAsCompleted();
</del><ins>+ pendingFrameLoad->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<PendingFrameLoad>(resourceKey, [this, frameID]() {
- auto frameLoad = m_pendingFrameLoads.take(frameID);
- auto optionalRecord = frameLoad->encodeAsSubresourcesRecord();
- if (!optionalRecord)
- return;
- m_storage.store(optionalRecord.value(), [](const Data&) { });
- }));
</del><ins>+ RefPtr<PendingFrameLoad> 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<SubresourcesEntry> entry) {
+ if (entry)
+ startSpeculativeRevalidation(frameID, *entry);
+
+ pendingFrameLoad->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& originalRequest, const GlobalFrameID& frameID, const Key& storageKey)
</del><ins>+void SpeculativeLoadManager::startSpeculativeRevalidation(const GlobalFrameID& frameID, SubresourcesEntry& entry)
</ins><span class="cx"> {
</span><del>- if (originalRequest.requester() != ResourceRequest::Requester::Main)
- return;
</del><ins>+ for (auto& subresource : entry.subresources()) {
+ if (!subresource.value.isTransient)
+ preloadEntry(subresource.key, frameID);
+ else
+ LOG(NetworkCacheSpeculativePreloading, "(NetworkProcess) Not preloading '%s' because it is marked as transient", subresource.key.identifier().utf8().data());
+ }
+}
</ins><span class="cx">
</span><ins>+void SpeculativeLoadManager::retrieveSubresourcesEntry(const Key& storageKey, std::function<void (std::unique_ptr<SubresourcesEntry>)> completionHandler)
+{
+ ASSERT(storageKey.type() == "resource");
</ins><span class="cx"> auto subresourcesStorageKey = makeSubresourcesKey(storageKey);
</span><del>-
- m_storage.retrieve(subresourcesStorageKey, static_cast<unsigned>(ResourceLoadPriority::Medium), [this, frameID](std::unique_ptr<Storage::Record> record) {
- if (!record)
</del><ins>+ m_storage.retrieve(subresourcesStorageKey, static_cast<unsigned>(ResourceLoadPriority::Medium), [completionHandler](std::unique_ptr<Storage::Record> 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& subresourceKey : subresourcesEntry->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<void (std::unique_ptr<Entry>)> RetrieveCompletionHandler;
</span><span class="cx"> bool retrieve(const Key& storageKey, const RetrieveCompletionHandler&);
</span><span class="cx">
</span><del>- void startSpeculativeRevalidation(const WebCore::ResourceRequest&, const GlobalFrameID&, const Key& storageKey);
-
</del><span class="cx"> private:
</span><span class="cx"> void addPreloadedEntry(std::unique_ptr<Entry>);
</span><span class="cx"> void preloadEntry(const Key&, const GlobalFrameID&);
</span><span class="cx"> void retrieveEntryFromStorage(const Key&, const RetrieveCompletionHandler&);
</span><span class="cx"> void revalidateEntry(std::unique_ptr<Entry>, const GlobalFrameID&);
</span><span class="cx"> bool satisfyPendingRequests(const Key&, Entry*);
</span><ins>+ void retrieveSubresourcesEntry(const Key& storageKey, std::function<void (std::unique_ptr<SubresourcesEntry>)>);
+ void startSpeculativeRevalidation(const GlobalFrameID&, SubresourcesEntry&);
</ins><span class="cx">
</span><span class="cx"> Storage& m_storage;
</span><span class="cx">
</span><span class="cx"> class PendingFrameLoad;
</span><del>- HashMap<GlobalFrameID, std::unique_ptr<PendingFrameLoad>> m_pendingFrameLoads;
</del><ins>+ HashMap<GlobalFrameID, RefPtr<PendingFrameLoad>> m_pendingFrameLoads;
</ins><span class="cx">
</span><span class="cx"> HashMap<Key, std::unique_ptr<SpeculativeLoad>> m_pendingPreloads;
</span><span class="cx"> HashMap<Key, std::unique_ptr<Vector<RetrieveCompletionHandler>>> 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 << m_subresourceKeys;
</del><ins>+ encoder << 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<SubresourcesEntry>(storageEntry);
</span><span class="cx">
</span><span class="cx"> Decoder decoder(storageEntry.header.data(), storageEntry.header.size());
</span><del>- if (!decoder.decode(entry->m_subresourceKeys))
</del><ins>+ if (!decoder.decode(entry->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() == "subresources");
</span><span class="cx"> }
</span><span class="cx">
</span><del>-SubresourcesEntry::SubresourcesEntry(Key&& key, Vector<Key>&& subresourceKeys)
</del><ins>+SubresourcesEntry::SubresourcesEntry(Key&& key, const Vector<Key>& 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() == "subresources");
</span><ins>+ for (auto& key : subresourceKeys)
+ m_subresources.add(key, SubresourceInfo());
</ins><span class="cx"> }
</span><span class="cx">
</span><ins>+void SubresourcesEntry::updateSubresourceKeys(const Vector<Key>& subresourceKeys)
+{
+ auto oldSubresources = WTF::move(m_subresources);
+
+ // Mark keys that are common with last load as non-Transient.
+ for (auto& 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 "NetworkCacheDecoder.h"
+#include "NetworkCacheEncoder.h"
</ins><span class="cx"> #include "NetworkCacheStorage.h"
</span><ins>+#include <wtf/HashMap.h>
</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&&, Vector<Key>&& subresourceKeys);
</del><ins>+ struct SubresourceInfo {
+ void encode(Encoder& encoder) const { encoder << isTransient; }
+ static bool decode(Decoder& decoder, SubresourceInfo& info) { return decoder.decode(info.isTransient); }
+
+ SubresourceInfo() = default;
+ SubresourceInfo(bool isTransient) : isTransient(isTransient) { }
+
+ bool isTransient { false };
+ };
+ SubresourcesEntry(Key&&, const Vector<Key>& subresourceKeys);
</ins><span class="cx"> explicit SubresourcesEntry(const Storage::Record&);
</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& key() const { return m_key; }
</span><span class="cx"> std::chrono::system_clock::time_point timeStamp() const { return m_timeStamp; }
</span><del>- const Vector<Key>& subresourceKeys() const { return m_subresourceKeys; }
</del><ins>+ const HashMap<Key, SubresourceInfo>& subresources() const { return m_subresources; }
</ins><span class="cx">
</span><ins>+ void updateSubresourceKeys(const Vector<Key>&);
+
</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<Key> m_subresourceKeys;
</del><ins>+ HashMap<Key, SubresourceInfo> m_subresources;
</ins><span class="cx"> };
</span><span class="cx">
</span><span class="cx"> } // namespace WebKit
</span></span></pre>
</div>
</div>
</body>
</html>