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_EVICTION_H_
6 #define NET_DISK_CACHE_EVICTION_H_
8 #include "base/basictypes.h"
9 #include "base/memory/weak_ptr.h"
10 #include "net/disk_cache/disk_format.h"
11 #include "net/disk_cache/rankings.h"
13 namespace disk_cache
{
18 // This class implements the eviction algorithm for the cache and it is tightly
19 // integrated with BackendImpl.
25 void Init(BackendImpl
* backend
);
28 // 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
31 void TrimCache(bool empty
);
33 // Notifications of interesting events for a given entry.
34 void OnOpenEntry(EntryImpl
* entry
);
35 void OnCreateEntry(EntryImpl
* entry
);
39 void TrimDeletedList(bool empty
);
42 void PostDelayedTrim();
45 bool ShouldTrimDeleted();
46 bool EvictEntry(CacheRankingsBlock
* node
, bool empty
, Rankings::List list
);
48 void TrimCacheV2(bool empty
);
49 void TrimDeleted(bool empty
);
51 bool NodeIsOldEnough(CacheRankingsBlock
* node
, int list
);
52 int SelectListByLength(Rankings::ScopedRankingsBlock
* next
);
53 void ReportListStats();
55 BackendImpl
* backend_
;
67 base::WeakPtrFactory
<Eviction
> ptr_factory_
;
69 DISALLOW_COPY_AND_ASSIGN(Eviction
);
72 } // namespace disk_cache
74 #endif // NET_DISK_CACHE_EVICTION_H_