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

Side by Side Diff: webkit/media/cache_util.cc

Issue 10387200: Suppress pause-and-buffer behavior when the HTTP response won't satisfy future requests via cache. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Bitfield for reasons and fix typo picking out the Date header. Created 8 years, 7 months 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 | Annotate | Revision Log
« no previous file with comments | « webkit/media/cache_util.h ('k') | webkit/media/cache_util_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 };
26
27 std::vector<UncacheableReason> GetReasonsForUncacheability(
darin (slow to review) 2012/05/23 23:38:43 the next logical step is to return an integer that
Ami GONE FROM CHROMIUM 2012/05/23 23:44:06 I think that's a worse API, though. Don't you?
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);
darin (slow to review) 2012/05/23 23:38:43 reasons |= kNoData; etc.
39 if (http_version < HttpVersion(1, 1) && code == kHttpPartialContent)
40 reasons.push_back(kPre11PartialResponse);
41 if (code == kHttpPartialContent &&
42 !net::HttpUtil::HasStrongValidators(
43 http_version,
44 response.httpHeaderField("etag").utf8(),
45 response.httpHeaderField("Last-Modified").utf8(),
46 response.httpHeaderField("Date").utf8())) {
47 reasons.push_back(kNoStrongValidatorOnPartialResponse);
48 }
49
50 std::string cache_control_header =
51 response.httpHeaderField("cache-control").utf8();
52 StringToLowerASCII(&cache_control_header);
53 if (cache_control_header.find("no-cache") != std::string::npos)
54 reasons.push_back(kNoCache);
55 if (cache_control_header.find("no-store") != std::string::npos)
56 reasons.push_back(kNoStore);
57 if (cache_control_header.find("must-revalidate") != std::string::npos)
58 reasons.push_back(kHasMustRevalidate);
59
60 const TimeDelta kMinimumAgeForUsefulness =
61 TimeDelta::FromSeconds(3600); // Arbitrary value.
62
63 const char kMaxAgePrefix[] = "max-age=";
64 const size_t kMaxAgePrefixLen = arraysize(kMaxAgePrefix) - 1;
65 if (LowerCaseEqualsASCII(cache_control_header.begin(),
66 cache_control_header.begin() + kMaxAgePrefixLen,
67 kMaxAgePrefix)) {
68 int64 max_age_seconds;
69 base::StringToInt64(
70 base::StringPiece(cache_control_header.begin() + kMaxAgePrefixLen,
71 cache_control_header.end()),
72 &max_age_seconds);
73 if (TimeDelta::FromSeconds(max_age_seconds) < kMinimumAgeForUsefulness)
74 reasons.push_back(kShortMaxAge);
75 }
76
77 Time date;
78 Time expires;
79 if (Time::FromString(response.httpHeaderField("Date").utf8().data(), &date) &&
80 Time::FromString(response.httpHeaderField("Expires").utf8().data(),
81 &expires) &&
82 date > Time() && expires > Time() &&
83 (expires - date) < kMinimumAgeForUsefulness) {
84 reasons.push_back(kExpiresTooSoon);
85 }
86
87 return reasons;
88 }
89
90 } // namespace webkit_media
OLDNEW
« no previous file with comments | « webkit/media/cache_util.h ('k') | webkit/media/cache_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698