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/compiler_specific.h" | |
11 #include "base/timer.h" | 10 #include "base/timer.h" |
12 #include "net/disk_cache/block_files.h" | 11 #include "net/disk_cache/block_files.h" |
13 #include "net/disk_cache/disk_cache.h" | 12 #include "net/disk_cache/disk_cache.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 public: | 24 public: |
24 explicit BackendImpl(const std::wstring& path) | 25 explicit BackendImpl(const std::wstring& path) |
25 : path_(path), block_files_(path), mask_(0), max_size_(0), | 26 : path_(path), block_files_(path), mask_(0), max_size_(0), init_(false), |
26 init_(false), restarted_(false), unit_test_(false), read_only_(false), | 27 restarted_(false), unit_test_(false), read_only_(false) {} |
27 ALLOW_THIS_IN_INITIALIZER_LIST(factory_(this)) {} | |
28 // mask can be used to limit the usable size of the hash table, for testing. | 28 // mask can be used to limit the usable size of the hash table, for testing. |
29 BackendImpl(const std::wstring& path, uint32 mask) | 29 BackendImpl(const std::wstring& path, uint32 mask) |
30 : path_(path), block_files_(path), mask_(mask), max_size_(0), | 30 : path_(path), block_files_(path), mask_(mask), max_size_(0), |
31 init_(false), restarted_(false), unit_test_(false), read_only_(false), | 31 init_(false), restarted_(false), unit_test_(false), read_only_(false) {} |
32 ALLOW_THIS_IN_INITIALIZER_LIST(factory_(this)) {} | |
33 ~BackendImpl(); | 32 ~BackendImpl(); |
34 | 33 |
35 // Performs general initialization for this current instance of the cache. | 34 // Performs general initialization for this current instance of the cache. |
36 bool Init(); | 35 bool Init(); |
37 | 36 |
38 // Backend interface. | 37 // Backend interface. |
39 virtual int32 GetEntryCount() const; | 38 virtual int32 GetEntryCount() const; |
40 virtual bool OpenEntry(const std::string& key, Entry** entry); | 39 virtual bool OpenEntry(const std::string& key, Entry** entry); |
41 virtual bool CreateEntry(const std::string& key, Entry** entry); | 40 virtual bool CreateEntry(const std::string& key, Entry** entry); |
42 virtual bool DoomEntry(const std::string& key); | 41 virtual bool DoomEntry(const std::string& key); |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 // key and hash, and the returned entry may be the matched one or it's parent | 145 // key and hash, and the returned entry may be the matched one or it's parent |
147 // on the list of entries with the same hash (or bucket). | 146 // on the list of entries with the same hash (or bucket). |
148 EntryImpl* MatchEntry(const std::string& key, uint32 hash, | 147 EntryImpl* MatchEntry(const std::string& key, uint32 hash, |
149 bool find_parent); | 148 bool find_parent); |
150 | 149 |
151 // Opens the next or previous entry on a cache iteration. | 150 // Opens the next or previous entry on a cache iteration. |
152 bool OpenFollowingEntry(bool forward, void** iter, Entry** next_entry); | 151 bool OpenFollowingEntry(bool forward, void** iter, Entry** next_entry); |
153 | 152 |
154 void DestroyInvalidEntry(Addr address, EntryImpl* entry); | 153 void DestroyInvalidEntry(Addr address, EntryImpl* entry); |
155 | 154 |
156 // Deletes entries from the cache until the current size is below the limit. | |
157 // If empty is true, the whole cache will be trimmed, regardless of being in | |
158 // use. | |
159 void TrimCache(bool empty); | |
160 void ReportTrimTimes(EntryImpl* entry); | |
161 | |
162 // Handles the used storage count. | 155 // Handles the used storage count. |
163 void AddStorageSize(int32 bytes); | 156 void AddStorageSize(int32 bytes); |
164 void SubstractStorageSize(int32 bytes); | 157 void SubstractStorageSize(int32 bytes); |
165 | 158 |
166 // Update the number of referenced cache entries. | 159 // Update the number of referenced cache entries. |
167 void IncreaseNumRefs(); | 160 void IncreaseNumRefs(); |
168 void DecreaseNumRefs(); | 161 void DecreaseNumRefs(); |
169 | 162 |
170 // Dumps current cache statistics to the log. | 163 // Dumps current cache statistics to the log. |
171 void LogStats(); | 164 void LogStats(); |
172 | 165 |
173 // Performs basic checks on the index file. Returns false on failure. | 166 // Performs basic checks on the index file. Returns false on failure. |
174 bool CheckIndex(); | 167 bool CheckIndex(); |
175 | 168 |
176 // Part of the selt test. Returns the number or dirty entries, or an error. | 169 // Part of the selt test. Returns the number or dirty entries, or an error. |
177 int CheckAllEntries(); | 170 int CheckAllEntries(); |
178 | 171 |
179 // Part of the self test. Returns false if the entry is corrupt. | 172 // Part of the self test. Returns false if the entry is corrupt. |
180 bool CheckEntry(EntryImpl* cache_entry); | 173 bool CheckEntry(EntryImpl* cache_entry); |
181 | 174 |
182 scoped_refptr<MappedFile> index_; // The main cache index. | 175 scoped_refptr<MappedFile> index_; // The main cache index. |
183 std::wstring path_; // Path to the folder used as backing storage. | 176 std::wstring path_; // Path to the folder used as backing storage. |
184 Index* data_; // Pointer to the index data. | 177 Index* data_; // Pointer to the index data. |
185 BlockFiles block_files_; // Set of files used to store all data. | 178 BlockFiles block_files_; // Set of files used to store all data. |
186 Rankings rankings_; // Rankings to be able to trim the cache. | 179 Rankings rankings_; // Rankings to be able to trim the cache. |
187 uint32 mask_; // Binary mask to map a hash to the hash table. | 180 uint32 mask_; // Binary mask to map a hash to the hash table. |
188 int32 max_size_; // Maximum data size for this instance. | 181 int32 max_size_; // Maximum data size for this instance. |
| 182 Eviction eviction_; // Handler of the eviction algorithm. |
189 int num_refs_; // Number of referenced cache entries. | 183 int num_refs_; // Number of referenced cache entries. |
190 int max_refs_; // Max number of eferenced cache entries. | 184 int max_refs_; // Max number of eferenced cache entries. |
191 int num_pending_io_; // Number of pending IO operations; | 185 int num_pending_io_; // Number of pending IO operations; |
192 bool init_; // controls the initialization of the system. | 186 bool init_; // controls the initialization of the system. |
193 bool restarted_; | 187 bool restarted_; |
194 bool unit_test_; | 188 bool unit_test_; |
195 bool read_only_; // Prevents updates of the rankings data (used by tools). | 189 bool read_only_; // Prevents updates of the rankings data (used by tools). |
196 bool disabled_; | 190 bool disabled_; |
197 | 191 |
198 Stats stats_; // Usage statistcs. | 192 Stats stats_; // Usage statistcs. |
199 base::RepeatingTimer<BackendImpl> timer_; // Usage timer. | 193 base::RepeatingTimer<BackendImpl> timer_; // Usage timer. |
200 TraceObject trace_object_; // Inits and destroys internal tracing. | 194 TraceObject trace_object_; // Inits and destroys internal tracing. |
201 ScopedRunnableMethodFactory<BackendImpl> factory_; | |
202 | 195 |
203 DISALLOW_EVIL_CONSTRUCTORS(BackendImpl); | 196 DISALLOW_EVIL_CONSTRUCTORS(BackendImpl); |
204 }; | 197 }; |
205 | 198 |
206 } // namespace disk_cache | 199 } // namespace disk_cache |
207 | 200 |
208 #endif // NET_DISK_CACHE_BACKEND_IMPL_H__ | 201 #endif // NET_DISK_CACHE_BACKEND_IMPL_H__ |
209 | 202 |
OLD | NEW |