| 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 // 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_BLOCKFILE_RANKINGS_H_ | 7 #ifndef NET_DISK_CACHE_BLOCKFILE_RANKINGS_H_ |
| 8 #define NET_DISK_CACHE_BLOCKFILE_RANKINGS_H_ | 8 #define NET_DISK_CACHE_BLOCKFILE_RANKINGS_H_ |
| 9 | 9 |
| 10 #include <list> | 10 #include <list> |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 REMOVE_LOAD_2, | 47 REMOVE_LOAD_2, |
| 48 REMOVE_LOAD_3, | 48 REMOVE_LOAD_3, |
| 49 MAX_CRASH | 49 MAX_CRASH |
| 50 }; | 50 }; |
| 51 | 51 |
| 52 // This class handles the ranking information for the cache. | 52 // This class handles the ranking information for the cache. |
| 53 class Rankings { | 53 class Rankings { |
| 54 public: | 54 public: |
| 55 // Possible lists of entries. | 55 // Possible lists of entries. |
| 56 enum List { | 56 enum List { |
| 57 NO_USE = 0, // List of entries that have not been reused. | 57 NO_USE = 0, // List of entries that have not been reused. |
| 58 LOW_USE, // List of entries with low reuse. | 58 LOW_USE, // List of entries with low reuse. |
| 59 HIGH_USE, // List of entries with high reuse. | 59 HIGH_USE, // List of entries with high reuse. |
| 60 RESERVED, // Reserved for future use. | 60 RESERVED, // Reserved for future use. |
| 61 DELETED, // List of recently deleted or doomed entries. | 61 DELETED, // List of recently deleted or doomed entries. |
| 62 LAST_ELEMENT | 62 LAST_ELEMENT |
| 63 }; | 63 }; |
| 64 | 64 |
| 65 // This class provides a specialized version of scoped_ptr, that calls | 65 // This class provides a specialized version of scoped_ptr, that calls |
| 66 // Rankings whenever a CacheRankingsBlock is deleted, to keep track of cache | 66 // Rankings whenever a CacheRankingsBlock is deleted, to keep track of cache |
| 67 // iterators that may go stale. | 67 // iterators that may go stale. |
| 68 class ScopedRankingsBlock : public scoped_ptr<CacheRankingsBlock> { | 68 class ScopedRankingsBlock : public scoped_ptr<CacheRankingsBlock> { |
| 69 public: | 69 public: |
| 70 ScopedRankingsBlock(); | 70 ScopedRankingsBlock(); |
| 71 explicit ScopedRankingsBlock(Rankings* rankings); | 71 explicit ScopedRankingsBlock(Rankings* rankings); |
| 72 ScopedRankingsBlock(Rankings* rankings, CacheRankingsBlock* node); | 72 ScopedRankingsBlock(Rankings* rankings, CacheRankingsBlock* node); |
| 73 | 73 |
| 74 ~ScopedRankingsBlock() { | 74 ~ScopedRankingsBlock() { rankings_->FreeRankingsBlock(get()); } |
| 75 rankings_->FreeRankingsBlock(get()); | |
| 76 } | |
| 77 | 75 |
| 78 void set_rankings(Rankings* rankings) { | 76 void set_rankings(Rankings* rankings) { rankings_ = rankings; } |
| 79 rankings_ = rankings; | |
| 80 } | |
| 81 | 77 |
| 82 // scoped_ptr::reset will delete the object. | 78 // scoped_ptr::reset will delete the object. |
| 83 void reset(CacheRankingsBlock* p = NULL) { | 79 void reset(CacheRankingsBlock* p = NULL) { |
| 84 if (p != get()) | 80 if (p != get()) |
| 85 rankings_->FreeRankingsBlock(get()); | 81 rankings_->FreeRankingsBlock(get()); |
| 86 scoped_ptr<CacheRankingsBlock>::reset(p); | 82 scoped_ptr<CacheRankingsBlock>::reset(p); |
| 87 } | 83 } |
| 88 | 84 |
| 89 private: | 85 private: |
| 90 Rankings* rankings_; | 86 Rankings* rankings_; |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 // Makes |rankings| suitable to live a long life. | 156 // Makes |rankings| suitable to live a long life. |
| 161 void ConvertToLongLived(CacheRankingsBlock* rankings); | 157 void ConvertToLongLived(CacheRankingsBlock* rankings); |
| 162 | 158 |
| 163 // Finishes a list modification after a crash. | 159 // Finishes a list modification after a crash. |
| 164 void CompleteTransaction(); | 160 void CompleteTransaction(); |
| 165 void FinishInsert(CacheRankingsBlock* rankings); | 161 void FinishInsert(CacheRankingsBlock* rankings); |
| 166 void RevertRemove(CacheRankingsBlock* rankings); | 162 void RevertRemove(CacheRankingsBlock* rankings); |
| 167 | 163 |
| 168 // Returns false if node is not properly linked. This method may change the | 164 // Returns false if node is not properly linked. This method may change the |
| 169 // provided |list| to reflect the list where this node is actually stored. | 165 // provided |list| to reflect the list where this node is actually stored. |
| 170 bool CheckLinks(CacheRankingsBlock* node, CacheRankingsBlock* prev, | 166 bool CheckLinks(CacheRankingsBlock* node, |
| 171 CacheRankingsBlock* next, List* list); | 167 CacheRankingsBlock* prev, |
| 168 CacheRankingsBlock* next, |
| 169 List* list); |
| 172 | 170 |
| 173 // Checks the links between two consecutive nodes. | 171 // Checks the links between two consecutive nodes. |
| 174 bool CheckSingleLink(CacheRankingsBlock* prev, CacheRankingsBlock* next); | 172 bool CheckSingleLink(CacheRankingsBlock* prev, CacheRankingsBlock* next); |
| 175 | 173 |
| 176 // Peforms a simple check of the list, and returns the number of items or an | 174 // Peforms a simple check of the list, and returns the number of items or an |
| 177 // error code (negative value). | 175 // error code (negative value). |
| 178 int CheckList(List list); | 176 int CheckList(List list); |
| 179 | 177 |
| 180 // Walks a list in the desired direction until the nodes |end1| or |end2| are | 178 // Walks a list in the desired direction until the nodes |end1| or |end2| are |
| 181 // reached. Returns an error code (0 on success), the number of items verified | 179 // reached. Returns an error code (0 on success), the number of items verified |
| 182 // and the addresses of the last nodes visited. | 180 // and the addresses of the last nodes visited. |
| 183 int CheckListSection(List list, Addr end1, Addr end2, bool forward, | 181 int CheckListSection(List list, |
| 184 Addr* last, Addr* second_last, int* num_items); | 182 Addr end1, |
| 183 Addr end2, |
| 184 bool forward, |
| 185 Addr* last, |
| 186 Addr* second_last, |
| 187 int* num_items); |
| 185 | 188 |
| 186 // Returns true if addr is the head or tail of any list. When there is a | 189 // Returns true if addr is the head or tail of any list. When there is a |
| 187 // match |list| will contain the list number for |addr|. | 190 // match |list| will contain the list number for |addr|. |
| 188 bool IsHead(CacheAddr addr, List* list) const; | 191 bool IsHead(CacheAddr addr, List* list) const; |
| 189 bool IsTail(CacheAddr addr, List* list) const; | 192 bool IsTail(CacheAddr addr, List* list) const; |
| 190 | 193 |
| 191 // Updates the iterators whenever node is being changed. | 194 // Updates the iterators whenever node is being changed. |
| 192 void UpdateIterators(CacheRankingsBlock* node); | 195 void UpdateIterators(CacheRankingsBlock* node); |
| 193 | 196 |
| 194 // Invalidates the iterators pointing to this node. | 197 // Invalidates the iterators pointing to this node. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 205 BackendImpl* backend_; | 208 BackendImpl* backend_; |
| 206 LruData* control_data_; // Data related to the LRU lists. | 209 LruData* control_data_; // Data related to the LRU lists. |
| 207 IteratorList iterators_; | 210 IteratorList iterators_; |
| 208 | 211 |
| 209 DISALLOW_COPY_AND_ASSIGN(Rankings); | 212 DISALLOW_COPY_AND_ASSIGN(Rankings); |
| 210 }; | 213 }; |
| 211 | 214 |
| 212 } // namespace disk_cache | 215 } // namespace disk_cache |
| 213 | 216 |
| 214 #endif // NET_DISK_CACHE_BLOCKFILE_RANKINGS_H_ | 217 #endif // NET_DISK_CACHE_BLOCKFILE_RANKINGS_H_ |
| OLD | NEW |