Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(389)

Unified Diff: net/http/http_response_headers.cc

Issue 665023002: Post-commit fixes for "stale-while-revalidate..." (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Make DCHECK_EQ work for TimeDelta objects. Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« base/time/time_logging.cc ('K') | « net/http/http_response_headers.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/http/http_response_headers.cc
diff --git a/net/http/http_response_headers.cc b/net/http/http_response_headers.cc
index 4ffed825b05888b8122b8deb8eb913bfe1ed72ad..2f28d9617df6894425ee9ba021c0d62381051038 100644
--- a/net/http/http_response_headers.cc
+++ b/net/http/http_response_headers.cc
@@ -20,6 +20,7 @@
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/time/time.h"
+#include "base/time/time_logging.h"
mmenke 2014/10/21 14:22:00 I wonder about requiring this include - I don't th
Adam Rice 2014/10/23 01:13:02 True. I got rid of the separate include file.
#include "base/values.h"
#include "net/base/escape.h"
#include "net/http/http_byte_range.h"
@@ -966,15 +967,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 +1002,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 +1021,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_EQ(TimeDelta(), lifetimes.staleness);
+ }
// 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 +1042,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_EQ(TimeDelta(), lifetimes.freshness);
return lifetimes;
}
@@ -1079,7 +1081,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 +1090,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_EQ(TimeDelta(), lifetimes.freshness);
return lifetimes;
}
« base/time/time_logging.cc ('K') | « net/http/http_response_headers.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698