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 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_BLOCKFILE_BACKEND_IMPL_V3_H_ | 7 #ifndef NET_DISK_CACHE_BLOCKFILE_BACKEND_IMPL_V3_H_ |
8 #define NET_DISK_CACHE_BLOCKFILE_BACKEND_IMPL_V3_H_ | 8 #define NET_DISK_CACHE_BLOCKFILE_BACKEND_IMPL_V3_H_ |
9 | 9 |
10 #include "base/containers/hash_tables.h" | 10 #include "base/containers/hash_tables.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 | 44 |
45 BackendImplV3(const base::FilePath& path, | 45 BackendImplV3(const base::FilePath& path, |
46 base::MessageLoopProxy* cache_thread, | 46 base::MessageLoopProxy* cache_thread, |
47 net::NetLog* net_log); | 47 net::NetLog* net_log); |
48 virtual ~BackendImplV3(); | 48 virtual ~BackendImplV3(); |
49 | 49 |
50 // Performs general initialization for this current instance of the cache. | 50 // Performs general initialization for this current instance of the cache. |
51 int Init(const CompletionCallback& callback); | 51 int Init(const CompletionCallback& callback); |
52 | 52 |
53 // Same behavior as OpenNextEntry but walks the list from back to front. | 53 // Same behavior as OpenNextEntry but walks the list from back to front. |
54 int OpenPrevEntry(void** iter, Entry** prev_entry, | 54 int OpenPrevEntry(void** iter, |
| 55 Entry** prev_entry, |
55 const CompletionCallback& callback); | 56 const CompletionCallback& callback); |
56 | 57 |
57 // Sets the maximum size for the total amount of data stored by this instance. | 58 // Sets the maximum size for the total amount of data stored by this instance. |
58 bool SetMaxSize(int max_bytes); | 59 bool SetMaxSize(int max_bytes); |
59 | 60 |
60 // Sets the cache type for this backend. | 61 // Sets the cache type for this backend. |
61 void SetType(net::CacheType type); | 62 void SetType(net::CacheType type); |
62 | 63 |
63 // Creates a new storage block of size block_count. | 64 // Creates a new storage block of size block_count. |
64 bool CreateBlock(FileType block_type, int block_count, | 65 bool CreateBlock(FileType block_type, int block_count, Addr* block_address); |
65 Addr* block_address); | |
66 | 66 |
67 // Updates the ranking information for an entry. | 67 // Updates the ranking information for an entry. |
68 void UpdateRank(EntryImplV3* entry, bool modified); | 68 void UpdateRank(EntryImplV3* entry, bool modified); |
69 | 69 |
70 // Permanently deletes an entry, but still keeps track of it. | 70 // Permanently deletes an entry, but still keeps track of it. |
71 void InternalDoomEntry(EntryImplV3* entry); | 71 void InternalDoomEntry(EntryImplV3* entry); |
72 | 72 |
73 // This method must be called when an entry is released for the last time, so | 73 // This method must be called when an entry is released for the last time, so |
74 // the entry should not be used anymore. |address| is the cache address of the | 74 // the entry should not be used anymore. |address| is the cache address of the |
75 // entry. | 75 // entry. |
(...skipping 20 matching lines...) Expand all Loading... |
96 // Logs requests that are denied due to being too big. | 96 // Logs requests that are denied due to being too big. |
97 void TooMuchStorageRequested(int32 size); | 97 void TooMuchStorageRequested(int32 size); |
98 | 98 |
99 // Returns true if a temporary buffer is allowed to be extended. | 99 // Returns true if a temporary buffer is allowed to be extended. |
100 bool IsAllocAllowed(int current_size, int new_size); | 100 bool IsAllocAllowed(int current_size, int new_size); |
101 | 101 |
102 // Tracks the release of |size| bytes by an entry buffer. | 102 // Tracks the release of |size| bytes by an entry buffer. |
103 void BufferDeleted(int size); | 103 void BufferDeleted(int size); |
104 | 104 |
105 // Only intended for testing the two previous methods. | 105 // Only intended for testing the two previous methods. |
106 int GetTotalBuffersSize() const { | 106 int GetTotalBuffersSize() const { return buffer_bytes_; } |
107 return buffer_bytes_; | |
108 } | |
109 | 107 |
110 // Returns true if this instance seems to be under heavy load. | 108 // Returns true if this instance seems to be under heavy load. |
111 bool IsLoaded() const; | 109 bool IsLoaded() const; |
112 | 110 |
113 // Returns the full histogram name, for the given base |name| and the current | 111 // Returns the full histogram name, for the given base |name| and the current |
114 // cache type. The name will be "DiskCache3.name_type". | 112 // cache type. The name will be "DiskCache3.name_type". |
115 std::string HistogramName(const char* name) const; | 113 std::string HistogramName(const char* name) const; |
116 | 114 |
117 net::CacheType cache_type() const { | 115 net::CacheType cache_type() const { return cache_type_; } |
118 return cache_type_; | |
119 } | |
120 | 116 |
121 bool read_only() const { | 117 bool read_only() const { return read_only_; } |
122 return read_only_; | |
123 } | |
124 | 118 |
125 // Returns a weak pointer to this object. | 119 // Returns a weak pointer to this object. |
126 base::WeakPtr<BackendImplV3> GetWeakPtr(); | 120 base::WeakPtr<BackendImplV3> GetWeakPtr(); |
127 | 121 |
128 // Returns true if we should send histograms for this user again. The caller | 122 // Returns true if we should send histograms for this user again. The caller |
129 // must call this function only once per run (because it returns always the | 123 // must call this function only once per run (because it returns always the |
130 // same thing on a given run). | 124 // same thing on a given run). |
131 bool ShouldReportAgain(); | 125 bool ShouldReportAgain(); |
132 | 126 |
133 // Reports some data when we filled up the cache. | 127 // Reports some data when we filled up the cache. |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 // entries. This method should be called directly on the cache thread. | 160 // entries. This method should be called directly on the cache thread. |
167 void TrimDeletedListForTest(bool empty); | 161 void TrimDeletedListForTest(bool empty); |
168 | 162 |
169 // Performs a simple self-check, and returns the number of dirty items | 163 // Performs a simple self-check, and returns the number of dirty items |
170 // or an error code (negative value). | 164 // or an error code (negative value). |
171 int SelfCheck(); | 165 int SelfCheck(); |
172 | 166 |
173 // Backend implementation. | 167 // Backend implementation. |
174 virtual net::CacheType GetCacheType() const OVERRIDE; | 168 virtual net::CacheType GetCacheType() const OVERRIDE; |
175 virtual int32 GetEntryCount() const OVERRIDE; | 169 virtual int32 GetEntryCount() const OVERRIDE; |
176 virtual int OpenEntry(const std::string& key, Entry** entry, | 170 virtual int OpenEntry(const std::string& key, |
| 171 Entry** entry, |
177 const CompletionCallback& callback) OVERRIDE; | 172 const CompletionCallback& callback) OVERRIDE; |
178 virtual int CreateEntry(const std::string& key, Entry** entry, | 173 virtual int CreateEntry(const std::string& key, |
| 174 Entry** entry, |
179 const CompletionCallback& callback) OVERRIDE; | 175 const CompletionCallback& callback) OVERRIDE; |
180 virtual int DoomEntry(const std::string& key, | 176 virtual int DoomEntry(const std::string& key, |
181 const CompletionCallback& callback) OVERRIDE; | 177 const CompletionCallback& callback) OVERRIDE; |
182 virtual int DoomAllEntries(const CompletionCallback& callback) OVERRIDE; | 178 virtual int DoomAllEntries(const CompletionCallback& callback) OVERRIDE; |
183 virtual int DoomEntriesBetween(base::Time initial_time, | 179 virtual int DoomEntriesBetween(base::Time initial_time, |
184 base::Time end_time, | 180 base::Time end_time, |
185 const CompletionCallback& callback) OVERRIDE; | 181 const CompletionCallback& callback) OVERRIDE; |
186 virtual int DoomEntriesSince(base::Time initial_time, | 182 virtual int DoomEntriesSince(base::Time initial_time, |
187 const CompletionCallback& callback) OVERRIDE; | 183 const CompletionCallback& callback) OVERRIDE; |
188 virtual int OpenNextEntry(void** iter, Entry** next_entry, | 184 virtual int OpenNextEntry(void** iter, |
| 185 Entry** next_entry, |
189 const CompletionCallback& callback) OVERRIDE; | 186 const CompletionCallback& callback) OVERRIDE; |
190 virtual void EndEnumeration(void** iter) OVERRIDE; | 187 virtual void EndEnumeration(void** iter) OVERRIDE; |
191 virtual void GetStats(StatsItems* stats) OVERRIDE; | 188 virtual void GetStats(StatsItems* stats) OVERRIDE; |
192 virtual void OnExternalCacheHit(const std::string& key) OVERRIDE; | 189 virtual void OnExternalCacheHit(const std::string& key) OVERRIDE; |
193 | 190 |
194 private: | 191 private: |
195 friend class EvictionV3; | 192 friend class EvictionV3; |
196 typedef base::hash_map<CacheAddr, EntryImplV3*> EntriesMap; | 193 typedef base::hash_map<CacheAddr, EntryImplV3*> EntriesMap; |
197 class Worker; | 194 class Worker; |
198 | 195 |
199 void AdjustMaxCacheSize(); | 196 void AdjustMaxCacheSize(); |
200 bool InitStats(void* stats_data); | 197 bool InitStats(void* stats_data); |
201 void StoreStats(); | 198 void StoreStats(); |
202 | 199 |
203 // Deletes the cache and starts again. | 200 // Deletes the cache and starts again. |
204 void RestartCache(bool failure); | 201 void RestartCache(bool failure); |
205 void PrepareForRestart(); | 202 void PrepareForRestart(); |
206 | 203 |
207 // Performs final cleanup. | 204 // Performs final cleanup. |
208 void CleanupCache(); | 205 void CleanupCache(); |
209 | 206 |
210 // Creates a new entry object. Returns zero on success, or a disk_cache error | 207 // Creates a new entry object. Returns zero on success, or a disk_cache error |
211 // on failure. | 208 // on failure. |
212 int NewEntry(Addr address, EntryImplV3** entry); | 209 int NewEntry(Addr address, EntryImplV3** entry); |
213 | 210 |
214 // Opens the next or previous entry on a cache iteration. | 211 // Opens the next or previous entry on a cache iteration. |
215 int OpenFollowingEntry(bool forward, void** iter, Entry** next_entry, | 212 int OpenFollowingEntry(bool forward, |
| 213 void** iter, |
| 214 Entry** next_entry, |
216 const CompletionCallback& callback); | 215 const CompletionCallback& callback); |
217 | 216 |
218 // Handles the used storage count. | 217 // Handles the used storage count. |
219 void AddStorageSize(int32 bytes); | 218 void AddStorageSize(int32 bytes); |
220 void SubstractStorageSize(int32 bytes); | 219 void SubstractStorageSize(int32 bytes); |
221 | 220 |
222 // Update the number of referenced cache entries. | 221 // Update the number of referenced cache entries. |
223 void IncreaseNumRefs(); | 222 void IncreaseNumRefs(); |
224 void DecreaseNumRefs(); | 223 void DecreaseNumRefs(); |
225 void IncreaseNumEntries(); | 224 void IncreaseNumEntries(); |
(...skipping 16 matching lines...) Expand all Loading... |
242 | 241 |
243 // Part of the self test. Returns false if the entry is corrupt. | 242 // Part of the self test. Returns false if the entry is corrupt. |
244 bool CheckEntry(EntryImplV3* cache_entry); | 243 bool CheckEntry(EntryImplV3* cache_entry); |
245 | 244 |
246 // Returns the maximum total memory for the memory buffers. | 245 // Returns the maximum total memory for the memory buffers. |
247 int MaxBuffersSize(); | 246 int MaxBuffersSize(); |
248 | 247 |
249 IndexTable index_; | 248 IndexTable index_; |
250 base::FilePath path_; // Path to the folder used as backing storage. | 249 base::FilePath path_; // Path to the folder used as backing storage. |
251 BlockBitmaps block_files_; | 250 BlockBitmaps block_files_; |
252 int32 max_size_; // Maximum data size for this instance. | 251 int32 max_size_; // Maximum data size for this instance. |
253 EvictionV3 eviction_; // Handler of the eviction algorithm. | 252 EvictionV3 eviction_; // Handler of the eviction algorithm. |
254 EntriesMap open_entries_; | 253 EntriesMap open_entries_; |
255 int num_refs_; // Number of referenced cache entries. | 254 int num_refs_; // Number of referenced cache entries. |
256 int max_refs_; // Max number of referenced cache entries. | 255 int max_refs_; // Max number of referenced cache entries. |
257 int entry_count_; // Number of entries accessed lately. | 256 int entry_count_; // Number of entries accessed lately. |
258 int byte_count_; // Number of bytes read/written lately. | 257 int byte_count_; // Number of bytes read/written lately. |
259 int buffer_bytes_; // Total size of the temporary entries' buffers. | 258 int buffer_bytes_; // Total size of the temporary entries' buffers. |
260 int up_ticks_; // The number of timer ticks received (OnTimerTick). | 259 int up_ticks_; // The number of timer ticks received (OnTimerTick). |
261 net::CacheType cache_type_; | 260 net::CacheType cache_type_; |
262 int uma_report_; // Controls transmission of UMA data. | 261 int uma_report_; // Controls transmission of UMA data. |
263 uint32 user_flags_; // Flags set by the user. | 262 uint32 user_flags_; // Flags set by the user. |
264 bool init_; // controls the initialization of the system. | 263 bool init_; // controls the initialization of the system. |
265 bool restarted_; | 264 bool restarted_; |
266 bool read_only_; // Prevents updates of the rankings data (used by tools). | 265 bool read_only_; // Prevents updates of the rankings data (used by tools). |
267 bool disabled_; | 266 bool disabled_; |
268 bool lru_eviction_; // What eviction algorithm should be used. | 267 bool lru_eviction_; // What eviction algorithm should be used. |
269 bool first_timer_; // True if the timer has not been called. | 268 bool first_timer_; // True if the timer has not been called. |
270 bool user_load_; // True if we see a high load coming from the caller. | 269 bool user_load_; // True if we see a high load coming from the caller. |
271 | 270 |
272 net::NetLog* net_log_; | 271 net::NetLog* net_log_; |
273 | 272 |
274 Stats stats_; // Usage statistics. | 273 Stats stats_; // Usage statistics. |
275 scoped_ptr<base::RepeatingTimer<BackendImplV3> > timer_; // Usage timer. | 274 scoped_ptr<base::RepeatingTimer<BackendImplV3> > timer_; // Usage timer. |
276 scoped_refptr<TraceObject> trace_object_; // Initializes internal tracing. | 275 scoped_refptr<TraceObject> trace_object_; // Initializes internal tracing. |
277 base::WeakPtrFactory<BackendImplV3> ptr_factory_; | 276 base::WeakPtrFactory<BackendImplV3> ptr_factory_; |
278 | 277 |
279 DISALLOW_COPY_AND_ASSIGN(BackendImplV3); | 278 DISALLOW_COPY_AND_ASSIGN(BackendImplV3); |
280 }; | 279 }; |
281 | 280 |
282 } // namespace disk_cache | 281 } // namespace disk_cache |
283 | 282 |
284 #endif // NET_DISK_CACHE_BLOCKFILE_BACKEND_IMPL_V3_H_ | 283 #endif // NET_DISK_CACHE_BLOCKFILE_BACKEND_IMPL_V3_H_ |
OLD | NEW |