<!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>[181970] 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/181970">181970</a></dd>
<dt>Author</dt> <dd>antti@apple.com</dd>
<dt>Date</dt> <dd>2015-03-25 13:59:18 -0700 (Wed, 25 Mar 2015)</dd>
</dl>
<h3>Log Message</h3>
<pre>Separate entry decoding from validation
https://bugs.webkit.org/show_bug.cgi?id=143052
Reviewed by Chris Dumez.
Make NetworkCache::Cache a class and move it to a file of its own.
Move the encoding/decoding code there.
* NetworkProcess/NetworkProcess.cpp:
(WebKit::fetchDiskCacheEntries):
(WebKit::clearDiskCacheEntries):
* NetworkProcess/NetworkResourceLoader.cpp:
(WebKit::sendReplyToSynchronousRequest):
(WebKit::NetworkResourceLoader::start):
(WebKit::NetworkResourceLoader::sendBufferMaybeAborting):
(WebKit::NetworkResourceLoader::didRetrieveCacheEntry):
(WebKit::NetworkResourceLoader::validateCacheEntry):
* NetworkProcess/NetworkResourceLoader.h:
* NetworkProcess/cache/NetworkCache.cpp:
(WebKit::NetworkCache::collectVaryingRequestHeaders):
(WebKit::NetworkCache::canUse):
Focused function for deciding if we can use a cache entry and if it needs validation.
(WebKit::NetworkCache::Cache::retrieve):
(WebKit::NetworkCache::Cache::store):
(WebKit::NetworkCache::Cache::update):
(WebKit::NetworkCache::Cache::traverse):
(WebKit::NetworkCache::encodeStorageEntry): Deleted.
(WebKit::NetworkCache::decodeStorageEntry): Deleted.
* NetworkProcess/cache/NetworkCache.h:
* NetworkProcess/cache/NetworkCacheEntry.cpp: Added.
(WebKit::NetworkCache::Entry::Entry):
(WebKit::NetworkCache::Entry::encode):
(WebKit::NetworkCache::Entry::decode):
(WebKit::NetworkCache::Entry::initializeBufferFromStorageEntry):
(WebKit::NetworkCache::Entry::buffer):
(WebKit::NetworkCache::Entry::shareableResourceHandle):
(WebKit::NetworkCache::Entry::needsValidation):
(WebKit::NetworkCache::Entry::setNeedsValidation):
* NetworkProcess/cache/NetworkCacheEntry.h: Added.
(WebKit::NetworkCache::Entry::key):
(WebKit::NetworkCache::Entry::timeStamp):
(WebKit::NetworkCache::Entry::response):
(WebKit::NetworkCache::Entry::varyingRequestHeaders):
(WebKit::NetworkCache::Entry::sourceStorageEntry):
* NetworkProcess/cache/NetworkCacheStatistics.h:
* NetworkProcess/cache/NetworkCacheStatisticsCocoa.mm:
(WebKit::NetworkCache::cachedEntryReuseFailureToDiagnosticKey):
(WebKit::NetworkCache::Statistics::recordRetrievedCachedEntry):
* WebKit2.xcodeproj/project.pbxproj:</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2NetworkProcessNetworkProcesscpp">trunk/Source/WebKit2/NetworkProcess/NetworkProcess.cpp</a></li>
<li><a href="#trunkSourceWebKit2NetworkProcessNetworkResourceLoadercpp">trunk/Source/WebKit2/NetworkProcess/NetworkResourceLoader.cpp</a></li>
<li><a href="#trunkSourceWebKit2NetworkProcessNetworkResourceLoaderh">trunk/Source/WebKit2/NetworkProcess/NetworkResourceLoader.h</a></li>
<li><a href="#trunkSourceWebKit2NetworkProcesscacheNetworkCachecpp">trunk/Source/WebKit2/NetworkProcess/cache/NetworkCache.cpp</a></li>
<li><a href="#trunkSourceWebKit2NetworkProcesscacheNetworkCacheh">trunk/Source/WebKit2/NetworkProcess/cache/NetworkCache.h</a></li>
<li><a href="#trunkSourceWebKit2NetworkProcesscacheNetworkCacheStatisticsh">trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStatistics.h</a></li>
<li><a href="#trunkSourceWebKit2NetworkProcesscacheNetworkCacheStatisticsCocoamm">trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStatisticsCocoa.mm</a></li>
<li><a href="#trunkSourceWebKit2WebKit2xcodeprojprojectpbxproj">trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a href="#trunkSourceWebKit2NetworkProcesscacheNetworkCacheEntrycpp">trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheEntry.cpp</a></li>
<li><a href="#trunkSourceWebKit2NetworkProcesscacheNetworkCacheEntryh">trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheEntry.h</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (181969 => 181970)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2015-03-25 19:35:49 UTC (rev 181969)
+++ trunk/Source/WebKit2/ChangeLog        2015-03-25 20:59:18 UTC (rev 181970)
</span><span class="lines">@@ -1,3 +1,57 @@
</span><ins>+2015-03-25 Antti Koivisto <antti@apple.com>
+
+ Separate entry decoding from validation
+ https://bugs.webkit.org/show_bug.cgi?id=143052
+
+ Reviewed by Chris Dumez.
+
+ Make NetworkCache::Cache a class and move it to a file of its own.
+ Move the encoding/decoding code there.
+
+ * NetworkProcess/NetworkProcess.cpp:
+ (WebKit::fetchDiskCacheEntries):
+ (WebKit::clearDiskCacheEntries):
+ * NetworkProcess/NetworkResourceLoader.cpp:
+ (WebKit::sendReplyToSynchronousRequest):
+ (WebKit::NetworkResourceLoader::start):
+ (WebKit::NetworkResourceLoader::sendBufferMaybeAborting):
+ (WebKit::NetworkResourceLoader::didRetrieveCacheEntry):
+ (WebKit::NetworkResourceLoader::validateCacheEntry):
+ * NetworkProcess/NetworkResourceLoader.h:
+ * NetworkProcess/cache/NetworkCache.cpp:
+ (WebKit::NetworkCache::collectVaryingRequestHeaders):
+ (WebKit::NetworkCache::canUse):
+
+ Focused function for deciding if we can use a cache entry and if it needs validation.
+
+ (WebKit::NetworkCache::Cache::retrieve):
+ (WebKit::NetworkCache::Cache::store):
+ (WebKit::NetworkCache::Cache::update):
+ (WebKit::NetworkCache::Cache::traverse):
+ (WebKit::NetworkCache::encodeStorageEntry): Deleted.
+ (WebKit::NetworkCache::decodeStorageEntry): Deleted.
+ * NetworkProcess/cache/NetworkCache.h:
+ * NetworkProcess/cache/NetworkCacheEntry.cpp: Added.
+ (WebKit::NetworkCache::Entry::Entry):
+ (WebKit::NetworkCache::Entry::encode):
+ (WebKit::NetworkCache::Entry::decode):
+ (WebKit::NetworkCache::Entry::initializeBufferFromStorageEntry):
+ (WebKit::NetworkCache::Entry::buffer):
+ (WebKit::NetworkCache::Entry::shareableResourceHandle):
+ (WebKit::NetworkCache::Entry::needsValidation):
+ (WebKit::NetworkCache::Entry::setNeedsValidation):
+ * NetworkProcess/cache/NetworkCacheEntry.h: Added.
+ (WebKit::NetworkCache::Entry::key):
+ (WebKit::NetworkCache::Entry::timeStamp):
+ (WebKit::NetworkCache::Entry::response):
+ (WebKit::NetworkCache::Entry::varyingRequestHeaders):
+ (WebKit::NetworkCache::Entry::sourceStorageEntry):
+ * NetworkProcess/cache/NetworkCacheStatistics.h:
+ * NetworkProcess/cache/NetworkCacheStatisticsCocoa.mm:
+ (WebKit::NetworkCache::cachedEntryReuseFailureToDiagnosticKey):
+ (WebKit::NetworkCache::Statistics::recordRetrievedCachedEntry):
+ * WebKit2.xcodeproj/project.pbxproj:
+
</ins><span class="cx"> 2015-03-25 David Hyatt <hyatt@apple.com>
</span><span class="cx">
</span><span class="cx"> Add a pref to enable the new block-inside-inline model
</span></span></pre></div>
<a id="trunkSourceWebKit2NetworkProcessNetworkProcesscpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/NetworkProcess/NetworkProcess.cpp (181969 => 181970)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/NetworkProcess/NetworkProcess.cpp        2015-03-25 19:35:49 UTC (rev 181969)
+++ trunk/Source/WebKit2/NetworkProcess/NetworkProcess.cpp        2015-03-25 20:59:18 UTC (rev 181970)
</span><span class="lines">@@ -287,7 +287,7 @@
</span><span class="cx"> return;
</span><span class="cx"> }
</span><span class="cx">
</span><del>- origins->add(SecurityOrigin::create(entry->response.url()));
</del><ins>+ origins->add(SecurityOrigin::create(entry->response().url()));
</ins><span class="cx"> });
</span><span class="cx">
</span><span class="cx"> return;
</span><span class="lines">@@ -379,8 +379,8 @@
</span><span class="cx"> NetworkCache::singleton().traverse([completionHandler, originsToDelete, cacheKeysToDelete](const NetworkCache::Entry *entry) {
</span><span class="cx">
</span><span class="cx"> if (entry) {
</span><del>- if (originsToDelete->contains(SecurityOrigin::create(entry->response.url())))
- cacheKeysToDelete->append(entry->storageEntry.key);
</del><ins>+ if (originsToDelete->contains(SecurityOrigin::create(entry->response().url())))
+ cacheKeysToDelete->append(entry->key());
</ins><span class="cx"> return;
</span><span class="cx"> }
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceWebKit2NetworkProcessNetworkResourceLoadercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/NetworkProcess/NetworkResourceLoader.cpp (181969 => 181970)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/NetworkProcess/NetworkResourceLoader.cpp        2015-03-25 19:35:49 UTC (rev 181969)
+++ trunk/Source/WebKit2/NetworkProcess/NetworkResourceLoader.cpp        2015-03-25 20:59:18 UTC (rev 181970)
</span><span class="lines">@@ -69,7 +69,7 @@
</span><span class="cx"> WebCore::ResourceError error;
</span><span class="cx"> };
</span><span class="cx">
</span><del>-static void sendReplyToSynchronousRequest(NetworkResourceLoader::SynchronousLoadData& data, WebCore::SharedBuffer* buffer)
</del><ins>+static void sendReplyToSynchronousRequest(NetworkResourceLoader::SynchronousLoadData& data, const WebCore::SharedBuffer* buffer)
</ins><span class="cx"> {
</span><span class="cx"> ASSERT(data.delayedReply);
</span><span class="cx"> ASSERT(!data.response.isNull() || !data.error.isNull());
</span><span class="lines">@@ -150,11 +150,11 @@
</span><span class="cx"> loader->startNetworkLoad();
</span><span class="cx"> return;
</span><span class="cx"> }
</span><del>- if (loader->m_parameters.needsCertificateInfo && !entry->response.containsCertificateInfo()) {
</del><ins>+ if (loader->m_parameters.needsCertificateInfo && !entry->response().containsCertificateInfo()) {
</ins><span class="cx"> loader->startNetworkLoad();
</span><span class="cx"> return;
</span><span class="cx"> }
</span><del>- if (entry->needsRevalidation) {
</del><ins>+ if (entry->needsValidation()) {
</ins><span class="cx"> loader->validateCacheEntry(WTF::move(entry));
</span><span class="cx"> return;
</span><span class="cx"> }
</span><span class="lines">@@ -529,13 +529,13 @@
</span><span class="cx"> sendAbortingOnFailure(Messages::WebResourceLoader::DidReceiveData(dataReference, encodedLength));
</span><span class="cx"> }
</span><span class="cx">
</span><del>-bool NetworkResourceLoader::sendBufferMaybeAborting(WebCore::SharedBuffer& buffer, size_t encodedDataLength)
</del><ins>+bool NetworkResourceLoader::sendBufferMaybeAborting(const WebCore::SharedBuffer& buffer, size_t encodedDataLength)
</ins><span class="cx"> {
</span><span class="cx"> ASSERT(!isSynchronous());
</span><span class="cx">
</span><span class="cx"> #if PLATFORM(COCOA)
</span><span class="cx"> ShareableResource::Handle shareableResourceHandle;
</span><del>- NetworkResourceLoader::tryGetShareableHandleFromSharedBuffer(shareableResourceHandle, buffer);
</del><ins>+ NetworkResourceLoader::tryGetShareableHandleFromSharedBuffer(shareableResourceHandle, const_cast<WebCore::SharedBuffer&>(buffer));
</ins><span class="cx"> if (!shareableResourceHandle.isNull()) {
</span><span class="cx"> send(Messages::WebResourceLoader::DidReceiveResource(shareableResourceHandle, currentTime()));
</span><span class="cx"> abort();
</span><span class="lines">@@ -543,7 +543,7 @@
</span><span class="cx"> }
</span><span class="cx"> #endif
</span><span class="cx">
</span><del>- IPC::SharedBufferDataReference dataReference(&buffer);
</del><ins>+ IPC::SharedBufferDataReference dataReference(&const_cast<WebCore::SharedBuffer&>(buffer));
</ins><span class="cx"> return sendAbortingOnFailure(Messages::WebResourceLoader::DidReceiveData(dataReference, encodedDataLength));
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -551,17 +551,17 @@
</span><span class="cx"> void NetworkResourceLoader::didRetrieveCacheEntry(std::unique_ptr<NetworkCache::Entry> entry)
</span><span class="cx"> {
</span><span class="cx"> if (isSynchronous()) {
</span><del>- m_synchronousLoadData->response = entry->response;
- sendReplyToSynchronousRequest(*m_synchronousLoadData, entry->buffer.get());
</del><ins>+ m_synchronousLoadData->response = entry->response();
+ sendReplyToSynchronousRequest(*m_synchronousLoadData, entry->buffer());
</ins><span class="cx"> } else {
</span><del>- sendAbortingOnFailure(Messages::WebResourceLoader::DidReceiveResponse(entry->response, m_parameters.isMainResource));
</del><ins>+ sendAbortingOnFailure(Messages::WebResourceLoader::DidReceiveResponse(entry->response(), m_parameters.isMainResource));
</ins><span class="cx">
</span><span class="cx"> #if ENABLE(SHAREABLE_RESOURCE)
</span><del>- if (!entry->shareableResourceHandle.isNull())
- send(Messages::WebResourceLoader::DidReceiveResource(entry->shareableResourceHandle, currentTime()));
</del><ins>+ if (!entry->shareableResourceHandle().isNull())
+ send(Messages::WebResourceLoader::DidReceiveResource(entry->shareableResourceHandle(), currentTime()));
</ins><span class="cx"> else {
</span><span class="cx"> #endif
</span><del>- bool shouldContinue = sendBufferMaybeAborting(*entry->buffer, entry->buffer->size());
</del><ins>+ bool shouldContinue = sendBufferMaybeAborting(*entry->buffer(), entry->buffer()->size());
</ins><span class="cx"> if (!shouldContinue)
</span><span class="cx"> return;
</span><span class="cx"> send(Messages::WebResourceLoader::DidFinishResourceLoad(currentTime()));
</span><span class="lines">@@ -577,8 +577,8 @@
</span><span class="cx"> {
</span><span class="cx"> ASSERT(!m_handle);
</span><span class="cx">
</span><del>- String eTag = entry->response.httpHeaderField(WebCore::HTTPHeaderName::ETag);
- String lastModified = entry->response.httpHeaderField(WebCore::HTTPHeaderName::LastModified);
</del><ins>+ String eTag = entry->response().httpHeaderField(WebCore::HTTPHeaderName::ETag);
+ String lastModified = entry->response().httpHeaderField(WebCore::HTTPHeaderName::LastModified);
</ins><span class="cx"> if (!eTag.isEmpty())
</span><span class="cx"> m_currentRequest.setHTTPHeaderField(WebCore::HTTPHeaderName::IfNoneMatch, eTag);
</span><span class="cx"> if (!lastModified.isEmpty())
</span></span></pre></div>
<a id="trunkSourceWebKit2NetworkProcessNetworkResourceLoaderh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/NetworkProcess/NetworkResourceLoader.h (181969 => 181970)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/NetworkProcess/NetworkResourceLoader.h        2015-03-25 19:35:49 UTC (rev 181969)
+++ trunk/Source/WebKit2/NetworkProcess/NetworkResourceLoader.h        2015-03-25 20:59:18 UTC (rev 181970)
</span><span class="lines">@@ -161,7 +161,7 @@
</span><span class="cx">
</span><span class="cx"> void startBufferingTimerIfNeeded();
</span><span class="cx"> void bufferingTimerFired();
</span><del>- bool sendBufferMaybeAborting(WebCore::SharedBuffer&, size_t encodedDataLength);
</del><ins>+ bool sendBufferMaybeAborting(const WebCore::SharedBuffer&, size_t encodedDataLength);
</ins><span class="cx">
</span><span class="cx"> bool isSynchronous() const;
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceWebKit2NetworkProcesscacheNetworkCachecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCache.cpp (181969 => 181970)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCache.cpp        2015-03-25 19:35:49 UTC (rev 181969)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCache.cpp        2015-03-25 20:59:18 UTC (rev 181970)
</span><span class="lines">@@ -29,21 +29,17 @@
</span><span class="cx"> #if ENABLE(NETWORK_CACHE)
</span><span class="cx">
</span><span class="cx"> #include "Logging.h"
</span><del>-#include "NetworkCacheCoders.h"
</del><span class="cx"> #include "NetworkCacheStatistics.h"
</span><span class="cx"> #include "NetworkCacheStorage.h"
</span><del>-#include "NetworkResourceLoader.h"
-#include "WebCoreArgumentCoders.h"
-#include <JavaScriptCore/JSONObject.h>
</del><span class="cx"> #include <WebCore/CacheValidation.h>
</span><span class="cx"> #include <WebCore/FileSystem.h>
</span><span class="cx"> #include <WebCore/HTTPHeaderNames.h>
</span><span class="cx"> #include <WebCore/NetworkStorageSession.h>
</span><span class="cx"> #include <WebCore/PlatformCookieJar.h>
</span><ins>+#include <WebCore/ResourceRequest.h>
</ins><span class="cx"> #include <WebCore/ResourceResponse.h>
</span><span class="cx"> #include <WebCore/SharedBuffer.h>
</span><span class="cx"> #include <wtf/NeverDestroyed.h>
</span><del>-#include <wtf/StringHasher.h>
</del><span class="cx"> #include <wtf/text/StringBuilder.h>
</span><span class="cx">
</span><span class="cx"> #if PLATFORM(COCOA)
</span><span class="lines">@@ -110,37 +106,21 @@
</span><span class="cx"> return request.httpHeaderField(headerName);
</span><span class="cx"> }
</span><span class="cx">
</span><del>-static Storage::Entry encodeStorageEntry(const WebCore::ResourceRequest& request, const WebCore::ResourceResponse& response, PassRefPtr<WebCore::SharedBuffer> responseData)
</del><ins>+static Vector<std::pair<String, String>> collectVaryingRequestHeaders(const WebCore::ResourceRequest& request, const WebCore::ResourceResponse& response)
</ins><span class="cx"> {
</span><del>- Encoder encoder;
- encoder << response;
-
</del><span class="cx"> String varyValue = response.httpHeaderField(WebCore::HTTPHeaderName::Vary);
</span><del>- bool hasVaryingRequestHeaders = !varyValue.isEmpty();
-
- encoder << hasVaryingRequestHeaders;
-
- if (hasVaryingRequestHeaders) {
- Vector<String> varyingHeaderNames;
- varyValue.split(',', false, varyingHeaderNames);
-
- Vector<std::pair<String, String>> varyingRequestHeaders;
- for (auto& varyHeaderName : varyingHeaderNames) {
- String headerName = varyHeaderName.stripWhiteSpace();
- String headerValue = headerValueForVary(request, headerName);
- varyingRequestHeaders.append(std::make_pair(headerName, headerValue));
- }
- encoder << varyingRequestHeaders;
</del><ins>+ if (varyValue.isEmpty())
+ return { };
+ Vector<String> varyingHeaderNames;
+ varyValue.split(',', /*allowEmptyEntries*/ false, varyingHeaderNames);
+ Vector<std::pair<String, String>> varyingRequestHeaders;
+ varyingRequestHeaders.reserveCapacity(varyingHeaderNames.size());
+ for (auto& varyHeaderName : varyingHeaderNames) {
+ String headerName = varyHeaderName.stripWhiteSpace();
+ String headerValue = headerValueForVary(request, headerName);
+ varyingRequestHeaders.append(std::make_pair(headerName, headerValue));
</ins><span class="cx"> }
</span><del>- encoder.encodeChecksum();
-
- auto timeStamp = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch());
- Data header(encoder.buffer(), encoder.bufferSize());
- Data body;
- if (responseData)
- body = { reinterpret_cast<const uint8_t*>(responseData->data()), responseData->size() };
-
- return { makeCacheKey(request), timeStamp, header, body };
</del><ins>+ return varyingRequestHeaders;
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> static bool verifyVaryingRequestHeaders(const Vector<std::pair<String, String>>& varyingRequestHeaders, const WebCore::ResourceRequest& request)
</span><span class="lines">@@ -170,77 +150,29 @@
</span><span class="cx"> return false;
</span><span class="cx"> }
</span><span class="cx">
</span><del>-static std::unique_ptr<Entry> decodeStorageEntry(const Storage::Entry& storageEntry, const WebCore::ResourceRequest& request, CachedEntryReuseFailure& failure)
</del><ins>+static UseDecision canUse(const Entry& entry, const WebCore::ResourceRequest& request)
</ins><span class="cx"> {
</span><del>- Decoder decoder(storageEntry.header.data(), storageEntry.header.size());
-
- WebCore::ResourceResponse cachedResponse;
- if (!decoder.decode(cachedResponse)) {
- LOG(NetworkCache, "(NetworkProcess) response decoding failed\n");
- failure = CachedEntryReuseFailure::Other;
- return nullptr;
</del><ins>+ if (!verifyVaryingRequestHeaders(entry.varyingRequestHeaders(), request)) {
+ LOG(NetworkCache, "(NetworkProcess) varying header mismatch\n");
+ return UseDecision::NoDueToVaryingHeaderMismatch;
</ins><span class="cx"> }
</span><span class="cx">
</span><del>- bool hasVaryingRequestHeaders;
- if (!decoder.decode(hasVaryingRequestHeaders)) {
- failure = CachedEntryReuseFailure::Other;
- return nullptr;
- }
-
- if (hasVaryingRequestHeaders) {
- Vector<std::pair<String, String>> varyingRequestHeaders;
- if (!decoder.decode(varyingRequestHeaders)) {
- failure = CachedEntryReuseFailure::Other;
- return nullptr;
- }
-
- if (!verifyVaryingRequestHeaders(varyingRequestHeaders, request)) {
- LOG(NetworkCache, "(NetworkProcess) varying header mismatch\n");
- failure = CachedEntryReuseFailure::VaryingHeaderMismatch;
- return nullptr;
- }
- }
- if (!decoder.verifyChecksum()) {
- LOG(NetworkCache, "(NetworkProcess) checksum verification failure\n");
- failure = CachedEntryReuseFailure::Other;
- return nullptr;
- }
-
</del><span class="cx"> bool allowExpired = cachePolicyAllowsExpired(request.cachePolicy());
</span><del>- auto timeStamp = std::chrono::duration_cast<std::chrono::duration<double>>(storageEntry.timeStamp);
- double age = WebCore::computeCurrentAge(cachedResponse, timeStamp.count());
- double lifetime = WebCore::computeFreshnessLifetimeForHTTPFamily(cachedResponse, timeStamp.count());
</del><ins>+ auto doubleTimeStamp = std::chrono::duration<double>(entry.timeStamp());
+ double age = WebCore::computeCurrentAge(entry.response(), doubleTimeStamp.count());
+ double lifetime = WebCore::computeFreshnessLifetimeForHTTPFamily(entry.response(), doubleTimeStamp.count());
</ins><span class="cx"> bool isExpired = age > lifetime;
</span><span class="cx"> // We never revalidate in the case of a history navigation (i.e. allowExpired is true).
</span><del>- bool needsRevalidation = !allowExpired && (cachedResponse.cacheControlContainsNoCache() || isExpired);
</del><ins>+ bool needsRevalidation = !allowExpired && (entry.response().cacheControlContainsNoCache() || isExpired);
+ if (!needsRevalidation)
+ return UseDecision::Use;
</ins><span class="cx">
</span><del>- if (needsRevalidation) {
- bool hasValidatorFields = cachedResponse.hasCacheValidatorFields();
- LOG(NetworkCache, "(NetworkProcess) needsRevalidation hasValidatorFields=%d isExpired=%d age=%f lifetime=%f", isExpired, hasValidatorFields, age, lifetime);
- if (!hasValidatorFields) {
- failure = CachedEntryReuseFailure::MissingValidatorFields;
- return nullptr;
- }
- }
</del><ins>+ bool hasValidatorFields = entry.response().hasCacheValidatorFields();
+ LOG(NetworkCache, "(NetworkProcess) needsRevalidation hasValidatorFields=%d isExpired=%d age=%f lifetime=%f", isExpired, hasValidatorFields, age, lifetime);
+ if (!hasValidatorFields)
+ return UseDecision::NoDueToMissingValidatorFields;
</ins><span class="cx">
</span><del>- auto entry = std::make_unique<Entry>();
- entry->storageEntry = storageEntry;
- entry->needsRevalidation = needsRevalidation;
-
- cachedResponse.setSource(needsRevalidation ? WebCore::ResourceResponse::Source::DiskCacheAfterValidation : WebCore::ResourceResponse::Source::DiskCache);
- entry->response = cachedResponse;
-
-#if ENABLE(SHAREABLE_RESOURCE)
- RefPtr<SharedMemory> sharedMemory = storageEntry.body.isMap() ? SharedMemory::createFromVMBuffer(const_cast<uint8_t*>(storageEntry.body.data()), storageEntry.body.size()) : nullptr;
- RefPtr<ShareableResource> shareableResource = sharedMemory ? ShareableResource::create(sharedMemory.release(), 0, storageEntry.body.size()) : nullptr;
-
- if (shareableResource && shareableResource->createHandle(entry->shareableResourceHandle))
- entry->buffer = entry->shareableResourceHandle.tryWrapInSharedBuffer();
- else
-#endif
- entry->buffer = WebCore::SharedBuffer::create(storageEntry.body.data(), storageEntry.body.size());
-
- return entry;
</del><ins>+ return UseDecision::Validate;
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> static RetrieveDecision canRetrieve(const WebCore::ResourceRequest& request)
</span><span class="lines">@@ -280,8 +212,8 @@
</span><span class="cx"> auto startTime = std::chrono::system_clock::now();
</span><span class="cx"> unsigned priority = originalRequest.priority();
</span><span class="cx">
</span><del>- m_storage->retrieve(storageKey, priority, [this, originalRequest, completionHandler, startTime, storageKey, webPageID](std::unique_ptr<Storage::Entry> entry) {
- if (!entry) {
</del><ins>+ m_storage->retrieve(storageKey, priority, [this, originalRequest, completionHandler, startTime, storageKey, webPageID](std::unique_ptr<Storage::Entry> storageEntry) {
+ if (!storageEntry) {
</ins><span class="cx"> LOG(NetworkCache, "(NetworkProcess) not found in storage");
</span><span class="cx">
</span><span class="cx"> if (m_statistics)
</span><span class="lines">@@ -290,20 +222,31 @@
</span><span class="cx"> completionHandler(nullptr);
</span><span class="cx"> return false;
</span><span class="cx"> }
</span><del>- ASSERT(entry->key == storageKey);
</del><span class="cx">
</span><del>- CachedEntryReuseFailure failure = CachedEntryReuseFailure::None;
- auto decodedEntry = decodeStorageEntry(*entry, originalRequest, failure);
- bool success = !!decodedEntry;
- if (m_statistics)
- m_statistics->recordRetrievedCachedEntry(webPageID, storageKey, originalRequest, failure);
</del><ins>+ ASSERT(storageEntry->key == storageKey);
</ins><span class="cx">
</span><ins>+ auto cacheEntry = Entry::decode(*storageEntry);
+
+ auto useDecision = cacheEntry ? canUse(*cacheEntry, originalRequest) : UseDecision::NoDueToDecodeFailure;
+ switch (useDecision) {
+ case UseDecision::Use:
+ break;
+ case UseDecision::Validate:
+ cacheEntry->setNeedsValidation();
+ break;
+ default:
+ cacheEntry = nullptr;
+ };
+
</ins><span class="cx"> #if !LOG_DISABLED
</span><span class="cx"> auto elapsedMS = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now() - startTime).count();
</span><span class="cx"> #endif
</span><del>- LOG(NetworkCache, "(NetworkProcess) retrieve complete success=%d priority=%u time=%lldms", success, originalRequest.priority(), elapsedMS);
- completionHandler(WTF::move(decodedEntry));
- return success;
</del><ins>+ LOG(NetworkCache, "(NetworkProcess) retrieve complete useDecision=%d priority=%u time=%lldms", useDecision, originalRequest.priority(), elapsedMS);
+ completionHandler(WTF::move(cacheEntry));
+
+ if (m_statistics)
+ m_statistics->recordRetrievedCachedEntry(webPageID, storageKey, originalRequest, useDecision);
+ return useDecision != UseDecision::NoDueToDecodeFailure;
</ins><span class="cx"> });
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -356,8 +299,10 @@
</span><span class="cx"> return;
</span><span class="cx"> }
</span><span class="cx">
</span><del>- auto storageEntry = encodeStorageEntry(originalRequest, response, WTF::move(responseData));
</del><ins>+ Entry cacheEntry(makeCacheKey(originalRequest), response, WTF::move(responseData), collectVaryingRequestHeaders(originalRequest, response));
</ins><span class="cx">
</span><ins>+ auto storageEntry = cacheEntry.encode();
+
</ins><span class="cx"> m_storage->store(storageEntry, [completionHandler](bool success, const Data& bodyData) {
</span><span class="cx"> MappedBody mappedBody;
</span><span class="cx"> #if ENABLE(SHAREABLE_RESOURCE)
</span><span class="lines">@@ -373,16 +318,18 @@
</span><span class="cx"> });
</span><span class="cx"> }
</span><span class="cx">
</span><del>-void Cache::update(const WebCore::ResourceRequest& originalRequest, const Entry& entry, const WebCore::ResourceResponse& validatingResponse)
</del><ins>+void Cache::update(const WebCore::ResourceRequest& originalRequest, const Entry& existingEntry, const WebCore::ResourceResponse& validatingResponse)
</ins><span class="cx"> {
</span><span class="cx"> LOG(NetworkCache, "(NetworkProcess) updating %s", originalRequest.url().string().latin1().data());
</span><span class="cx">
</span><del>- WebCore::ResourceResponse response = entry.response;
</del><ins>+ WebCore::ResourceResponse response = existingEntry.response();
</ins><span class="cx"> WebCore::updateResponseHeadersAfterRevalidation(response, validatingResponse);
</span><span class="cx">
</span><del>- auto updateEntry = encodeStorageEntry(originalRequest, response, entry.buffer);
</del><ins>+ Entry updateEntry(existingEntry.key(), response, existingEntry.buffer(), collectVaryingRequestHeaders(originalRequest, response));
</ins><span class="cx">
</span><del>- m_storage->update(updateEntry, entry.storageEntry, [](bool success, const Data&) {
</del><ins>+ auto updateStorageEntry = updateEntry.encode();
+
+ m_storage->update(updateStorageEntry, existingEntry.sourceStorageEntry(), [](bool success, const Data&) {
</ins><span class="cx"> LOG(NetworkCache, "(NetworkProcess) updated, success=%d", success);
</span><span class="cx"> });
</span><span class="cx"> }
</span><span class="lines">@@ -398,20 +345,17 @@
</span><span class="cx"> {
</span><span class="cx"> ASSERT(isEnabled());
</span><span class="cx">
</span><del>- m_storage->traverse([traverseHandler](const Storage::Entry* entry) {
- if (!entry) {
</del><ins>+ m_storage->traverse([traverseHandler](const Storage::Entry* storageEntry) {
+ if (!storageEntry) {
</ins><span class="cx"> traverseHandler(nullptr);
</span><span class="cx"> return;
</span><span class="cx"> }
</span><span class="cx">
</span><del>- Entry cacheEntry;
- cacheEntry.storageEntry = *entry;
-
- Decoder decoder(cacheEntry.storageEntry.header.data(), cacheEntry.storageEntry.header.size());
- if (!decoder.decode(cacheEntry.response))
</del><ins>+ auto cacheEntry = Entry::decode(*storageEntry);
+ if (!cacheEntry)
</ins><span class="cx"> return;
</span><span class="cx">
</span><del>- traverseHandler(&cacheEntry);
</del><ins>+ traverseHandler(cacheEntry.get());
</ins><span class="cx"> });
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -420,41 +364,6 @@
</span><span class="cx"> return WebCore::pathByAppendingComponent(m_storage->baseDirectoryPath(), "dump.json");
</span><span class="cx"> }
</span><span class="cx">
</span><del>-static bool entryAsJSON(StringBuilder& json, const Storage::Entry& entry)
-{
- Decoder decoder(entry.header.data(), entry.header.size());
- WebCore::ResourceResponse cachedResponse;
- if (!decoder.decode(cachedResponse))
- return false;
- json.append("{\n");
- json.append("\"hash\": ");
- JSC::appendQuotedJSONStringToBuilder(json, entry.key.hashAsString());
- json.append(",\n");
- json.append("\"partition\": ");
- JSC::appendQuotedJSONStringToBuilder(json, entry.key.partition());
- json.append(",\n");
- json.append("\"timestamp\": ");
- json.appendNumber(entry.timeStamp.count());
- json.append(",\n");
- json.append("\"URL\": ");
- JSC::appendQuotedJSONStringToBuilder(json, cachedResponse.url().string());
- json.append(",\n");
- json.append("\"headers\": {\n");
- bool firstHeader = true;
- for (auto& header : cachedResponse.httpHeaderFields()) {
- if (!firstHeader)
- json.append(",\n");
- firstHeader = false;
- json.append(" ");
- JSC::appendQuotedJSONStringToBuilder(json, header.key);
- json.append(": ");
- JSC::appendQuotedJSONStringToBuilder(json, header.value);
- }
- json.append("\n}\n");
- json.append("}");
- return true;
-}
-
</del><span class="cx"> void Cache::dumpContentsToFile()
</span><span class="cx"> {
</span><span class="cx"> if (!m_storage)
</span><span class="lines">@@ -470,9 +379,11 @@
</span><span class="cx"> WebCore::closeFile(handle);
</span><span class="cx"> return;
</span><span class="cx"> }
</span><del>- StringBuilder json;
- if (!entryAsJSON(json, *entry))
</del><ins>+ auto cacheEntry = Entry::decode(*entry);
+ if (!cacheEntry)
</ins><span class="cx"> return;
</span><ins>+ StringBuilder json;
+ cacheEntry->asJSON(json);
</ins><span class="cx"> json.append(",\n");
</span><span class="cx"> auto writeData = json.toString().utf8();
</span><span class="cx"> WebCore::writeToFile(dumpFileHandle, writeData.data(), writeData.length());
</span></span></pre></div>
<a id="trunkSourceWebKit2NetworkProcesscacheNetworkCacheh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCache.h (181969 => 181970)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCache.h        2015-03-25 19:35:49 UTC (rev 181969)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCache.h        2015-03-25 20:59:18 UTC (rev 181970)
</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 "NetworkCacheEntry.h"
</ins><span class="cx"> #include "NetworkCacheStorage.h"
</span><span class="cx"> #include "ShareableResource.h"
</span><span class="cx"> #include <WebCore/ResourceResponse.h>
</span><span class="lines">@@ -54,16 +55,6 @@
</span><span class="cx"> #endif
</span><span class="cx"> };
</span><span class="cx">
</span><del>-struct Entry {
- Storage::Entry storageEntry;
- WebCore::ResourceResponse response;
- RefPtr<WebCore::SharedBuffer> buffer;
-#if ENABLE(SHAREABLE_RESOURCE)
- ShareableResource::Handle shareableResourceHandle;
-#endif
- bool needsRevalidation;
-};
-
</del><span class="cx"> enum class RetrieveDecision {
</span><span class="cx"> Yes,
</span><span class="cx"> NoDueToHTTPMethod,
</span><span class="lines">@@ -80,11 +71,12 @@
</span><span class="cx"> NoDueToHTTPStatusCode
</span><span class="cx"> };
</span><span class="cx">
</span><del>-enum class CachedEntryReuseFailure {
- None,
- VaryingHeaderMismatch,
- MissingValidatorFields,
- Other,
</del><ins>+enum class UseDecision {
+ Use,
+ Validate,
+ NoDueToVaryingHeaderMismatch,
+ NoDueToMissingValidatorFields,
+ NoDueToDecodeFailure,
</ins><span class="cx"> };
</span><span class="cx">
</span><span class="cx"> class Cache {
</span></span></pre></div>
<a id="trunkSourceWebKit2NetworkProcesscacheNetworkCacheEntrycpp"></a>
<div class="addfile"><h4>Added: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheEntry.cpp (0 => 181970)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheEntry.cpp         (rev 0)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheEntry.cpp        2015-03-25 20:59:18 UTC (rev 181970)
</span><span class="lines">@@ -0,0 +1,180 @@
</span><ins>+/*
+ * Copyright (C) 2015 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "NetworkCache.h"
+
+#include "Logging.h"
+#include "NetworkCacheCoders.h"
+#include "NetworkCacheDecoder.h"
+#include "NetworkCacheEncoder.h"
+#include <JavaScriptCore/JSONObject.h>
+#include <WebCore/ResourceRequest.h>
+#include <WebCore/SharedBuffer.h>
+#include <wtf/text/StringBuilder.h>
+
+#if ENABLE(NETWORK_CACHE)
+
+namespace WebKit {
+namespace NetworkCache {
+
+Entry::Entry(const Key& key, const WebCore::ResourceResponse& response, RefPtr<WebCore::SharedBuffer>&& buffer, const Vector<std::pair<String, String>>& varyingRequestHeaders)
+ : m_key(key)
+ , m_timeStamp(std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()))
+ , m_response(response)
+ , m_varyingRequestHeaders(varyingRequestHeaders)
+ , m_buffer(WTF::move(buffer))
+{
+}
+
+Entry::Entry(const Storage::Entry& storageEntry)
+ : m_key(storageEntry.key)
+ , m_timeStamp(storageEntry.timeStamp)
+ , m_sourceStorageEntry(storageEntry)
+{
+}
+
+Storage::Entry Entry::encode() const
+{
+ Encoder encoder;
+ encoder << m_response;
+
+ bool hasVaryingRequestHeaders = !m_varyingRequestHeaders.isEmpty();
+ encoder << hasVaryingRequestHeaders;
+ if (hasVaryingRequestHeaders)
+ encoder << m_varyingRequestHeaders;
+
+ encoder.encodeChecksum();
+
+ Data header(encoder.buffer(), encoder.bufferSize());
+ Data body;
+ if (m_buffer)
+ body = { reinterpret_cast<const uint8_t*>(m_buffer->data()), m_buffer->size() };
+
+ return { m_key, m_timeStamp, header, body };
+}
+
+std::unique_ptr<Entry> Entry::decode(const Storage::Entry& storageEntry)
+{
+ std::unique_ptr<Entry> entry(new Entry(storageEntry));
+
+ Decoder decoder(storageEntry.header.data(), storageEntry.header.size());
+ if (!decoder.decode(entry->m_response))
+ return nullptr;
+ entry->m_response.setSource(WebCore::ResourceResponse::Source::DiskCache);
+
+ bool hasVaryingRequestHeaders;
+ if (!decoder.decode(hasVaryingRequestHeaders))
+ return nullptr;
+
+ if (hasVaryingRequestHeaders) {
+ if (!decoder.decode(entry->m_varyingRequestHeaders))
+ return nullptr;
+ }
+
+ if (!decoder.verifyChecksum()) {
+ LOG(NetworkCache, "(NetworkProcess) checksum verification failure\n");
+ return nullptr;
+ }
+
+ return entry;
+}
+
+void Entry::initializeBufferFromStorageEntry() const
+{
+ auto* data = m_sourceStorageEntry.body.data();
+ size_t size = m_sourceStorageEntry.body.size();
+#if ENABLE(SHAREABLE_RESOURCE)
+ RefPtr<SharedMemory> sharedMemory = m_sourceStorageEntry.body.isMap() ? SharedMemory::createFromVMBuffer(const_cast<uint8_t*>(data), size) : nullptr;
+ RefPtr<ShareableResource> shareableResource = sharedMemory ? ShareableResource::create(sharedMemory.release(), 0, m_sourceStorageEntry.body.size()) : nullptr;
+
+ if (shareableResource && shareableResource->createHandle(m_shareableResourceHandle))
+ m_buffer = m_shareableResourceHandle.tryWrapInSharedBuffer();
+#endif
+ if (!m_buffer)
+ m_buffer = WebCore::SharedBuffer::create(data, size);
+}
+
+WebCore::SharedBuffer* Entry::buffer() const
+{
+ if (!m_buffer)
+ initializeBufferFromStorageEntry();
+
+ return m_buffer.get();
+}
+
+ShareableResource::Handle& Entry::shareableResourceHandle() const
+{
+ if (!m_buffer)
+ initializeBufferFromStorageEntry();
+
+ return m_shareableResourceHandle;
+}
+
+bool Entry::needsValidation() const
+{
+ return m_response.source() == WebCore::ResourceResponse::Source::DiskCacheAfterValidation;
+}
+
+void Entry::setNeedsValidation()
+{
+ ASSERT(m_response.source() == WebCore::ResourceResponse::Source::DiskCache);
+ m_response.setSource(WebCore::ResourceResponse::Source::DiskCacheAfterValidation);
+}
+
+void Entry::asJSON(StringBuilder& json) const
+{
+ json.appendLiteral("{\n");
+ json.appendLiteral("\"hash\": ");
+ JSC::appendQuotedJSONStringToBuilder(json, m_key.hashAsString());
+ json.appendLiteral(",\n");
+ json.appendLiteral("\"partition\": ");
+ JSC::appendQuotedJSONStringToBuilder(json, m_key.partition());
+ json.appendLiteral(",\n");
+ json.appendLiteral("\"timestamp\": ");
+ json.appendNumber(m_timeStamp.count());
+ json.appendLiteral(",\n");
+ json.appendLiteral("\"URL\": ");
+ JSC::appendQuotedJSONStringToBuilder(json, m_response.url().string());
+ json.appendLiteral(",\n");
+ json.appendLiteral("\"headers\": {\n");
+ bool firstHeader = true;
+ for (auto& header : m_response.httpHeaderFields()) {
+ if (!firstHeader)
+ json.appendLiteral(",\n");
+ firstHeader = false;
+ json.appendLiteral(" ");
+ JSC::appendQuotedJSONStringToBuilder(json, header.key);
+ json.appendLiteral(": ");
+ JSC::appendQuotedJSONStringToBuilder(json, header.value);
+ }
+ json.appendLiteral("\n}\n");
+ json.appendLiteral("}");
+}
+
+}
+}
+
+#endif
</ins></span></pre></div>
<a id="trunkSourceWebKit2NetworkProcesscacheNetworkCacheEntryh"></a>
<div class="addfile"><h4>Added: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheEntry.h (0 => 181970)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheEntry.h         (rev 0)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheEntry.h        2015-03-25 20:59:18 UTC (rev 181970)
</span><span class="lines">@@ -0,0 +1,91 @@
</span><ins>+/*
+ * Copyright (C) 2015 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef NetworkCacheEntry_h
+#define NetworkCacheEntry_h
+
+#if ENABLE(NETWORK_CACHE)
+
+#include "NetworkCacheStorage.h"
+#include "ShareableResource.h"
+#include <WebCore/ResourceResponse.h>
+#include <wtf/Noncopyable.h>
+#include <wtf/text/WTFString.h>
+
+namespace WebCore {
+class ResourceRequest;
+class SharedBuffer;
+}
+
+namespace WebKit {
+namespace NetworkCache {
+
+class Entry {
+ WTF_MAKE_NONCOPYABLE(Entry); WTF_MAKE_FAST_ALLOCATED;
+public:
+ Entry(const Key&, const WebCore::ResourceResponse&, RefPtr<WebCore::SharedBuffer>&&, const Vector<std::pair<String, String>>& varyingRequestHeaders);
+
+ Storage::Entry encode() const;
+ static std::unique_ptr<Entry> decode(const Storage::Entry&);
+
+ const Key& key() const { return m_key; }
+ std::chrono::milliseconds timeStamp() const { return m_timeStamp; }
+ const WebCore::ResourceResponse& response() const { return m_response; }
+ const Vector<std::pair<String, String>>& varyingRequestHeaders() const { return m_varyingRequestHeaders; }
+
+ WebCore::SharedBuffer* buffer() const;
+#if ENABLE(SHAREABLE_RESOURCE)
+ ShareableResource::Handle& shareableResourceHandle() const;
+#endif
+
+ bool needsValidation() const;
+ void setNeedsValidation();
+
+ const Storage::Entry& sourceStorageEntry() const { return m_sourceStorageEntry; }
+
+ void asJSON(StringBuilder&) const;
+
+private:
+ Entry(const Storage::Entry&);
+ void initializeBufferFromStorageEntry() const;
+
+ Key m_key;
+ std::chrono::milliseconds m_timeStamp;
+ WebCore::ResourceResponse m_response;
+ Vector<std::pair<String, String>> m_varyingRequestHeaders;
+
+ mutable RefPtr<WebCore::SharedBuffer> m_buffer;
+#if ENABLE(SHAREABLE_RESOURCE)
+ mutable ShareableResource::Handle m_shareableResourceHandle;
+#endif
+
+ Storage::Entry m_sourceStorageEntry { };
+};
+
+}
+}
+
+#endif
+#endif
</ins></span></pre></div>
<a id="trunkSourceWebKit2NetworkProcesscacheNetworkCacheStatisticsh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStatistics.h (181969 => 181970)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStatistics.h        2015-03-25 19:35:49 UTC (rev 181969)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStatistics.h        2015-03-25 20:59:18 UTC (rev 181970)
</span><span class="lines">@@ -51,7 +51,7 @@
</span><span class="cx"> void recordNotCachingResponse(const Key&, StoreDecision);
</span><span class="cx"> void recordNotUsingCacheForRequest(uint64_t webPageID, const Key&, const WebCore::ResourceRequest&, RetrieveDecision);
</span><span class="cx"> void recordRetrievalFailure(uint64_t webPageID, const Key&, const WebCore::ResourceRequest&);
</span><del>- void recordRetrievedCachedEntry(uint64_t webPageID, const Key&, const WebCore::ResourceRequest&, CachedEntryReuseFailure);
</del><ins>+ void recordRetrievedCachedEntry(uint64_t webPageID, const Key&, const WebCore::ResourceRequest&, UseDecision);
</ins><span class="cx">
</span><span class="cx"> private:
</span><span class="cx"> explicit Statistics(const String& databasePath);
</span></span></pre></div>
<a id="trunkSourceWebKit2NetworkProcesscacheNetworkCacheStatisticsCocoamm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStatisticsCocoa.mm (181969 => 181970)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStatisticsCocoa.mm        2015-03-25 19:35:49 UTC (rev 181969)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStatisticsCocoa.mm        2015-03-25 20:59:18 UTC (rev 181970)
</span><span class="lines">@@ -262,32 +262,33 @@
</span><span class="cx"> });
</span><span class="cx"> }
</span><span class="cx">
</span><del>-static String cachedEntryReuseFailureToDiagnosticKey(CachedEntryReuseFailure failure)
</del><ins>+static String cachedEntryReuseFailureToDiagnosticKey(UseDecision decision)
</ins><span class="cx"> {
</span><del>- switch (failure) {
- case CachedEntryReuseFailure::VaryingHeaderMismatch:
</del><ins>+ switch (decision) {
+ case UseDecision::NoDueToVaryingHeaderMismatch:
</ins><span class="cx"> return WebCore::DiagnosticLoggingKeys::varyingHeaderMismatchKey();
</span><del>- case CachedEntryReuseFailure::MissingValidatorFields:
</del><ins>+ case UseDecision::NoDueToMissingValidatorFields:
</ins><span class="cx"> return WebCore::DiagnosticLoggingKeys::missingValidatorFieldsKey();
</span><del>- case CachedEntryReuseFailure::Other:
</del><ins>+ case UseDecision::NoDueToDecodeFailure:
</ins><span class="cx"> return WebCore::DiagnosticLoggingKeys::otherKey();
</span><del>- case CachedEntryReuseFailure::None:
</del><ins>+ case UseDecision::Use:
+ case UseDecision::Validate:
</ins><span class="cx"> ASSERT_NOT_REACHED();
</span><span class="cx"> break;
</span><span class="cx"> }
</span><span class="cx"> return emptyString();
</span><span class="cx"> }
</span><span class="cx">
</span><del>-void Statistics::recordRetrievedCachedEntry(uint64_t webPageID, const Key& key, const WebCore::ResourceRequest& request, CachedEntryReuseFailure failure)
</del><ins>+void Statistics::recordRetrievedCachedEntry(uint64_t webPageID, const Key& key, const WebCore::ResourceRequest& request, UseDecision decision)
</ins><span class="cx"> {
</span><span class="cx"> WebCore::URL requestURL = request.url();
</span><del>- if (failure == CachedEntryReuseFailure::None) {
</del><ins>+ if (decision == UseDecision::Use || decision == UseDecision::Validate) {
</ins><span class="cx"> LOG(NetworkCache, "(NetworkProcess) webPageID %llu: %s is in the cache and is used", webPageID, requestURL.string().ascii().data());
</span><span class="cx"> NetworkProcess::singleton().logDiagnosticMessageWithResult(webPageID, WebCore::DiagnosticLoggingKeys::networkCacheKey(), WebCore::DiagnosticLoggingKeys::retrievalKey(), WebCore::DiagnosticLoggingResultPass, WebCore::ShouldSample::Yes);
</span><span class="cx"> return;
</span><span class="cx"> }
</span><span class="cx">
</span><del>- String diagnosticKey = cachedEntryReuseFailureToDiagnosticKey(failure);
</del><ins>+ String diagnosticKey = cachedEntryReuseFailureToDiagnosticKey(decision);
</ins><span class="cx"> LOG(NetworkCache, "(NetworkProcess) webPageID %llu: %s is in the cache but wasn't used, reason: %s", webPageID, requestURL.string().ascii().data(), diagnosticKey.utf8().data());
</span><span class="cx"> NetworkProcess::singleton().logDiagnosticMessageWithValue(webPageID, WebCore::DiagnosticLoggingKeys::networkCacheKey(), WebCore::DiagnosticLoggingKeys::unusableCachedEntryKey(), diagnosticKey, WebCore::ShouldSample::Yes);
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebKit2WebKit2xcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj (181969 => 181970)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj        2015-03-25 19:35:49 UTC (rev 181969)
+++ trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj        2015-03-25 20:59:18 UTC (rev 181970)
</span><span class="lines">@@ -1766,6 +1766,8 @@
</span><span class="cx">                 E1E552C516AE065F004ED653 /* SandboxInitializationParameters.h in Headers */ = {isa = PBXBuildFile; fileRef = E1E552C316AE065E004ED653 /* SandboxInitializationParameters.h */; };
</span><span class="cx">                 E1EE53E311F8CFC000CCBEE4 /* InjectedBundlePageEditorClient.h in Headers */ = {isa = PBXBuildFile; fileRef = E1EE53DC11F8CF9F00CCBEE4 /* InjectedBundlePageEditorClient.h */; };
</span><span class="cx">                 E1EE53E711F8CFFB00CCBEE4 /* InjectedBundlePageEditorClient.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E1EE53E611F8CFFB00CCBEE4 /* InjectedBundlePageEditorClient.cpp */; };
</span><ins>+                E413F59D1AC1ADC400345360 /* NetworkCacheEntry.h in Headers */ = {isa = PBXBuildFile; fileRef = E413F59B1AC1ADB600345360 /* NetworkCacheEntry.h */; };
+                E413F59F1AC1AF9D00345360 /* NetworkCacheEntry.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E413F59E1AC1AF9D00345360 /* NetworkCacheEntry.cpp */; };
</ins><span class="cx">                 E42E060F1AA7523400B11699 /* NetworkCacheIOChannelCocoa.mm in Sources */ = {isa = PBXBuildFile; fileRef = E42E060D1AA750E500B11699 /* NetworkCacheIOChannelCocoa.mm */; };
</span><span class="cx">                 E42E06101AA7523B00B11699 /* NetworkCacheIOChannel.h in Headers */ = {isa = PBXBuildFile; fileRef = E42E060B1AA7440D00B11699 /* NetworkCacheIOChannel.h */; };
</span><span class="cx">                 E42E06121AA75ABD00B11699 /* NetworkCacheData.h in Headers */ = {isa = PBXBuildFile; fileRef = E42E06111AA75ABD00B11699 /* NetworkCacheData.h */; };
</span><span class="lines">@@ -4015,6 +4017,8 @@
</span><span class="cx">                 E1EE53E611F8CFFB00CCBEE4 /* InjectedBundlePageEditorClient.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InjectedBundlePageEditorClient.cpp; sourceTree = "<group>"; };
</span><span class="cx">                 E1FEF39A190F76F300731658 /* com.apple.WebKit.Databases.sb.in */ = {isa = PBXFileReference; lastKnownFileType = text; path = com.apple.WebKit.Databases.sb.in; sourceTree = "<group>"; };
</span><span class="cx">                 E1FEF39C190F791C00731658 /* DatabaseProcessIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DatabaseProcessIOS.mm; sourceTree = "<group>"; };
</span><ins>+                E413F59B1AC1ADB600345360 /* NetworkCacheEntry.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NetworkCacheEntry.h; sourceTree = "<group>"; };
+                E413F59E1AC1AF9D00345360 /* NetworkCacheEntry.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NetworkCacheEntry.cpp; sourceTree = "<group>"; };
</ins><span class="cx">                 E42E060B1AA7440D00B11699 /* NetworkCacheIOChannel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NetworkCacheIOChannel.h; sourceTree = "<group>"; };
</span><span class="cx">                 E42E060D1AA750E500B11699 /* NetworkCacheIOChannelCocoa.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = NetworkCacheIOChannelCocoa.mm; sourceTree = "<group>"; };
</span><span class="cx">                 E42E06111AA75ABD00B11699 /* NetworkCacheData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NetworkCacheData.h; sourceTree = "<group>"; };
</span><span class="lines">@@ -7470,6 +7474,8 @@
</span><span class="cx">                                 E489D2871A0A2DB80078C06A /* NetworkCacheDecoder.h */,
</span><span class="cx">                                 E489D2881A0A2DB80078C06A /* NetworkCacheEncoder.cpp */,
</span><span class="cx">                                 E489D2891A0A2DB80078C06A /* NetworkCacheEncoder.h */,
</span><ins>+                                E413F59E1AC1AF9D00345360 /* NetworkCacheEntry.cpp */,
+                                E413F59B1AC1ADB600345360 /* NetworkCacheEntry.h */,
</ins><span class="cx">                                 834B250E1A831A8D00CFB150 /* NetworkCacheFileSystemPosix.h */,
</span><span class="cx">                                 E42E060B1AA7440D00B11699 /* NetworkCacheIOChannel.h */,
</span><span class="cx">                                 E42E060D1AA750E500B11699 /* NetworkCacheIOChannelCocoa.mm */,
</span><span class="lines">@@ -7829,6 +7835,7 @@
</span><span class="cx">                                 1A4A9F3312B844E2008FE984 /* PluginQuirks.h in Headers */,
</span><span class="cx">                                 7CD622781739D863005BD7FF /* PluginSandboxProfile.h in Headers */,
</span><span class="cx">                                 1A6FB7AF11E64B6800DB1371 /* PluginView.h in Headers */,
</span><ins>+                                E413F59D1AC1ADC400345360 /* NetworkCacheEntry.h in Headers */,
</ins><span class="cx">                                 E1CC1B9012D7EADF00625838 /* PrintInfo.h in Headers */,
</span><span class="cx">                                 86F9536518FF58F5001DB2EF /* ProcessAssertion.h in Headers */,
</span><span class="cx">                                 BC1A7C581136E19C00FB7167 /* ProcessLauncher.h in Headers */,
</span><span class="lines">@@ -9383,6 +9390,7 @@
</span><span class="cx">                                 1A2D957012848564001EB962 /* ChildProcess.cpp in Sources */,
</span><span class="cx">                                 BC82837B16B36A4F00A278FE /* ChildProcessEntryPoint.mm in Sources */,
</span><span class="cx">                                 A7E93CED1925331100A1DC48 /* ChildProcessIOS.mm in Sources */,
</span><ins>+                                E413F59F1AC1AF9D00345360 /* NetworkCacheEntry.cpp in Sources */,
</ins><span class="cx">                                 9F54F88F16488E87007DF81A /* ChildProcessMac.mm in Sources */,
</span><span class="cx">                                 E1513C66166EABB200149FCB /* ChildProcessProxy.cpp in Sources */,
</span><span class="cx">                                 1A2A4B0E1586A2240090C9E9 /* ColorSpaceData.mm in Sources */,
</span></span></pre>
</div>
</div>
</body>
</html>