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 // See net/disk_cache/disk_cache.h for the public interface of the cache. | 5 // See net/disk_cache/disk_cache.h for the public interface of the cache. |
6 | 6 |
7 #ifndef NET_DISK_CACHE_BACKEND_IMPL_H__ | 7 #ifndef NET_DISK_CACHE_BACKEND_IMPL_H_ |
8 #define NET_DISK_CACHE_BACKEND_IMPL_H__ | 8 #define NET_DISK_CACHE_BACKEND_IMPL_H_ |
9 | 9 |
10 #include "base/timer.h" | 10 #include "base/timer.h" |
11 #include "net/disk_cache/block_files.h" | 11 #include "net/disk_cache/block_files.h" |
12 #include "net/disk_cache/disk_cache.h" | 12 #include "net/disk_cache/disk_cache.h" |
13 #include "net/disk_cache/eviction.h" | 13 #include "net/disk_cache/eviction.h" |
14 #include "net/disk_cache/rankings.h" | 14 #include "net/disk_cache/rankings.h" |
15 #include "net/disk_cache/stats.h" | 15 #include "net/disk_cache/stats.h" |
16 #include "net/disk_cache/trace.h" | 16 #include "net/disk_cache/trace.h" |
17 | 17 |
18 namespace disk_cache { | 18 namespace disk_cache { |
19 | 19 |
20 // This class implements the Backend interface. An object of this | 20 // This class implements the Backend interface. An object of this |
21 // class handles the operations of the cache for a particular profile. | 21 // class handles the operations of the cache for a particular profile. |
22 class BackendImpl : public Backend { | 22 class BackendImpl : public Backend { |
23 friend class Eviction; | 23 friend class Eviction; |
24 public: | 24 public: |
25 explicit BackendImpl(const std::wstring& path) | 25 explicit BackendImpl(const std::wstring& path) |
26 : path_(path), block_files_(path), mask_(0), max_size_(0), init_(false), | 26 : path_(path), block_files_(path), mask_(0), max_size_(0), init_(false), |
27 restarted_(false), unit_test_(false), read_only_(false) {} | 27 restarted_(false), unit_test_(false), read_only_(false), |
| 28 new_eviction_(false) {} |
28 // mask can be used to limit the usable size of the hash table, for testing. | 29 // mask can be used to limit the usable size of the hash table, for testing. |
29 BackendImpl(const std::wstring& path, uint32 mask) | 30 BackendImpl(const std::wstring& path, uint32 mask) |
30 : path_(path), block_files_(path), mask_(mask), max_size_(0), | 31 : path_(path), block_files_(path), mask_(mask), max_size_(0), |
31 init_(false), restarted_(false), unit_test_(false), read_only_(false) {} | 32 init_(false), restarted_(false), unit_test_(false), read_only_(false), |
| 33 new_eviction_(false) {} |
32 ~BackendImpl(); | 34 ~BackendImpl(); |
33 | 35 |
34 // Performs general initialization for this current instance of the cache. | 36 // Performs general initialization for this current instance of the cache. |
35 bool Init(); | 37 bool Init(); |
36 | 38 |
37 // Backend interface. | 39 // Backend interface. |
38 virtual int32 GetEntryCount() const; | 40 virtual int32 GetEntryCount() const; |
39 virtual bool OpenEntry(const std::string& key, Entry** entry); | 41 virtual bool OpenEntry(const std::string& key, Entry** entry); |
40 virtual bool CreateEntry(const std::string& key, Entry** entry); | 42 virtual bool CreateEntry(const std::string& key, Entry** entry); |
41 virtual bool DoomEntry(const std::string& key); | 43 virtual bool DoomEntry(const std::string& key); |
(...skipping 28 matching lines...) Expand all Loading... |
70 // Retrieves a pointer to the lru-related data. | 72 // Retrieves a pointer to the lru-related data. |
71 LruData* GetLruData(); | 73 LruData* GetLruData(); |
72 | 74 |
73 // Updates the ranking information for an entry. | 75 // Updates the ranking information for an entry. |
74 void UpdateRank(EntryImpl* entry, bool modified); | 76 void UpdateRank(EntryImpl* entry, bool modified); |
75 | 77 |
76 // A node was recovered from a crash, it may not be on the index, so this | 78 // A node was recovered from a crash, it may not be on the index, so this |
77 // method checks it and takes the appropriate action. | 79 // method checks it and takes the appropriate action. |
78 void RecoveredEntry(CacheRankingsBlock* rankings); | 80 void RecoveredEntry(CacheRankingsBlock* rankings); |
79 | 81 |
80 // Permanently deletes an entry. | 82 // Permanently deletes an entry, but still keeps track of it. |
81 void InternalDoomEntry(EntryImpl* entry); | 83 void InternalDoomEntry(EntryImpl* entry); |
82 | 84 |
| 85 // Removes all references to this entry. |
| 86 void RemoveEntry(EntryImpl* entry); |
| 87 |
83 // This method must be called whenever an entry is released for the last time. | 88 // This method must be called whenever an entry is released for the last time. |
84 void CacheEntryDestroyed(); | 89 void CacheEntryDestroyed(); |
85 | 90 |
86 // Returns the id being used on this run of the cache. | 91 // Returns the id being used on this run of the cache. |
87 int32 GetCurrentEntryId(); | 92 int32 GetCurrentEntryId(); |
88 | 93 |
89 // Returns the maximum size for a file to reside on the cache. | 94 // Returns the maximum size for a file to reside on the cache. |
90 int MaxFileSize() const; | 95 int MaxFileSize() const; |
91 | 96 |
92 // A user data block is being created, extended or truncated. | 97 // A user data block is being created, extended or truncated. |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 void RestartCache(); | 142 void RestartCache(); |
138 void PrepareForRestart(); | 143 void PrepareForRestart(); |
139 | 144 |
140 // Creates a new entry object and checks to see if it is dirty. Returns zero | 145 // Creates a new entry object and checks to see if it is dirty. Returns zero |
141 // on success, or a disk_cache error on failure. | 146 // on success, or a disk_cache error on failure. |
142 int NewEntry(Addr address, EntryImpl** entry, bool* dirty); | 147 int NewEntry(Addr address, EntryImpl** entry, bool* dirty); |
143 | 148 |
144 // Returns a given entry from the cache. The entry to match is determined by | 149 // Returns a given entry from the cache. The entry to match is determined by |
145 // key and hash, and the returned entry may be the matched one or it's parent | 150 // key and hash, and the returned entry may be the matched one or it's parent |
146 // on the list of entries with the same hash (or bucket). | 151 // on the list of entries with the same hash (or bucket). |
147 EntryImpl* MatchEntry(const std::string& key, uint32 hash, | 152 EntryImpl* MatchEntry(const std::string& key, uint32 hash, bool find_parent); |
148 bool find_parent); | |
149 | 153 |
150 // Opens the next or previous entry on a cache iteration. | 154 // Opens the next or previous entry on a cache iteration. |
151 bool OpenFollowingEntry(bool forward, void** iter, Entry** next_entry); | 155 bool OpenFollowingEntry(bool forward, void** iter, Entry** next_entry); |
152 | 156 |
| 157 // Opens the next or previous entry on a single list. If successfull, |
| 158 // |from_entry| will be updated to point to the new entry, otherwise it will |
| 159 // be set to NULL; in other words, it is used as an explicit iterator. |
| 160 bool OpenFollowingEntryFromList(bool forward, Rankings::List list, |
| 161 CacheRankingsBlock** from_entry, |
| 162 EntryImpl** next_entry); |
| 163 |
| 164 // Returns the entry that is pointed by |next|. |
| 165 EntryImpl* GetEnumeratedEntry(CacheRankingsBlock* next); |
| 166 |
| 167 // Re-opens an entry that was previously deleted. |
| 168 bool ResurrectEntry(EntryImpl* deleted_entry, Entry** entry); |
| 169 |
153 void DestroyInvalidEntry(Addr address, EntryImpl* entry); | 170 void DestroyInvalidEntry(Addr address, EntryImpl* entry); |
154 | 171 |
155 // Handles the used storage count. | 172 // Handles the used storage count. |
156 void AddStorageSize(int32 bytes); | 173 void AddStorageSize(int32 bytes); |
157 void SubstractStorageSize(int32 bytes); | 174 void SubstractStorageSize(int32 bytes); |
158 | 175 |
159 // Update the number of referenced cache entries. | 176 // Update the number of referenced cache entries. |
160 void IncreaseNumRefs(); | 177 void IncreaseNumRefs(); |
161 void DecreaseNumRefs(); | 178 void DecreaseNumRefs(); |
| 179 void IncreaseNumEntries(); |
| 180 void DecreaseNumEntries(); |
162 | 181 |
163 // Dumps current cache statistics to the log. | 182 // Dumps current cache statistics to the log. |
164 void LogStats(); | 183 void LogStats(); |
165 | 184 |
| 185 // Upgrades the index file to version 2.1. |
| 186 void UpgradeTo2_1(); |
| 187 |
166 // Performs basic checks on the index file. Returns false on failure. | 188 // Performs basic checks on the index file. Returns false on failure. |
167 bool CheckIndex(); | 189 bool CheckIndex(); |
168 | 190 |
169 // Part of the selt test. Returns the number or dirty entries, or an error. | 191 // Part of the selt test. Returns the number or dirty entries, or an error. |
170 int CheckAllEntries(); | 192 int CheckAllEntries(); |
171 | 193 |
172 // Part of the self test. Returns false if the entry is corrupt. | 194 // Part of the self test. Returns false if the entry is corrupt. |
173 bool CheckEntry(EntryImpl* cache_entry); | 195 bool CheckEntry(EntryImpl* cache_entry); |
174 | 196 |
175 scoped_refptr<MappedFile> index_; // The main cache index. | 197 scoped_refptr<MappedFile> index_; // The main cache index. |
176 std::wstring path_; // Path to the folder used as backing storage. | 198 std::wstring path_; // Path to the folder used as backing storage. |
177 Index* data_; // Pointer to the index data. | 199 Index* data_; // Pointer to the index data. |
178 BlockFiles block_files_; // Set of files used to store all data. | 200 BlockFiles block_files_; // Set of files used to store all data. |
179 Rankings rankings_; // Rankings to be able to trim the cache. | 201 Rankings rankings_; // Rankings to be able to trim the cache. |
180 uint32 mask_; // Binary mask to map a hash to the hash table. | 202 uint32 mask_; // Binary mask to map a hash to the hash table. |
181 int32 max_size_; // Maximum data size for this instance. | 203 int32 max_size_; // Maximum data size for this instance. |
182 Eviction eviction_; // Handler of the eviction algorithm. | 204 Eviction eviction_; // Handler of the eviction algorithm. |
183 int num_refs_; // Number of referenced cache entries. | 205 int num_refs_; // Number of referenced cache entries. |
184 int max_refs_; // Max number of eferenced cache entries. | 206 int max_refs_; // Max number of referenced cache entries. |
185 int num_pending_io_; // Number of pending IO operations; | 207 int num_pending_io_; // Number of pending IO operations; |
186 bool init_; // controls the initialization of the system. | 208 bool init_; // controls the initialization of the system. |
187 bool restarted_; | 209 bool restarted_; |
188 bool unit_test_; | 210 bool unit_test_; |
189 bool read_only_; // Prevents updates of the rankings data (used by tools). | 211 bool read_only_; // Prevents updates of the rankings data (used by tools). |
190 bool disabled_; | 212 bool disabled_; |
| 213 bool new_eviction_; // What eviction algorithm should be used. |
191 | 214 |
192 Stats stats_; // Usage statistcs. | 215 Stats stats_; // Usage statistcs. |
193 base::RepeatingTimer<BackendImpl> timer_; // Usage timer. | 216 base::RepeatingTimer<BackendImpl> timer_; // Usage timer. |
194 TraceObject trace_object_; // Inits and destroys internal tracing. | 217 TraceObject trace_object_; // Inits and destroys internal tracing. |
195 | 218 |
196 DISALLOW_EVIL_CONSTRUCTORS(BackendImpl); | 219 DISALLOW_EVIL_CONSTRUCTORS(BackendImpl); |
197 }; | 220 }; |
198 | 221 |
199 } // namespace disk_cache | 222 } // namespace disk_cache |
200 | 223 |
201 #endif // NET_DISK_CACHE_BACKEND_IMPL_H__ | 224 #endif // NET_DISK_CACHE_BACKEND_IMPL_H_ |
202 | 225 |
OLD | NEW |