| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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_ADDR_H__ | 8 #ifndef NET_DISK_CACHE_ADDR_H_ |
| 9 #define NET_DISK_CACHE_ADDR_H__ | 9 #define NET_DISK_CACHE_ADDR_H_ |
| 10 | 10 |
| 11 #include "base/basictypes.h" | |
| 12 #include "base/logging.h" | |
| 13 #include "net/disk_cache/disk_format.h" | 11 #include "net/disk_cache/disk_format.h" |
| 14 | 12 |
| 15 namespace disk_cache { | 13 namespace disk_cache { |
| 16 | 14 |
| 17 enum FileType { | 15 enum FileType { |
| 18 EXTERNAL = 0, | 16 EXTERNAL = 0, |
| 19 RANKINGS = 1, | 17 RANKINGS = 1, |
| 20 BLOCK_256, | 18 BLOCK_256, |
| 21 BLOCK_1K, | 19 BLOCK_1K, |
| 22 BLOCK_4K, | 20 BLOCK_4K, |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 return static_cast<FileType>((value_ & kFileTypeMask) >> kFileTypeOffset); | 78 return static_cast<FileType>((value_ & kFileTypeMask) >> kFileTypeOffset); |
| 81 } | 79 } |
| 82 | 80 |
| 83 int FileNumber() const { | 81 int FileNumber() const { |
| 84 if (is_separate_file()) | 82 if (is_separate_file()) |
| 85 return value_ & kFileNameMask; | 83 return value_ & kFileNameMask; |
| 86 else | 84 else |
| 87 return ((value_ & kFileSelectorMask) >> kFileSelectorOffset); | 85 return ((value_ & kFileSelectorMask) >> kFileSelectorOffset); |
| 88 } | 86 } |
| 89 | 87 |
| 90 int start_block() const { | 88 int start_block() const; |
| 91 DCHECK(is_block_file()); | 89 int num_blocks() const; |
| 92 return value_ & kStartBlockMask; | 90 bool SetFileNumber(int file_number); |
| 93 } | |
| 94 | |
| 95 int num_blocks() const { | |
| 96 DCHECK(is_block_file() || !value_); | |
| 97 return ((value_ & kNumBlocksMask) >> kNumBlocksOffset) + 1; | |
| 98 } | |
| 99 | |
| 100 bool SetFileNumber(int file_number) { | |
| 101 DCHECK(is_separate_file()); | |
| 102 if (file_number & ~kFileNameMask) | |
| 103 return false; | |
| 104 value_ = kInitializedMask | file_number; | |
| 105 return true; | |
| 106 } | |
| 107 | |
| 108 int BlockSize() const { | 91 int BlockSize() const { |
| 109 return BlockSizeForFileType(file_type()); | 92 return BlockSizeForFileType(file_type()); |
| 110 } | 93 } |
| 111 | 94 |
| 112 static int BlockSizeForFileType(FileType file_type) { | 95 static int BlockSizeForFileType(FileType file_type) { |
| 113 switch (file_type) { | 96 switch (file_type) { |
| 114 case RANKINGS: | 97 case RANKINGS: |
| 115 return 36; | 98 return 36; |
| 116 case BLOCK_256: | 99 case BLOCK_256: |
| 117 return 256; | 100 return 256; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 144 static const uint32 kFileSelectorMask = 0x00ff0000; | 127 static const uint32 kFileSelectorMask = 0x00ff0000; |
| 145 static const uint32 kFileSelectorOffset = 16; | 128 static const uint32 kFileSelectorOffset = 16; |
| 146 static const uint32 kStartBlockMask = 0x0000FFFF; | 129 static const uint32 kStartBlockMask = 0x0000FFFF; |
| 147 static const uint32 kFileNameMask = 0x0FFFFFFF; | 130 static const uint32 kFileNameMask = 0x0FFFFFFF; |
| 148 | 131 |
| 149 CacheAddr value_; | 132 CacheAddr value_; |
| 150 }; | 133 }; |
| 151 | 134 |
| 152 } // namespace disk_cache | 135 } // namespace disk_cache |
| 153 | 136 |
| 154 #endif // NET_DISK_CACHE_ADDR_H__ | 137 #endif // NET_DISK_CACHE_ADDR_H_ |
| 155 | |
| OLD | NEW |