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/hash_tables.h" |
10 #include "base/timer.h" | 11 #include "base/timer.h" |
11 #include "net/disk_cache/block_files.h" | 12 #include "net/disk_cache/block_files.h" |
12 #include "net/disk_cache/disk_cache.h" | 13 #include "net/disk_cache/disk_cache.h" |
13 #include "net/disk_cache/eviction.h" | 14 #include "net/disk_cache/eviction.h" |
14 #include "net/disk_cache/rankings.h" | 15 #include "net/disk_cache/rankings.h" |
15 #include "net/disk_cache/stats.h" | 16 #include "net/disk_cache/stats.h" |
16 #include "net/disk_cache/trace.h" | 17 #include "net/disk_cache/trace.h" |
17 | 18 |
18 namespace disk_cache { | 19 namespace disk_cache { |
19 | 20 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 // method checks it and takes the appropriate action. | 93 // method checks it and takes the appropriate action. |
93 void RecoveredEntry(CacheRankingsBlock* rankings); | 94 void RecoveredEntry(CacheRankingsBlock* rankings); |
94 | 95 |
95 // Permanently deletes an entry, but still keeps track of it. | 96 // Permanently deletes an entry, but still keeps track of it. |
96 void InternalDoomEntry(EntryImpl* entry); | 97 void InternalDoomEntry(EntryImpl* entry); |
97 | 98 |
98 // Removes all references to this entry. | 99 // Removes all references to this entry. |
99 void RemoveEntry(EntryImpl* entry); | 100 void RemoveEntry(EntryImpl* entry); |
100 | 101 |
101 // This method must be called whenever an entry is released for the last time. | 102 // This method must be called whenever an entry is released for the last time. |
102 void CacheEntryDestroyed(); | 103 // |address| is the cache address of the entry. |
| 104 void CacheEntryDestroyed(Addr address); |
| 105 |
| 106 // Returns true if the data stored by the provided |rankings| points to an |
| 107 // open entry, false otherwise. |
| 108 bool IsOpen(CacheRankingsBlock* rankings) const; |
103 | 109 |
104 // Returns the id being used on this run of the cache. | 110 // Returns the id being used on this run of the cache. |
105 int32 GetCurrentEntryId(); | 111 int32 GetCurrentEntryId() const; |
106 | 112 |
107 // Returns the maximum size for a file to reside on the cache. | 113 // Returns the maximum size for a file to reside on the cache. |
108 int MaxFileSize() const; | 114 int MaxFileSize() const; |
109 | 115 |
110 // A user data block is being created, extended or truncated. | 116 // A user data block is being created, extended or truncated. |
111 void ModifyStorageSize(int32 old_size, int32 new_size); | 117 void ModifyStorageSize(int32 old_size, int32 new_size); |
112 | 118 |
113 // Logs requests that are denied due to being too big. | 119 // Logs requests that are denied due to being too big. |
114 void TooMuchStorageRequested(int32 size); | 120 void TooMuchStorageRequested(int32 size); |
115 | 121 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 void ClearRefCountForTest(); | 168 void ClearRefCountForTest(); |
163 | 169 |
164 // Peforms a simple self-check, and returns the number of dirty items | 170 // Peforms a simple self-check, and returns the number of dirty items |
165 // or an error code (negative value). | 171 // or an error code (negative value). |
166 int SelfCheck(); | 172 int SelfCheck(); |
167 | 173 |
168 // Same bahavior as OpenNextEntry but walks the list from back to front. | 174 // Same bahavior as OpenNextEntry but walks the list from back to front. |
169 bool OpenPrevEntry(void** iter, Entry** prev_entry); | 175 bool OpenPrevEntry(void** iter, Entry** prev_entry); |
170 | 176 |
171 private: | 177 private: |
| 178 typedef base::hash_map<CacheAddr, EntryImpl*> EntriesMap; |
| 179 |
172 // Creates a new backing file for the cache index. | 180 // Creates a new backing file for the cache index. |
173 bool CreateBackingStore(disk_cache::File* file); | 181 bool CreateBackingStore(disk_cache::File* file); |
174 bool InitBackingStore(bool* file_created); | 182 bool InitBackingStore(bool* file_created); |
175 void AdjustMaxCacheSize(int table_len); | 183 void AdjustMaxCacheSize(int table_len); |
176 | 184 |
177 // Deletes the cache and starts again. | 185 // Deletes the cache and starts again. |
178 void RestartCache(); | 186 void RestartCache(); |
179 void PrepareForRestart(); | 187 void PrepareForRestart(); |
180 | 188 |
181 // Creates a new entry object and checks to see if it is dirty. Returns zero | 189 // Creates a new entry object and checks to see if it is dirty. Returns zero |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 bool CheckEntry(EntryImpl* cache_entry); | 242 bool CheckEntry(EntryImpl* cache_entry); |
235 | 243 |
236 scoped_refptr<MappedFile> index_; // The main cache index. | 244 scoped_refptr<MappedFile> index_; // The main cache index. |
237 std::wstring path_; // Path to the folder used as backing storage. | 245 std::wstring path_; // Path to the folder used as backing storage. |
238 Index* data_; // Pointer to the index data. | 246 Index* data_; // Pointer to the index data. |
239 BlockFiles block_files_; // Set of files used to store all data. | 247 BlockFiles block_files_; // Set of files used to store all data. |
240 Rankings rankings_; // Rankings to be able to trim the cache. | 248 Rankings rankings_; // Rankings to be able to trim the cache. |
241 uint32 mask_; // Binary mask to map a hash to the hash table. | 249 uint32 mask_; // Binary mask to map a hash to the hash table. |
242 int32 max_size_; // Maximum data size for this instance. | 250 int32 max_size_; // Maximum data size for this instance. |
243 Eviction eviction_; // Handler of the eviction algorithm. | 251 Eviction eviction_; // Handler of the eviction algorithm. |
| 252 EntriesMap open_entries_; // Map of open entries. |
244 int num_refs_; // Number of referenced cache entries. | 253 int num_refs_; // Number of referenced cache entries. |
245 int max_refs_; // Max number of referenced cache entries. | 254 int max_refs_; // Max number of referenced cache entries. |
246 int num_pending_io_; // Number of pending IO operations. | 255 int num_pending_io_; // Number of pending IO operations. |
247 net::CacheType cache_type_; | 256 net::CacheType cache_type_; |
248 int uma_report_; // Controls transmision of UMA data. | 257 int uma_report_; // Controls transmision of UMA data. |
249 uint32 user_flags_; // Flags set by the user. | 258 uint32 user_flags_; // Flags set by the user. |
250 bool init_; // controls the initialization of the system. | 259 bool init_; // controls the initialization of the system. |
251 bool restarted_; | 260 bool restarted_; |
252 bool unit_test_; | 261 bool unit_test_; |
253 bool read_only_; // Prevents updates of the rankings data (used by tools). | 262 bool read_only_; // Prevents updates of the rankings data (used by tools). |
254 bool disabled_; | 263 bool disabled_; |
255 bool new_eviction_; // What eviction algorithm should be used. | 264 bool new_eviction_; // What eviction algorithm should be used. |
256 bool first_timer_; // True if the timer has not been called. | 265 bool first_timer_; // True if the timer has not been called. |
257 | 266 |
258 Stats stats_; // Usage statistcs. | 267 Stats stats_; // Usage statistcs. |
259 base::RepeatingTimer<BackendImpl> timer_; // Usage timer. | 268 base::RepeatingTimer<BackendImpl> timer_; // Usage timer. |
260 scoped_refptr<TraceObject> trace_object_; // Inits internal tracing. | 269 scoped_refptr<TraceObject> trace_object_; // Inits internal tracing. |
261 | 270 |
262 DISALLOW_EVIL_CONSTRUCTORS(BackendImpl); | 271 DISALLOW_EVIL_CONSTRUCTORS(BackendImpl); |
263 }; | 272 }; |
264 | 273 |
265 // Returns the prefered max cache size given the available disk space. | 274 // Returns the prefered max cache size given the available disk space. |
266 int PreferedCacheSize(int64 available); | 275 int PreferedCacheSize(int64 available); |
267 | 276 |
268 } // namespace disk_cache | 277 } // namespace disk_cache |
269 | 278 |
270 #endif // NET_DISK_CACHE_BACKEND_IMPL_H_ | 279 #endif // NET_DISK_CACHE_BACKEND_IMPL_H_ |
OLD | NEW |