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 bool EvictionV3::CellIsOldEnough(const IndexIterator& iterator, |
| 57 int multiplier); |
| 58 EntryGroup SelectListByLength(); |
| 59 void ReportListStats(int time1, int time2, int time3); |
| 60 |
| 61 BackendImplV3* backend_; |
| 62 IndexTable* index_; |
| 63 IndexHeaderV3* header_; |
| 64 int max_size_; |
| 65 int trim_delays_; |
| 66 int index_size_; |
| 67 bool lru_; |
| 68 bool first_trim_; |
| 69 bool trimming_; |
| 70 bool delay_trim_; |
| 71 bool init_; |
| 72 bool test_mode_; |
| 73 bool empty_; |
| 74 base::WeakPtrFactory<EvictionV3> ptr_factory_; |
| 75 IndexIterator no_use_cells_; |
| 76 IndexIterator low_use_cells_; |
| 77 IndexIterator high_use_cells_; |
| 78 IndexIterator* cells_to_evict_; |
| 79 net::CompletionCallback callback_; |
| 80 |
| 81 DISALLOW_COPY_AND_ASSIGN(EvictionV3); |
| 82 }; |
| 83 |
| 84 } // namespace disk_cache |
| 85 |
| 86 #endif // NET_DISK_CACHE_V3_EVICTION_V3_H_ |
OLD | NEW |