Index: net/http/http_cache_transaction.cc |
diff --git a/net/http/http_cache_transaction.cc b/net/http/http_cache_transaction.cc |
index af3487378b1bc7134d55c9708a61b428ae53a274..eb6ee6ddfe1dafc8e0f4974856b57afbe7fe3026 100644 |
--- a/net/http/http_cache_transaction.cc |
+++ b/net/http/http_cache_transaction.cc |
@@ -16,16 +16,13 @@ |
#include "base/bind.h" |
#include "base/callback_helpers.h" |
#include "base/compiler_specific.h" |
-#include "base/format_macros.h" |
#include "base/location.h" |
#include "base/macros.h" |
#include "base/metrics/histogram_macros.h" |
#include "base/metrics/sparse_histogram.h" |
#include "base/single_thread_task_runner.h" |
#include "base/strings/string_number_conversions.h" // For HexEncode. |
-#include "base/strings/string_piece.h" |
#include "base/strings/string_util.h" // For LowerCaseEqualsASCII. |
-#include "base/strings/stringprintf.h" |
#include "base/threading/thread_task_runner_handle.h" |
#include "base/time/clock.h" |
#include "base/trace_event/trace_event.h" |
@@ -55,9 +52,6 @@ using CacheEntryStatus = HttpResponseInfo::CacheEntryStatus; |
namespace { |
-// TODO(ricea): Move this to HttpResponseHeaders once it is standardised. |
-static const char kFreshnessHeader[] = "Resource-Freshness"; |
- |
// From http://tools.ietf.org/html/draft-ietf-httpbis-p6-cache-21#section-6 |
// a "non-error response" is one with a 2xx (Successful) or 3xx |
// (Redirection) status code. |
@@ -2101,7 +2095,7 @@ int HttpCache::Transaction::BeginCacheRead() { |
return ERR_CACHE_MISS; |
} |
- if (RequiresValidation() != VALIDATION_NONE) { |
+ if (RequiresValidation()) { |
next_state_ = STATE_NONE; |
return ERR_CACHE_MISS; |
} |
@@ -2120,16 +2114,7 @@ int HttpCache::Transaction::BeginCacheRead() { |
int HttpCache::Transaction::BeginCacheValidation() { |
DCHECK_EQ(mode_, READ_WRITE); |
- ValidationType required_validation = RequiresValidation(); |
- |
- bool skip_validation = (required_validation == VALIDATION_NONE); |
- |
- if ((effective_load_flags_ & LOAD_SUPPORT_ASYNC_REVALIDATION) && |
- required_validation == VALIDATION_ASYNCHRONOUS) { |
- DCHECK_EQ(request_->method, "GET"); |
- skip_validation = true; |
- response_.async_revalidation_required = true; |
- } |
+ bool skip_validation = !RequiresValidation(); |
if (request_->method == "HEAD" && |
(truncated_ || response_.headers->response_code() == 206)) { |
@@ -2258,10 +2243,9 @@ int HttpCache::Transaction::BeginExternallyConditionalizedRequest() { |
EXTERNALLY_CONDITIONALIZED_CACHE_USABLE; |
if (mode_ == NONE) |
type = EXTERNALLY_CONDITIONALIZED_MISMATCHED_VALIDATORS; |
- else if (RequiresValidation() != VALIDATION_NONE) |
+ else if (RequiresValidation()) |
type = EXTERNALLY_CONDITIONALIZED_CACHE_REQUIRES_VALIDATION; |
- // TODO(ricea): Add CACHE_USABLE_STALE once stale-while-revalidate CL landed. |
// TODO(ricea): Either remove this histogram or make it permanent by M40. |
UMA_HISTOGRAM_ENUMERATION("HttpCache.ExternallyConditionalized", |
type, |
@@ -2311,7 +2295,7 @@ int HttpCache::Transaction::RestartNetworkRequestWithAuth( |
return rv; |
} |
-ValidationType HttpCache::Transaction::RequiresValidation() { |
+bool 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 |
@@ -2322,11 +2306,11 @@ ValidationType HttpCache::Transaction::RequiresValidation() { |
*response_.headers.get())) { |
vary_mismatch_ = true; |
validation_cause_ = VALIDATION_CAUSE_VARY_MISMATCH; |
- return VALIDATION_SYNCHRONOUS; |
+ return true; |
} |
if (effective_load_flags_ & LOAD_SKIP_CACHE_VALIDATION) |
- return VALIDATION_NONE; |
+ return false; |
if (response_.unused_since_prefetch && |
!(effective_load_flags_ & LOAD_PREFETCH) && |
@@ -2335,23 +2319,21 @@ ValidationType HttpCache::Transaction::RequiresValidation() { |
cache_->clock_->Now()) < TimeDelta::FromMinutes(kPrefetchReuseMins)) { |
// The first use of a resource after prefetch within a short window skips |
// validation. |
- return VALIDATION_NONE; |
+ return false; |
} |
if (effective_load_flags_ & LOAD_VALIDATE_CACHE) { |
validation_cause_ = VALIDATION_CAUSE_VALIDATE_FLAG; |
- return VALIDATION_SYNCHRONOUS; |
+ return true; |
} |
if (request_->method == "PUT" || request_->method == "DELETE") |
- return VALIDATION_SYNCHRONOUS; |
+ return true; |
- ValidationType validation_required_by_headers = |
- response_.headers->RequiresValidation(response_.request_time, |
- response_.response_time, |
- cache_->clock_->Now()); |
+ bool validation_required_by_headers = response_.headers->RequiresValidation( |
+ response_.request_time, response_.response_time, cache_->clock_->Now()); |
- if (validation_required_by_headers != VALIDATION_NONE) { |
+ if (validation_required_by_headers) { |
HttpResponseHeaders::FreshnessLifetimes lifetimes = |
response_.headers->GetFreshnessLifetimes(response_.response_time); |
if (lifetimes.freshness == base::TimeDelta()) { |
@@ -2365,12 +2347,6 @@ ValidationType HttpCache::Transaction::RequiresValidation() { |
} |
} |
- if (validation_required_by_headers == VALIDATION_ASYNCHRONOUS) { |
- // Asynchronous revalidation is only supported for GET methods. |
- if (request_->method != "GET") |
- return VALIDATION_SYNCHRONOUS; |
- } |
- |
return validation_required_by_headers; |
} |
@@ -2418,26 +2394,6 @@ bool HttpCache::Transaction::ConditionalizeRequest() { |
bool use_if_range = |
partial_ && !partial_->IsCurrentRangeCached() && !invalid_range_; |
- 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()); |
- |
- custom_request_->extra_headers.SetHeader( |
- kFreshnessHeader, |
- base::StringPrintf("max-age=%" PRId64 |
- ",stale-while-revalidate=%" PRId64 ",age=%" PRId64, |
- lifetimes.freshness.InSeconds(), |
- lifetimes.staleness.InSeconds(), |
- current_age.InSeconds())); |
- } |
- } |
- |
if (!etag_value.empty()) { |
if (use_if_range) { |
// We don't want to switch to WRITE mode if we don't have this block of a |