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
3 // found in the LICENSE file.
5 #include "net/disk_cache/blockfile/addr.h"
7 #include "base/logging.h"
11 int Addr::start_block() const {
12 DCHECK(is_block_file());
13 return value_
& kStartBlockMask
;
16 int Addr::num_blocks() const {
17 DCHECK(is_block_file() || !value_
);
18 return ((value_
& kNumBlocksMask
) >> kNumBlocksOffset
) + 1;
21 bool Addr::SetFileNumber(int file_number
) {
22 DCHECK(is_separate_file());
23 if (file_number
& ~kFileNameMask
)
25 value_
= kInitializedMask
| file_number
;
29 bool Addr::SanityCheckV2() const {
30 if (!is_initialized())
33 if (file_type() > BLOCK_4K
)
36 if (is_separate_file())
39 return !reserved_bits();
42 bool Addr::SanityCheckV3() const {
43 if (!is_initialized())
46 // For actual entries, SanityCheckForEntryV3 should be used.
47 if (file_type() > BLOCK_FILES
)
50 if (is_separate_file())
53 return !reserved_bits();
56 bool Addr::SanityCheckForEntryV2() const {
57 if (!SanityCheckV2() || !is_initialized())
60 if (is_separate_file() || file_type() != BLOCK_256
)
66 bool Addr::SanityCheckForEntryV3() const {
67 if (!is_initialized())
73 if (file_type() != BLOCK_ENTRIES
&& file_type() != BLOCK_EVICTED
)
76 if (num_blocks() != 1)
82 bool Addr::SanityCheckForRankings() const {
83 if (!SanityCheckV2() || !is_initialized())
86 if (is_separate_file() || file_type() != RANKINGS
|| num_blocks() != 1)
92 } // namespace disk_cache