Changeset 182271 in webkit
- Timestamp:
- Apr 2, 2015 8:45:58 AM (9 years ago)
- Location:
- trunk/Source
- Files:
-
- 19 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r182270 r182271 1 2015-04-01 Antti Koivisto <antti@apple.com> 2 3 Use std::chrono types to represent time in response and cache classes 4 https://bugs.webkit.org/show_bug.cgi?id=143316 5 6 Reviewed by Andreas Kling. 7 8 Use std::chrono::system_clock::time_point to represent clock times and std::chrono::microseconds to 9 represent durations. Also use WTF::Optional for optional values (instead of coding them as NaNs). 10 11 * dom/Document.cpp: 12 (WebCore::Document::lastModified): 13 * loader/cache/CachedResource.cpp: 14 (WebCore::CachedResource::CachedResource): 15 (WebCore::CachedResource::freshnessLifetime): 16 (WebCore::CachedResource::responseReceived): 17 (WebCore::CachedResource::updateResponseAfterRevalidation): 18 * loader/cache/CachedResource.h: 19 * platform/network/CacheValidation.cpp: 20 (WebCore::computeCurrentAge): 21 (WebCore::computeFreshnessLifetimeForHTTPFamily): 22 (WebCore::updateRedirectChainStatus): 23 (WebCore::redirectChainAllowsReuse): 24 (WebCore::parseCacheControlDirectives): 25 * platform/network/CacheValidation.h: 26 (WebCore::RedirectChainCacheStatus::RedirectChainCacheStatus): 27 * platform/network/HTTPParsers.cpp: 28 (WebCore::parseHTTPDate): 29 (WebCore::parseDate): Deleted. 30 * platform/network/HTTPParsers.h: 31 * platform/network/ResourceResponseBase.cpp: 32 (WebCore::ResourceResponseBase::ResourceResponseBase): 33 (WebCore::ResourceResponseBase::cacheControlMaxAge): 34 (WebCore::parseDateValueInHeader): 35 (WebCore::ResourceResponseBase::date): 36 (WebCore::ResourceResponseBase::age): 37 (WebCore::ResourceResponseBase::expires): 38 (WebCore::ResourceResponseBase::lastModified): 39 * platform/network/ResourceResponseBase.h: 40 1 41 2015-04-02 Joonghun Park <jh718.park@samsung.com> 2 42 -
trunk/Source/WebCore/dom/Document.cpp
r182242 r182271 4132 4132 bool foundDate = false; 4133 4133 if (m_frame) { 4134 String httpLastModified; 4135 if (DocumentLoader* documentLoader = loader()) 4136 httpLastModified = documentLoader->response().httpHeaderField(HTTPHeaderName::LastModified); 4137 if (!httpLastModified.isEmpty()) { 4138 date.setMillisecondsSinceEpochForDateTime(parseDate(httpLastModified)); 4134 auto lastModifiedDate = loader() ? loader()->response().lastModified() : Nullopt; 4135 if (lastModifiedDate) { 4136 using namespace std::chrono; 4137 date.setMillisecondsSinceEpochForDateTime(duration_cast<milliseconds>(lastModifiedDate.value().time_since_epoch()).count()); 4139 4138 foundDate = true; 4140 4139 } -
trunk/Source/WebCore/loader/cache/CachedResource.cpp
r181766 r182271 117 117 , m_sessionID(sessionID) 118 118 , m_loadPriority(defaultPriorityForResourceType(type)) 119 , m_responseTimestamp( currentTime())119 , m_responseTimestamp(std::chrono::system_clock::now()) 120 120 , m_lastDecodedAccessTime(0) 121 121 , m_loadFinishTime(0) … … 348 348 } 349 349 350 doubleCachedResource::freshnessLifetime(const ResourceResponse& response) const350 std::chrono::microseconds CachedResource::freshnessLifetime(const ResourceResponse& response) const 351 351 { 352 352 if (!response.url().protocolIsInHTTPFamily()) { … … 355 355 // it caused performance and flakiness issues in our test infrastructure. 356 356 if (m_type == MainResource && !SchemeRegistry::shouldCacheResponsesFromURLSchemeIndefinitely(response.url().protocol())) 357 return 0;358 359 return std:: numeric_limits<double>::max();357 return std::chrono::microseconds::zero(); 358 359 return std::chrono::microseconds::max(); 360 360 } 361 361 … … 374 374 { 375 375 setResponse(response); 376 m_responseTimestamp = currentTime();376 m_responseTimestamp = std::chrono::system_clock::now(); 377 377 String encoding = response.textEncodingName(); 378 378 if (!encoding.isNull()) … … 647 647 void CachedResource::updateResponseAfterRevalidation(const ResourceResponse& validatingResponse) 648 648 { 649 m_responseTimestamp = currentTime();649 m_responseTimestamp = std::chrono::system_clock::now(); 650 650 651 651 updateResponseHeadersAfterRevalidation(m_response, validatingResponse); -
trunk/Source/WebCore/loader/cache/CachedResource.h
r181480 r182271 281 281 virtual bool mayTryReplaceEncodedData() const { return false; } 282 282 283 doublefreshnessLifetime(const ResourceResponse&) const;283 std::chrono::microseconds freshnessLifetime(const ResourceResponse&) const; 284 284 285 285 void addAdditionalRequestHeaders(CachedResourceLoader&); … … 290 290 String m_accept; 291 291 ResourceLoadPriority m_loadPriority; 292 doublem_responseTimestamp;292 std::chrono::system_clock::time_point m_responseTimestamp; 293 293 294 294 String m_fragmentIdentifierForRequest; -
trunk/Source/WebCore/platform/network/CacheValidation.cpp
r182157 r182271 90 90 } 91 91 92 double computeCurrentAge(const ResourceResponse& response, double responseTimestamp) 93 { 92 std::chrono::microseconds computeCurrentAge(const ResourceResponse& response, std::chrono::system_clock::time_point responseTimestamp) 93 { 94 using namespace std::chrono; 95 94 96 // RFC2616 13.2.3 95 97 // No compensation for latency as that is not terribly important in practice 96 doubledateValue = response.date();97 double apparentAge = std::isfinite(dateValue) ? std::max(0., responseTimestamp - dateValue) : 0;98 doubleageValue = response.age();99 double correctedReceivedAge = std::isfinite(ageValue) ? std::max(apparentAge, ageValue) : apparentAge;100 double residentTime = currentTime() - responseTimestamp;98 auto dateValue = response.date(); 99 auto apparentAge = dateValue ? std::max(microseconds::zero(), duration_cast<microseconds>(responseTimestamp - dateValue.value())) : microseconds::zero(); 100 auto ageValue = response.age(); 101 auto correctedReceivedAge = ageValue ? std::max(apparentAge, ageValue.value()) : apparentAge; 102 auto residentTime = duration_cast<microseconds>(system_clock::now() - responseTimestamp); 101 103 return correctedReceivedAge + residentTime; 102 104 } 103 105 104 double computeFreshnessLifetimeForHTTPFamily(const ResourceResponse& response, double responseTimestamp) 105 { 106 std::chrono::microseconds computeFreshnessLifetimeForHTTPFamily(const ResourceResponse& response, std::chrono::system_clock::time_point responseTimestamp) 107 { 108 using namespace std::chrono; 106 109 ASSERT(response.url().protocolIsInHTTPFamily()); 110 107 111 // RFC2616 13.2.4 108 double maxAgeValue = response.cacheControlMaxAge();109 if ( std::isfinite(maxAgeValue))110 return maxAge Value;111 double expiresValue= response.expires();112 double dateValue = response.date();113 double creationTime = std::isfinite(dateValue) ? dateValue: responseTimestamp;114 if ( std::isfinite(expiresValue))115 return expiresValue - creationTime;116 double lastModifiedValue= response.lastModified();117 if ( std::isfinite(lastModifiedValue))118 return (creationTime - lastModifiedValue) * 0.1;112 auto maxAge = response.cacheControlMaxAge(); 113 if (maxAge) 114 return maxAge.value(); 115 auto expires = response.expires(); 116 auto date = response.date(); 117 auto creationTime = date ? date.value() : responseTimestamp; 118 if (expires) 119 return duration_cast<microseconds>(expires.value() - creationTime); 120 auto lastModified = response.lastModified(); 121 if (lastModified) 122 return duration_cast<microseconds>((creationTime - lastModified.value()) * 0.1); 119 123 // If no cache headers are present, the specification leaves the decision to the UA. Other browsers seem to opt for 0. 120 return 0;124 return microseconds::zero(); 121 125 } 122 126 123 127 void updateRedirectChainStatus(RedirectChainCacheStatus& redirectChainCacheStatus, const ResourceResponse& response) 124 128 { 129 using namespace std::chrono; 130 125 131 if (redirectChainCacheStatus.status == RedirectChainCacheStatus::NotCachedRedirection) 126 132 return; … … 129 135 return; 130 136 } 137 131 138 redirectChainCacheStatus.status = RedirectChainCacheStatus::CachedRedirection; 132 double responseTimestamp = currentTime();139 auto responseTimestamp = system_clock::now(); 133 140 // Store the nearest end of cache validity date 134 doubleendOfValidity = responseTimestamp + computeFreshnessLifetimeForHTTPFamily(response, responseTimestamp) - computeCurrentAge(response, responseTimestamp);141 auto endOfValidity = responseTimestamp + computeFreshnessLifetimeForHTTPFamily(response, responseTimestamp) - computeCurrentAge(response, responseTimestamp); 135 142 redirectChainCacheStatus.endOfValidity = std::min(redirectChainCacheStatus.endOfValidity, endOfValidity); 136 143 } … … 144 151 return false; 145 152 case RedirectChainCacheStatus::CachedRedirection: 146 return reuseExpiredRedirection || currentTime() <= redirectChainCacheStatus.endOfValidity;153 return reuseExpiredRedirection || std::chrono::system_clock::now() <= redirectChainCacheStatus.endOfValidity; 147 154 } 148 155 ASSERT_NOT_REACHED(); … … 249 256 CacheControlDirectives parseCacheControlDirectives(const HTTPHeaderMap& headers) 250 257 { 258 using namespace std::chrono; 259 251 260 CacheControlDirectives result; 252 261 … … 266 275 result.mustRevalidate = true; 267 276 else if (equalIgnoringCase(directives[i].first, "max-age")) { 268 if ( !std::isnan(result.maxAge)) {277 if (result.maxAge) { 269 278 // First max-age directive wins if there are multiple ones. 270 279 continue; … … 273 282 double maxAge = directives[i].second.toDouble(&ok); 274 283 if (ok) 275 result.maxAge = maxAge;284 result.maxAge = duration_cast<microseconds>(duration<double>(maxAge)); 276 285 } else if (equalIgnoringCase(directives[i].first, "max-stale")) { 277 286 // https://tools.ietf.org/html/rfc7234#section-5.2.1.2 278 if ( !std::isnan(result.maxStale)) {287 if (result.maxStale) { 279 288 // First max-stale directive wins if there are multiple ones. 280 289 continue; … … 282 291 if (directives[i].second.isEmpty()) { 283 292 // if no value is assigned to max-stale, then the client is willing to accept a stale response of any age. 284 result.maxStale = std::numeric_limits<double>::max();293 result.maxStale = microseconds::max(); 285 294 continue; 286 295 } … … 288 297 double maxStale = directives[i].second.toDouble(&ok); 289 298 if (ok) 290 result.maxStale = maxStale;299 result.maxStale = duration_cast<microseconds>(duration<double>(maxStale)); 291 300 } 292 301 } -
trunk/Source/WebCore/platform/network/CacheValidation.h
r182145 r182271 27 27 #define CacheValidation_h 28 28 29 #include <wtf/Optional.h> 30 29 31 namespace WebCore { 30 32 … … 40 42 RedirectChainCacheStatus() 41 43 : status(NoRedirection) 42 , endOfValidity(std:: numeric_limits<double>::max())44 , endOfValidity(std::chrono::system_clock::time_point::max()) 43 45 { } 44 46 Status status; 45 doubleendOfValidity;47 std::chrono::system_clock::time_point endOfValidity; 46 48 }; 47 49 48 WEBCORE_EXPORT double computeCurrentAge(const ResourceResponse&, doubleresponseTimestamp);49 WEBCORE_EXPORT double computeFreshnessLifetimeForHTTPFamily(const ResourceResponse&, doubleresponseTimestamp);50 WEBCORE_EXPORT std::chrono::microseconds computeCurrentAge(const ResourceResponse&, std::chrono::system_clock::time_point responseTimestamp); 51 WEBCORE_EXPORT std::chrono::microseconds computeFreshnessLifetimeForHTTPFamily(const ResourceResponse&, std::chrono::system_clock::time_point responseTimestamp); 50 52 WEBCORE_EXPORT void updateResponseHeadersAfterRevalidation(ResourceResponse&, const ResourceResponse& validatingResponse); 51 53 WEBCORE_EXPORT void updateRedirectChainStatus(RedirectChainCacheStatus&, const ResourceResponse&); … … 55 57 56 58 struct CacheControlDirectives { 57 double maxAge { std::numeric_limits<double>::quiet_NaN() };58 double maxStale { std::numeric_limits<double>::quiet_NaN() };59 Optional<std::chrono::microseconds> maxAge; 60 Optional<std::chrono::microseconds> maxStale; 59 61 bool noCache { false }; 60 62 bool noStore { false }; -
trunk/Source/WebCore/platform/network/HTTPParsers.cpp
r174920 r182271 235 235 } 236 236 237 double parseDate(const String& value) 238 { 239 return parseDateFromNullTerminatedCharacters(value.utf8().data()); 237 Optional<std::chrono::system_clock::time_point> parseHTTPDate(const String& value) 238 { 239 double dateInMillisecondsSinceEpoch = parseDateFromNullTerminatedCharacters(value.utf8().data()); 240 if (!std::isfinite(dateInMillisecondsSinceEpoch)) 241 return { }; 242 // This assumes system_clock epoch equals Unix epoch which is true for all implementations but unspecified. 243 // FIXME: The parsing function should be switched to std::chrono too. 244 return std::chrono::system_clock::time_point(std::chrono::milliseconds(static_cast<long long>(dateInMillisecondsSinceEpoch))); 240 245 } 241 246 -
trunk/Source/WebCore/platform/network/HTTPParsers.h
r170029 r182271 34 34 #include "ContentSecurityPolicy.h" 35 35 #include <wtf/Forward.h> 36 #include <wtf/Optional.h> 36 37 #include <wtf/Vector.h> 37 38 … … 65 66 bool isValidHTTPToken(const String&); 66 67 bool parseHTTPRefresh(const String& refresh, bool fromHttpEquivMeta, double& delay, String& url); 67 double parseDate(const String&);68 Optional<std::chrono::system_clock::time_point> parseHTTPDate(const String&); 68 69 String filenameFromHTTPContentDisposition(const String&); 69 70 String extractMIMETypeFromMediaType(const String&); -
trunk/Source/WebCore/platform/network/ResourceResponseBase.cpp
r182059 r182271 44 44 } 45 45 46 ResourceResponseBase::ResourceResponseBase() 47 : m_expectedContentLength(0) 46 ResourceResponseBase::ResourceResponseBase() 47 : m_isNull(true) 48 , m_expectedContentLength(0) 48 49 , m_includesCertificateInfo(false) 49 50 , m_httpStatusCode(0) 50 , m_age(0)51 , m_date(0)52 , m_expires(0)53 , m_lastModified(0)54 , m_isNull(true)55 , m_haveParsedCacheControlHeader(false)56 , m_haveParsedAgeHeader(false)57 , m_haveParsedDateHeader(false)58 , m_haveParsedExpiresHeader(false)59 , m_haveParsedLastModifiedHeader(false)60 , m_source(Source::Unknown)61 51 { 62 52 } 63 53 64 54 ResourceResponseBase::ResourceResponseBase(const URL& url, const String& mimeType, long long expectedLength, const String& textEncodingName) 65 : m_url(url) 55 : m_isNull(false) 56 , m_url(url) 66 57 , m_mimeType(mimeType) 67 58 , m_expectedContentLength(expectedLength) … … 69 60 , m_includesCertificateInfo(true) // Empty but valid for synthetic responses. 70 61 , m_httpStatusCode(0) 71 , m_age(0)72 , m_date(0)73 , m_expires(0)74 , m_lastModified(0)75 , m_isNull(false)76 , m_haveParsedCacheControlHeader(false)77 , m_haveParsedAgeHeader(false)78 , m_haveParsedDateHeader(false)79 , m_haveParsedExpiresHeader(false)80 , m_haveParsedLastModifiedHeader(false)81 , m_source(Source::Unknown)82 62 { 83 63 } … … 382 362 } 383 363 384 doubleResourceResponseBase::cacheControlMaxAge() const364 Optional<std::chrono::microseconds> ResourceResponseBase::cacheControlMaxAge() const 385 365 { 386 366 if (!m_haveParsedCacheControlHeader) … … 389 369 } 390 370 391 static doubleparseDateValueInHeader(const HTTPHeaderMap& headers, HTTPHeaderName headerName)371 static Optional<std::chrono::system_clock::time_point> parseDateValueInHeader(const HTTPHeaderMap& headers, HTTPHeaderName headerName) 392 372 { 393 373 String headerValue = headers.get(headerName); 394 374 if (headerValue.isEmpty()) 395 return std::numeric_limits<double>::quiet_NaN();375 return { }; 396 376 // This handles all date formats required by RFC2616: 397 377 // Sun, 06 Nov 1994 08:49:37 GMT ; RFC 822, updated by RFC 1123 398 378 // Sunday, 06-Nov-94 08:49:37 GMT ; RFC 850, obsoleted by RFC 1036 399 379 // Sun Nov 6 08:49:37 1994 ; ANSI C's asctime() format 400 double dateInMilliseconds = parseDate(headerValue); 401 if (!std::isfinite(dateInMilliseconds)) 402 return std::numeric_limits<double>::quiet_NaN(); 403 return dateInMilliseconds / 1000; 404 } 405 406 double ResourceResponseBase::date() const 380 return parseHTTPDate(headerValue); 381 } 382 383 Optional<std::chrono::system_clock::time_point> ResourceResponseBase::date() const 407 384 { 408 385 lazyInit(CommonFieldsOnly); … … 415 392 } 416 393 417 double ResourceResponseBase::age() const 418 { 394 Optional<std::chrono::microseconds> ResourceResponseBase::age() const 395 { 396 using namespace std::chrono; 397 419 398 lazyInit(CommonFieldsOnly); 420 399 … … 422 401 String headerValue = m_httpHeaderFields.get(HTTPHeaderName::Age); 423 402 bool ok; 424 m_age = headerValue.toDouble(&ok);425 if ( !ok)426 m_age = std::numeric_limits<double>::quiet_NaN();403 double ageDouble = headerValue.toDouble(&ok); 404 if (ok) 405 m_age = duration_cast<microseconds>(duration<double>(ageDouble)); 427 406 m_haveParsedAgeHeader = true; 428 407 } … … 430 409 } 431 410 432 doubleResourceResponseBase::expires() const411 Optional<std::chrono::system_clock::time_point> ResourceResponseBase::expires() const 433 412 { 434 413 lazyInit(CommonFieldsOnly); … … 441 420 } 442 421 443 doubleResourceResponseBase::lastModified() const422 Optional<std::chrono::system_clock::time_point> ResourceResponseBase::lastModified() const 444 423 { 445 424 lazyInit(CommonFieldsOnly); -
trunk/Source/WebCore/platform/network/ResourceResponseBase.h
r182071 r182271 105 105 WEBCORE_EXPORT bool cacheControlContainsMustRevalidate() const; 106 106 WEBCORE_EXPORT bool hasCacheValidatorFields() const; 107 WEBCORE_EXPORT doublecacheControlMaxAge() const;108 doubledate() const;109 doubleage() const;110 WEBCORE_EXPORT doubleexpires() const;111 WEBCORE_EXPORT doublelastModified() const;107 WEBCORE_EXPORT Optional<std::chrono::microseconds> cacheControlMaxAge() const; 108 WEBCORE_EXPORT Optional<std::chrono::system_clock::time_point> date() const; 109 WEBCORE_EXPORT Optional<std::chrono::microseconds> age() const; 110 WEBCORE_EXPORT Optional<std::chrono::system_clock::time_point> expires() const; 111 WEBCORE_EXPORT Optional<std::chrono::system_clock::time_point> lastModified() const; 112 112 113 113 enum class Source { Unknown, Network, DiskCache, DiskCacheAfterValidation }; … … 148 148 static bool platformCompare(const ResourceResponse&, const ResourceResponse&) { return true; } 149 149 150 private: 151 const ResourceResponse& asResourceResponse() const; 152 void parseCacheControlDirectives() const; 153 void updateHeaderParsedState(HTTPHeaderName); 154 155 protected: 156 bool m_isNull; 150 157 URL m_url; 151 158 AtomicString m_mimeType; … … 162 169 163 170 private: 164 mutable doublem_age;165 mutable doublem_date;166 mutable doublem_expires;167 mutable doublem_lastModified;171 mutable Optional<std::chrono::microseconds> m_age; 172 mutable Optional<std::chrono::system_clock::time_point> m_date; 173 mutable Optional<std::chrono::system_clock::time_point> m_expires; 174 mutable Optional<std::chrono::system_clock::time_point> m_lastModified; 168 175 mutable CacheControlDirectives m_cacheControlDirectives; 169 176 170 public: 171 bool m_isNull : 1; 172 173 private: 174 const ResourceResponse& asResourceResponse() const; 175 void parseCacheControlDirectives() const; 176 void updateHeaderParsedState(HTTPHeaderName); 177 178 mutable bool m_haveParsedCacheControlHeader : 1; 179 mutable bool m_haveParsedAgeHeader : 1; 180 mutable bool m_haveParsedDateHeader : 1; 181 mutable bool m_haveParsedExpiresHeader : 1; 182 mutable bool m_haveParsedLastModifiedHeader : 1; 183 184 Source m_source; 177 mutable bool m_haveParsedCacheControlHeader { false }; 178 mutable bool m_haveParsedAgeHeader { false }; 179 mutable bool m_haveParsedDateHeader { false }; 180 mutable bool m_haveParsedExpiresHeader { false }; 181 mutable bool m_haveParsedLastModifiedHeader { false }; 182 183 Source m_source { Source::Unknown }; 185 184 }; 186 185 -
trunk/Source/WebKit/win/Plugins/PluginStream.cpp
r178219 r182271 124 124 } 125 125 126 static uint32_t lastModifiedDate (const ResourceResponse& response)127 { 128 doublelastModified = response.lastModified();129 if (! std::isfinite(lastModified))126 static uint32_t lastModifiedDateMS(const ResourceResponse& response) 127 { 128 auto lastModified = response.lastModified(); 129 if (!lastModified) 130 130 return 0; 131 131 132 return lastModified * 1000;132 return std::chrono::duration_cast<std::chrono::milliseconds>(lastModified.value().time_since_epoch()).count(); 133 133 } 134 134 … … 179 179 m_stream.ndata = this; 180 180 m_stream.end = max(expectedContentLength, 0LL); 181 m_stream.lastmodified = lastModifiedDate (m_resourceResponse);181 m_stream.lastmodified = lastModifiedDateMS(m_resourceResponse); 182 182 m_stream.notifyData = m_notifyData; 183 183 -
trunk/Source/WebKit2/ChangeLog
r182267 r182271 1 2015-04-01 Antti Koivisto <antti@apple.com> 2 3 Use std::chrono types to represent time in response and cache classes 4 https://bugs.webkit.org/show_bug.cgi?id=143316 5 6 Reviewed by Andreas Kling. 7 8 * NetworkProcess/NetworkResourceLoader.cpp: 9 (WebKit::NetworkResourceLoader::didFinishLoading): 10 * NetworkProcess/cache/NetworkCache.cpp: 11 (WebKit::NetworkCache::responseHasExpired): 12 (WebKit::NetworkCache::responseNeedsRevalidation): 13 (WebKit::NetworkCache::makeStoreDecision): 14 (WebKit::NetworkCache::Cache::store): 15 * NetworkProcess/cache/NetworkCacheEntry.cpp: 16 (WebKit::NetworkCache::Entry::Entry): 17 (WebKit::NetworkCache::Entry::asJSON): 18 * NetworkProcess/cache/NetworkCacheEntry.h: 19 (WebKit::NetworkCache::Entry::timeStamp): 20 * NetworkProcess/cache/NetworkCacheStorage.cpp: 21 (WebKit::NetworkCache::decodeRecordMetaData): 22 (WebKit::NetworkCache::decodeRecord): 23 24 Sanity check the timestamp on decode. 25 26 (WebKit::NetworkCache::encodeRecordMetaData): 27 (WebKit::NetworkCache::encodeRecordHeader): 28 (WebKit::NetworkCache::Storage::traverse): 29 * NetworkProcess/cache/NetworkCacheStorage.h: 30 * WebProcess/Plugins/PluginView.cpp: 31 (WebKit::lastModifiedDateMS): 32 (WebKit::PluginView::Stream::didReceiveResponse): 33 (WebKit::PluginView::manualLoadDidReceiveResponse): 34 (WebKit::lastModifiedDate): Deleted. 35 1 36 2015-04-01 Chris Dumez <cdumez@apple.com> 2 37 -
trunk/Source/WebKit2/NetworkProcess/NetworkResourceLoader.cpp
r182020 r182271 319 319 bool hasCacheableRedirect = m_response.isHTTP() && WebCore::redirectChainAllowsReuse(m_redirectChainCacheStatus, allowStale ? WebCore::ReuseExpiredRedirection : WebCore::DoNotReuseExpiredRedirection); 320 320 if (hasCacheableRedirect && m_redirectChainCacheStatus.status == RedirectChainCacheStatus::CachedRedirection) { 321 // FIXME: Cache the actual redirects instead of the end result.322 double now = currentTime();323 doubleresponseEndOfValidity = now + WebCore::computeFreshnessLifetimeForHTTPFamily(m_response, now) - WebCore::computeCurrentAge(m_response, now);321 // Maybe we should cache the actual redirects instead of the end result? 322 auto now = std::chrono::system_clock::now(); 323 auto responseEndOfValidity = now + WebCore::computeFreshnessLifetimeForHTTPFamily(m_response, now) - WebCore::computeCurrentAge(m_response, now); 324 324 hasCacheableRedirect = responseEndOfValidity <= m_redirectChainCacheStatus.endOfValidity; 325 325 } -
trunk/Source/WebKit2/NetworkProcess/cache/NetworkCache.cpp
r182154 r182271 151 151 } 152 152 153 static bool responseHasExpired(const WebCore::ResourceResponse& response, std::chrono:: milliseconds timestamp, doublemaxStale)153 static bool responseHasExpired(const WebCore::ResourceResponse& response, std::chrono::system_clock::time_point timestamp, Optional<std::chrono::microseconds> maxStale) 154 154 { 155 155 if (response.cacheControlContainsNoCache()) 156 156 return true; 157 157 158 auto doubleTimeStamp = std::chrono::duration<double>(timestamp); 159 double age = WebCore::computeCurrentAge(response, doubleTimeStamp.count()); 160 double lifetime = WebCore::computeFreshnessLifetimeForHTTPFamily(response, doubleTimeStamp.count()); 161 162 maxStale = std::isnan(maxStale) ? 0 : maxStale; 163 bool hasExpired = age - lifetime > maxStale; 158 auto age = WebCore::computeCurrentAge(response, timestamp); 159 auto lifetime = WebCore::computeFreshnessLifetimeForHTTPFamily(response, timestamp); 160 161 auto maximumStaleness = maxStale ? maxStale.value() : 0_ms; 162 bool hasExpired = age - lifetime > maximumStaleness; 164 163 165 164 #ifndef LOG_DISABLED … … 171 170 } 172 171 173 static bool responseNeedsRevalidation(const WebCore::ResourceResponse& response, const WebCore::ResourceRequest& request, std::chrono:: millisecondstimestamp)172 static bool responseNeedsRevalidation(const WebCore::ResourceResponse& response, const WebCore::ResourceRequest& request, std::chrono::system_clock::time_point timestamp) 174 173 { 175 174 auto requestDirectives = WebCore::parseCacheControlDirectives(request.httpHeaderFields()); … … 177 176 return true; 178 177 // For requests we ignore max-age values other than zero. 179 if (requestDirectives.maxAge == 0)178 if (requestDirectives.maxAge && requestDirectives.maxAge.value() == 0_ms) 180 179 return true; 181 180 … … 270 269 if (!isStatusCodeCacheableByDefault(response.httpStatusCode())) { 271 270 // http://tools.ietf.org/html/rfc7234#section-4.3.2 272 bool hasExpirationHeaders = std::isfinite(response.expires()) || std::isfinite(response.cacheControlMaxAge());271 bool hasExpirationHeaders = response.expires() || response.cacheControlMaxAge(); 273 272 bool expirationHeadersAllowCaching = isStatusCodePotentiallyCacheable(response.httpStatusCode()) && hasExpirationHeaders; 274 273 if (!expirationHeadersAllowCaching) … … 279 278 bool storeUnconditionallyForHistoryNavigation = originalRequest.priority() == WebCore::ResourceLoadPriorityVeryHigh; 280 279 if (!storeUnconditionallyForHistoryNavigation) { 281 auto currentTime = std::chrono::duration<double>(std::chrono::system_clock::now().time_since_epoch());282 bool hasNonZeroLifetime = !response.cacheControlContainsNoCache() && WebCore::computeFreshnessLifetimeForHTTPFamily(response, currentTime.count()) > 0;280 auto now = std::chrono::system_clock::now(); 281 bool hasNonZeroLifetime = !response.cacheControlContainsNoCache() && WebCore::computeFreshnessLifetimeForHTTPFamily(response, now) > 0_ms; 283 282 284 283 bool possiblyReusable = response.hasCacheValidatorFields() || hasNonZeroLifetime; … … 359 358 360 359 StoreDecision storeDecision = makeStoreDecision(originalRequest, response); 361 362 360 if (storeDecision != StoreDecision::Yes) { 363 361 LOG(NetworkCache, "(NetworkProcess) didn't store, storeDecision=%d", storeDecision); -
trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheEntry.cpp
r182136 r182271 43 43 Entry::Entry(const Key& key, const WebCore::ResourceResponse& response, RefPtr<WebCore::SharedBuffer>&& buffer, const Vector<std::pair<String, String>>& varyingRequestHeaders) 44 44 : m_key(key) 45 , m_timeStamp(std::chrono:: duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()))45 , m_timeStamp(std::chrono::system_clock::now()) 46 46 , m_response(response) 47 47 , m_varyingRequestHeaders(varyingRequestHeaders) … … 161 161 json.appendLiteral(",\n"); 162 162 json.appendLiteral("\"timestamp\": "); 163 json.appendNumber( m_timeStamp.count());163 json.appendNumber(std::chrono::duration_cast<std::chrono::milliseconds>(m_timeStamp.time_since_epoch()).count()); 164 164 json.appendLiteral(",\n"); 165 165 json.appendLiteral("\"URL\": "); -
trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheEntry.h
r182136 r182271 52 52 53 53 const Key& key() const { return m_key; } 54 std::chrono:: millisecondstimeStamp() const { return m_timeStamp; }54 std::chrono::system_clock::time_point timeStamp() const { return m_timeStamp; } 55 55 const WebCore::ResourceResponse& response() const { return m_response; } 56 56 const Vector<std::pair<String, String>>& varyingRequestHeaders() const { return m_varyingRequestHeaders; } … … 73 73 74 74 Key m_key; 75 std::chrono:: millisecondsm_timeStamp;75 std::chrono::system_clock::time_point m_timeStamp; 76 76 WebCore::ResourceResponse m_response; 77 77 Vector<std::pair<String, String>> m_varyingRequestHeaders; -
trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.cpp
r182153 r182271 143 143 unsigned cacheStorageVersion; 144 144 Key key; 145 std::chrono::milliseconds timeStamp; 145 // FIXME: Add encoder/decoder for time_point. 146 std::chrono::milliseconds epochRelativeTimeStamp; 146 147 unsigned headerChecksum; 147 148 uint64_t headerOffset; … … 161 162 if (!decoder.decode(metaData.key)) 162 163 return false; 163 if (!decoder.decode(metaData. timeStamp))164 if (!decoder.decode(metaData.epochRelativeTimeStamp)) 164 165 return false; 165 166 if (!decoder.decode(metaData.headerChecksum)) … … 216 217 return nullptr; 217 218 219 // Sanity check against time stamps in future. 220 auto timeStamp = std::chrono::system_clock::time_point(metaData.epochRelativeTimeStamp); 221 if (timeStamp > std::chrono::system_clock::now()) 222 return nullptr; 223 218 224 Data bodyData; 219 225 if (metaData.bodySize) { … … 235 241 return std::make_unique<Storage::Record>(Storage::Record { 236 242 metaData.key, 237 metaData.timeStamp,243 timeStamp, 238 244 headerData, 239 245 bodyData … … 247 253 encoder << metaData.cacheStorageVersion; 248 254 encoder << metaData.key; 249 encoder << metaData. timeStamp;255 encoder << metaData.epochRelativeTimeStamp; 250 256 encoder << metaData.headerChecksum; 251 257 encoder << metaData.headerSize; … … 261 267 { 262 268 RecordMetaData metaData(record.key); 263 metaData. timeStamp = record.timeStamp;269 metaData.epochRelativeTimeStamp = std::chrono::duration_cast<std::chrono::milliseconds>(record.timeStamp.time_since_epoch()); 264 270 metaData.headerChecksum = hashData(record.header); 265 271 metaData.headerSize = record.header.size(); … … 447 453 Data headerData; 448 454 if (decodeRecordHeader(fileData, metaData, headerData)) { 449 Record record { metaData.key, metaData.timeStamp, headerData, { } };455 Record record { metaData.key, std::chrono::system_clock::time_point(metaData.epochRelativeTimeStamp), headerData, { } }; 450 456 info.bodySize = metaData.bodySize; 451 457 traverseHandler(&record, info); … … 600 606 601 607 // For sanity. 602 if (age <= seconds::zero() || accessAge < seconds::zero()|| accessAge > age)608 if (age <= 0_s || accessAge < 0_s || accessAge > age) 603 609 return 0; 604 610 -
trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.h
r182136 r182271 50 50 struct Record { 51 51 Key key; 52 std::chrono:: millisecondstimeStamp;52 std::chrono::system_clock::time_point timeStamp; 53 53 Data header; 54 54 Data body; -
trunk/Source/WebKit2/WebProcess/Plugins/PluginView.cpp
r181599 r182271 202 202 } 203 203 204 static uint32_t lastModifiedDate (const ResourceResponse& response)205 { 206 doublelastModified = response.lastModified();207 if (! std::isfinite(lastModified))204 static uint32_t lastModifiedDateMS(const ResourceResponse& response) 205 { 206 auto lastModified = response.lastModified(); 207 if (!lastModified) 208 208 return 0; 209 209 210 return lastModified * 1000;210 return std::chrono::duration_cast<std::chrono::milliseconds>(lastModified.value().time_since_epoch()).count(); 211 211 } 212 212 … … 224 224 streamLength = expectedContentLength; 225 225 226 m_pluginView->m_plugin->streamDidReceiveResponse(m_streamID, responseURL, streamLength, lastModifiedDate (response), mimeType, headers, response.suggestedFilename());226 m_pluginView->m_plugin->streamDidReceiveResponse(m_streamID, responseURL, streamLength, lastModifiedDateMS(response), mimeType, headers, response.suggestedFilename()); 227 227 } 228 228 … … 414 414 streamLength = expectedContentLength; 415 415 416 m_plugin->manualStreamDidReceiveResponse(responseURL, streamLength, lastModifiedDate (response), mimeType, headers, response.suggestedFilename());416 m_plugin->manualStreamDidReceiveResponse(responseURL, streamLength, lastModifiedDateMS(response), mimeType, headers, response.suggestedFilename()); 417 417 } 418 418
Note: See TracChangeset
for help on using the changeset viewer.