Index: net/disk_cache/addr.cc |
=================================================================== |
--- net/disk_cache/addr.cc (revision 205902) |
+++ net/disk_cache/addr.cc (working copy) |
@@ -6,6 +6,16 @@ |
#include "base/logging.h" |
+namespace { |
+ |
+bool AreReservedBitsValid(uint32 value) { |
+ // These two bits of a block address should not be set. |
+ const uint32 kReservedBitsMask = 0x0c000000; |
+ return !(value & kReservedBitsMask); |
+} |
+ |
+} // namespace |
+ |
namespace disk_cache { |
int Addr::start_block() const { |
@@ -26,22 +36,47 @@ |
return true; |
} |
-bool Addr::SanityCheck() const { |
+Addr Addr::AsExternal() const { |
+ DCHECK(file_type() == BLOCK_FILES); |
+ 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,
|
+ return Addr(new_value); |
+} |
+ |
+Addr Addr::AsBlockFile() const { |
+ DCHECK(is_separate_file()); |
+ 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
|
+ return Addr(new_value); |
+} |
+ |
+bool Addr::SanityCheckV2() const { |
if (!is_initialized()) |
return !value_; |
- if (((value_ & kFileTypeMask) >> kFileTypeOffset) > 4) |
+ if (file_type() > BLOCK_4K) |
return false; |
if (is_separate_file()) |
return true; |
- const uint32 kReservedBitsMask = 0x0c000000; |
- return !(value_ & kReservedBitsMask); |
+ return AreReservedBitsValid(value_); |
} |
+bool Addr::SanityCheckV3() const { |
+ if (!is_initialized()) |
+ return !value_; |
+ |
+ // For actual entries, SanityCheckForEntryV3 should be used. |
+ if (file_type() > BLOCK_FILES) |
+ return false; |
+ |
+ if (is_separate_file()) |
+ return true; |
+ |
+ return AreReservedBitsValid(value_); |
+} |
+ |
bool Addr::SanityCheckForEntryV2() const { |
- if (!SanityCheck() || !is_initialized()) |
+ if (!SanityCheckV2() || !is_initialized()) |
return false; |
if (is_separate_file() || file_type() != BLOCK_256) |
@@ -50,8 +85,24 @@ |
return true; |
} |
+bool Addr::SanityCheckForEntryV3() const { |
+ if (!is_initialized()) |
+ return false; |
+ |
+ if (!AreReservedBitsValid(value_)) |
+ return false; |
+ |
+ if (file_type() != BLOCK_ENTRIES && file_type() != BLOCK_EVICTED) |
+ return false; |
+ |
+ if (num_blocks() != 1) |
+ return false; |
+ |
+ return true; |
+} |
+ |
bool Addr::SanityCheckForRankings() const { |
- if (!SanityCheck() || !is_initialized()) |
+ if (!SanityCheckV2() || !is_initialized()) |
return false; |
if (is_separate_file() || file_type() != RANKINGS || num_blocks() != 1) |