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

Side by Side 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: compile fixes 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "media/blink/cache_util.h" 5 #include "media/blink/cache_util.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 Time::FromString(response.httpHeaderField("Expires").utf8().data(), 81 Time::FromString(response.httpHeaderField("Expires").utf8().data(),
82 &expires) && 82 &expires) &&
83 date > Time() && expires > Time() && 83 date > Time() && expires > Time() &&
84 (expires - date) < kMinimumAgeForUsefulness) { 84 (expires - date) < kMinimumAgeForUsefulness) {
85 reasons |= kExpiresTooSoon; 85 reasons |= kExpiresTooSoon;
86 } 86 }
87 87
88 return reasons; 88 return reasons;
89 } 89 }
90 90
91 base::TimeTicks GetMemoryCacheValidUntil(const WebURLResponse& response) {
92 std::string cache_control_header =
93 base::ToLowerASCII(response.httpHeaderField("cache-control").utf8());
94 if (cache_control_header.find("no-cache") != std::string::npos)
95 return base::TimeTicks::Now();
96 if (cache_control_header.find("must-revalidate") != std::string::npos)
97 return base::TimeTicks::Now();
98
99 // Max cache timeout ~= 1 month.
100 base::TimeDelta ret = base::TimeDelta::FromDays(30);
101
102 const char kMaxAgePrefix[] = "max-age=";
103 const size_t kMaxAgePrefixLen = arraysize(kMaxAgePrefix) - 1;
104 if (cache_control_header.substr(0, kMaxAgePrefixLen) == kMaxAgePrefix) {
105 int64 max_age_seconds;
106 base::StringToInt64(
107 base::StringPiece(cache_control_header.begin() + kMaxAgePrefixLen,
108 cache_control_header.end()),
109 &max_age_seconds);
110
111 ret = std::min(ret, TimeDelta::FromSeconds(max_age_seconds));
112 } else {
113 Time date;
114 Time expires;
115 if (Time::FromString(response.httpHeaderField("Date").utf8().data(),
116 &date) &&
117 Time::FromString(response.httpHeaderField("Expires").utf8().data(),
118 &expires) &&
119 date > Time() && expires > Time()) {
xhwang 2015/11/19 23:34:17 What if expires <= date? We'll return some time th
hubbe 2015/11/20 23:24:22 Done.
120 ret = std::min(ret, expires - date);
121 }
122 }
123
124 return base::TimeTicks::Now() + ret;
125 }
126
91 } // namespace media 127 } // namespace media
OLDNEW
« no previous file with comments | « media/blink/cache_util.h ('k') | media/blink/media_blink.gyp » ('j') | media/blink/multibuffer.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698