Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / net / disk_cache / blockfile / eviction_v3.h
blob01fe61361157954a7d92b8a75ee4979427cb53a9
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.
5 #ifndef NET_DISK_CACHE_BLOCKFILE_EVICTION_V3_H_
6 #define NET_DISK_CACHE_BLOCKFILE_EVICTION_V3_H_
8 #include "base/basictypes.h"
9 #include "base/memory/weak_ptr.h"
10 #include "net/disk_cache/blockfile/disk_format_v3.h"
11 #include "net/disk_cache/blockfile/index_table_v3.h"
13 namespace disk_cache {
15 class BackendImplV3;
16 class CacheRankingsBlock;
17 class EntryImplV3;
19 namespace Rankings {
20 typedef int List;
23 // This class implements the eviction algorithm for the cache and it is tightly
24 // integrated with BackendImpl.
25 class EvictionV3 {
26 public:
27 EvictionV3();
28 ~EvictionV3();
30 void Init(BackendImplV3* backend);
31 void Stop();
33 // Deletes entries from the cache until the current size is below the limit.
34 // If empty is true, the whole cache will be trimmed, regardless of being in
35 // use.
36 void TrimCache(bool empty);
38 // Notifications of interesting events for a given entry.
39 void OnOpenEntry(EntryImplV3* entry);
40 void OnCreateEntry(EntryImplV3* entry);
42 // Testing interface.
43 void SetTestMode();
44 void TrimDeletedList(bool empty);
46 private:
47 void PostDelayedTrim();
48 void DelayedTrim();
49 bool ShouldTrim();
50 bool ShouldTrimDeleted();
51 bool EvictEntry(CacheRankingsBlock* node, bool empty, Rankings::List list);
53 void TrimCacheV2(bool empty);
54 void TrimDeleted(bool empty);
56 bool NodeIsOldEnough(CacheRankingsBlock* node, int list);
57 int SelectListByLength();
58 void ReportListStats();
60 BackendImplV3* backend_;
61 IndexTable* index_;
62 IndexHeaderV3* header_;
63 int max_size_;
64 int trim_delays_;
65 bool lru_;
66 bool first_trim_;
67 bool trimming_;
68 bool delay_trim_;
69 bool init_;
70 bool test_mode_;
71 base::WeakPtrFactory<EvictionV3> ptr_factory_;
73 DISALLOW_COPY_AND_ASSIGN(EvictionV3);
76 } // namespace disk_cache
78 #endif // NET_DISK_CACHE_BLOCKFILE_EVICTION_V3_H_