| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 ~Rankings(); | 105 ~Rankings(); |
| 106 | 106 |
| 107 bool Init(BackendImpl* backend, bool count_lists); | 107 bool Init(BackendImpl* backend, bool count_lists); |
| 108 | 108 |
| 109 // Restores original state, leaving the object ready for initialization. | 109 // Restores original state, leaving the object ready for initialization. |
| 110 void Reset(); | 110 void Reset(); |
| 111 | 111 |
| 112 // Inserts a given entry at the head of the queue. | 112 // Inserts a given entry at the head of the queue. |
| 113 void Insert(CacheRankingsBlock* node, bool modified, List list); | 113 void Insert(CacheRankingsBlock* node, bool modified, List list); |
| 114 | 114 |
| 115 // Removes a given entry from the LRU list. | 115 // Removes a given entry from the LRU list. If |strict| is true, this method |
| 116 void Remove(CacheRankingsBlock* node, List list); | 116 // assumes that |node| is not pointed to by an active iterator. On the other |
| 117 // hand, removing that restriction allows the current "head" of an iterator |
| 118 // to be removed from the list (basically without control of the code that is |
| 119 // performing the iteration), so it should be used with extra care. |
| 120 void Remove(CacheRankingsBlock* node, List list, bool strict); |
| 117 | 121 |
| 118 // Moves a given entry to the head. | 122 // Moves a given entry to the head. |
| 119 void UpdateRank(CacheRankingsBlock* node, bool modified, List list); | 123 void UpdateRank(CacheRankingsBlock* node, bool modified, List list); |
| 120 | 124 |
| 121 // Iterates through the list. | 125 // Iterates through the list. |
| 122 CacheRankingsBlock* GetNext(CacheRankingsBlock* node, List list); | 126 CacheRankingsBlock* GetNext(CacheRankingsBlock* node, List list); |
| 123 CacheRankingsBlock* GetPrev(CacheRankingsBlock* node, List list); | 127 CacheRankingsBlock* GetPrev(CacheRankingsBlock* node, List list); |
| 124 void FreeRankingsBlock(CacheRankingsBlock* node); | 128 void FreeRankingsBlock(CacheRankingsBlock* node); |
| 125 | 129 |
| 126 // Controls tracking of nodes used for enumerations. | 130 // Controls tracking of nodes used for enumerations. |
| 127 void TrackRankingsBlock(CacheRankingsBlock* node, bool start_tracking); | 131 void TrackRankingsBlock(CacheRankingsBlock* node, bool start_tracking); |
| 128 | 132 |
| 129 // Peforms a simple self-check of the lists, and returns the number of items | 133 // Peforms a simple self-check of the lists, and returns the number of items |
| 130 // or an error code (negative value). | 134 // or an error code (negative value). |
| 131 int SelfCheck(); | 135 int SelfCheck(); |
| 132 | 136 |
| 133 // Returns false if the entry is clearly invalid. from_list is true if the | 137 // Returns false if the entry is clearly invalid. from_list is true if the |
| 134 // node comes from the LRU list. | 138 // node comes from the LRU list. |
| 135 bool SanityCheck(CacheRankingsBlock* node, bool from_list); | 139 bool SanityCheck(CacheRankingsBlock* node, bool from_list) const; |
| 140 bool DataSanityCheck(CacheRankingsBlock* node, bool from_list) const; |
| 141 |
| 142 // Sets the |contents| field of |node| to |address|. |
| 143 void SetContents(CacheRankingsBlock* node, CacheAddr address); |
| 136 | 144 |
| 137 private: | 145 private: |
| 138 typedef std::pair<CacheAddr, CacheRankingsBlock*> IteratorPair; | 146 typedef std::pair<CacheAddr, CacheRankingsBlock*> IteratorPair; |
| 139 typedef std::list<IteratorPair> IteratorList; | 147 typedef std::list<IteratorPair> IteratorList; |
| 140 | 148 |
| 141 void ReadHeads(); | 149 void ReadHeads(); |
| 142 void ReadTails(); | 150 void ReadTails(); |
| 143 void WriteHead(List list); | 151 void WriteHead(List list); |
| 144 void WriteTail(List list); | 152 void WriteTail(List list); |
| 145 | 153 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 167 | 175 |
| 168 // Checks the links between two consecutive nodes. | 176 // Checks the links between two consecutive nodes. |
| 169 bool CheckSingleLink(CacheRankingsBlock* prev, CacheRankingsBlock* next); | 177 bool CheckSingleLink(CacheRankingsBlock* prev, CacheRankingsBlock* next); |
| 170 | 178 |
| 171 // Peforms a simple check of the list, and returns the number of items or an | 179 // Peforms a simple check of the list, and returns the number of items or an |
| 172 // error code (negative value). | 180 // error code (negative value). |
| 173 int CheckList(List list); | 181 int CheckList(List list); |
| 174 | 182 |
| 175 // Returns true if addr is the head or tail of any list. When there is a | 183 // Returns true if addr is the head or tail of any list. When there is a |
| 176 // match |list| will contain the list number for |addr|. | 184 // match |list| will contain the list number for |addr|. |
| 177 bool IsHead(CacheAddr addr, List* list); | 185 bool IsHead(CacheAddr addr, List* list) const; |
| 178 bool IsTail(CacheAddr addr, List* list); | 186 bool IsTail(CacheAddr addr, List* list) const; |
| 179 | 187 |
| 180 // Updates the iterators whenever node is being changed. | 188 // Updates the iterators whenever node is being changed. |
| 181 void UpdateIterators(CacheRankingsBlock* node); | 189 void UpdateIterators(CacheRankingsBlock* node); |
| 182 | 190 |
| 183 // Invalidates the iterators pointing to this node. | 191 // Invalidates the iterators pointing to this node. |
| 184 void InvalidateIterators(CacheRankingsBlock* node); | 192 void InvalidateIterators(CacheRankingsBlock* node); |
| 185 | 193 |
| 186 // Keeps track of the number of entries on a list. | 194 // Keeps track of the number of entries on a list. |
| 187 void IncrementCounter(List list); | 195 void IncrementCounter(List list); |
| 188 void DecrementCounter(List list); | 196 void DecrementCounter(List list); |
| 189 | 197 |
| 190 bool init_; | 198 bool init_; |
| 191 bool count_lists_; | 199 bool count_lists_; |
| 192 Addr heads_[LAST_ELEMENT]; | 200 Addr heads_[LAST_ELEMENT]; |
| 193 Addr tails_[LAST_ELEMENT]; | 201 Addr tails_[LAST_ELEMENT]; |
| 194 BackendImpl* backend_; | 202 BackendImpl* backend_; |
| 195 LruData* control_data_; // Data related to the LRU lists. | 203 LruData* control_data_; // Data related to the LRU lists. |
| 196 IteratorList iterators_; | 204 IteratorList iterators_; |
| 197 | 205 |
| 198 DISALLOW_COPY_AND_ASSIGN(Rankings); | 206 DISALLOW_COPY_AND_ASSIGN(Rankings); |
| 199 }; | 207 }; |
| 200 | 208 |
| 201 } // namespace disk_cache | 209 } // namespace disk_cache |
| 202 | 210 |
| 203 #endif // NET_DISK_CACHE_RANKINGS_H_ | 211 #endif // NET_DISK_CACHE_RANKINGS_H_ |
| OLD | NEW |