diff options
author | ricea <ricea@chromium.org> | 2014-10-30 02:15:48 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-10-30 09:16:06 +0000 |
commit | 4373698a495a4949e673f885bfc9ed2da0afb1d3 (patch) | |
tree | 42910860f36c0a8a4adc446d2049d78a38dd993f | |
parent | 1c92a1af190ca21f93e746f1f42026211d3ea3a8 (diff) | |
download | chromium_src-4373698a495a4949e673f885bfc9ed2da0afb1d3.zip chromium_src-4373698a495a4949e673f885bfc9ed2da0afb1d3.tar.gz chromium_src-4373698a495a4949e673f885bfc9ed2da0afb1d3.tar.bz2 |
Post-commit fixes for "stale-while-revalidate..."
I accidentally committed http://crrev.com/455623003 before getting LGTM from
mmenke@. This CL is for additional fixes that he requested.
BUG=348877
TEST=net_unittests
Review URL: https://codereview.chromium.org/665023002
Cr-Commit-Position: refs/heads/master@{#302056}
-rw-r--r-- | chrome/browser/io_thread.cc | 16 | ||||
-rw-r--r-- | chrome/browser/net/chrome_network_delegate.cc | 6 | ||||
-rw-r--r-- | chrome/browser/predictors/resource_prefetch_predictor.cc | 2 | ||||
-rw-r--r-- | net/http/http_cache_transaction.cc | 8 | ||||
-rw-r--r-- | net/http/http_response_headers.cc | 27 | ||||
-rw-r--r-- | net/http/http_response_headers.h | 16 |
6 files changed, 39 insertions, 36 deletions
diff --git a/chrome/browser/io_thread.cc b/chrome/browser/io_thread.cc index b84a24b..7ca1526 100644 --- a/chrome/browser/io_thread.cc +++ b/chrome/browser/io_thread.cc @@ -311,6 +311,15 @@ const std::string& GetVariationParam( return it->second; } +// Return true if stale-while-revalidate support should be enabled. +bool IsStaleWhileRevalidateEnabled(const base::CommandLine& command_line) { + if (command_line.HasSwitch(switches::kEnableStaleWhileRevalidate)) + return true; + const std::string group_name = + base::FieldTrialList::FindFullName(kStaleWhileRevalidateFieldTrialName); + return group_name == "Enabled"; +} + } // namespace class IOThread::LoggingNetworkChangeObserver @@ -660,11 +669,8 @@ void IOThread::InitAsync() { globals_->enable_ssl_connect_job_waiting = true; if (command_line.HasSwitch(switches::kIgnoreCertificateErrors)) globals_->ignore_certificate_errors = true; - if (command_line.HasSwitch(switches::kEnableStaleWhileRevalidate)) - globals_->use_stale_while_revalidate = true; - if (base::FieldTrialList::FindFullName(kStaleWhileRevalidateFieldTrialName) == - "Enabled") - globals_->use_stale_while_revalidate = true; + globals_->use_stale_while_revalidate = + IsStaleWhileRevalidateEnabled(command_line); if (command_line.HasSwitch(switches::kTestingFixedHttpPort)) { globals_->testing_fixed_http_port = GetSwitchValueAsInt(command_line, switches::kTestingFixedHttpPort); diff --git a/chrome/browser/net/chrome_network_delegate.cc b/chrome/browser/net/chrome_network_delegate.cc index fd9afe6..a4c911f 100644 --- a/chrome/browser/net/chrome_network_delegate.cc +++ b/chrome/browser/net/chrome_network_delegate.cc @@ -572,10 +572,8 @@ void ChromeNetworkDelegate::OnCompleted(net::URLRequest* request, data_reduction_proxy::GetDataReductionProxyRequestType(request); base::TimeDelta freshness_lifetime = - request->response_info() - .headers->GetFreshnessLifetimes( - request->response_info().response_time) - .fresh; + request->response_info().headers->GetFreshnessLifetimes( + request->response_info().response_time).freshness; int64 adjusted_original_content_length = data_reduction_proxy::GetAdjustedOriginalContentLength( request_type, original_content_length, diff --git a/chrome/browser/predictors/resource_prefetch_predictor.cc b/chrome/browser/predictors/resource_prefetch_predictor.cc index 878113d..a34dda4 100644 --- a/chrome/browser/predictors/resource_prefetch_predictor.cc +++ b/chrome/browser/predictors/resource_prefetch_predictor.cc @@ -247,7 +247,7 @@ bool ResourcePrefetchPredictor::IsCacheable(const net::URLRequest* response) { base::Time response_time(response_info.response_time); response_time += base::TimeDelta::FromSeconds(1); base::TimeDelta freshness = - response_info.headers->GetFreshnessLifetimes(response_time).fresh; + response_info.headers->GetFreshnessLifetimes(response_time).freshness; return freshness > base::TimeDelta(); } diff --git a/net/http/http_cache_transaction.cc b/net/http/http_cache_transaction.cc index 4a0d82d..0b0700c 100644 --- a/net/http/http_cache_transaction.cc +++ b/net/http/http_cache_transaction.cc @@ -2407,9 +2407,9 @@ 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 lifetime = + HttpResponseHeaders::FreshnessLifetimes lifetimes = response_.headers->GetFreshnessLifetimes(response_.response_time); - if (lifetime.stale > TimeDelta()) { + if (lifetimes.staleness > TimeDelta()) { TimeDelta current_age = response_.headers->GetCurrentAge( response_.request_time, response_.response_time, Time::Now()); @@ -2417,8 +2417,8 @@ bool HttpCache::Transaction::ConditionalizeRequest() { kFreshnessHeader, base::StringPrintf("max-age=%" PRId64 ",stale-while-revalidate=%" PRId64 ",age=%" PRId64, - lifetime.fresh.InSeconds(), - lifetime.stale.InSeconds(), + lifetimes.freshness.InSeconds(), + lifetimes.staleness.InSeconds(), current_age.InSeconds())); } } diff --git a/net/http/http_response_headers.cc b/net/http/http_response_headers.cc index 4ffed82..180d088 100644 --- a/net/http/http_response_headers.cc +++ b/net/http/http_response_headers.cc @@ -966,15 +966,15 @@ ValidationType HttpResponseHeaders::RequiresValidation( const Time& response_time, const Time& current_time) const { FreshnessLifetimes lifetimes = GetFreshnessLifetimes(response_time); - if (lifetimes.fresh == TimeDelta() && lifetimes.stale == TimeDelta()) + if (lifetimes.freshness == TimeDelta() && lifetimes.staleness == TimeDelta()) return VALIDATION_SYNCHRONOUS; TimeDelta age = GetCurrentAge(request_time, response_time, current_time); - if (lifetimes.fresh > age) + if (lifetimes.freshness > age) return VALIDATION_NONE; - if (lifetimes.fresh + lifetimes.stale > age) + if (lifetimes.freshness + lifetimes.staleness > age) return VALIDATION_ASYNCHRONOUS; return VALIDATION_SYNCHRONOUS; @@ -1001,7 +1001,7 @@ ValidationType HttpResponseHeaders::RequiresValidation( // freshness_lifetime = (date_value - last_modified_value) * 0.10 // // If the stale-while-revalidate directive is present, then it is used to set -// the |stale| time, unless it overridden by another directive. +// the |staleness| time, unless it overridden by another directive. // HttpResponseHeaders::FreshnessLifetimes HttpResponseHeaders::GetFreshnessLifetimes(const Time& response_time) const { @@ -1020,14 +1020,15 @@ HttpResponseHeaders::GetFreshnessLifetimes(const Time& response_time) const { // Cache-Control directive must_revalidate overrides stale-while-revalidate. bool must_revalidate = HasHeaderValue("cache-control", "must-revalidate"); - if (must_revalidate || !GetStaleWhileRevalidateValue(&lifetimes.stale)) - DCHECK(lifetimes.stale == TimeDelta()); + if (must_revalidate || !GetStaleWhileRevalidateValue(&lifetimes.staleness)) { + DCHECK(lifetimes.staleness == TimeDelta()); + } // NOTE: "Cache-Control: max-age" overrides Expires, so we only check the // Expires header after checking for max-age in GetFreshnessLifetimes. This // is important since "Expires: <date in the past>" means not fresh, but // it should not trump a max-age value. - if (GetMaxAgeValue(&lifetimes.fresh)) + if (GetMaxAgeValue(&lifetimes.freshness)) return lifetimes; // If there is no Date header, then assume that the server response was @@ -1040,11 +1041,11 @@ HttpResponseHeaders::GetFreshnessLifetimes(const Time& response_time) const { if (GetExpiresValue(&expires_value)) { // The expires value can be a date in the past! if (expires_value > date_value) { - lifetimes.fresh = expires_value - date_value; + lifetimes.freshness = expires_value - date_value; return lifetimes; } - DCHECK(lifetimes.fresh == TimeDelta()); + DCHECK(lifetimes.freshness == TimeDelta()); return lifetimes; } @@ -1079,7 +1080,7 @@ HttpResponseHeaders::GetFreshnessLifetimes(const Time& response_time) const { if (GetLastModifiedValue(&last_modified_value)) { // The last-modified value can be a date in the future! if (last_modified_value <= date_value) { - lifetimes.fresh = (date_value - last_modified_value) / 10; + lifetimes.freshness = (date_value - last_modified_value) / 10; return lifetimes; } } @@ -1088,15 +1089,15 @@ HttpResponseHeaders::GetFreshnessLifetimes(const Time& response_time) const { // These responses are implicitly fresh (unless otherwise overruled): if (response_code_ == 300 || response_code_ == 301 || response_code_ == 308 || response_code_ == 410) { - lifetimes.fresh = TimeDelta::Max(); - lifetimes.stale = TimeDelta(); // It should never be stale. + lifetimes.freshness = TimeDelta::Max(); + lifetimes.staleness = TimeDelta(); // It should never be stale. return lifetimes; } // Our heuristic freshness estimate for this resource is 0 seconds, in // accordance with common browser behaviour. However, stale-while-revalidate // may still apply. - DCHECK(lifetimes.fresh == TimeDelta()); + DCHECK(lifetimes.freshness == TimeDelta()); return lifetimes; } diff --git a/net/http/http_response_headers.h b/net/http/http_response_headers.h index ac7c351..a093df5 100644 --- a/net/http/http_response_headers.h +++ b/net/http/http_response_headers.h @@ -29,7 +29,7 @@ namespace net { class HttpByteRange; enum ValidationType { - VALIDATION_NONE = 0, // The resource is fresh. + VALIDATION_NONE, // The resource is fresh. VALIDATION_ASYNCHRONOUS, // The resource requires async revalidation. VALIDATION_SYNCHRONOUS // The resource requires sync revalidation. }; @@ -51,10 +51,10 @@ class NET_EXPORT HttpResponseHeaders struct FreshnessLifetimes { // How long the resource will be fresh for. - base::TimeDelta fresh; + base::TimeDelta freshness; // How long after becoming not fresh that the resource will be stale but // usable (if async revalidation is enabled). - base::TimeDelta stale; + base::TimeDelta staleness; }; static const char kContentRange[]; @@ -229,12 +229,10 @@ class NET_EXPORT HttpResponseHeaders // Calculates the amount of time the server claims the response is fresh from // the time the response was generated. See section 13.2.4 of RFC 2616. See - // RequiresValidation for a description of the response_time parameter. Sets - // |FreshnessLifetimes.fresh| to the length of time the response may be used - // without revalidation, and |FreshnessLifetimes.stale| to the length of time - // the response may be used stale with asynchronous revalidation if - // stale-while-revalidate support is enabled. See RFC 5861 section 3 for the - // definition of stale-while-revalidate. + // RequiresValidation for a description of the response_time parameter. See + // the definition of FreshnessLifetimes above for the meaning of the return + // value. See RFC 5861 section 3 for the definition of + // stale-while-revalidate. FreshnessLifetimes GetFreshnessLifetimes( const base::Time& response_time) const; |