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

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

Issue 1534273002: Switch to standard integer types in media/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: more Created 5 years 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"
11 #include "base/time/time.h" 11 #include "base/time/time.h"
12 #include "net/http/http_util.h" 12 #include "net/http/http_util.h"
13 #include "net/http/http_version.h" 13 #include "net/http/http_version.h"
14 #include "third_party/WebKit/public/platform/WebCString.h" 14 #include "third_party/WebKit/public/platform/WebCString.h"
15 #include "third_party/WebKit/public/platform/WebString.h" 15 #include "third_party/WebKit/public/platform/WebString.h"
16 #include "third_party/WebKit/public/platform/WebURLResponse.h" 16 #include "third_party/WebKit/public/platform/WebURLResponse.h"
17 17
18 using base::Time; 18 using base::Time;
19 using base::TimeDelta; 19 using base::TimeDelta;
20 using net::HttpVersion; 20 using net::HttpVersion;
21 using blink::WebURLResponse; 21 using blink::WebURLResponse;
22 22
23 namespace media { 23 namespace media {
24 24
25 enum { kHttpOK = 200, kHttpPartialContent = 206 }; 25 enum { kHttpOK = 200, kHttpPartialContent = 206 };
26 26
27 uint32 GetReasonsForUncacheability(const WebURLResponse& response) { 27 uint32_t GetReasonsForUncacheability(const WebURLResponse& response) {
28 uint32 reasons = 0; 28 uint32_t reasons = 0;
29 const int code = response.httpStatusCode(); 29 const int code = response.httpStatusCode();
30 const int version = response.httpVersion(); 30 const int version = response.httpVersion();
31 const HttpVersion http_version = 31 const HttpVersion http_version =
32 version == WebURLResponse::HTTPVersion_2_0 32 version == WebURLResponse::HTTPVersion_2_0
33 ? HttpVersion(2, 0) 33 ? HttpVersion(2, 0)
34 : version == WebURLResponse::HTTPVersion_1_1 34 : version == WebURLResponse::HTTPVersion_1_1
35 ? HttpVersion(1, 1) 35 ? HttpVersion(1, 1)
36 : version == WebURLResponse::HTTPVersion_1_0 36 : version == WebURLResponse::HTTPVersion_1_0
37 ? HttpVersion(1, 0) 37 ? HttpVersion(1, 0)
38 : version == WebURLResponse::HTTPVersion_0_9 38 : version == WebURLResponse::HTTPVersion_0_9
(...skipping 20 matching lines...) Expand all
59 reasons |= kNoStore; 59 reasons |= kNoStore;
60 if (cache_control_header.find("must-revalidate") != std::string::npos) 60 if (cache_control_header.find("must-revalidate") != std::string::npos)
61 reasons |= kHasMustRevalidate; 61 reasons |= kHasMustRevalidate;
62 62
63 const TimeDelta kMinimumAgeForUsefulness = 63 const TimeDelta kMinimumAgeForUsefulness =
64 TimeDelta::FromSeconds(3600); // Arbitrary value. 64 TimeDelta::FromSeconds(3600); // Arbitrary value.
65 65
66 const char kMaxAgePrefix[] = "max-age="; 66 const char kMaxAgePrefix[] = "max-age=";
67 const size_t kMaxAgePrefixLen = arraysize(kMaxAgePrefix) - 1; 67 const size_t kMaxAgePrefixLen = arraysize(kMaxAgePrefix) - 1;
68 if (cache_control_header.substr(0, kMaxAgePrefixLen) == kMaxAgePrefix) { 68 if (cache_control_header.substr(0, kMaxAgePrefixLen) == kMaxAgePrefix) {
69 int64 max_age_seconds; 69 int64_t max_age_seconds;
70 base::StringToInt64( 70 base::StringToInt64(
71 base::StringPiece(cache_control_header.begin() + kMaxAgePrefixLen, 71 base::StringPiece(cache_control_header.begin() + kMaxAgePrefixLen,
72 cache_control_header.end()), 72 cache_control_header.end()),
73 &max_age_seconds); 73 &max_age_seconds);
74 if (TimeDelta::FromSeconds(max_age_seconds) < kMinimumAgeForUsefulness) 74 if (TimeDelta::FromSeconds(max_age_seconds) < kMinimumAgeForUsefulness)
75 reasons |= kShortMaxAge; 75 reasons |= kShortMaxAge;
76 } 76 }
77 77
78 Time date; 78 Time date;
79 Time expires; 79 Time expires;
(...skipping 15 matching lines...) Expand all
95 return base::TimeDelta(); 95 return base::TimeDelta();
96 if (cache_control_header.find("must-revalidate") != std::string::npos) 96 if (cache_control_header.find("must-revalidate") != std::string::npos)
97 return base::TimeDelta(); 97 return base::TimeDelta();
98 98
99 // Max cache timeout ~= 1 month. 99 // Max cache timeout ~= 1 month.
100 base::TimeDelta ret = base::TimeDelta::FromDays(30); 100 base::TimeDelta ret = base::TimeDelta::FromDays(30);
101 101
102 const char kMaxAgePrefix[] = "max-age="; 102 const char kMaxAgePrefix[] = "max-age=";
103 const size_t kMaxAgePrefixLen = arraysize(kMaxAgePrefix) - 1; 103 const size_t kMaxAgePrefixLen = arraysize(kMaxAgePrefix) - 1;
104 if (cache_control_header.substr(0, kMaxAgePrefixLen) == kMaxAgePrefix) { 104 if (cache_control_header.substr(0, kMaxAgePrefixLen) == kMaxAgePrefix) {
105 int64 max_age_seconds; 105 int64_t max_age_seconds;
106 base::StringToInt64( 106 base::StringToInt64(
107 base::StringPiece(cache_control_header.begin() + kMaxAgePrefixLen, 107 base::StringPiece(cache_control_header.begin() + kMaxAgePrefixLen,
108 cache_control_header.end()), 108 cache_control_header.end()),
109 &max_age_seconds); 109 &max_age_seconds);
110 110
111 ret = std::min(ret, TimeDelta::FromSeconds(max_age_seconds)); 111 ret = std::min(ret, TimeDelta::FromSeconds(max_age_seconds));
112 } else { 112 } else {
113 // Note that |date| may be smaller than |expires|, which means we'll 113 // Note that |date| may be smaller than |expires|, which means we'll
114 // return a timetick some time in the past. 114 // return a timetick some time in the past.
115 Time date; 115 Time date;
116 Time expires; 116 Time expires;
117 if (Time::FromString(response.httpHeaderField("Date").utf8().data(), 117 if (Time::FromString(response.httpHeaderField("Date").utf8().data(),
118 &date) && 118 &date) &&
119 Time::FromString(response.httpHeaderField("Expires").utf8().data(), 119 Time::FromString(response.httpHeaderField("Expires").utf8().data(),
120 &expires) && 120 &expires) &&
121 date > Time() && expires > Time()) { 121 date > Time() && expires > Time()) {
122 ret = std::min(ret, expires - date); 122 ret = std::min(ret, expires - date);
123 } 123 }
124 } 124 }
125 125
126 return ret; 126 return ret;
127 } 127 }
128 128
129 } // namespace media 129 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698