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

Unified Diff: media/blink/cache_util.cc

Issue 1399603003: Tie multibuffers to URLs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@media_cache
Patch Set: formatted Created 5 years, 1 month 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
« no previous file with comments | « media/blink/cache_util.h ('k') | media/blink/media_blink.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/blink/cache_util.cc
diff --git a/media/blink/cache_util.cc b/media/blink/cache_util.cc
index e8cb56333ba43e3f3ff04847041fc8b16ea5ebca..0f55b1ff92f639b25329ba8382e4ce27e4c89ba4 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::TimeDelta 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::TimeDelta();
+ if (cache_control_header.find("must-revalidate") != std::string::npos)
+ return base::TimeDelta();
+
+ // 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 ret;
+}
+
} // namespace media
« no previous file with comments | « media/blink/cache_util.h ('k') | media/blink/media_blink.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698