1 // Copyright 2012 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "net/disk_cache/blockfile/addr.h" 6 7 #include "base/check.h" 8 9 namespace disk_cache { 10 start_block() const11int Addr::start_block() const { 12 DCHECK(is_block_file()); 13 return value_ & kStartBlockMask; 14 } 15 num_blocks() const16int Addr::num_blocks() const { 17 DCHECK(is_block_file() || !value_); 18 return ((value_ & kNumBlocksMask) >> kNumBlocksOffset) + 1; 19 } 20 SetFileNumber(int file_number)21bool Addr::SetFileNumber(int file_number) { 22 DCHECK(is_separate_file()); 23 if (file_number & ~kFileNameMask) 24 return false; 25 value_ = kInitializedMask | file_number; 26 return true; 27 } 28 SanityCheck() const29bool Addr::SanityCheck() const { 30 if (!is_initialized()) 31 return !value_; 32 33 if (file_type() > BLOCK_4K) 34 return false; 35 36 if (is_separate_file()) 37 return true; 38 39 return !reserved_bits(); 40 } 41 SanityCheckForEntry() const42bool Addr::SanityCheckForEntry() const { 43 if (!SanityCheck() || !is_initialized()) 44 return false; 45 46 if (is_separate_file() || file_type() != BLOCK_256) 47 return false; 48 49 return true; 50 } 51 SanityCheckForRankings() const52bool Addr::SanityCheckForRankings() const { 53 if (!SanityCheck() || !is_initialized()) 54 return false; 55 56 if (is_separate_file() || file_type() != RANKINGS || num_blocks() != 1) 57 return false; 58 59 return true; 60 } 61 62 } // namespace disk_cache 63