Index: net/http/http_response_headers.cc |
diff --git a/net/http/http_response_headers.cc b/net/http/http_response_headers.cc |
index b45012569c67fe6c5bbc45551a30df6465dd877b..e96b8cd7f1afec1d4e25a499525f42ed429a4e06 100644 |
--- a/net/http/http_response_headers.cc |
+++ b/net/http/http_response_headers.cc |
@@ -905,18 +905,32 @@ bool HttpResponseHeaders::IsRedirectResponseCode(int response_code) { |
// |
// response_is_fresh = (freshness_lifetime > current_age) |
// |
+// Into this equation, we substitute |current_age = now - freshness_origin|, |
+// giving: |
+// |
+// response_is_fresh = (freshness_lifetime > now - freshness_origin) |
+// |
+// response_is_fresh = (freshness_lifetime + freshness_origin > now) |
+// |
+// And we call this quantity |freshness_lifetime + freshness_origin| the |
+// freshness_expiry. |
+// |
// Of course, there are other factors that can force a response to always be |
// validated or re-fetched. |
// |
-bool HttpResponseHeaders::RequiresValidation(const Time& request_time, |
- const Time& response_time, |
- const Time& current_time) const { |
- TimeDelta lifetime = |
- GetFreshnessLifetime(response_time); |
- if (lifetime == TimeDelta()) |
- return true; |
+Time HttpResponseHeaders::GetFreshnessExpiry(Time request_time, |
+ Time response_time) const { |
+ TimeDelta lifetime = GetFreshnessLifetime(response_time); |
+ if (lifetime.is_max()) |
+ return Time::Max(); |
+ Time origin = GetFreshnessOrigin(request_time, response_time); |
+ return origin + lifetime; |
+} |
- return lifetime <= GetCurrentAge(request_time, response_time, current_time); |
+bool HttpResponseHeaders::RequiresValidation(base::Time request_time, |
gavinp
2014/02/13 18:50:26
s/base::Time/Time/
|
+ base::Time response_time, |
+ base::Time current_time) const { |
+ return GetFreshnessExpiry(request_time, response_time) <= current_time; |
} |
// From RFC 2616 section 13.2.4: |
@@ -939,8 +953,7 @@ bool HttpResponseHeaders::RequiresValidation(const Time& request_time, |
// |
// freshness_lifetime = (date_value - last_modified_value) * 0.10 |
// |
-TimeDelta HttpResponseHeaders::GetFreshnessLifetime( |
- const Time& response_time) const { |
+TimeDelta HttpResponseHeaders::GetFreshnessLifetime(Time response_time) const { |
// Check for headers that force a response to never be fresh. For backwards |
// compat, we treat "Pragma: no-cache" as a synonym for "Cache-Control: |
// no-cache" even though RFC 2616 does not specify it. |
@@ -1040,9 +1053,15 @@ TimeDelta HttpResponseHeaders::GetFreshnessLifetime( |
// resident_time = now - response_time; |
// current_age = corrected_initial_age + resident_time; |
// |
-TimeDelta HttpResponseHeaders::GetCurrentAge(const Time& request_time, |
- const Time& response_time, |
- const Time& current_time) const { |
+// From this, we can derive the freshness origin, the time at which the |
+// current_age = 0 and solve for now (aka freshness_origin): |
+// |
+// corrected_initial_age + resident_time = 0 |
+// corrected_initial_age + freshness_origin - response_time = 0 |
+// freshness_origin = response_time - corrected_initial_age |
+// |
+Time HttpResponseHeaders::GetFreshnessOrigin(Time request_time, |
+ Time response_time) const { |
// If there is no Date header, then assume that the server response was |
// generated at the time when we received the response. |
Time date_value; |
@@ -1058,10 +1077,8 @@ TimeDelta HttpResponseHeaders::GetCurrentAge(const Time& request_time, |
TimeDelta corrected_received_age = std::max(apparent_age, age_value); |
TimeDelta response_delay = response_time - request_time; |
TimeDelta corrected_initial_age = corrected_received_age + response_delay; |
- TimeDelta resident_time = current_time - response_time; |
- TimeDelta current_age = corrected_initial_age + resident_time; |
- return current_age; |
+ return response_time - corrected_initial_age; |
} |
bool HttpResponseHeaders::GetMaxAgeValue(TimeDelta* result) const { |