Index: net/http/http_cache_transaction.cc |
diff --git a/net/http/http_cache_transaction.cc b/net/http/http_cache_transaction.cc |
index 23295ad154c6babc791d99404ff253305bcbd089..0f5709b6c8682df81d90bf432e0d7f767a5e2db1 100644 |
--- a/net/http/http_cache_transaction.cc |
+++ b/net/http/http_cache_transaction.cc |
@@ -2149,7 +2149,8 @@ int HttpCache::Transaction::RestartNetworkRequestWithAuth( |
return rv; |
} |
-ValidationType HttpCache::Transaction::RequiresValidation() { |
+HttpCache::Transaction::ValidationType |
+HttpCache::Transaction::RequiresValidation() { |
// TODO(darin): need to do more work here: |
// - make sure we have a matching request method |
// - watch out for cached responses that depend on authentication |
@@ -2164,11 +2165,15 @@ ValidationType HttpCache::Transaction::RequiresValidation() { |
if (effective_load_flags_ & LOAD_PREFERRING_CACHE) |
return VALIDATION_NONE; |
+ HttpResponseHeaders::ExpirationTimes expiration_times = |
+ response_.headers->GetExpirationTimes(response_.request_time, |
+ response_.response_time); |
+ base::Time now = cache_->clock_->Now(); |
+ |
if (response_.unused_since_prefetch && |
!(effective_load_flags_ & LOAD_PREFETCH) && |
- response_.headers->GetCurrentAge( |
- response_.request_time, response_.response_time, |
- cache_->clock_->Now()) < TimeDelta::FromMinutes(kPrefetchReuseMins)) { |
+ now - expiration_times.corrected_response_time < |
+ TimeDelta::FromMinutes(kPrefetchReuseMins)) { |
// The first use of a resource after prefetch within a short window skips |
// validation. |
return VALIDATION_NONE; |
@@ -2180,18 +2185,15 @@ ValidationType HttpCache::Transaction::RequiresValidation() { |
if (request_->method == "PUT" || request_->method == "DELETE") |
return VALIDATION_SYNCHRONOUS; |
- ValidationType validation_required_by_headers = |
- response_.headers->RequiresValidation(response_.request_time, |
- response_.response_time, |
- cache_->clock_->Now()); |
- |
- if (validation_required_by_headers == VALIDATION_ASYNCHRONOUS) { |
- // Asynchronous revalidation is only supported for GET methods. |
- if (request_->method != "GET") |
- return VALIDATION_SYNCHRONOUS; |
- } |
+ if (now < expiration_times.GetFreshnessExpiry()) |
+ return VALIDATION_NONE; |
+ if (now > expiration_times.GetStalenessExpiry()) |
+ return VALIDATION_SYNCHRONOUS; |
- return validation_required_by_headers; |
+ // Asynchronous revalidation is only supported for GET methods. |
+ if (request_->method != "GET") |
+ return VALIDATION_SYNCHRONOUS; |
+ return VALIDATION_ASYNCHRONOUS; |
} |
bool HttpCache::Transaction::ConditionalizeRequest() { |
@@ -2241,19 +2243,18 @@ bool HttpCache::Transaction::ConditionalizeRequest() { |
if (!use_if_range) { |
// stale-while-revalidate is not useful when we only have a partial response |
// cached, so don't set the header in that case. |
- HttpResponseHeaders::FreshnessLifetimes lifetimes = |
- response_.headers->GetFreshnessLifetimes(response_.response_time); |
- if (lifetimes.staleness > TimeDelta()) { |
- TimeDelta current_age = response_.headers->GetCurrentAge( |
- response_.request_time, response_.response_time, |
- cache_->clock_->Now()); |
- |
+ HttpResponseHeaders::ExpirationTimes expirations = |
+ response_.headers->GetExpirationTimes(response_.request_time, |
+ response_.response_time); |
+ if (!expirations.staleness_lifetime.is_zero()) { |
+ TimeDelta current_age = |
+ cache_->clock_->Now() - expirations.corrected_response_time; |
custom_request_->extra_headers.SetHeader( |
kFreshnessHeader, |
base::StringPrintf("max-age=%" PRId64 |
",stale-while-revalidate=%" PRId64 ",age=%" PRId64, |
- lifetimes.freshness.InSeconds(), |
- lifetimes.staleness.InSeconds(), |
+ expirations.freshness_lifetime.InSeconds(), |
+ expirations.staleness_lifetime.InSeconds(), |
current_age.InSeconds())); |
} |
} |