diff options
Diffstat (limited to 'net/disk_cache/memory/mem_backend_impl.h')
-rw-r--r-- | net/disk_cache/memory/mem_backend_impl.h | 66 |
1 files changed, 36 insertions, 30 deletions
diff --git a/net/disk_cache/memory/mem_backend_impl.h b/net/disk_cache/memory/mem_backend_impl.h index 8abcca5..e2a9f1a 100644 --- a/net/disk_cache/memory/mem_backend_impl.h +++ b/net/disk_cache/memory/mem_backend_impl.h @@ -9,17 +9,13 @@ #include <stdint.h> -#include <string> - #include "base/compiler_specific.h" #include "base/containers/hash_tables.h" -#include "base/containers/linked_list.h" #include "base/macros.h" #include "base/memory/weak_ptr.h" #include "base/strings/string_split.h" -#include "base/time/time.h" #include "net/disk_cache/disk_cache.h" -#include "net/disk_cache/memory/mem_entry_impl.h" +#include "net/disk_cache/memory/mem_rankings.h" namespace net { class NetLog; @@ -27,9 +23,11 @@ class NetLog; namespace disk_cache { +class MemEntryImpl; + // This class implements the Backend interface. An object of this class handles // the operations of the cache without writing to disk. -class NET_EXPORT_PRIVATE MemBackendImpl final : public Backend { +class NET_EXPORT_PRIVATE MemBackendImpl : public Backend { public: explicit MemBackendImpl(net::NetLog* net_log); ~MemBackendImpl() override; @@ -47,29 +45,26 @@ class NET_EXPORT_PRIVATE MemBackendImpl final : public Backend { // Sets the maximum size for the total amount of data stored by this instance. bool SetMaxSize(int max_bytes); - // Returns the maximum size for a file to reside on the cache. - int MaxFileSize() const; + // Permanently deletes an entry. + void InternalDoomEntry(MemEntryImpl* entry); - // These next methods (before the implementation of the Backend interface) are - // called by MemEntryImpl to update the state of the backend during the entry - // lifecycle. + // Updates the ranking information for an entry. + void UpdateRank(MemEntryImpl* node); - // Signals that new entry has been created, and should be placed in - // |lru_list_| so that it is eligable for eviction. - void OnEntryInserted(MemEntryImpl* entry); + // A user data block is being created, extended or truncated. + void ModifyStorageSize(int32_t old_size, int32_t new_size); - // Signals that an entry has been updated, and thus should be moved to the end - // of |lru_list_|. - void OnEntryUpdated(MemEntryImpl* entry); + // Returns the maximum size for a file to reside on the cache. + int MaxFileSize() const; - // Signals that an entry has been doomed, and so it should be removed from the - // list of active entries as appropriate, as well as removed from the - // |lru_list_|. - void OnEntryDoomed(MemEntryImpl* entry); + // Insert an MemEntryImpl into the ranking list. This method is only called + // from MemEntryImpl to insert child entries. The reference can be removed + // by calling RemoveFromRankingList(|entry|). + void InsertIntoRankingList(MemEntryImpl* entry); - // Adjust the current size of this backend by |delta|. This is used to - // determine if eviction is neccessary and when eviction is finished. - void ModifyStorageSize(int32_t delta); + // Remove |entry| from ranking list. This method is only called from + // MemEntryImpl to remove a child entry from the ranking list. + void RemoveFromRankingList(MemEntryImpl* entry); // Backend interface. net::CacheType GetCacheType() const override; @@ -99,15 +94,26 @@ class NET_EXPORT_PRIVATE MemBackendImpl final : public Backend { typedef base::hash_map<std::string, MemEntryImpl*> EntryMap; - // Deletes entries from the cache until the current size is below the limit. - void EvictIfNeeded(); + // Old Backend interface. + bool OpenEntry(const std::string& key, Entry** entry); + bool CreateEntry(const std::string& key, Entry** entry); + bool DoomEntry(const std::string& key); + bool DoomAllEntries(); + bool DoomEntriesBetween(const base::Time initial_time, + const base::Time end_time); + bool DoomEntriesSince(const base::Time initial_time); - EntryMap entries_; + // Deletes entries from the cache until the current size is below the limit. + // If empty is true, the whole cache will be trimmed, regardless of being in + // use. + void TrimCache(bool empty); - // Stored in increasing order of last use time, from least recently used to - // most recently used. - base::LinkedList<MemEntryImpl> lru_list_; + // Handles the used storage count. + void AddStorageSize(int32_t bytes); + void SubstractStorageSize(int32_t bytes); + EntryMap entries_; + MemRankings rankings_; // Rankings to be able to trim the cache. int32_t max_size_; // Maximum data size for this instance. int32_t current_size_; |