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