| 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..20af67e0fbe72d50f45c831a0d651aedb5f75854 100644
|
| --- a/net/http/http_cache_transaction.cc
|
| +++ b/net/http/http_cache_transaction.cc
|
| @@ -1960,10 +1960,10 @@ int HttpCache::Transaction::BeginCacheValidation() {
|
|
|
| ValidationType required_validation = RequiresValidation();
|
|
|
| - bool skip_validation = (required_validation == VALIDATION_NONE);
|
| + bool skip_validation = (required_validation == ValidationType::NONE);
|
|
|
| if ((effective_load_flags_ & LOAD_SUPPORT_ASYNC_REVALIDATION) &&
|
| - required_validation == VALIDATION_ASYNCHRONOUS) {
|
| + required_validation == ValidationType::ASYNCHRONOUS) {
|
| DCHECK_EQ(request_->method, "GET");
|
| skip_validation = true;
|
| response_.async_revalidation_required = true;
|
| @@ -2096,7 +2096,7 @@ int HttpCache::Transaction::BeginExternallyConditionalizedRequest() {
|
| EXTERNALLY_CONDITIONALIZED_CACHE_USABLE;
|
| if (mode_ == NONE)
|
| type = EXTERNALLY_CONDITIONALIZED_MISMATCHED_VALIDATORS;
|
| - else if (RequiresValidation() != VALIDATION_NONE)
|
| + else if (RequiresValidation() != ValidationType::NONE)
|
| type = EXTERNALLY_CONDITIONALIZED_CACHE_REQUIRES_VALIDATION;
|
|
|
| // TODO(ricea): Add CACHE_USABLE_STALE once stale-while-revalidate CL landed.
|
| @@ -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
|
| @@ -2158,40 +2159,41 @@ ValidationType HttpCache::Transaction::RequiresValidation() {
|
| !response_.vary_data.MatchesRequest(*request_,
|
| *response_.headers.get())) {
|
| vary_mismatch_ = true;
|
| - return VALIDATION_SYNCHRONOUS;
|
| + return ValidationType::SYNCHRONOUS;
|
| }
|
|
|
| if (effective_load_flags_ & LOAD_PREFERRING_CACHE)
|
| - return VALIDATION_NONE;
|
| + return ValidationType::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;
|
| + return ValidationType::NONE;
|
| }
|
|
|
| if (effective_load_flags_ & LOAD_VALIDATE_CACHE)
|
| - return VALIDATION_SYNCHRONOUS;
|
| + return ValidationType::SYNCHRONOUS;
|
|
|
| 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());
|
| + return ValidationType::SYNCHRONOUS;
|
|
|
| - 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.GetExpirationTime())
|
| + return ValidationType::NONE;
|
| + if (now > expiration_times.GetAsyncExpirationTime())
|
| + return ValidationType::SYNCHRONOUS;
|
|
|
| - return validation_required_by_headers;
|
| + // Asynchronous revalidation is only supported for GET methods.
|
| + if (request_->method != "GET")
|
| + return ValidationType::SYNCHRONOUS;
|
| + return ValidationType::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()));
|
| }
|
| }
|
|
|