OLD | NEW |
---|---|
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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
77 Time::FromString(response.httpHeaderField("Expires").utf8().data(), | 77 Time::FromString(response.httpHeaderField("Expires").utf8().data(), |
78 &expires) && | 78 &expires) && |
79 date > Time() && expires > Time() && | 79 date > Time() && expires > Time() && |
80 (expires - date) < kMinimumAgeForUsefulness) { | 80 (expires - date) < kMinimumAgeForUsefulness) { |
81 reasons |= kExpiresTooSoon; | 81 reasons |= kExpiresTooSoon; |
82 } | 82 } |
83 | 83 |
84 return reasons; | 84 return reasons; |
85 } | 85 } |
86 | 86 |
87 base::TimeTicks GetMemoryCacheValidUntil(const WebURLResponse& response) { | |
88 std::string cache_control_header = | |
89 base::ToLowerASCII(response.httpHeaderField("cache-control").utf8()); | |
90 if (cache_control_header.find("no-cache") != std::string::npos) | |
91 return base::TimeTicks::Now(); | |
92 if (cache_control_header.find("must-revalidate") != std::string::npos) | |
93 return base::TimeTicks::Now(); | |
94 | |
95 // Max cache timeout ~= 1 month. | |
96 base::TimeDelta ret = base::TimeDelta::FromDays(30); | |
97 | |
98 const char kMaxAgePrefix[] = "max-age="; | |
99 const size_t kMaxAgePrefixLen = arraysize(kMaxAgePrefix) - 1; | |
100 if (cache_control_header.substr(0, kMaxAgePrefixLen) == kMaxAgePrefix) { | |
101 int64 max_age_seconds; | |
102 base::StringToInt64( | |
103 base::StringPiece(cache_control_header.begin() + kMaxAgePrefixLen, | |
104 cache_control_header.end()), | |
105 &max_age_seconds); | |
106 | |
107 ret = std::min(ret, TimeDelta::FromSeconds(max_age_seconds)); | |
108 } | |
109 | |
110 Time date; | |
111 Time expires; | |
112 if (Time::FromString(response.httpHeaderField("Date").utf8().data(), &date) && | |
liberato (no reviews please)
2015/11/05 19:03:18
i think that max-age is supposed to take precedenc
hubbe
2015/11/13 22:56:52
Done.
| |
113 Time::FromString(response.httpHeaderField("Expires").utf8().data(), | |
114 &expires) && | |
115 date > Time() && expires > Time()) { | |
116 ret = std::min(ret, expires - date); | |
117 } | |
118 | |
119 return base::TimeTicks::Now() + ret; | |
120 } | |
121 | |
87 } // namespace media | 122 } // namespace media |
OLD | NEW |