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 "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
11 #include "base/containers/hash_tables.h" | 11 #include "base/containers/hash_tables.h" |
12 #include "base/memory/weak_ptr.h" | |
13 #include "net/disk_cache/disk_cache.h" | 12 #include "net/disk_cache/disk_cache.h" |
14 #include "net/disk_cache/memory/mem_rankings.h" | 13 #include "net/disk_cache/memory/mem_rankings.h" |
15 | 14 |
16 namespace net { | 15 namespace net { |
17 class NetLog; | 16 class NetLog; |
18 } // namespace net | 17 } // namespace net |
19 | 18 |
20 namespace disk_cache { | 19 namespace disk_cache { |
21 | 20 |
22 class MemEntryImpl; | 21 class MemEntryImpl; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 virtual int CreateEntry(const std::string& key, Entry** entry, | 69 virtual int CreateEntry(const std::string& key, Entry** entry, |
71 const CompletionCallback& callback) OVERRIDE; | 70 const CompletionCallback& callback) OVERRIDE; |
72 virtual int DoomEntry(const std::string& key, | 71 virtual int DoomEntry(const std::string& key, |
73 const CompletionCallback& callback) OVERRIDE; | 72 const CompletionCallback& callback) OVERRIDE; |
74 virtual int DoomAllEntries(const CompletionCallback& callback) OVERRIDE; | 73 virtual int DoomAllEntries(const CompletionCallback& callback) OVERRIDE; |
75 virtual int DoomEntriesBetween(base::Time initial_time, | 74 virtual int DoomEntriesBetween(base::Time initial_time, |
76 base::Time end_time, | 75 base::Time end_time, |
77 const CompletionCallback& callback) OVERRIDE; | 76 const CompletionCallback& callback) OVERRIDE; |
78 virtual int DoomEntriesSince(base::Time initial_time, | 77 virtual int DoomEntriesSince(base::Time initial_time, |
79 const CompletionCallback& callback) OVERRIDE; | 78 const CompletionCallback& callback) OVERRIDE; |
80 virtual scoped_ptr<Iterator> CreateIterator() OVERRIDE; | 79 virtual int OpenNextEntry(void** iter, Entry** next_entry, |
| 80 const CompletionCallback& callback) OVERRIDE; |
| 81 virtual void EndEnumeration(void** iter) OVERRIDE; |
81 virtual void GetStats( | 82 virtual void GetStats( |
82 std::vector<std::pair<std::string, std::string> >* stats) OVERRIDE {} | 83 std::vector<std::pair<std::string, std::string> >* stats) OVERRIDE {} |
83 virtual void OnExternalCacheHit(const std::string& key) OVERRIDE; | 84 virtual void OnExternalCacheHit(const std::string& key) OVERRIDE; |
84 | 85 |
85 private: | 86 private: |
86 class MemIterator; | |
87 friend class MemIterator; | |
88 | |
89 typedef base::hash_map<std::string, MemEntryImpl*> EntryMap; | 87 typedef base::hash_map<std::string, MemEntryImpl*> EntryMap; |
90 | 88 |
91 // Old Backend interface. | 89 // Old Backend interface. |
92 bool OpenEntry(const std::string& key, Entry** entry); | 90 bool OpenEntry(const std::string& key, Entry** entry); |
93 bool CreateEntry(const std::string& key, Entry** entry); | 91 bool CreateEntry(const std::string& key, Entry** entry); |
94 bool DoomEntry(const std::string& key); | 92 bool DoomEntry(const std::string& key); |
95 bool DoomAllEntries(); | 93 bool DoomAllEntries(); |
96 bool DoomEntriesBetween(const base::Time initial_time, | 94 bool DoomEntriesBetween(const base::Time initial_time, |
97 const base::Time end_time); | 95 const base::Time end_time); |
98 bool DoomEntriesSince(const base::Time initial_time); | 96 bool DoomEntriesSince(const base::Time initial_time); |
| 97 bool OpenNextEntry(void** iter, Entry** next_entry); |
99 | 98 |
100 // Deletes entries from the cache until the current size is below the limit. | 99 // Deletes entries from the cache until the current size is below the limit. |
101 // If empty is true, the whole cache will be trimmed, regardless of being in | 100 // If empty is true, the whole cache will be trimmed, regardless of being in |
102 // use. | 101 // use. |
103 void TrimCache(bool empty); | 102 void TrimCache(bool empty); |
104 | 103 |
105 // Handles the used storage count. | 104 // Handles the used storage count. |
106 void AddStorageSize(int32 bytes); | 105 void AddStorageSize(int32 bytes); |
107 void SubstractStorageSize(int32 bytes); | 106 void SubstractStorageSize(int32 bytes); |
108 | 107 |
109 EntryMap entries_; | 108 EntryMap entries_; |
110 MemRankings rankings_; // Rankings to be able to trim the cache. | 109 MemRankings rankings_; // Rankings to be able to trim the cache. |
111 int32 max_size_; // Maximum data size for this instance. | 110 int32 max_size_; // Maximum data size for this instance. |
112 int32 current_size_; | 111 int32 current_size_; |
113 | 112 |
114 net::NetLog* net_log_; | 113 net::NetLog* net_log_; |
115 | 114 |
116 base::WeakPtrFactory<MemBackendImpl> weak_factory_; | |
117 | |
118 DISALLOW_COPY_AND_ASSIGN(MemBackendImpl); | 115 DISALLOW_COPY_AND_ASSIGN(MemBackendImpl); |
119 }; | 116 }; |
120 | 117 |
121 } // namespace disk_cache | 118 } // namespace disk_cache |
122 | 119 |
123 #endif // NET_DISK_CACHE_MEMORY_MEM_BACKEND_IMPL_H_ | 120 #endif // NET_DISK_CACHE_MEMORY_MEM_BACKEND_IMPL_H_ |
OLD | NEW |