OLD | NEW |
1 // Copyright (c) 2011 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 // See net/disk_cache/disk_cache.h for the public interface. | 5 // See net/disk_cache/disk_cache.h for the public interface. |
6 | 6 |
7 #ifndef NET_DISK_CACHE_RANKINGS_H_ | 7 #ifndef NET_DISK_CACHE_RANKINGS_H_ |
8 #define NET_DISK_CACHE_RANKINGS_H_ | 8 #define NET_DISK_CACHE_RANKINGS_H_ |
9 #pragma once | 9 #pragma once |
10 | 10 |
11 #include <list> | 11 #include <list> |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 bool SanityCheck(CacheRankingsBlock* node, bool from_list) const; | 139 bool SanityCheck(CacheRankingsBlock* node, bool from_list) const; |
140 bool DataSanityCheck(CacheRankingsBlock* node, bool from_list) const; | 140 bool DataSanityCheck(CacheRankingsBlock* node, bool from_list) const; |
141 | 141 |
142 // Sets the |contents| field of |node| to |address|. | 142 // Sets the |contents| field of |node| to |address|. |
143 void SetContents(CacheRankingsBlock* node, CacheAddr address); | 143 void SetContents(CacheRankingsBlock* node, CacheAddr address); |
144 | 144 |
145 private: | 145 private: |
146 typedef std::pair<CacheAddr, CacheRankingsBlock*> IteratorPair; | 146 typedef std::pair<CacheAddr, CacheRankingsBlock*> IteratorPair; |
147 typedef std::list<IteratorPair> IteratorList; | 147 typedef std::list<IteratorPair> IteratorList; |
148 | 148 |
| 149 enum ListDirection { |
| 150 FORWARD, |
| 151 BACKWARD |
| 152 }; |
| 153 |
149 void ReadHeads(); | 154 void ReadHeads(); |
150 void ReadTails(); | 155 void ReadTails(); |
151 void WriteHead(List list); | 156 void WriteHead(List list); |
152 void WriteTail(List list); | 157 void WriteTail(List list); |
153 | 158 |
154 // Gets the rankings information for a given rankings node. We may end up | 159 // Gets the rankings information for a given rankings node. We may end up |
155 // sharing the actual memory with a loaded entry, but we are not taking a | 160 // sharing the actual memory with a loaded entry, but we are not taking a |
156 // reference to that entry, so |rankings| must be short lived. | 161 // reference to that entry, so |rankings| must be short lived. |
157 bool GetRanking(CacheRankingsBlock* rankings); | 162 bool GetRanking(CacheRankingsBlock* rankings); |
158 | 163 |
159 // Makes |rankings| suitable to live a long life. | 164 // Makes |rankings| suitable to live a long life. |
160 void ConvertToLongLived(CacheRankingsBlock* rankings); | 165 void ConvertToLongLived(CacheRankingsBlock* rankings); |
161 | 166 |
162 // Finishes a list modification after a crash. | 167 // Finishes a list modification after a crash. |
163 void CompleteTransaction(); | 168 void CompleteTransaction(); |
164 void FinishInsert(CacheRankingsBlock* rankings); | 169 void FinishInsert(CacheRankingsBlock* rankings); |
165 void RevertRemove(CacheRankingsBlock* rankings); | 170 void RevertRemove(CacheRankingsBlock* rankings); |
166 | 171 |
167 // Returns false if this entry will not be recognized as dirty (called during | |
168 // selfcheck). | |
169 bool CheckEntry(CacheRankingsBlock* rankings); | |
170 | |
171 // Returns false if node is not properly linked. This method may change the | 172 // Returns false if node is not properly linked. This method may change the |
172 // provided |list| to reflect the list where this node is actually stored. | 173 // provided |list| to reflect the list where this node is actually stored. |
173 bool CheckLinks(CacheRankingsBlock* node, CacheRankingsBlock* prev, | 174 bool CheckLinks(CacheRankingsBlock* node, CacheRankingsBlock* prev, |
174 CacheRankingsBlock* next, List* list); | 175 CacheRankingsBlock* next, List* list); |
175 | 176 |
176 // Checks the links between two consecutive nodes. | 177 // Checks the links between two consecutive nodes. |
177 bool CheckSingleLink(CacheRankingsBlock* prev, CacheRankingsBlock* next); | 178 bool CheckSingleLink(CacheRankingsBlock* prev, CacheRankingsBlock* next); |
178 | 179 |
179 // Peforms a simple check of the list, and returns the number of items or an | 180 // Peforms a simple check of the list, and returns the number of items or an |
180 // error code (negative value). | 181 // error code (negative value). |
181 int CheckList(List list); | 182 int CheckList(List list); |
182 | 183 |
| 184 // Walks a list in the desired direction until the nodes |end1| or |end2| are |
| 185 // reached. Returns an error code (0 on success), the number of items verified |
| 186 // and the addresses of the last nodes visited. |
| 187 int CheckListSection(List list, Addr end1, Addr end2, ListDirection dir, |
| 188 Addr* last, Addr* second_last, int* num_items); |
| 189 |
183 // Returns true if addr is the head or tail of any list. When there is a | 190 // Returns true if addr is the head or tail of any list. When there is a |
184 // match |list| will contain the list number for |addr|. | 191 // match |list| will contain the list number for |addr|. |
185 bool IsHead(CacheAddr addr, List* list) const; | 192 bool IsHead(CacheAddr addr, List* list) const; |
186 bool IsTail(CacheAddr addr, List* list) const; | 193 bool IsTail(CacheAddr addr, List* list) const; |
187 | 194 |
188 // Updates the iterators whenever node is being changed. | 195 // Updates the iterators whenever node is being changed. |
189 void UpdateIterators(CacheRankingsBlock* node); | 196 void UpdateIterators(CacheRankingsBlock* node); |
190 | 197 |
191 // Invalidates the iterators pointing to this node. | 198 // Invalidates the iterators pointing to this node. |
192 void InvalidateIterators(CacheRankingsBlock* node); | 199 void InvalidateIterators(CacheRankingsBlock* node); |
193 | 200 |
194 // Keeps track of the number of entries on a list. | 201 // Keeps track of the number of entries on a list. |
195 void IncrementCounter(List list); | 202 void IncrementCounter(List list); |
196 void DecrementCounter(List list); | 203 void DecrementCounter(List list); |
197 | 204 |
198 bool init_; | 205 bool init_; |
199 bool count_lists_; | 206 bool count_lists_; |
200 Addr heads_[LAST_ELEMENT]; | 207 Addr heads_[LAST_ELEMENT]; |
201 Addr tails_[LAST_ELEMENT]; | 208 Addr tails_[LAST_ELEMENT]; |
202 BackendImpl* backend_; | 209 BackendImpl* backend_; |
203 LruData* control_data_; // Data related to the LRU lists. | 210 LruData* control_data_; // Data related to the LRU lists. |
204 IteratorList iterators_; | 211 IteratorList iterators_; |
205 | 212 |
206 DISALLOW_COPY_AND_ASSIGN(Rankings); | 213 DISALLOW_COPY_AND_ASSIGN(Rankings); |
207 }; | 214 }; |
208 | 215 |
209 } // namespace disk_cache | 216 } // namespace disk_cache |
210 | 217 |
211 #endif // NET_DISK_CACHE_RANKINGS_H_ | 218 #endif // NET_DISK_CACHE_RANKINGS_H_ |
OLD | NEW |