OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef NET_DISK_CACHE_V3_EVICTION_V3_H_ |
| 6 #define NET_DISK_CACHE_V3_EVICTION_V3_H_ |
| 7 |
| 8 #include "base/basictypes.h" |
| 9 #include "base/memory/weak_ptr.h" |
| 10 #include "net/base/completion_callback.h" |
| 11 #include "net/disk_cache/v3/disk_format_v3.h" |
| 12 #include "net/disk_cache/v3/index_table.h" |
| 13 |
| 14 namespace disk_cache { |
| 15 |
| 16 class BackendImplV3; |
| 17 class EntryImplV3; |
| 18 |
| 19 // This class implements the eviction algorithm for the cache and it is tightly |
| 20 // integrated with BackendImpl. |
| 21 class EvictionV3 { |
| 22 public: |
| 23 EvictionV3(); |
| 24 ~EvictionV3(); |
| 25 |
| 26 void Init(BackendImplV3* backend); |
| 27 void Stop(); |
| 28 |
| 29 // Deletes entries from the cache until the current size is below the limit. |
| 30 // If empty is true, the whole cache will be trimmed, regardless of being in |
| 31 // use. |
| 32 void TrimCache(); |
| 33 int TrimAllCache(const net::CompletionCallback& callback); |
| 34 |
| 35 // Notifications of interesting events for a given entry. |
| 36 void OnOpenEntry(EntryImplV3* entry); |
| 37 void OnCreateEntry(EntryImplV3* entry); |
| 38 void OnResurrectEntry(EntryImplV3* entry); |
| 39 void OnEvictEntryComplete(); |
| 40 |
| 41 // Testing interface. |
| 42 void SetTestMode(); |
| 43 void TrimDeletedList(bool empty); |
| 44 |
| 45 private: |
| 46 void PostDelayedTrim(); |
| 47 void DelayedTrim(); |
| 48 bool ShouldTrim(); |
| 49 bool ShouldTrimDeleted(); |
| 50 int EvictEntry(uint32 hash, Addr address); |
| 51 |
| 52 // Returns false when done trimming the cache. |
| 53 bool TrimCacheImpl(); |
| 54 void TrimDeleted(bool empty); |
| 55 |
| 56 int GetTimestampForGoup(int group); |
| 57 |
| 58 bool EvictionV3::CellIsOldEnough(const CellList& cells, int multiplier); |
| 59 EntryGroup SelectListByLength(); |
| 60 void ReportListStats(int time1, int time2, int time3); |
| 61 |
| 62 BackendImplV3* backend_; |
| 63 IndexTable* index_; |
| 64 IndexHeaderV3* header_; |
| 65 int max_size_; |
| 66 int trim_delays_; |
| 67 int index_size_; |
| 68 bool lru_; |
| 69 bool first_trim_; |
| 70 bool trimming_; |
| 71 bool delay_trim_; |
| 72 bool init_; |
| 73 bool test_mode_; |
| 74 bool empty_; |
| 75 base::WeakPtrFactory<EvictionV3> ptr_factory_; |
| 76 CellList no_use_cells_; |
| 77 CellList low_use_cells_; |
| 78 CellList high_use_cells_; |
| 79 CellList* cells_to_evict_; |
| 80 net::CompletionCallback callback_; |
| 81 |
| 82 DISALLOW_COPY_AND_ASSIGN(EvictionV3); |
| 83 }; |
| 84 |
| 85 } // namespace disk_cache |
| 86 |
| 87 #endif // NET_DISK_CACHE_V3_EVICTION_V3_H_ |
OLD | NEW |