| 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 // This is an internal class that handles the address of a cache record. | 5 // This is an internal class that handles the address of a cache record. |
| 6 // See net/disk_cache/disk_cache.h for the public interface of the cache. | 6 // See net/disk_cache/disk_cache.h for the public interface of the cache. |
| 7 | 7 |
| 8 #ifndef NET_DISK_CACHE_BLOCKFILE_ADDR_H_ | 8 #ifndef NET_DISK_CACHE_BLOCKFILE_ADDR_H_ |
| 9 #define NET_DISK_CACHE_BLOCKFILE_ADDR_H_ | 9 #define NET_DISK_CACHE_BLOCKFILE_ADDR_H_ |
| 10 | 10 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 // address space is bigger for independent files (2^28), but that would not be | 67 // address space is bigger for independent files (2^28), but that would not be |
| 68 // the general case. | 68 // the general case. |
| 69 class NET_EXPORT_PRIVATE Addr { | 69 class NET_EXPORT_PRIVATE Addr { |
| 70 public: | 70 public: |
| 71 Addr() : value_(0) {} | 71 Addr() : value_(0) {} |
| 72 explicit Addr(CacheAddr address) : value_(address) {} | 72 explicit Addr(CacheAddr address) : value_(address) {} |
| 73 Addr(FileType file_type, int max_blocks, int block_file, int index) { | 73 Addr(FileType file_type, int max_blocks, int block_file, int index) { |
| 74 value_ = ((file_type << kFileTypeOffset) & kFileTypeMask) | | 74 value_ = ((file_type << kFileTypeOffset) & kFileTypeMask) | |
| 75 (((max_blocks - 1) << kNumBlocksOffset) & kNumBlocksMask) | | 75 (((max_blocks - 1) << kNumBlocksOffset) & kNumBlocksMask) | |
| 76 ((block_file << kFileSelectorOffset) & kFileSelectorMask) | | 76 ((block_file << kFileSelectorOffset) & kFileSelectorMask) | |
| 77 (index & kStartBlockMask) | kInitializedMask; | 77 (index & kStartBlockMask) | kInitializedMask; |
| 78 } | 78 } |
| 79 | 79 |
| 80 CacheAddr value() const { return value_; } | 80 CacheAddr value() const { return value_; } |
| 81 void set_value(CacheAddr address) { | 81 void set_value(CacheAddr address) { value_ = address; } |
| 82 value_ = address; | |
| 83 } | |
| 84 | 82 |
| 85 bool is_initialized() const { | 83 bool is_initialized() const { return (value_ & kInitializedMask) != 0; } |
| 86 return (value_ & kInitializedMask) != 0; | |
| 87 } | |
| 88 | 84 |
| 89 bool is_separate_file() const { | 85 bool is_separate_file() const { return (value_ & kFileTypeMask) == 0; } |
| 90 return (value_ & kFileTypeMask) == 0; | |
| 91 } | |
| 92 | 86 |
| 93 bool is_block_file() const { | 87 bool is_block_file() const { return !is_separate_file(); } |
| 94 return !is_separate_file(); | |
| 95 } | |
| 96 | 88 |
| 97 FileType file_type() const { | 89 FileType file_type() const { |
| 98 return static_cast<FileType>((value_ & kFileTypeMask) >> kFileTypeOffset); | 90 return static_cast<FileType>((value_ & kFileTypeMask) >> kFileTypeOffset); |
| 99 } | 91 } |
| 100 | 92 |
| 101 int FileNumber() const { | 93 int FileNumber() const { |
| 102 if (is_separate_file()) | 94 if (is_separate_file()) |
| 103 return value_ & kFileNameMask; | 95 return value_ & kFileNameMask; |
| 104 else | 96 else |
| 105 return ((value_ & kFileSelectorMask) >> kFileSelectorOffset); | 97 return ((value_ & kFileSelectorMask) >> kFileSelectorOffset); |
| 106 } | 98 } |
| 107 | 99 |
| 108 int start_block() const; | 100 int start_block() const; |
| 109 int num_blocks() const; | 101 int num_blocks() const; |
| 110 bool SetFileNumber(int file_number); | 102 bool SetFileNumber(int file_number); |
| 111 int BlockSize() const { | 103 int BlockSize() const { return BlockSizeForFileType(file_type()); } |
| 112 return BlockSizeForFileType(file_type()); | |
| 113 } | |
| 114 | 104 |
| 115 bool operator==(Addr other) const { | 105 bool operator==(Addr other) const { return value_ == other.value_; } |
| 116 return value_ == other.value_; | |
| 117 } | |
| 118 | 106 |
| 119 bool operator!=(Addr other) const { | 107 bool operator!=(Addr other) const { return value_ != other.value_; } |
| 120 return value_ != other.value_; | |
| 121 } | |
| 122 | 108 |
| 123 static int BlockSizeForFileType(FileType file_type) { | 109 static int BlockSizeForFileType(FileType file_type) { |
| 124 switch (file_type) { | 110 switch (file_type) { |
| 125 case RANKINGS: | 111 case RANKINGS: |
| 126 return 36; | 112 return 36; |
| 127 case BLOCK_256: | 113 case BLOCK_256: |
| 128 return 256; | 114 return 256; |
| 129 case BLOCK_1K: | 115 case BLOCK_1K: |
| 130 return 1024; | 116 return 1024; |
| 131 case BLOCK_4K: | 117 case BLOCK_4K: |
| (...skipping 26 matching lines...) Expand all Loading... |
| 158 } | 144 } |
| 159 | 145 |
| 160 // Returns true if this address looks like a valid one. | 146 // Returns true if this address looks like a valid one. |
| 161 bool SanityCheckV2() const; | 147 bool SanityCheckV2() const; |
| 162 bool SanityCheckV3() const; | 148 bool SanityCheckV3() const; |
| 163 bool SanityCheckForEntryV2() const; | 149 bool SanityCheckForEntryV2() const; |
| 164 bool SanityCheckForEntryV3() const; | 150 bool SanityCheckForEntryV3() const; |
| 165 bool SanityCheckForRankings() const; | 151 bool SanityCheckForRankings() const; |
| 166 | 152 |
| 167 private: | 153 private: |
| 168 uint32 reserved_bits() const { | 154 uint32 reserved_bits() const { return value_ & kReservedBitsMask; } |
| 169 return value_ & kReservedBitsMask; | |
| 170 } | |
| 171 | 155 |
| 172 static const uint32 kInitializedMask = 0x80000000; | 156 static const uint32 kInitializedMask = 0x80000000; |
| 173 static const uint32 kFileTypeMask = 0x70000000; | 157 static const uint32 kFileTypeMask = 0x70000000; |
| 174 static const uint32 kFileTypeOffset = 28; | 158 static const uint32 kFileTypeOffset = 28; |
| 175 static const uint32 kReservedBitsMask = 0x0c000000; | 159 static const uint32 kReservedBitsMask = 0x0c000000; |
| 176 static const uint32 kNumBlocksMask = 0x03000000; | 160 static const uint32 kNumBlocksMask = 0x03000000; |
| 177 static const uint32 kNumBlocksOffset = 24; | 161 static const uint32 kNumBlocksOffset = 24; |
| 178 static const uint32 kFileSelectorMask = 0x00ff0000; | 162 static const uint32 kFileSelectorMask = 0x00ff0000; |
| 179 static const uint32 kFileSelectorOffset = 16; | 163 static const uint32 kFileSelectorOffset = 16; |
| 180 static const uint32 kStartBlockMask = 0x0000FFFF; | 164 static const uint32 kStartBlockMask = 0x0000FFFF; |
| 181 static const uint32 kFileNameMask = 0x0FFFFFFF; | 165 static const uint32 kFileNameMask = 0x0FFFFFFF; |
| 182 | 166 |
| 183 CacheAddr value_; | 167 CacheAddr value_; |
| 184 }; | 168 }; |
| 185 | 169 |
| 186 } // namespace disk_cache | 170 } // namespace disk_cache |
| 187 | 171 |
| 188 #endif // NET_DISK_CACHE_BLOCKFILE_ADDR_H_ | 172 #endif // NET_DISK_CACHE_BLOCKFILE_ADDR_H_ |
| OLD | NEW |