<!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>[182271] trunk/Source</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/182271">182271</a></dd>
<dt>Author</dt> <dd>antti@apple.com</dd>
<dt>Date</dt> <dd>2015-04-02 08:45:58 -0700 (Thu, 02 Apr 2015)</dd>
</dl>
<h3>Log Message</h3>
<pre>Use std::chrono types to represent time in response and cache classes
https://bugs.webkit.org/show_bug.cgi?id=143316
Reviewed by Andreas Kling.
Source/WebCore:
Use std::chrono::system_clock::time_point to represent clock times and std::chrono::microseconds to
represent durations. Also use WTF::Optional for optional values (instead of coding them as NaNs).
* dom/Document.cpp:
(WebCore::Document::lastModified):
* loader/cache/CachedResource.cpp:
(WebCore::CachedResource::CachedResource):
(WebCore::CachedResource::freshnessLifetime):
(WebCore::CachedResource::responseReceived):
(WebCore::CachedResource::updateResponseAfterRevalidation):
* loader/cache/CachedResource.h:
* platform/network/CacheValidation.cpp:
(WebCore::computeCurrentAge):
(WebCore::computeFreshnessLifetimeForHTTPFamily):
(WebCore::updateRedirectChainStatus):
(WebCore::redirectChainAllowsReuse):
(WebCore::parseCacheControlDirectives):
* platform/network/CacheValidation.h:
(WebCore::RedirectChainCacheStatus::RedirectChainCacheStatus):
* platform/network/HTTPParsers.cpp:
(WebCore::parseHTTPDate):
(WebCore::parseDate): Deleted.
* platform/network/HTTPParsers.h:
* platform/network/ResourceResponseBase.cpp:
(WebCore::ResourceResponseBase::ResourceResponseBase):
(WebCore::ResourceResponseBase::cacheControlMaxAge):
(WebCore::parseDateValueInHeader):
(WebCore::ResourceResponseBase::date):
(WebCore::ResourceResponseBase::age):
(WebCore::ResourceResponseBase::expires):
(WebCore::ResourceResponseBase::lastModified):
* platform/network/ResourceResponseBase.h:
Source/WebKit2:
* NetworkProcess/NetworkResourceLoader.cpp:
(WebKit::NetworkResourceLoader::didFinishLoading):
* NetworkProcess/cache/NetworkCache.cpp:
(WebKit::NetworkCache::responseHasExpired):
(WebKit::NetworkCache::responseNeedsRevalidation):
(WebKit::NetworkCache::makeStoreDecision):
(WebKit::NetworkCache::Cache::store):
* NetworkProcess/cache/NetworkCacheEntry.cpp:
(WebKit::NetworkCache::Entry::Entry):
(WebKit::NetworkCache::Entry::asJSON):
* NetworkProcess/cache/NetworkCacheEntry.h:
(WebKit::NetworkCache::Entry::timeStamp):
* NetworkProcess/cache/NetworkCacheStorage.cpp:
(WebKit::NetworkCache::decodeRecordMetaData):
(WebKit::NetworkCache::decodeRecord):
Sanity check the timestamp on decode.
(WebKit::NetworkCache::encodeRecordMetaData):
(WebKit::NetworkCache::encodeRecordHeader):
(WebKit::NetworkCache::Storage::traverse):
* NetworkProcess/cache/NetworkCacheStorage.h:
* WebProcess/Plugins/PluginView.cpp:
(WebKit::lastModifiedDateMS):
(WebKit::PluginView::Stream::didReceiveResponse):
(WebKit::PluginView::manualLoadDidReceiveResponse):
(WebKit::lastModifiedDate): Deleted.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoredomDocumentcpp">trunk/Source/WebCore/dom/Document.cpp</a></li>
<li><a href="#trunkSourceWebCoreloadercacheCachedResourcecpp">trunk/Source/WebCore/loader/cache/CachedResource.cpp</a></li>
<li><a href="#trunkSourceWebCoreloadercacheCachedResourceh">trunk/Source/WebCore/loader/cache/CachedResource.h</a></li>
<li><a href="#trunkSourceWebCoreplatformnetworkCacheValidationcpp">trunk/Source/WebCore/platform/network/CacheValidation.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformnetworkCacheValidationh">trunk/Source/WebCore/platform/network/CacheValidation.h</a></li>
<li><a href="#trunkSourceWebCoreplatformnetworkHTTPParserscpp">trunk/Source/WebCore/platform/network/HTTPParsers.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformnetworkHTTPParsersh">trunk/Source/WebCore/platform/network/HTTPParsers.h</a></li>
<li><a href="#trunkSourceWebCoreplatformnetworkResourceResponseBasecpp">trunk/Source/WebCore/platform/network/ResourceResponseBase.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformnetworkResourceResponseBaseh">trunk/Source/WebCore/platform/network/ResourceResponseBase.h</a></li>
<li><a href="#trunkSourceWebKitwinPluginsPluginStreamcpp">trunk/Source/WebKit/win/Plugins/PluginStream.cpp</a></li>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2NetworkProcessNetworkResourceLoadercpp">trunk/Source/WebKit2/NetworkProcess/NetworkResourceLoader.cpp</a></li>
<li><a href="#trunkSourceWebKit2NetworkProcesscacheNetworkCachecpp">trunk/Source/WebKit2/NetworkProcess/cache/NetworkCache.cpp</a></li>
<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>
<li><a href="#trunkSourceWebKit2NetworkProcesscacheNetworkCacheStoragecpp">trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.cpp</a></li>
<li><a href="#trunkSourceWebKit2NetworkProcesscacheNetworkCacheStorageh">trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.h</a></li>
<li><a href="#trunkSourceWebKit2WebProcessPluginsPluginViewcpp">trunk/Source/WebKit2/WebProcess/Plugins/PluginView.cpp</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (182270 => 182271)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2015-04-02 08:51:23 UTC (rev 182270)
+++ trunk/Source/WebCore/ChangeLog        2015-04-02 15:45:58 UTC (rev 182271)
</span><span class="lines">@@ -1,3 +1,43 @@
</span><ins>+2015-04-01 Antti Koivisto <antti@apple.com>
+
+ Use std::chrono types to represent time in response and cache classes
+ https://bugs.webkit.org/show_bug.cgi?id=143316
+
+ Reviewed by Andreas Kling.
+
+ Use std::chrono::system_clock::time_point to represent clock times and std::chrono::microseconds to
+ represent durations. Also use WTF::Optional for optional values (instead of coding them as NaNs).
+
+ * dom/Document.cpp:
+ (WebCore::Document::lastModified):
+ * loader/cache/CachedResource.cpp:
+ (WebCore::CachedResource::CachedResource):
+ (WebCore::CachedResource::freshnessLifetime):
+ (WebCore::CachedResource::responseReceived):
+ (WebCore::CachedResource::updateResponseAfterRevalidation):
+ * loader/cache/CachedResource.h:
+ * platform/network/CacheValidation.cpp:
+ (WebCore::computeCurrentAge):
+ (WebCore::computeFreshnessLifetimeForHTTPFamily):
+ (WebCore::updateRedirectChainStatus):
+ (WebCore::redirectChainAllowsReuse):
+ (WebCore::parseCacheControlDirectives):
+ * platform/network/CacheValidation.h:
+ (WebCore::RedirectChainCacheStatus::RedirectChainCacheStatus):
+ * platform/network/HTTPParsers.cpp:
+ (WebCore::parseHTTPDate):
+ (WebCore::parseDate): Deleted.
+ * platform/network/HTTPParsers.h:
+ * platform/network/ResourceResponseBase.cpp:
+ (WebCore::ResourceResponseBase::ResourceResponseBase):
+ (WebCore::ResourceResponseBase::cacheControlMaxAge):
+ (WebCore::parseDateValueInHeader):
+ (WebCore::ResourceResponseBase::date):
+ (WebCore::ResourceResponseBase::age):
+ (WebCore::ResourceResponseBase::expires):
+ (WebCore::ResourceResponseBase::lastModified):
+ * platform/network/ResourceResponseBase.h:
+
</ins><span class="cx"> 2015-04-02 Joonghun Park <jh718.park@samsung.com>
</span><span class="cx">
</span><span class="cx"> [CSS MultiColumn] Parse "columns: auto <length>" shorthand property value properly
</span></span></pre></div>
<a id="trunkSourceWebCoredomDocumentcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/Document.cpp (182270 => 182271)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/Document.cpp        2015-04-02 08:51:23 UTC (rev 182270)
+++ trunk/Source/WebCore/dom/Document.cpp        2015-04-02 15:45:58 UTC (rev 182271)
</span><span class="lines">@@ -4131,11 +4131,10 @@
</span><span class="cx"> DateComponents date;
</span><span class="cx"> bool foundDate = false;
</span><span class="cx"> if (m_frame) {
</span><del>- String httpLastModified;
- if (DocumentLoader* documentLoader = loader())
- httpLastModified = documentLoader->response().httpHeaderField(HTTPHeaderName::LastModified);
- if (!httpLastModified.isEmpty()) {
- date.setMillisecondsSinceEpochForDateTime(parseDate(httpLastModified));
</del><ins>+ auto lastModifiedDate = loader() ? loader()->response().lastModified() : Nullopt;
+ if (lastModifiedDate) {
+ using namespace std::chrono;
+ date.setMillisecondsSinceEpochForDateTime(duration_cast<milliseconds>(lastModifiedDate.value().time_since_epoch()).count());
</ins><span class="cx"> foundDate = true;
</span><span class="cx"> }
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebCoreloadercacheCachedResourcecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/loader/cache/CachedResource.cpp (182270 => 182271)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/loader/cache/CachedResource.cpp        2015-04-02 08:51:23 UTC (rev 182270)
+++ trunk/Source/WebCore/loader/cache/CachedResource.cpp        2015-04-02 15:45:58 UTC (rev 182271)
</span><span class="lines">@@ -116,7 +116,7 @@
</span><span class="cx"> , m_decodedDataDeletionTimer(*this, &CachedResource::decodedDataDeletionTimerFired, deadDecodedDataDeletionIntervalForResourceType(type))
</span><span class="cx"> , m_sessionID(sessionID)
</span><span class="cx"> , m_loadPriority(defaultPriorityForResourceType(type))
</span><del>- , m_responseTimestamp(currentTime())
</del><ins>+ , m_responseTimestamp(std::chrono::system_clock::now())
</ins><span class="cx"> , m_lastDecodedAccessTime(0)
</span><span class="cx"> , m_loadFinishTime(0)
</span><span class="cx"> , m_encodedSize(0)
</span><span class="lines">@@ -347,16 +347,16 @@
</span><span class="cx"> return computeCurrentAge(m_response, m_responseTimestamp) > freshnessLifetime(m_response);
</span><span class="cx"> }
</span><span class="cx">
</span><del>-double CachedResource::freshnessLifetime(const ResourceResponse& response) const
</del><ins>+std::chrono::microseconds CachedResource::freshnessLifetime(const ResourceResponse& response) const
</ins><span class="cx"> {
</span><span class="cx"> if (!response.url().protocolIsInHTTPFamily()) {
</span><span class="cx"> // Don't cache non-HTTP main resources since we can't check for freshness.
</span><span class="cx"> // FIXME: We should not cache subresources either, but when we tried this
</span><span class="cx"> // it caused performance and flakiness issues in our test infrastructure.
</span><span class="cx"> if (m_type == MainResource && !SchemeRegistry::shouldCacheResponsesFromURLSchemeIndefinitely(response.url().protocol()))
</span><del>- return 0;
</del><ins>+ return std::chrono::microseconds::zero();
</ins><span class="cx">
</span><del>- return std::numeric_limits<double>::max();
</del><ins>+ return std::chrono::microseconds::max();
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> return computeFreshnessLifetimeForHTTPFamily(response, m_responseTimestamp);
</span><span class="lines">@@ -373,7 +373,7 @@
</span><span class="cx"> void CachedResource::responseReceived(const ResourceResponse& response)
</span><span class="cx"> {
</span><span class="cx"> setResponse(response);
</span><del>- m_responseTimestamp = currentTime();
</del><ins>+ m_responseTimestamp = std::chrono::system_clock::now();
</ins><span class="cx"> String encoding = response.textEncodingName();
</span><span class="cx"> if (!encoding.isNull())
</span><span class="cx"> setEncoding(encoding);
</span><span class="lines">@@ -646,7 +646,7 @@
</span><span class="cx">
</span><span class="cx"> void CachedResource::updateResponseAfterRevalidation(const ResourceResponse& validatingResponse)
</span><span class="cx"> {
</span><del>- m_responseTimestamp = currentTime();
</del><ins>+ m_responseTimestamp = std::chrono::system_clock::now();
</ins><span class="cx">
</span><span class="cx"> updateResponseHeadersAfterRevalidation(m_response, validatingResponse);
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebCoreloadercacheCachedResourceh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/loader/cache/CachedResource.h (182270 => 182271)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/loader/cache/CachedResource.h        2015-04-02 08:51:23 UTC (rev 182270)
+++ trunk/Source/WebCore/loader/cache/CachedResource.h        2015-04-02 15:45:58 UTC (rev 182271)
</span><span class="lines">@@ -280,7 +280,7 @@
</span><span class="cx"> virtual void checkNotify();
</span><span class="cx"> virtual bool mayTryReplaceEncodedData() const { return false; }
</span><span class="cx">
</span><del>- double freshnessLifetime(const ResourceResponse&) const;
</del><ins>+ std::chrono::microseconds freshnessLifetime(const ResourceResponse&) const;
</ins><span class="cx">
</span><span class="cx"> void addAdditionalRequestHeaders(CachedResourceLoader&);
</span><span class="cx"> void failBeforeStarting();
</span><span class="lines">@@ -289,7 +289,7 @@
</span><span class="cx"> SessionID m_sessionID;
</span><span class="cx"> String m_accept;
</span><span class="cx"> ResourceLoadPriority m_loadPriority;
</span><del>- double m_responseTimestamp;
</del><ins>+ std::chrono::system_clock::time_point m_responseTimestamp;
</ins><span class="cx">
</span><span class="cx"> String m_fragmentIdentifierForRequest;
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformnetworkCacheValidationcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/network/CacheValidation.cpp (182270 => 182271)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/network/CacheValidation.cpp        2015-04-02 08:51:23 UTC (rev 182270)
+++ trunk/Source/WebCore/platform/network/CacheValidation.cpp        2015-04-02 15:45:58 UTC (rev 182271)
</span><span class="lines">@@ -89,49 +89,56 @@
</span><span class="cx"> }
</span><span class="cx"> }
</span><span class="cx">
</span><del>-double computeCurrentAge(const ResourceResponse& response, double responseTimestamp)
</del><ins>+std::chrono::microseconds computeCurrentAge(const ResourceResponse& response, std::chrono::system_clock::time_point responseTimestamp)
</ins><span class="cx"> {
</span><ins>+ using namespace std::chrono;
+
</ins><span class="cx"> // RFC2616 13.2.3
</span><span class="cx"> // No compensation for latency as that is not terribly important in practice
</span><del>- double dateValue = response.date();
- double apparentAge = std::isfinite(dateValue) ? std::max(0., responseTimestamp - dateValue) : 0;
- double ageValue = response.age();
- double correctedReceivedAge = std::isfinite(ageValue) ? std::max(apparentAge, ageValue) : apparentAge;
- double residentTime = currentTime() - responseTimestamp;
</del><ins>+ auto dateValue = response.date();
+ auto apparentAge = dateValue ? std::max(microseconds::zero(), duration_cast<microseconds>(responseTimestamp - dateValue.value())) : microseconds::zero();
+ auto ageValue = response.age();
+ auto correctedReceivedAge = ageValue ? std::max(apparentAge, ageValue.value()) : apparentAge;
+ auto residentTime = duration_cast<microseconds>(system_clock::now() - responseTimestamp);
</ins><span class="cx"> return correctedReceivedAge + residentTime;
</span><span class="cx"> }
</span><span class="cx">
</span><del>-double computeFreshnessLifetimeForHTTPFamily(const ResourceResponse& response, double responseTimestamp)
</del><ins>+std::chrono::microseconds computeFreshnessLifetimeForHTTPFamily(const ResourceResponse& response, std::chrono::system_clock::time_point responseTimestamp)
</ins><span class="cx"> {
</span><ins>+ using namespace std::chrono;
</ins><span class="cx"> ASSERT(response.url().protocolIsInHTTPFamily());
</span><ins>+
</ins><span class="cx"> // RFC2616 13.2.4
</span><del>- double maxAgeValue = response.cacheControlMaxAge();
- if (std::isfinite(maxAgeValue))
- return maxAgeValue;
- double expiresValue = response.expires();
- double dateValue = response.date();
- double creationTime = std::isfinite(dateValue) ? dateValue : responseTimestamp;
- if (std::isfinite(expiresValue))
- return expiresValue - creationTime;
- double lastModifiedValue = response.lastModified();
- if (std::isfinite(lastModifiedValue))
- return (creationTime - lastModifiedValue) * 0.1;
</del><ins>+ auto maxAge = response.cacheControlMaxAge();
+ if (maxAge)
+ return maxAge.value();
+ auto expires = response.expires();
+ auto date = response.date();
+ auto creationTime = date ? date.value() : responseTimestamp;
+ if (expires)
+ return duration_cast<microseconds>(expires.value() - creationTime);
+ auto lastModified = response.lastModified();
+ if (lastModified)
+ return duration_cast<microseconds>((creationTime - lastModified.value()) * 0.1);
</ins><span class="cx"> // If no cache headers are present, the specification leaves the decision to the UA. Other browsers seem to opt for 0.
</span><del>- return 0;
</del><ins>+ return microseconds::zero();
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> void updateRedirectChainStatus(RedirectChainCacheStatus& redirectChainCacheStatus, const ResourceResponse& response)
</span><span class="cx"> {
</span><ins>+ using namespace std::chrono;
+
</ins><span class="cx"> if (redirectChainCacheStatus.status == RedirectChainCacheStatus::NotCachedRedirection)
</span><span class="cx"> return;
</span><span class="cx"> if (response.cacheControlContainsNoStore() || response.cacheControlContainsNoCache() || response.cacheControlContainsMustRevalidate()) {
</span><span class="cx"> redirectChainCacheStatus.status = RedirectChainCacheStatus::NotCachedRedirection;
</span><span class="cx"> return;
</span><span class="cx"> }
</span><ins>+
</ins><span class="cx"> redirectChainCacheStatus.status = RedirectChainCacheStatus::CachedRedirection;
</span><del>- double responseTimestamp = currentTime();
</del><ins>+ auto responseTimestamp = system_clock::now();
</ins><span class="cx"> // Store the nearest end of cache validity date
</span><del>- double endOfValidity = responseTimestamp + computeFreshnessLifetimeForHTTPFamily(response, responseTimestamp) - computeCurrentAge(response, responseTimestamp);
</del><ins>+ auto endOfValidity = responseTimestamp + computeFreshnessLifetimeForHTTPFamily(response, responseTimestamp) - computeCurrentAge(response, responseTimestamp);
</ins><span class="cx"> redirectChainCacheStatus.endOfValidity = std::min(redirectChainCacheStatus.endOfValidity, endOfValidity);
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -143,7 +150,7 @@
</span><span class="cx"> case RedirectChainCacheStatus::NotCachedRedirection:
</span><span class="cx"> return false;
</span><span class="cx"> case RedirectChainCacheStatus::CachedRedirection:
</span><del>- return reuseExpiredRedirection || currentTime() <= redirectChainCacheStatus.endOfValidity;
</del><ins>+ return reuseExpiredRedirection || std::chrono::system_clock::now() <= redirectChainCacheStatus.endOfValidity;
</ins><span class="cx"> }
</span><span class="cx"> ASSERT_NOT_REACHED();
</span><span class="cx"> return false;
</span><span class="lines">@@ -248,6 +255,8 @@
</span><span class="cx">
</span><span class="cx"> CacheControlDirectives parseCacheControlDirectives(const HTTPHeaderMap& headers)
</span><span class="cx"> {
</span><ins>+ using namespace std::chrono;
+
</ins><span class="cx"> CacheControlDirectives result;
</span><span class="cx">
</span><span class="cx"> String cacheControlValue = headers.get(HTTPHeaderName::CacheControl);
</span><span class="lines">@@ -265,29 +274,29 @@
</span><span class="cx"> else if (equalIgnoringCase(directives[i].first, "must-revalidate"))
</span><span class="cx"> result.mustRevalidate = true;
</span><span class="cx"> else if (equalIgnoringCase(directives[i].first, "max-age")) {
</span><del>- if (!std::isnan(result.maxAge)) {
</del><ins>+ if (result.maxAge) {
</ins><span class="cx"> // First max-age directive wins if there are multiple ones.
</span><span class="cx"> continue;
</span><span class="cx"> }
</span><span class="cx"> bool ok;
</span><span class="cx"> double maxAge = directives[i].second.toDouble(&ok);
</span><span class="cx"> if (ok)
</span><del>- result.maxAge = maxAge;
</del><ins>+ result.maxAge = duration_cast<microseconds>(duration<double>(maxAge));
</ins><span class="cx"> } else if (equalIgnoringCase(directives[i].first, "max-stale")) {
</span><span class="cx"> // https://tools.ietf.org/html/rfc7234#section-5.2.1.2
</span><del>- if (!std::isnan(result.maxStale)) {
</del><ins>+ if (result.maxStale) {
</ins><span class="cx"> // First max-stale directive wins if there are multiple ones.
</span><span class="cx"> continue;
</span><span class="cx"> }
</span><span class="cx"> if (directives[i].second.isEmpty()) {
</span><span class="cx"> // if no value is assigned to max-stale, then the client is willing to accept a stale response of any age.
</span><del>- result.maxStale = std::numeric_limits<double>::max();
</del><ins>+ result.maxStale = microseconds::max();
</ins><span class="cx"> continue;
</span><span class="cx"> }
</span><span class="cx"> bool ok;
</span><span class="cx"> double maxStale = directives[i].second.toDouble(&ok);
</span><span class="cx"> if (ok)
</span><del>- result.maxStale = maxStale;
</del><ins>+ result.maxStale = duration_cast<microseconds>(duration<double>(maxStale));
</ins><span class="cx"> }
</span><span class="cx"> }
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformnetworkCacheValidationh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/network/CacheValidation.h (182270 => 182271)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/network/CacheValidation.h        2015-04-02 08:51:23 UTC (rev 182270)
+++ trunk/Source/WebCore/platform/network/CacheValidation.h        2015-04-02 15:45:58 UTC (rev 182271)
</span><span class="lines">@@ -26,6 +26,8 @@
</span><span class="cx"> #ifndef CacheValidation_h
</span><span class="cx"> #define CacheValidation_h
</span><span class="cx">
</span><ins>+#include <wtf/Optional.h>
+
</ins><span class="cx"> namespace WebCore {
</span><span class="cx">
</span><span class="cx"> class HTTPHeaderMap;
</span><span class="lines">@@ -39,14 +41,14 @@
</span><span class="cx"> };
</span><span class="cx"> RedirectChainCacheStatus()
</span><span class="cx"> : status(NoRedirection)
</span><del>- , endOfValidity(std::numeric_limits<double>::max())
</del><ins>+ , endOfValidity(std::chrono::system_clock::time_point::max())
</ins><span class="cx"> { }
</span><span class="cx"> Status status;
</span><del>- double endOfValidity;
</del><ins>+ std::chrono::system_clock::time_point endOfValidity;
</ins><span class="cx"> };
</span><span class="cx">
</span><del>-WEBCORE_EXPORT double computeCurrentAge(const ResourceResponse&, double responseTimestamp);
-WEBCORE_EXPORT double computeFreshnessLifetimeForHTTPFamily(const ResourceResponse&, double responseTimestamp);
</del><ins>+WEBCORE_EXPORT std::chrono::microseconds computeCurrentAge(const ResourceResponse&, std::chrono::system_clock::time_point responseTimestamp);
+WEBCORE_EXPORT std::chrono::microseconds computeFreshnessLifetimeForHTTPFamily(const ResourceResponse&, std::chrono::system_clock::time_point responseTimestamp);
</ins><span class="cx"> WEBCORE_EXPORT void updateResponseHeadersAfterRevalidation(ResourceResponse&, const ResourceResponse& validatingResponse);
</span><span class="cx"> WEBCORE_EXPORT void updateRedirectChainStatus(RedirectChainCacheStatus&, const ResourceResponse&);
</span><span class="cx">
</span><span class="lines">@@ -54,8 +56,8 @@
</span><span class="cx"> WEBCORE_EXPORT bool redirectChainAllowsReuse(RedirectChainCacheStatus, ReuseExpiredRedirectionOrNot);
</span><span class="cx">
</span><span class="cx"> struct CacheControlDirectives {
</span><del>- double maxAge { std::numeric_limits<double>::quiet_NaN() };
- double maxStale { std::numeric_limits<double>::quiet_NaN() };
</del><ins>+ Optional<std::chrono::microseconds> maxAge;
+ Optional<std::chrono::microseconds> maxStale;
</ins><span class="cx"> bool noCache { false };
</span><span class="cx"> bool noStore { false };
</span><span class="cx"> bool mustRevalidate { false };
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformnetworkHTTPParserscpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/network/HTTPParsers.cpp (182270 => 182271)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/network/HTTPParsers.cpp        2015-04-02 08:51:23 UTC (rev 182270)
+++ trunk/Source/WebCore/platform/network/HTTPParsers.cpp        2015-04-02 15:45:58 UTC (rev 182271)
</span><span class="lines">@@ -234,9 +234,14 @@
</span><span class="cx"> }
</span><span class="cx"> }
</span><span class="cx">
</span><del>-double parseDate(const String& value)
</del><ins>+Optional<std::chrono::system_clock::time_point> parseHTTPDate(const String& value)
</ins><span class="cx"> {
</span><del>- return parseDateFromNullTerminatedCharacters(value.utf8().data());
</del><ins>+ double dateInMillisecondsSinceEpoch = parseDateFromNullTerminatedCharacters(value.utf8().data());
+ if (!std::isfinite(dateInMillisecondsSinceEpoch))
+ return { };
+ // This assumes system_clock epoch equals Unix epoch which is true for all implementations but unspecified.
+ // FIXME: The parsing function should be switched to std::chrono too.
+ return std::chrono::system_clock::time_point(std::chrono::milliseconds(static_cast<long long>(dateInMillisecondsSinceEpoch)));
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> // FIXME: This function doesn't comply with RFC 6266.
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformnetworkHTTPParsersh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/network/HTTPParsers.h (182270 => 182271)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/network/HTTPParsers.h        2015-04-02 08:51:23 UTC (rev 182270)
+++ trunk/Source/WebCore/platform/network/HTTPParsers.h        2015-04-02 15:45:58 UTC (rev 182271)
</span><span class="lines">@@ -33,6 +33,7 @@
</span><span class="cx">
</span><span class="cx"> #include "ContentSecurityPolicy.h"
</span><span class="cx"> #include <wtf/Forward.h>
</span><ins>+#include <wtf/Optional.h>
</ins><span class="cx"> #include <wtf/Vector.h>
</span><span class="cx">
</span><span class="cx"> namespace WebCore {
</span><span class="lines">@@ -64,7 +65,7 @@
</span><span class="cx"> bool isValidHTTPHeaderValue(const String&);
</span><span class="cx"> bool isValidHTTPToken(const String&);
</span><span class="cx"> bool parseHTTPRefresh(const String& refresh, bool fromHttpEquivMeta, double& delay, String& url);
</span><del>-double parseDate(const String&);
</del><ins>+Optional<std::chrono::system_clock::time_point> parseHTTPDate(const String&);
</ins><span class="cx"> String filenameFromHTTPContentDisposition(const String&);
</span><span class="cx"> String extractMIMETypeFromMediaType(const String&);
</span><span class="cx"> String extractCharsetFromMediaType(const String&);
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformnetworkResourceResponseBasecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/network/ResourceResponseBase.cpp (182270 => 182271)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/network/ResourceResponseBase.cpp        2015-04-02 08:51:23 UTC (rev 182270)
+++ trunk/Source/WebCore/platform/network/ResourceResponseBase.cpp        2015-04-02 15:45:58 UTC (rev 182271)
</span><span class="lines">@@ -43,42 +43,22 @@
</span><span class="cx"> return *static_cast<const ResourceResponse*>(this);
</span><span class="cx"> }
</span><span class="cx">
</span><del>-ResourceResponseBase::ResourceResponseBase()
- : m_expectedContentLength(0)
</del><ins>+ResourceResponseBase::ResourceResponseBase()
+ : m_isNull(true)
+ , m_expectedContentLength(0)
</ins><span class="cx"> , m_includesCertificateInfo(false)
</span><span class="cx"> , m_httpStatusCode(0)
</span><del>- , m_age(0)
- , m_date(0)
- , m_expires(0)
- , m_lastModified(0)
- , m_isNull(true)
- , m_haveParsedCacheControlHeader(false)
- , m_haveParsedAgeHeader(false)
- , m_haveParsedDateHeader(false)
- , m_haveParsedExpiresHeader(false)
- , m_haveParsedLastModifiedHeader(false)
- , m_source(Source::Unknown)
</del><span class="cx"> {
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> ResourceResponseBase::ResourceResponseBase(const URL& url, const String& mimeType, long long expectedLength, const String& textEncodingName)
</span><del>- : m_url(url)
</del><ins>+ : m_isNull(false)
+ , m_url(url)
</ins><span class="cx"> , m_mimeType(mimeType)
</span><span class="cx"> , m_expectedContentLength(expectedLength)
</span><span class="cx"> , m_textEncodingName(textEncodingName)
</span><span class="cx"> , m_includesCertificateInfo(true) // Empty but valid for synthetic responses.
</span><span class="cx"> , m_httpStatusCode(0)
</span><del>- , m_age(0)
- , m_date(0)
- , m_expires(0)
- , m_lastModified(0)
- , m_isNull(false)
- , m_haveParsedCacheControlHeader(false)
- , m_haveParsedAgeHeader(false)
- , m_haveParsedDateHeader(false)
- , m_haveParsedExpiresHeader(false)
- , m_haveParsedLastModifiedHeader(false)
- , m_source(Source::Unknown)
</del><span class="cx"> {
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -381,29 +361,26 @@
</span><span class="cx"> return !m_httpHeaderFields.get(HTTPHeaderName::LastModified).isEmpty() || !m_httpHeaderFields.get(HTTPHeaderName::ETag).isEmpty();
</span><span class="cx"> }
</span><span class="cx">
</span><del>-double ResourceResponseBase::cacheControlMaxAge() const
</del><ins>+Optional<std::chrono::microseconds> ResourceResponseBase::cacheControlMaxAge() const
</ins><span class="cx"> {
</span><span class="cx"> if (!m_haveParsedCacheControlHeader)
</span><span class="cx"> parseCacheControlDirectives();
</span><span class="cx"> return m_cacheControlDirectives.maxAge;
</span><span class="cx"> }
</span><span class="cx">
</span><del>-static double parseDateValueInHeader(const HTTPHeaderMap& headers, HTTPHeaderName headerName)
</del><ins>+static Optional<std::chrono::system_clock::time_point> parseDateValueInHeader(const HTTPHeaderMap& headers, HTTPHeaderName headerName)
</ins><span class="cx"> {
</span><span class="cx"> String headerValue = headers.get(headerName);
</span><span class="cx"> if (headerValue.isEmpty())
</span><del>- return std::numeric_limits<double>::quiet_NaN();
</del><ins>+ return { };
</ins><span class="cx"> // This handles all date formats required by RFC2616:
</span><span class="cx"> // Sun, 06 Nov 1994 08:49:37 GMT ; RFC 822, updated by RFC 1123
</span><span class="cx"> // Sunday, 06-Nov-94 08:49:37 GMT ; RFC 850, obsoleted by RFC 1036
</span><span class="cx"> // Sun Nov 6 08:49:37 1994 ; ANSI C's asctime() format
</span><del>- double dateInMilliseconds = parseDate(headerValue);
- if (!std::isfinite(dateInMilliseconds))
- return std::numeric_limits<double>::quiet_NaN();
- return dateInMilliseconds / 1000;
</del><ins>+ return parseHTTPDate(headerValue);
</ins><span class="cx"> }
</span><span class="cx">
</span><del>-double ResourceResponseBase::date() const
</del><ins>+Optional<std::chrono::system_clock::time_point> ResourceResponseBase::date() const
</ins><span class="cx"> {
</span><span class="cx"> lazyInit(CommonFieldsOnly);
</span><span class="cx">
</span><span class="lines">@@ -414,22 +391,24 @@
</span><span class="cx"> return m_date;
</span><span class="cx"> }
</span><span class="cx">
</span><del>-double ResourceResponseBase::age() const
</del><ins>+Optional<std::chrono::microseconds> ResourceResponseBase::age() const
</ins><span class="cx"> {
</span><ins>+ using namespace std::chrono;
+
</ins><span class="cx"> lazyInit(CommonFieldsOnly);
</span><span class="cx">
</span><span class="cx"> if (!m_haveParsedAgeHeader) {
</span><span class="cx"> String headerValue = m_httpHeaderFields.get(HTTPHeaderName::Age);
</span><span class="cx"> bool ok;
</span><del>- m_age = headerValue.toDouble(&ok);
- if (!ok)
- m_age = std::numeric_limits<double>::quiet_NaN();
</del><ins>+ double ageDouble = headerValue.toDouble(&ok);
+ if (ok)
+ m_age = duration_cast<microseconds>(duration<double>(ageDouble));
</ins><span class="cx"> m_haveParsedAgeHeader = true;
</span><span class="cx"> }
</span><span class="cx"> return m_age;
</span><span class="cx"> }
</span><span class="cx">
</span><del>-double ResourceResponseBase::expires() const
</del><ins>+Optional<std::chrono::system_clock::time_point> ResourceResponseBase::expires() const
</ins><span class="cx"> {
</span><span class="cx"> lazyInit(CommonFieldsOnly);
</span><span class="cx">
</span><span class="lines">@@ -440,7 +419,7 @@
</span><span class="cx"> return m_expires;
</span><span class="cx"> }
</span><span class="cx">
</span><del>-double ResourceResponseBase::lastModified() const
</del><ins>+Optional<std::chrono::system_clock::time_point> ResourceResponseBase::lastModified() const
</ins><span class="cx"> {
</span><span class="cx"> lazyInit(CommonFieldsOnly);
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformnetworkResourceResponseBaseh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/network/ResourceResponseBase.h (182270 => 182271)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/network/ResourceResponseBase.h        2015-04-02 08:51:23 UTC (rev 182270)
+++ trunk/Source/WebCore/platform/network/ResourceResponseBase.h        2015-04-02 15:45:58 UTC (rev 182271)
</span><span class="lines">@@ -104,11 +104,11 @@
</span><span class="cx"> WEBCORE_EXPORT bool cacheControlContainsNoStore() const;
</span><span class="cx"> WEBCORE_EXPORT bool cacheControlContainsMustRevalidate() const;
</span><span class="cx"> WEBCORE_EXPORT bool hasCacheValidatorFields() const;
</span><del>- WEBCORE_EXPORT double cacheControlMaxAge() const;
- double date() const;
- double age() const;
- WEBCORE_EXPORT double expires() const;
- WEBCORE_EXPORT double lastModified() const;
</del><ins>+ WEBCORE_EXPORT Optional<std::chrono::microseconds> cacheControlMaxAge() const;
+ WEBCORE_EXPORT Optional<std::chrono::system_clock::time_point> date() const;
+ WEBCORE_EXPORT Optional<std::chrono::microseconds> age() const;
+ WEBCORE_EXPORT Optional<std::chrono::system_clock::time_point> expires() const;
+ WEBCORE_EXPORT Optional<std::chrono::system_clock::time_point> lastModified() const;
</ins><span class="cx">
</span><span class="cx"> enum class Source { Unknown, Network, DiskCache, DiskCacheAfterValidation };
</span><span class="cx"> WEBCORE_EXPORT Source source() const;
</span><span class="lines">@@ -147,6 +147,13 @@
</span><span class="cx">
</span><span class="cx"> static bool platformCompare(const ResourceResponse&, const ResourceResponse&) { return true; }
</span><span class="cx">
</span><ins>+private:
+ const ResourceResponse& asResourceResponse() const;
+ void parseCacheControlDirectives() const;
+ void updateHeaderParsedState(HTTPHeaderName);
+
+protected:
+ bool m_isNull;
</ins><span class="cx"> URL m_url;
</span><span class="cx"> AtomicString m_mimeType;
</span><span class="cx"> long long m_expectedContentLength;
</span><span class="lines">@@ -161,27 +168,19 @@
</span><span class="cx"> int m_httpStatusCode;
</span><span class="cx">
</span><span class="cx"> private:
</span><del>- mutable double m_age;
- mutable double m_date;
- mutable double m_expires;
- mutable double m_lastModified;
</del><ins>+ mutable Optional<std::chrono::microseconds> m_age;
+ mutable Optional<std::chrono::system_clock::time_point> m_date;
+ mutable Optional<std::chrono::system_clock::time_point> m_expires;
+ mutable Optional<std::chrono::system_clock::time_point> m_lastModified;
</ins><span class="cx"> mutable CacheControlDirectives m_cacheControlDirectives;
</span><span class="cx">
</span><del>-public:
- bool m_isNull : 1;
-
-private:
- const ResourceResponse& asResourceResponse() const;
- void parseCacheControlDirectives() const;
- void updateHeaderParsedState(HTTPHeaderName);
</del><ins>+ mutable bool m_haveParsedCacheControlHeader { false };
+ mutable bool m_haveParsedAgeHeader { false };
+ mutable bool m_haveParsedDateHeader { false };
+ mutable bool m_haveParsedExpiresHeader { false };
+ mutable bool m_haveParsedLastModifiedHeader { false };
</ins><span class="cx">
</span><del>- mutable bool m_haveParsedCacheControlHeader : 1;
- mutable bool m_haveParsedAgeHeader : 1;
- mutable bool m_haveParsedDateHeader : 1;
- mutable bool m_haveParsedExpiresHeader : 1;
- mutable bool m_haveParsedLastModifiedHeader : 1;
-
- Source m_source;
</del><ins>+ Source m_source { Source::Unknown };
</ins><span class="cx"> };
</span><span class="cx">
</span><span class="cx"> inline bool operator==(const ResourceResponse& a, const ResourceResponse& b) { return ResourceResponseBase::compare(a, b); }
</span></span></pre></div>
<a id="trunkSourceWebKitwinPluginsPluginStreamcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/win/Plugins/PluginStream.cpp (182270 => 182271)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/win/Plugins/PluginStream.cpp        2015-04-02 08:51:23 UTC (rev 182270)
+++ trunk/Source/WebKit/win/Plugins/PluginStream.cpp        2015-04-02 15:45:58 UTC (rev 182271)
</span><span class="lines">@@ -123,13 +123,13 @@
</span><span class="cx"> m_client = 0;
</span><span class="cx"> }
</span><span class="cx">
</span><del>-static uint32_t lastModifiedDate(const ResourceResponse& response)
</del><ins>+static uint32_t lastModifiedDateMS(const ResourceResponse& response)
</ins><span class="cx"> {
</span><del>- double lastModified = response.lastModified();
- if (!std::isfinite(lastModified))
</del><ins>+ auto lastModified = response.lastModified();
+ if (!lastModified)
</ins><span class="cx"> return 0;
</span><span class="cx">
</span><del>- return lastModified * 1000;
</del><ins>+ return std::chrono::duration_cast<std::chrono::milliseconds>(lastModified.value().time_since_epoch()).count();
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> void PluginStream::startStream()
</span><span class="lines">@@ -178,7 +178,7 @@
</span><span class="cx"> m_stream.pdata = 0;
</span><span class="cx"> m_stream.ndata = this;
</span><span class="cx"> m_stream.end = max(expectedContentLength, 0LL);
</span><del>- m_stream.lastmodified = lastModifiedDate(m_resourceResponse);
</del><ins>+ m_stream.lastmodified = lastModifiedDateMS(m_resourceResponse);
</ins><span class="cx"> m_stream.notifyData = m_notifyData;
</span><span class="cx">
</span><span class="cx"> m_transferMode = NP_NORMAL;
</span></span></pre></div>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (182270 => 182271)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2015-04-02 08:51:23 UTC (rev 182270)
+++ trunk/Source/WebKit2/ChangeLog        2015-04-02 15:45:58 UTC (rev 182271)
</span><span class="lines">@@ -1,3 +1,38 @@
</span><ins>+2015-04-01 Antti Koivisto <antti@apple.com>
+
+ Use std::chrono types to represent time in response and cache classes
+ https://bugs.webkit.org/show_bug.cgi?id=143316
+
+ Reviewed by Andreas Kling.
+
+ * NetworkProcess/NetworkResourceLoader.cpp:
+ (WebKit::NetworkResourceLoader::didFinishLoading):
+ * NetworkProcess/cache/NetworkCache.cpp:
+ (WebKit::NetworkCache::responseHasExpired):
+ (WebKit::NetworkCache::responseNeedsRevalidation):
+ (WebKit::NetworkCache::makeStoreDecision):
+ (WebKit::NetworkCache::Cache::store):
+ * NetworkProcess/cache/NetworkCacheEntry.cpp:
+ (WebKit::NetworkCache::Entry::Entry):
+ (WebKit::NetworkCache::Entry::asJSON):
+ * NetworkProcess/cache/NetworkCacheEntry.h:
+ (WebKit::NetworkCache::Entry::timeStamp):
+ * NetworkProcess/cache/NetworkCacheStorage.cpp:
+ (WebKit::NetworkCache::decodeRecordMetaData):
+ (WebKit::NetworkCache::decodeRecord):
+
+ Sanity check the timestamp on decode.
+
+ (WebKit::NetworkCache::encodeRecordMetaData):
+ (WebKit::NetworkCache::encodeRecordHeader):
+ (WebKit::NetworkCache::Storage::traverse):
+ * NetworkProcess/cache/NetworkCacheStorage.h:
+ * WebProcess/Plugins/PluginView.cpp:
+ (WebKit::lastModifiedDateMS):
+ (WebKit::PluginView::Stream::didReceiveResponse):
+ (WebKit::PluginView::manualLoadDidReceiveResponse):
+ (WebKit::lastModifiedDate): Deleted.
+
</ins><span class="cx"> 2015-04-01 Chris Dumez <cdumez@apple.com>
</span><span class="cx">
</span><span class="cx"> [WK2][Cocoa] Add didFailProvisionalLoadWithErrorForFrame callback to WKWebProcessPlugInLoadDelegate
</span></span></pre></div>
<a id="trunkSourceWebKit2NetworkProcessNetworkResourceLoadercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/NetworkProcess/NetworkResourceLoader.cpp (182270 => 182271)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/NetworkProcess/NetworkResourceLoader.cpp        2015-04-02 08:51:23 UTC (rev 182270)
+++ trunk/Source/WebKit2/NetworkProcess/NetworkResourceLoader.cpp        2015-04-02 15:45:58 UTC (rev 182271)
</span><span class="lines">@@ -318,9 +318,9 @@
</span><span class="cx"> bool allowStale = originalRequest().cachePolicy() >= ReturnCacheDataElseLoad;
</span><span class="cx"> bool hasCacheableRedirect = m_response.isHTTP() && WebCore::redirectChainAllowsReuse(m_redirectChainCacheStatus, allowStale ? WebCore::ReuseExpiredRedirection : WebCore::DoNotReuseExpiredRedirection);
</span><span class="cx"> if (hasCacheableRedirect && m_redirectChainCacheStatus.status == RedirectChainCacheStatus::CachedRedirection) {
</span><del>- // FIXME: Cache the actual redirects instead of the end result.
- double now = currentTime();
- double responseEndOfValidity = now + WebCore::computeFreshnessLifetimeForHTTPFamily(m_response, now) - WebCore::computeCurrentAge(m_response, now);
</del><ins>+ // Maybe we should cache the actual redirects instead of the end result?
+ auto now = std::chrono::system_clock::now();
+ auto responseEndOfValidity = now + WebCore::computeFreshnessLifetimeForHTTPFamily(m_response, now) - WebCore::computeCurrentAge(m_response, now);
</ins><span class="cx"> hasCacheableRedirect = responseEndOfValidity <= m_redirectChainCacheStatus.endOfValidity;
</span><span class="cx"> }
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceWebKit2NetworkProcesscacheNetworkCachecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCache.cpp (182270 => 182271)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCache.cpp        2015-04-02 08:51:23 UTC (rev 182270)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCache.cpp        2015-04-02 15:45:58 UTC (rev 182271)
</span><span class="lines">@@ -150,17 +150,16 @@
</span><span class="cx"> return false;
</span><span class="cx"> }
</span><span class="cx">
</span><del>-static bool responseHasExpired(const WebCore::ResourceResponse& response, std::chrono::milliseconds timestamp, double maxStale)
</del><ins>+static bool responseHasExpired(const WebCore::ResourceResponse& response, std::chrono::system_clock::time_point timestamp, Optional<std::chrono::microseconds> maxStale)
</ins><span class="cx"> {
</span><span class="cx"> if (response.cacheControlContainsNoCache())
</span><span class="cx"> return true;
</span><span class="cx">
</span><del>- auto doubleTimeStamp = std::chrono::duration<double>(timestamp);
- double age = WebCore::computeCurrentAge(response, doubleTimeStamp.count());
- double lifetime = WebCore::computeFreshnessLifetimeForHTTPFamily(response, doubleTimeStamp.count());
</del><ins>+ auto age = WebCore::computeCurrentAge(response, timestamp);
+ auto lifetime = WebCore::computeFreshnessLifetimeForHTTPFamily(response, timestamp);
</ins><span class="cx">
</span><del>- maxStale = std::isnan(maxStale) ? 0 : maxStale;
- bool hasExpired = age - lifetime > maxStale;
</del><ins>+ auto maximumStaleness = maxStale ? maxStale.value() : 0_ms;
+ bool hasExpired = age - lifetime > maximumStaleness;
</ins><span class="cx">
</span><span class="cx"> #ifndef LOG_DISABLED
</span><span class="cx"> if (hasExpired)
</span><span class="lines">@@ -170,13 +169,13 @@
</span><span class="cx"> return hasExpired;
</span><span class="cx"> }
</span><span class="cx">
</span><del>-static bool responseNeedsRevalidation(const WebCore::ResourceResponse& response, const WebCore::ResourceRequest& request, std::chrono::milliseconds timestamp)
</del><ins>+static bool responseNeedsRevalidation(const WebCore::ResourceResponse& response, const WebCore::ResourceRequest& request, std::chrono::system_clock::time_point timestamp)
</ins><span class="cx"> {
</span><span class="cx"> auto requestDirectives = WebCore::parseCacheControlDirectives(request.httpHeaderFields());
</span><span class="cx"> if (requestDirectives.noCache)
</span><span class="cx"> return true;
</span><span class="cx"> // For requests we ignore max-age values other than zero.
</span><del>- if (requestDirectives.maxAge == 0)
</del><ins>+ if (requestDirectives.maxAge && requestDirectives.maxAge.value() == 0_ms)
</ins><span class="cx"> return true;
</span><span class="cx">
</span><span class="cx"> return responseHasExpired(response, timestamp, requestDirectives.maxStale);
</span><span class="lines">@@ -269,7 +268,7 @@
</span><span class="cx">
</span><span class="cx"> if (!isStatusCodeCacheableByDefault(response.httpStatusCode())) {
</span><span class="cx"> // http://tools.ietf.org/html/rfc7234#section-4.3.2
</span><del>- bool hasExpirationHeaders = std::isfinite(response.expires()) || std::isfinite(response.cacheControlMaxAge());
</del><ins>+ bool hasExpirationHeaders = response.expires() || response.cacheControlMaxAge();
</ins><span class="cx"> bool expirationHeadersAllowCaching = isStatusCodePotentiallyCacheable(response.httpStatusCode()) && hasExpirationHeaders;
</span><span class="cx"> if (!expirationHeadersAllowCaching)
</span><span class="cx"> return StoreDecision::NoDueToHTTPStatusCode;
</span><span class="lines">@@ -278,8 +277,8 @@
</span><span class="cx"> // Main resource has ResourceLoadPriorityVeryHigh.
</span><span class="cx"> bool storeUnconditionallyForHistoryNavigation = originalRequest.priority() == WebCore::ResourceLoadPriorityVeryHigh;
</span><span class="cx"> if (!storeUnconditionallyForHistoryNavigation) {
</span><del>- auto currentTime = std::chrono::duration<double>(std::chrono::system_clock::now().time_since_epoch());
- bool hasNonZeroLifetime = !response.cacheControlContainsNoCache() && WebCore::computeFreshnessLifetimeForHTTPFamily(response, currentTime.count()) > 0;
</del><ins>+ auto now = std::chrono::system_clock::now();
+ bool hasNonZeroLifetime = !response.cacheControlContainsNoCache() && WebCore::computeFreshnessLifetimeForHTTPFamily(response, now) > 0_ms;
</ins><span class="cx">
</span><span class="cx"> bool possiblyReusable = response.hasCacheValidatorFields() || hasNonZeroLifetime;
</span><span class="cx"> if (!possiblyReusable)
</span><span class="lines">@@ -358,7 +357,6 @@
</span><span class="cx"> LOG(NetworkCache, "(NetworkProcess) storing %s, partition %s", originalRequest.url().string().latin1().data(), originalRequest.cachePartition().latin1().data());
</span><span class="cx">
</span><span class="cx"> StoreDecision storeDecision = makeStoreDecision(originalRequest, response);
</span><del>-
</del><span class="cx"> if (storeDecision != StoreDecision::Yes) {
</span><span class="cx"> LOG(NetworkCache, "(NetworkProcess) didn't store, storeDecision=%d", storeDecision);
</span><span class="cx"> if (m_statistics) {
</span></span></pre></div>
<a id="trunkSourceWebKit2NetworkProcesscacheNetworkCacheEntrycpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheEntry.cpp (182270 => 182271)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheEntry.cpp        2015-04-02 08:51:23 UTC (rev 182270)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheEntry.cpp        2015-04-02 15:45:58 UTC (rev 182271)
</span><span class="lines">@@ -42,7 +42,7 @@
</span><span class="cx">
</span><span class="cx"> Entry::Entry(const Key& key, const WebCore::ResourceResponse& response, RefPtr<WebCore::SharedBuffer>&& buffer, const Vector<std::pair<String, String>>& varyingRequestHeaders)
</span><span class="cx"> : m_key(key)
</span><del>- , m_timeStamp(std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()))
</del><ins>+ , m_timeStamp(std::chrono::system_clock::now())
</ins><span class="cx"> , m_response(response)
</span><span class="cx"> , m_varyingRequestHeaders(varyingRequestHeaders)
</span><span class="cx"> , m_buffer(WTF::move(buffer))
</span><span class="lines">@@ -160,7 +160,7 @@
</span><span class="cx"> JSC::appendQuotedJSONStringToBuilder(json, m_key.partition());
</span><span class="cx"> json.appendLiteral(",\n");
</span><span class="cx"> json.appendLiteral("\"timestamp\": ");
</span><del>- json.appendNumber(m_timeStamp.count());
</del><ins>+ json.appendNumber(std::chrono::duration_cast<std::chrono::milliseconds>(m_timeStamp.time_since_epoch()).count());
</ins><span class="cx"> json.appendLiteral(",\n");
</span><span class="cx"> json.appendLiteral("\"URL\": ");
</span><span class="cx"> JSC::appendQuotedJSONStringToBuilder(json, m_response.url().string());
</span></span></pre></div>
<a id="trunkSourceWebKit2NetworkProcesscacheNetworkCacheEntryh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheEntry.h (182270 => 182271)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheEntry.h        2015-04-02 08:51:23 UTC (rev 182270)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheEntry.h        2015-04-02 15:45:58 UTC (rev 182271)
</span><span class="lines">@@ -51,7 +51,7 @@
</span><span class="cx"> static std::unique_ptr<Entry> decodeStorageRecord(const Storage::Record&);
</span><span class="cx">
</span><span class="cx"> const Key& key() const { return m_key; }
</span><del>- std::chrono::milliseconds timeStamp() const { return m_timeStamp; }
</del><ins>+ std::chrono::system_clock::time_point timeStamp() const { return m_timeStamp; }
</ins><span class="cx"> const WebCore::ResourceResponse& response() const { return m_response; }
</span><span class="cx"> const Vector<std::pair<String, String>>& varyingRequestHeaders() const { return m_varyingRequestHeaders; }
</span><span class="cx">
</span><span class="lines">@@ -72,7 +72,7 @@
</span><span class="cx"> void initializeBufferFromStorageRecord() const;
</span><span class="cx">
</span><span class="cx"> Key m_key;
</span><del>- std::chrono::milliseconds m_timeStamp;
</del><ins>+ std::chrono::system_clock::time_point m_timeStamp;
</ins><span class="cx"> WebCore::ResourceResponse m_response;
</span><span class="cx"> Vector<std::pair<String, String>> m_varyingRequestHeaders;
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceWebKit2NetworkProcesscacheNetworkCacheStoragecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.cpp (182270 => 182271)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.cpp        2015-04-02 08:51:23 UTC (rev 182270)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.cpp        2015-04-02 15:45:58 UTC (rev 182271)
</span><span class="lines">@@ -142,7 +142,8 @@
</span><span class="cx">
</span><span class="cx"> unsigned cacheStorageVersion;
</span><span class="cx"> Key key;
</span><del>- std::chrono::milliseconds timeStamp;
</del><ins>+ // FIXME: Add encoder/decoder for time_point.
+ std::chrono::milliseconds epochRelativeTimeStamp;
</ins><span class="cx"> unsigned headerChecksum;
</span><span class="cx"> uint64_t headerOffset;
</span><span class="cx"> uint64_t headerSize;
</span><span class="lines">@@ -160,7 +161,7 @@
</span><span class="cx"> return false;
</span><span class="cx"> if (!decoder.decode(metaData.key))
</span><span class="cx"> return false;
</span><del>- if (!decoder.decode(metaData.timeStamp))
</del><ins>+ if (!decoder.decode(metaData.epochRelativeTimeStamp))
</ins><span class="cx"> return false;
</span><span class="cx"> if (!decoder.decode(metaData.headerChecksum))
</span><span class="cx"> return false;
</span><span class="lines">@@ -215,6 +216,11 @@
</span><span class="cx"> if (metaData.key != key)
</span><span class="cx"> return nullptr;
</span><span class="cx">
</span><ins>+ // Sanity check against time stamps in future.
+ auto timeStamp = std::chrono::system_clock::time_point(metaData.epochRelativeTimeStamp);
+ if (timeStamp > std::chrono::system_clock::now())
+ return nullptr;
+
</ins><span class="cx"> Data bodyData;
</span><span class="cx"> if (metaData.bodySize) {
</span><span class="cx"> if (metaData.bodyOffset + metaData.bodySize != fileData.size())
</span><span class="lines">@@ -234,7 +240,7 @@
</span><span class="cx">
</span><span class="cx"> return std::make_unique<Storage::Record>(Storage::Record {
</span><span class="cx"> metaData.key,
</span><del>- metaData.timeStamp,
</del><ins>+ timeStamp,
</ins><span class="cx"> headerData,
</span><span class="cx"> bodyData
</span><span class="cx"> });
</span><span class="lines">@@ -246,7 +252,7 @@
</span><span class="cx">
</span><span class="cx"> encoder << metaData.cacheStorageVersion;
</span><span class="cx"> encoder << metaData.key;
</span><del>- encoder << metaData.timeStamp;
</del><ins>+ encoder << metaData.epochRelativeTimeStamp;
</ins><span class="cx"> encoder << metaData.headerChecksum;
</span><span class="cx"> encoder << metaData.headerSize;
</span><span class="cx"> encoder << metaData.bodyChecksum;
</span><span class="lines">@@ -260,7 +266,7 @@
</span><span class="cx"> static Data encodeRecordHeader(const Storage::Record& record)
</span><span class="cx"> {
</span><span class="cx"> RecordMetaData metaData(record.key);
</span><del>- metaData.timeStamp = record.timeStamp;
</del><ins>+ metaData.epochRelativeTimeStamp = std::chrono::duration_cast<std::chrono::milliseconds>(record.timeStamp.time_since_epoch());
</ins><span class="cx"> metaData.headerChecksum = hashData(record.header);
</span><span class="cx"> metaData.headerSize = record.header.size();
</span><span class="cx"> metaData.bodyChecksum = hashData(record.body);
</span><span class="lines">@@ -446,7 +452,7 @@
</span><span class="cx"> RecordMetaData metaData;
</span><span class="cx"> Data headerData;
</span><span class="cx"> if (decodeRecordHeader(fileData, metaData, headerData)) {
</span><del>- Record record { metaData.key, metaData.timeStamp, headerData, { } };
</del><ins>+ Record record { metaData.key, std::chrono::system_clock::time_point(metaData.epochRelativeTimeStamp), headerData, { } };
</ins><span class="cx"> info.bodySize = metaData.bodySize;
</span><span class="cx"> traverseHandler(&record, info);
</span><span class="cx"> }
</span><span class="lines">@@ -599,7 +605,7 @@
</span><span class="cx"> auto accessAge = times.modification - times.creation;
</span><span class="cx">
</span><span class="cx"> // For sanity.
</span><del>- if (age <= seconds::zero() || accessAge < seconds::zero() || accessAge > age)
</del><ins>+ if (age <= 0_s || accessAge < 0_s || accessAge > age)
</ins><span class="cx"> return 0;
</span><span class="cx">
</span><span class="cx"> // We like old entries that have been accessed recently.
</span></span></pre></div>
<a id="trunkSourceWebKit2NetworkProcesscacheNetworkCacheStorageh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.h (182270 => 182271)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.h        2015-04-02 08:51:23 UTC (rev 182270)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.h        2015-04-02 15:45:58 UTC (rev 182271)
</span><span class="lines">@@ -49,7 +49,7 @@
</span><span class="cx">
</span><span class="cx"> struct Record {
</span><span class="cx"> Key key;
</span><del>- std::chrono::milliseconds timeStamp;
</del><ins>+ std::chrono::system_clock::time_point timeStamp;
</ins><span class="cx"> Data header;
</span><span class="cx"> Data body;
</span><span class="cx"> };
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessPluginsPluginViewcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/Plugins/PluginView.cpp (182270 => 182271)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/Plugins/PluginView.cpp        2015-04-02 08:51:23 UTC (rev 182270)
+++ trunk/Source/WebKit2/WebProcess/Plugins/PluginView.cpp        2015-04-02 15:45:58 UTC (rev 182271)
</span><span class="lines">@@ -201,13 +201,13 @@
</span><span class="cx"> return headers;
</span><span class="cx"> }
</span><span class="cx">
</span><del>-static uint32_t lastModifiedDate(const ResourceResponse& response)
</del><ins>+static uint32_t lastModifiedDateMS(const ResourceResponse& response)
</ins><span class="cx"> {
</span><del>- double lastModified = response.lastModified();
- if (!std::isfinite(lastModified))
</del><ins>+ auto lastModified = response.lastModified();
+ if (!lastModified)
</ins><span class="cx"> return 0;
</span><span class="cx">
</span><del>- return lastModified * 1000;
</del><ins>+ return std::chrono::duration_cast<std::chrono::milliseconds>(lastModified.value().time_since_epoch()).count();
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> void PluginView::Stream::didReceiveResponse(NetscapePlugInStreamLoader*, const ResourceResponse& response)
</span><span class="lines">@@ -223,7 +223,7 @@
</span><span class="cx"> if (expectedContentLength > 0)
</span><span class="cx"> streamLength = expectedContentLength;
</span><span class="cx">
</span><del>- m_pluginView->m_plugin->streamDidReceiveResponse(m_streamID, responseURL, streamLength, lastModifiedDate(response), mimeType, headers, response.suggestedFilename());
</del><ins>+ m_pluginView->m_plugin->streamDidReceiveResponse(m_streamID, responseURL, streamLength, lastModifiedDateMS(response), mimeType, headers, response.suggestedFilename());
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> void PluginView::Stream::didReceiveData(NetscapePlugInStreamLoader*, const char* bytes, int length)
</span><span class="lines">@@ -413,7 +413,7 @@
</span><span class="cx"> if (expectedContentLength > 0)
</span><span class="cx"> streamLength = expectedContentLength;
</span><span class="cx">
</span><del>- m_plugin->manualStreamDidReceiveResponse(responseURL, streamLength, lastModifiedDate(response), mimeType, headers, response.suggestedFilename());
</del><ins>+ m_plugin->manualStreamDidReceiveResponse(responseURL, streamLength, lastModifiedDateMS(response), mimeType, headers, response.suggestedFilename());
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> void PluginView::manualLoadDidReceiveData(const char* bytes, int length)
</span></span></pre>
</div>
</div>
</body>
</html>