Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "webkit/media/cache_util.h" | |
| 6 | |
| 7 #include <string> | |
| 8 | |
| 9 #include "base/string_number_conversions.h" | |
| 10 #include "base/string_util.h" | |
| 11 #include "base/time.h" | |
| 12 #include "net/http/http_util.h" | |
| 13 #include "net/http/http_version.h" | |
| 14 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCString.h " | |
| 15 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" | |
| 16 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLRespon se.h" | |
| 17 | |
| 18 using base::Time; | |
| 19 using base::TimeDelta; | |
| 20 using net::HttpVersion; | |
| 21 using WebKit::WebURLResponse; | |
| 22 | |
| 23 namespace webkit_media { | |
| 24 | |
| 25 enum { kHttpOK = 200, kHttpPartialContent = 206 }; | |
|
rvargas (doing something else)
2012/05/23 02:04:12
nit: enums are supposed to be upper case.
Ami GONE FROM CHROMIUM
2012/05/23 03:55:23
Yeah... This is a place where chromium's style gui
| |
| 26 | |
| 27 std::vector<UncacheableReason> GetReasonsForUncacheability( | |
| 28 const WebURLResponse& response) { | |
| 29 std::vector<UncacheableReason> reasons; | |
| 30 const int code = response.httpStatusCode(); | |
| 31 const int version = response.httpVersion(); | |
| 32 const HttpVersion http_version = | |
| 33 version == WebURLResponse::HTTP_1_1 ? HttpVersion(1, 1) : | |
| 34 version == WebURLResponse::HTTP_1_0 ? HttpVersion(1, 0) : | |
| 35 version == WebURLResponse::HTTP_0_9 ? HttpVersion(0, 9) : | |
| 36 HttpVersion(); | |
| 37 if (code != kHttpOK && code != kHttpPartialContent) | |
| 38 reasons.push_back(kNoData); | |
| 39 if (http_version < HttpVersion(1, 1) && code == kHttpPartialContent) | |
| 40 reasons.push_back(kPre11PartialResponse); | |
| 41 if (code == kHttpPartialContent && !net::HttpUtil::HasStrongValidators( | |
|
rvargas (doing something else)
2012/05/23 02:04:12
nit: could you break this at the &&
Ami GONE FROM CHROMIUM
2012/05/23 03:55:23
Done, though I don't think it helps...
| |
| 42 http_version, | |
| 43 response.httpHeaderField("etag").utf8(), | |
| 44 response.httpHeaderField("Last-Modified").utf8(), | |
|
scherkus (not reviewing)
2012/05/23 01:16:03
minor ocd nit again: I wonder if we should be cons
Ami GONE FROM CHROMIUM
2012/05/23 01:27:28
rfc2616 4.2: header names are case-insensitive (wh
| |
| 45 response.httpHeaderField("Date").utf8())) { | |
| 46 reasons.push_back(kNoStrongValidatorOnPartialResponse); | |
| 47 } | |
| 48 | |
| 49 std::string cache_control_header = | |
| 50 response.httpHeaderField("cache-control").utf8(); | |
| 51 StringToLowerASCII(&cache_control_header); | |
| 52 if (cache_control_header.find("no-cache") != std::string::npos) | |
| 53 reasons.push_back(kNoCache); | |
| 54 if (cache_control_header.find("no-store") != std::string::npos) | |
| 55 reasons.push_back(kNoStore); | |
| 56 if (cache_control_header.find("must-revalidate") != std::string::npos) | |
| 57 reasons.push_back(kHasMustRevalidate); | |
| 58 | |
| 59 const TimeDelta kMinimumAgeForUsefulness = | |
| 60 TimeDelta::FromSeconds(3600); // Arbitrary value. | |
| 61 | |
| 62 const char kMaxAgePrefix[] = "max-age="; | |
| 63 const size_t kMaxAgePrefixLen = arraysize(kMaxAgePrefix) - 1; | |
| 64 if (LowerCaseEqualsASCII( | |
| 65 cache_control_header.begin(), | |
|
rvargas (doing something else)
2012/05/23 02:04:12
nit: prev line
Ami GONE FROM CHROMIUM
2012/05/23 03:55:23
Nope :)
| |
| 66 cache_control_header.begin() + kMaxAgePrefixLen, | |
| 67 kMaxAgePrefix)) { | |
| 68 int64 max_age_seconds; | |
| 69 base::StringToInt64( | |
| 70 base::StringPiece( | |
| 71 cache_control_header.begin() + kMaxAgePrefixLen, | |
|
rvargas (doing something else)
2012/05/23 02:04:12
nit:prev line
Ami GONE FROM CHROMIUM
2012/05/23 03:55:23
Ditto.
| |
| 72 cache_control_header.end()), | |
| 73 &max_age_seconds); | |
| 74 if (TimeDelta::FromSeconds(max_age_seconds) < kMinimumAgeForUsefulness) | |
| 75 reasons.push_back(kShortMaxAge); | |
| 76 } | |
| 77 | |
| 78 Time date; | |
| 79 Time expires; | |
| 80 if (Time::FromString(response.httpHeaderField("Date").utf8().data(), &date) && | |
| 81 Time::FromString( | |
| 82 response.httpHeaderField("Expires").utf8().data(), &expires) && | |
|
rvargas (doing something else)
2012/05/23 02:04:12
nit: I'd also move the first arg to the previousli
Ami GONE FROM CHROMIUM
2012/05/23 03:55:23
Ditto.
| |
| 83 date > Time() && expires > Time() && | |
| 84 (expires - date) < kMinimumAgeForUsefulness) { | |
| 85 reasons.push_back(kExpiresTooSoon); | |
| 86 } | |
| 87 | |
| 88 return reasons; | |
| 89 } | |
| 90 | |
| 91 } // namespace webkit_media | |
| OLD | NEW |