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

Side by Side Diff: net/disk_cache/addr.h

Issue 53313004: Disk cache v3: The main index table. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 6 years, 11 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | net/disk_cache/disk_format_base.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_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
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 // 7 = evicted entries block file 47 // 7 = evicted entries block file
48 // 48 //
49 // If separate file: 49 // If separate file:
50 // 0000 1111 1111 1111 1111 1111 1111 1111 : file# 0 - 268,435,456 (2^28) 50 // 0000 1111 1111 1111 1111 1111 1111 1111 : file# 0 - 268,435,456 (2^28)
51 // 51 //
52 // If block file: 52 // If block file:
53 // 0000 1100 0000 0000 0000 0000 0000 0000 : reserved bits 53 // 0000 1100 0000 0000 0000 0000 0000 0000 : reserved bits
54 // 0000 0011 0000 0000 0000 0000 0000 0000 : number of contiguous blocks 1-4 54 // 0000 0011 0000 0000 0000 0000 0000 0000 : number of contiguous blocks 1-4
55 // 0000 0000 1111 1111 0000 0000 0000 0000 : file selector 0 - 255 55 // 0000 0000 1111 1111 0000 0000 0000 0000 : file selector 0 - 255
56 // 0000 0000 0000 0000 1111 1111 1111 1111 : block# 0 - 65,535 (2^16) 56 // 0000 0000 0000 0000 1111 1111 1111 1111 : block# 0 - 65,535 (2^16)
57 //
58 // Note that an Addr can be used to "point" to a variety of different objects,
59 // from a given type of entry to random blobs of data. Conceptually, an Addr is
60 // just a number that someone can inspect to find out how to locate the desired
61 // record. Most users will not care about the specific bits inside Addr, for
62 // example, what parts of it point to a file number; only the code that has to
63 // select a specific file would care about those specific bits.
64 //
65 // From a general point of view, an Addr has a total capacity of 2^24 entities,
66 // in that it has 24 bits that can identify individual records. Note that the
67 // address space is bigger for independent files (2^28), but that would not be
68 // the general case.
57 class NET_EXPORT_PRIVATE Addr { 69 class NET_EXPORT_PRIVATE Addr {
58 public: 70 public:
59 Addr() : value_(0) {} 71 Addr() : value_(0) {}
60 explicit Addr(CacheAddr address) : value_(address) {} 72 explicit Addr(CacheAddr address) : value_(address) {}
61 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) {
62 value_ = ((file_type << kFileTypeOffset) & kFileTypeMask) | 74 value_ = ((file_type << kFileTypeOffset) & kFileTypeMask) |
63 (((max_blocks - 1) << kNumBlocksOffset) & kNumBlocksMask) | 75 (((max_blocks - 1) << kNumBlocksOffset) & kNumBlocksMask) |
64 ((block_file << kFileSelectorOffset) & kFileSelectorMask) | 76 ((block_file << kFileSelectorOffset) & kFileSelectorMask) |
65 (index & kStartBlockMask) | kInitializedMask; 77 (index & kStartBlockMask) | kInitializedMask;
66 } 78 }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 } 113 }
102 114
103 bool operator==(Addr other) const { 115 bool operator==(Addr other) const {
104 return value_ == other.value_; 116 return value_ == other.value_;
105 } 117 }
106 118
107 bool operator!=(Addr other) const { 119 bool operator!=(Addr other) const {
108 return value_ != other.value_; 120 return value_ != other.value_;
109 } 121 }
110 122
111 static Addr FromEntryAddress(uint32 value) {
112 return Addr(kInitializedMask + (BLOCK_ENTRIES << kFileTypeOffset) + value);
113 }
114
115 static Addr FromEvictedAddress(uint32 value) {
116 return Addr(kInitializedMask + (BLOCK_EVICTED << kFileTypeOffset) + value);
117 }
118
119 static int BlockSizeForFileType(FileType file_type) { 123 static int BlockSizeForFileType(FileType file_type) {
120 switch (file_type) { 124 switch (file_type) {
121 case RANKINGS: 125 case RANKINGS:
122 return 36; 126 return 36;
123 case BLOCK_256: 127 case BLOCK_256:
124 return 256; 128 return 256;
125 case BLOCK_1K: 129 case BLOCK_1K:
126 return 1024; 130 return 1024;
127 case BLOCK_4K: 131 case BLOCK_4K:
128 return 4096; 132 return 4096;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 static const uint32 kFileSelectorOffset = 16; 179 static const uint32 kFileSelectorOffset = 16;
176 static const uint32 kStartBlockMask = 0x0000FFFF; 180 static const uint32 kStartBlockMask = 0x0000FFFF;
177 static const uint32 kFileNameMask = 0x0FFFFFFF; 181 static const uint32 kFileNameMask = 0x0FFFFFFF;
178 182
179 CacheAddr value_; 183 CacheAddr value_;
180 }; 184 };
181 185
182 } // namespace disk_cache 186 } // namespace disk_cache
183 187
184 #endif // NET_DISK_CACHE_ADDR_H_ 188 #endif // NET_DISK_CACHE_ADDR_H_
OLDNEW
« no previous file with comments | « no previous file | net/disk_cache/disk_format_base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698