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 // See net/disk_cache/disk_cache.h for the public interface of the cache. | 5 // See net/disk_cache/disk_cache.h for the public interface of the cache. |
6 | 6 |
7 #ifndef NET_DISK_CACHE_MEMORY_MEM_BACKEND_IMPL_H_ | 7 #ifndef NET_DISK_CACHE_MEMORY_MEM_BACKEND_IMPL_H_ |
8 #define NET_DISK_CACHE_MEMORY_MEM_BACKEND_IMPL_H_ | 8 #define NET_DISK_CACHE_MEMORY_MEM_BACKEND_IMPL_H_ |
9 | 9 |
10 #include <stdint.h> | 10 #include <stdint.h> |
11 | 11 |
12 #include <string> | 12 #include <string> |
| 13 #include <unordered_map> |
13 | 14 |
14 #include "base/compiler_specific.h" | 15 #include "base/compiler_specific.h" |
15 #include "base/containers/hash_tables.h" | |
16 #include "base/containers/linked_list.h" | 16 #include "base/containers/linked_list.h" |
17 #include "base/macros.h" | 17 #include "base/macros.h" |
18 #include "base/memory/weak_ptr.h" | 18 #include "base/memory/weak_ptr.h" |
19 #include "base/strings/string_split.h" | 19 #include "base/strings/string_split.h" |
20 #include "base/time/time.h" | 20 #include "base/time/time.h" |
21 #include "net/disk_cache/disk_cache.h" | 21 #include "net/disk_cache/disk_cache.h" |
22 #include "net/disk_cache/memory/mem_entry_impl.h" | 22 #include "net/disk_cache/memory/mem_entry_impl.h" |
23 | 23 |
24 namespace net { | 24 namespace net { |
25 class NetLog; | 25 class NetLog; |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 const CompletionCallback& callback) override; | 91 const CompletionCallback& callback) override; |
92 int CalculateSizeOfAllEntries(const CompletionCallback& callback) override; | 92 int CalculateSizeOfAllEntries(const CompletionCallback& callback) override; |
93 std::unique_ptr<Iterator> CreateIterator() override; | 93 std::unique_ptr<Iterator> CreateIterator() override; |
94 void GetStats(base::StringPairs* stats) override {} | 94 void GetStats(base::StringPairs* stats) override {} |
95 void OnExternalCacheHit(const std::string& key) override; | 95 void OnExternalCacheHit(const std::string& key) override; |
96 | 96 |
97 private: | 97 private: |
98 class MemIterator; | 98 class MemIterator; |
99 friend class MemIterator; | 99 friend class MemIterator; |
100 | 100 |
101 typedef base::hash_map<std::string, MemEntryImpl*> EntryMap; | 101 using EntryMap = std::unordered_map<std::string, MemEntryImpl*>; |
102 | 102 |
103 // Deletes entries from the cache until the current size is below the limit. | 103 // Deletes entries from the cache until the current size is below the limit. |
104 void EvictIfNeeded(); | 104 void EvictIfNeeded(); |
105 | 105 |
106 EntryMap entries_; | 106 EntryMap entries_; |
107 | 107 |
108 // Stored in increasing order of last use time, from least recently used to | 108 // Stored in increasing order of last use time, from least recently used to |
109 // most recently used. | 109 // most recently used. |
110 base::LinkedList<MemEntryImpl> lru_list_; | 110 base::LinkedList<MemEntryImpl> lru_list_; |
111 | 111 |
112 int32_t max_size_; // Maximum data size for this instance. | 112 int32_t max_size_; // Maximum data size for this instance. |
113 int32_t current_size_; | 113 int32_t current_size_; |
114 | 114 |
115 net::NetLog* net_log_; | 115 net::NetLog* net_log_; |
116 | 116 |
117 base::WeakPtrFactory<MemBackendImpl> weak_factory_; | 117 base::WeakPtrFactory<MemBackendImpl> weak_factory_; |
118 | 118 |
119 DISALLOW_COPY_AND_ASSIGN(MemBackendImpl); | 119 DISALLOW_COPY_AND_ASSIGN(MemBackendImpl); |
120 }; | 120 }; |
121 | 121 |
122 } // namespace disk_cache | 122 } // namespace disk_cache |
123 | 123 |
124 #endif // NET_DISK_CACHE_MEMORY_MEM_BACKEND_IMPL_H_ | 124 #endif // NET_DISK_CACHE_MEMORY_MEM_BACKEND_IMPL_H_ |
OLD | NEW |