OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 #ifndef NET_DISK_CACHE_SIMPLE_SIMPLE_ENTRY_FORMAT_H_ | 5 #ifndef NET_DISK_CACHE_SIMPLE_SIMPLE_ENTRY_FORMAT_H_ |
6 #define NET_DISK_CACHE_SIMPLE_SIMPLE_ENTRY_FORMAT_H_ | 6 #define NET_DISK_CACHE_SIMPLE_SIMPLE_ENTRY_FORMAT_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include "net/base/net_export.h" | 10 #include "net/base/net_export.h" |
11 | 11 |
12 namespace base { | 12 namespace base { |
13 class Time; | 13 class Time; |
14 } | 14 } |
15 | 15 |
16 namespace disk_cache { | 16 namespace disk_cache { |
17 | 17 |
18 const uint64_t kSimpleInitialMagicNumber = UINT64_C(0xfcfb6d1ba7725c30); | 18 const uint64_t kSimpleInitialMagicNumber = UINT64_C(0xfcfb6d1ba7725c30); |
19 const uint64_t kSimpleFinalMagicNumber = UINT64_C(0xf4fa6f45970d41d8); | 19 const uint64_t kSimpleFinalMagicNumber = UINT64_C(0xf4fa6f45970d41d8); |
20 const uint64_t kSimpleSparseRangeMagicNumber = UINT64_C(0xeb97bf016553676b); | 20 const uint64_t kSimpleSparseRangeMagicNumber = UINT64_C(0xeb97bf016553676b); |
21 | 21 |
22 // A file containing stream 0 and stream 1 in the Simple cache consists of: | 22 // A file containing stream 0 and stream 1 in the Simple cache consists of: |
23 // - a SimpleFileHeader. | 23 // - a SimpleFileHeader. |
24 // - the key. | 24 // - the key. |
25 // - the data from stream 1. | 25 // - the data from stream 1. |
26 // - a SimpleFileEOF record for stream 1. | 26 // - a SimpleFileEOF record for stream 1. |
27 // - the data from stream 0. | 27 // - the data from stream 0. |
| 28 // - (optionally) the SHA256 of the key. |
28 // - a SimpleFileEOF record for stream 0. | 29 // - a SimpleFileEOF record for stream 0. |
| 30 // |
| 31 // Because stream 0 data (typically HTTP headers) is on the critical path of |
| 32 // requests, on open, the cache reads the end of the record and does not |
| 33 // read the SimpleFileHeader. If the key can be validated with a SHA256, then |
| 34 // the stream 0 data can be returned to the caller without reading the |
| 35 // SimpleFileHeader. If the key SHA256 is not present, then the cache must |
| 36 // read the SimpleFileHeader to confirm key equality. |
29 | 37 |
30 // A file containing stream 2 in the Simple cache consists of: | 38 // A file containing stream 2 in the Simple cache consists of: |
31 // - a SimpleFileHeader. | 39 // - a SimpleFileHeader. |
32 // - the key. | 40 // - the key. |
33 // - the data. | 41 // - the data. |
34 // - at the end, a SimpleFileEOF record. | 42 // - at the end, a SimpleFileEOF record. |
35 static const int kSimpleEntryFileCount = 2; | 43 static const int kSimpleEntryFileCount = 2; |
36 static const int kSimpleEntryStreamCount = 3; | 44 static const int kSimpleEntryStreamCount = 3; |
37 | 45 |
38 struct NET_EXPORT_PRIVATE SimpleFileHeader { | 46 struct NET_EXPORT_PRIVATE SimpleFileHeader { |
39 SimpleFileHeader(); | 47 SimpleFileHeader(); |
40 | 48 |
41 uint64_t initial_magic_number; | 49 uint64_t initial_magic_number; |
42 uint32_t version; | 50 uint32_t version; |
43 uint32_t key_length; | 51 uint32_t key_length; |
44 uint32_t key_hash; | 52 uint32_t key_hash; |
45 }; | 53 }; |
46 | 54 |
47 struct NET_EXPORT_PRIVATE SimpleFileEOF { | 55 struct NET_EXPORT_PRIVATE SimpleFileEOF { |
48 enum Flags { | 56 enum Flags { |
49 FLAG_HAS_CRC32 = (1U << 0), | 57 FLAG_HAS_CRC32 = (1U << 0), |
| 58 FLAG_HAS_KEY_SHA256 = (1U << 1), // Preceding the record if present. |
50 }; | 59 }; |
51 | 60 |
52 SimpleFileEOF(); | 61 SimpleFileEOF(); |
53 | 62 |
54 uint64_t final_magic_number; | 63 uint64_t final_magic_number; |
55 uint32_t flags; | 64 uint32_t flags; |
56 uint32_t data_crc32; | 65 uint32_t data_crc32; |
57 // |stream_size| is only used in the EOF record for stream 0. | 66 // |stream_size| is only used in the EOF record for stream 0. |
58 uint32_t stream_size; | 67 uint32_t stream_size; |
59 }; | 68 }; |
60 | 69 |
61 struct SimpleFileSparseRangeHeader { | 70 struct SimpleFileSparseRangeHeader { |
62 SimpleFileSparseRangeHeader(); | 71 SimpleFileSparseRangeHeader(); |
63 | 72 |
64 uint64_t sparse_range_magic_number; | 73 uint64_t sparse_range_magic_number; |
65 int64_t offset; | 74 int64_t offset; |
66 int64_t length; | 75 int64_t length; |
67 uint32_t data_crc32; | 76 uint32_t data_crc32; |
68 }; | 77 }; |
69 | 78 |
70 } // namespace disk_cache | 79 } // namespace disk_cache |
71 | 80 |
72 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_ENTRY_FORMAT_H_ | 81 #endif // NET_DISK_CACHE_SIMPLE_SIMPLE_ENTRY_FORMAT_H_ |
OLD | NEW |