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
3 // found in the LICENSE file.
4 
5 #ifndef MEDIA_BLINK_CACHE_UTIL_H_
6 #define MEDIA_BLINK_CACHE_UTIL_H_
7 
8 #include <stdint.h>
9 
10 #include <vector>
11 
12 #include "base/time/time.h"
13 #include "media/blink/media_blink_export.h"
14 
15 namespace blink {
16 class WebURLResponse;
17 }
18 
19 namespace media {
20 
21 // Reasons that a cached WebURLResponse will *not* prevent a future request to
22 // the server.  Reported via UMA, so don't change/reuse previously-existing
23 // values.
24 enum UncacheableReason {
25   kNoData = 1 << 0,  // Not 200 or 206.
26   kPre11PartialResponse = 1 << 1,  // 206 but HTTP version < 1.1.
27   kNoStrongValidatorOnPartialResponse = 1 << 2,  // 206, no strong validator.
28   kShortMaxAge = 1 << 3,  // Max age less than 1h (arbitrary value).
29   kExpiresTooSoon = 1 << 4,  // Expires in less than 1h (arbitrary value).
30   kHasMustRevalidate = 1 << 5,  // Response asks for revalidation.
31   kNoCache = 1 << 6,  // Response included a no-cache header.
32   kNoStore = 1 << 7,  // Response included a no-store header.
33   kMaxReason  // Needs to be one more than max legitimate reason.
34 };
35 
36 // Return the logical OR of the reasons "response" cannot be used for a future
37 // request (using the disk cache), or 0 if it might be useful.
38 uint32_t MEDIA_BLINK_EXPORT
39 GetReasonsForUncacheability(const blink::WebURLResponse& response);
40 
41 // Returns when we should evict data from this response from our
42 // memory cache. Note that we may still cache data longer if
43 // a audio/video tag is currently using it. Returns a TimeDelta
44 // which is should be added to base::Time::Now() or base::TimeTicks::Now().
45 base::TimeDelta MEDIA_BLINK_EXPORT
46 GetCacheValidUntil(const blink::WebURLResponse& response);
47 
48 }  // namespace media
49 
50 #endif  // MEDIA_BLINK_CACHE_UTIL_H_
51