OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 "net/disk_cache/addr.h" | 5 #include "net/disk_cache/addr.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 | 8 |
9 namespace { | |
10 | |
11 bool AreReservedBitsValid(uint32 value) { | |
12 // These two bits of a block address should not be set. | |
13 const uint32 kReservedBitsMask = 0x0c000000; | |
14 return !(value & kReservedBitsMask); | |
15 } | |
16 | |
17 } // namespace | |
18 | |
9 namespace disk_cache { | 19 namespace disk_cache { |
10 | 20 |
11 int Addr::start_block() const { | 21 int Addr::start_block() const { |
12 DCHECK(is_block_file()); | 22 DCHECK(is_block_file()); |
13 return value_ & kStartBlockMask; | 23 return value_ & kStartBlockMask; |
14 } | 24 } |
15 | 25 |
16 int Addr::num_blocks() const { | 26 int Addr::num_blocks() const { |
17 DCHECK(is_block_file() || !value_); | 27 DCHECK(is_block_file() || !value_); |
18 return ((value_ & kNumBlocksMask) >> kNumBlocksOffset) + 1; | 28 return ((value_ & kNumBlocksMask) >> kNumBlocksOffset) + 1; |
19 } | 29 } |
20 | 30 |
21 bool Addr::SetFileNumber(int file_number) { | 31 bool Addr::SetFileNumber(int file_number) { |
22 DCHECK(is_separate_file()); | 32 DCHECK(is_separate_file()); |
23 if (file_number & ~kFileNameMask) | 33 if (file_number & ~kFileNameMask) |
24 return false; | 34 return false; |
25 value_ = kInitializedMask | file_number; | 35 value_ = kInitializedMask | file_number; |
26 return true; | 36 return true; |
27 } | 37 } |
28 | 38 |
29 bool Addr::SanityCheck() const { | 39 Addr Addr::AsExternal() const { |
40 DCHECK(file_type() == BLOCK_FILES); | |
41 CacheAddr new_value = value() & ~kFileTypeMask; | |
gavinp
2013/06/13 19:49:00
Addr ret(*this);
ret.set_file_type(EXTERNAL);
??
rvargas (doing something else)
2013/06/13 22:46:29
BLOCK_FILES is a type of file that holds a small m
gavinp
2013/06/13 23:38:27
What's a marker for a file?
rvargas (doing something else)
2013/06/14 02:15:44
The hash of the key (although I'm saving also Entr
gavinp
2013/06/14 15:15:23
I don't understand this at all. Please remove Addr
rvargas (doing something else)
2013/06/14 19:25:17
What is it that you don't understand?
----
Yes,
| |
42 return Addr(new_value); | |
43 } | |
44 | |
45 Addr Addr::AsBlockFile() const { | |
46 DCHECK(is_separate_file()); | |
47 CacheAddr new_value = value() + (BLOCK_FILES << kFileTypeOffset); | |
gavinp
2013/06/13 19:49:00
Addr ret(*this);
ret.set_file_type(BLOCK_FILES);
rvargas (doing something else)
2013/06/13 22:46:29
The only thing we need is BLOCK_FILES (5) -> 0, an
gavinp
2013/06/14 15:15:23
They compile to the same thing. See:
#include <st
rvargas (doing something else)
2013/06/14 19:25:17
You are aware that I changed the code to what you
| |
48 return Addr(new_value); | |
49 } | |
50 | |
51 bool Addr::SanityCheckV2() const { | |
30 if (!is_initialized()) | 52 if (!is_initialized()) |
31 return !value_; | 53 return !value_; |
32 | 54 |
33 if (((value_ & kFileTypeMask) >> kFileTypeOffset) > 4) | 55 if (file_type() > BLOCK_4K) |
34 return false; | 56 return false; |
35 | 57 |
36 if (is_separate_file()) | 58 if (is_separate_file()) |
37 return true; | 59 return true; |
38 | 60 |
39 const uint32 kReservedBitsMask = 0x0c000000; | 61 return AreReservedBitsValid(value_); |
40 return !(value_ & kReservedBitsMask); | 62 } |
63 | |
64 bool Addr::SanityCheckV3() const { | |
65 if (!is_initialized()) | |
66 return !value_; | |
67 | |
68 // For actual entries, SanityCheckForEntryV3 should be used. | |
69 if (file_type() > BLOCK_FILES) | |
70 return false; | |
71 | |
72 if (is_separate_file()) | |
73 return true; | |
74 | |
75 return AreReservedBitsValid(value_); | |
41 } | 76 } |
42 | 77 |
43 bool Addr::SanityCheckForEntryV2() const { | 78 bool Addr::SanityCheckForEntryV2() const { |
44 if (!SanityCheck() || !is_initialized()) | 79 if (!SanityCheckV2() || !is_initialized()) |
45 return false; | 80 return false; |
46 | 81 |
47 if (is_separate_file() || file_type() != BLOCK_256) | 82 if (is_separate_file() || file_type() != BLOCK_256) |
48 return false; | 83 return false; |
49 | 84 |
50 return true; | 85 return true; |
51 } | 86 } |
52 | 87 |
88 bool Addr::SanityCheckForEntryV3() const { | |
89 if (!is_initialized()) | |
90 return false; | |
91 | |
92 if (!AreReservedBitsValid(value_)) | |
93 return false; | |
94 | |
95 if (file_type() != BLOCK_ENTRIES && file_type() != BLOCK_EVICTED) | |
96 return false; | |
97 | |
98 if (num_blocks() != 1) | |
99 return false; | |
100 | |
101 return true; | |
102 } | |
103 | |
53 bool Addr::SanityCheckForRankings() const { | 104 bool Addr::SanityCheckForRankings() const { |
54 if (!SanityCheck() || !is_initialized()) | 105 if (!SanityCheckV2() || !is_initialized()) |
55 return false; | 106 return false; |
56 | 107 |
57 if (is_separate_file() || file_type() != RANKINGS || num_blocks() != 1) | 108 if (is_separate_file() || file_type() != RANKINGS || num_blocks() != 1) |
58 return false; | 109 return false; |
59 | 110 |
60 return true; | 111 return true; |
61 } | 112 } |
62 | 113 |
63 } // namespace disk_cache | 114 } // namespace disk_cache |
OLD | NEW |