Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(637)

Unified Diff: net/disk_cache/addr.cc

Issue 16837003: Disk cache: Update Addr to handle file format version 3. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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) {
gavinp 2013/06/16 23:44:15 Make this an inline getter.
+ // These two bits of a block address should not be set.
+ const uint32 kReservedBitsMask = 0x0c000000;
gavinp 2013/06/16 23:44:15 Move this into the header.
+ return !(value & kReservedBitsMask);
+}
+
+} // namespace
+
namespace disk_cache {
int Addr::start_block() const {
@@ -26,22 +36,35 @@
return true;
}
-bool Addr::SanityCheck() const {
+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 +73,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)

Powered by Google App Engine
This is Rietveld 408576698