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 disk_cache { | 9 namespace disk_cache { |
10 | 10 |
11 int Addr::start_block() const { | 11 int Addr::start_block() const { |
12 DCHECK(is_block_file()); | 12 DCHECK(is_block_file()); |
13 return value_ & kStartBlockMask; | 13 return value_ & kStartBlockMask; |
14 } | 14 } |
15 | 15 |
16 int Addr::num_blocks() const { | 16 int Addr::num_blocks() const { |
17 DCHECK(is_block_file() || !value_); | 17 DCHECK(is_block_file() || !value_); |
18 return ((value_ & kNumBlocksMask) >> kNumBlocksOffset) + 1; | 18 return ((value_ & kNumBlocksMask) >> kNumBlocksOffset) + 1; |
19 } | 19 } |
20 | 20 |
21 bool Addr::SetFileNumber(int file_number) { | 21 bool Addr::SetFileNumber(int file_number) { |
22 DCHECK(is_separate_file()); | 22 DCHECK(is_separate_file()); |
23 if (file_number & ~kFileNameMask) | 23 if (file_number & ~kFileNameMask) |
24 return false; | 24 return false; |
25 value_ = kInitializedMask | file_number; | 25 value_ = kInitializedMask | file_number; |
26 return true; | 26 return true; |
27 } | 27 } |
28 | 28 |
29 bool Addr::SanityCheck() const { | 29 Addr Addr::AsExternal() const { |
30 DCHECK(file_type() == BLOCK_FILES); | |
31 CacheAddr new_value = value() & ~kFileTypeMask; | |
32 return Addr(new_value); | |
33 } | |
34 | |
35 Addr Addr::AsBlockFile() const { | |
36 DCHECK(is_separate_file()); | |
37 CacheAddr new_value = value() + (BLOCK_FILES << kFileTypeOffset); | |
38 return Addr(new_value); | |
39 } | |
40 | |
41 bool Addr::SanityCheckV2() const { | |
30 if (!is_initialized()) | 42 if (!is_initialized()) |
31 return !value_; | 43 return !value_; |
32 | 44 |
33 if (((value_ & kFileTypeMask) >> kFileTypeOffset) > 4) | 45 if (((value_ & kFileTypeMask) >> kFileTypeOffset) > 4) |
34 return false; | 46 return false; |
35 | 47 |
36 if (is_separate_file()) | 48 if (is_separate_file()) |
37 return true; | 49 return true; |
38 | 50 |
39 const uint32 kReservedBitsMask = 0x0c000000; | 51 const uint32 kReservedBitsMask = 0x0c000000; |
40 return !(value_ & kReservedBitsMask); | 52 return !(value_ & kReservedBitsMask); |
41 } | 53 } |
42 | 54 |
55 bool Addr::SanityCheckV3() const { | |
56 if (!is_initialized()) | |
57 return !value_; | |
rvargas (doing something else)
2013/06/13 19:07:25
Just so that I understand your comment, are you sa
gavinp
2013/06/13 19:49:00
No, and this is probably one of the few uses of va
| |
58 | |
59 if (((value_ & kFileTypeMask) >> kFileTypeOffset) > BLOCK_FILES) | |
gavinp
2013/06/13 13:10:58
I don't understand this.
rvargas (doing something else)
2013/06/13 19:07:25
This is exactly the same check of SanityCheckV2 th
| |
60 return false; | |
61 | |
62 if (is_separate_file()) | |
63 return true; | |
64 | |
65 const uint32 kReservedBitsMask = 0x0c000000; | |
gavinp
2013/06/13 13:10:58
What's 0x0c000000?
rvargas (doing something else)
2013/06/13 19:07:25
That's the mask for the reserved bits of the value
gavinp
2013/06/13 19:49:00
Yeah, I saw that. But why not reserved_bits() == 0
| |
66 return !(value_ & kReservedBitsMask); | |
67 } | |
68 | |
43 bool Addr::SanityCheckForEntryV2() const { | 69 bool Addr::SanityCheckForEntryV2() const { |
44 if (!SanityCheck() || !is_initialized()) | 70 if (!SanityCheckV2() || !is_initialized()) |
45 return false; | 71 return false; |
46 | 72 |
47 if (is_separate_file() || file_type() != BLOCK_256) | 73 if (is_separate_file() || file_type() != BLOCK_256) |
48 return false; | 74 return false; |
49 | 75 |
50 return true; | 76 return true; |
51 } | 77 } |
52 | 78 |
79 bool Addr::SanityCheckForEntryV3() const { | |
80 if (!is_initialized()) | |
81 return false; | |
82 | |
83 const uint32 kReservedBitsMask = 0x0c000000; | |
84 if (value_ & kReservedBitsMask) | |
85 return false; | |
86 | |
87 if (file_type() != BLOCK_ENTRIES && file_type() != BLOCK_EVICTED) | |
88 return false; | |
89 | |
90 if (num_blocks() != 1) | |
91 return false; | |
92 | |
93 return true; | |
94 } | |
95 | |
53 bool Addr::SanityCheckForRankings() const { | 96 bool Addr::SanityCheckForRankings() const { |
54 if (!SanityCheck() || !is_initialized()) | 97 if (!SanityCheckV2() || !is_initialized()) |
55 return false; | 98 return false; |
56 | 99 |
57 if (is_separate_file() || file_type() != RANKINGS || num_blocks() != 1) | 100 if (is_separate_file() || file_type() != RANKINGS || num_blocks() != 1) |
58 return false; | 101 return false; |
59 | 102 |
60 return true; | 103 return true; |
61 } | 104 } |
62 | 105 |
63 } // namespace disk_cache | 106 } // namespace disk_cache |
OLD | NEW |