| Index: media/blink/cache_util.cc
|
| diff --git a/media/blink/cache_util.cc b/media/blink/cache_util.cc
|
| index e8cb56333ba43e3f3ff04847041fc8b16ea5ebca..1df9271ba57f9693873092e71c8a20c7d58d98e3 100644
|
| --- a/media/blink/cache_util.cc
|
| +++ b/media/blink/cache_util.cc
|
| @@ -88,4 +88,42 @@ uint32 GetReasonsForUncacheability(const WebURLResponse& response) {
|
| return reasons;
|
| }
|
|
|
| +base::TimeTicks GetCacheValidUntil(const WebURLResponse& response) {
|
| + std::string cache_control_header =
|
| + base::ToLowerASCII(response.httpHeaderField("cache-control").utf8());
|
| + if (cache_control_header.find("no-cache") != std::string::npos)
|
| + return base::TimeTicks::Now();
|
| + if (cache_control_header.find("must-revalidate") != std::string::npos)
|
| + return base::TimeTicks::Now();
|
| +
|
| + // Max cache timeout ~= 1 month.
|
| + base::TimeDelta ret = base::TimeDelta::FromDays(30);
|
| +
|
| + const char kMaxAgePrefix[] = "max-age=";
|
| + const size_t kMaxAgePrefixLen = arraysize(kMaxAgePrefix) - 1;
|
| + if (cache_control_header.substr(0, kMaxAgePrefixLen) == kMaxAgePrefix) {
|
| + int64 max_age_seconds;
|
| + base::StringToInt64(
|
| + base::StringPiece(cache_control_header.begin() + kMaxAgePrefixLen,
|
| + cache_control_header.end()),
|
| + &max_age_seconds);
|
| +
|
| + ret = std::min(ret, TimeDelta::FromSeconds(max_age_seconds));
|
| + } else {
|
| + // Note that |date| may be smaller than |expires|, which means we'll
|
| + // return a timetick some time in the past.
|
| + Time date;
|
| + Time expires;
|
| + if (Time::FromString(response.httpHeaderField("Date").utf8().data(),
|
| + &date) &&
|
| + Time::FromString(response.httpHeaderField("Expires").utf8().data(),
|
| + &expires) &&
|
| + date > Time() && expires > Time()) {
|
| + ret = std::min(ret, expires - date);
|
| + }
|
| + }
|
| +
|
| + return base::TimeTicks::Now() + ret;
|
| +}
|
| +
|
| } // namespace media
|
|
|