OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_MEM_BACKEND_IMPL_H__ | 7 #ifndef NET_DISK_CACHE_MEM_BACKEND_IMPL_H__ |
8 #define NET_DISK_CACHE_MEM_BACKEND_IMPL_H__ | 8 #define NET_DISK_CACHE_MEM_BACKEND_IMPL_H__ |
9 | 9 |
10 #include "base/hash_tables.h" | 10 #include "base/hash_tables.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 // size the cache can grow to. If zero is passed in as max_bytes, the cache | 28 // size the cache can grow to. If zero is passed in as max_bytes, the cache |
29 // will determine the value to use based on the available memory. The returned | 29 // will determine the value to use based on the available memory. The returned |
30 // pointer can be NULL if a fatal error is found. | 30 // pointer can be NULL if a fatal error is found. |
31 static Backend* CreateBackend(int max_bytes); | 31 static Backend* CreateBackend(int max_bytes); |
32 | 32 |
33 // Performs general initialization for this current instance of the cache. | 33 // Performs general initialization for this current instance of the cache. |
34 bool Init(); | 34 bool Init(); |
35 | 35 |
36 // Backend interface. | 36 // Backend interface. |
37 virtual int32 GetEntryCount() const; | 37 virtual int32 GetEntryCount() const; |
38 virtual bool OpenEntry(const std::string& key, Entry** entry); | |
39 virtual int OpenEntry(const std::string& key, Entry** entry, | 38 virtual int OpenEntry(const std::string& key, Entry** entry, |
40 CompletionCallback* callback); | 39 CompletionCallback* callback); |
41 virtual bool CreateEntry(const std::string& key, Entry** entry); | |
42 virtual int CreateEntry(const std::string& key, Entry** entry, | 40 virtual int CreateEntry(const std::string& key, Entry** entry, |
43 CompletionCallback* callback); | 41 CompletionCallback* callback); |
44 virtual bool DoomEntry(const std::string& key); | |
45 virtual int DoomEntry(const std::string& key, CompletionCallback* callback); | 42 virtual int DoomEntry(const std::string& key, CompletionCallback* callback); |
46 virtual bool DoomAllEntries(); | |
47 virtual int DoomAllEntries(CompletionCallback* callback); | 43 virtual int DoomAllEntries(CompletionCallback* callback); |
48 virtual bool DoomEntriesBetween(const base::Time initial_time, | |
49 const base::Time end_time); | |
50 virtual int DoomEntriesBetween(const base::Time initial_time, | 44 virtual int DoomEntriesBetween(const base::Time initial_time, |
51 const base::Time end_time, | 45 const base::Time end_time, |
52 CompletionCallback* callback); | 46 CompletionCallback* callback); |
53 virtual bool DoomEntriesSince(const base::Time initial_time); | |
54 virtual int DoomEntriesSince(const base::Time initial_time, | 47 virtual int DoomEntriesSince(const base::Time initial_time, |
55 CompletionCallback* callback); | 48 CompletionCallback* callback); |
56 virtual bool OpenNextEntry(void** iter, Entry** next_entry); | |
57 virtual int OpenNextEntry(void** iter, Entry** next_entry, | 49 virtual int OpenNextEntry(void** iter, Entry** next_entry, |
58 CompletionCallback* callback); | 50 CompletionCallback* callback); |
59 virtual void EndEnumeration(void** iter); | 51 virtual void EndEnumeration(void** iter); |
60 virtual void GetStats( | 52 virtual void GetStats( |
61 std::vector<std::pair<std::string, std::string> >* stats) {} | 53 std::vector<std::pair<std::string, std::string> >* stats) {} |
62 | 54 |
63 // Sets the maximum size for the total amount of data stored by this instance. | 55 // Sets the maximum size for the total amount of data stored by this instance. |
64 bool SetMaxSize(int max_bytes); | 56 bool SetMaxSize(int max_bytes); |
65 | 57 |
66 // Permanently deletes an entry. | 58 // Permanently deletes an entry. |
(...skipping 11 matching lines...) Expand all Loading... |
78 // Insert an MemEntryImpl into the ranking list. This method is only called | 70 // Insert an MemEntryImpl into the ranking list. This method is only called |
79 // from MemEntryImpl to insert child entries. The reference can be removed | 71 // from MemEntryImpl to insert child entries. The reference can be removed |
80 // by calling RemoveFromRankingList(|entry|). | 72 // by calling RemoveFromRankingList(|entry|). |
81 void InsertIntoRankingList(MemEntryImpl* entry); | 73 void InsertIntoRankingList(MemEntryImpl* entry); |
82 | 74 |
83 // Remove |entry| from ranking list. This method is only called from | 75 // Remove |entry| from ranking list. This method is only called from |
84 // MemEntryImpl to remove a child entry from the ranking list. | 76 // MemEntryImpl to remove a child entry from the ranking list. |
85 void RemoveFromRankingList(MemEntryImpl* entry); | 77 void RemoveFromRankingList(MemEntryImpl* entry); |
86 | 78 |
87 private: | 79 private: |
| 80 // Old Backend interface. |
| 81 bool OpenEntry(const std::string& key, Entry** entry); |
| 82 bool CreateEntry(const std::string& key, Entry** entry); |
| 83 bool DoomEntry(const std::string& key); |
| 84 bool DoomAllEntries(); |
| 85 bool DoomEntriesBetween(const base::Time initial_time, |
| 86 const base::Time end_time); |
| 87 bool DoomEntriesSince(const base::Time initial_time); |
| 88 bool OpenNextEntry(void** iter, Entry** next_entry); |
| 89 |
88 // Deletes entries from the cache until the current size is below the limit. | 90 // Deletes entries from the cache until the current size is below the limit. |
89 // If empty is true, the whole cache will be trimmed, regardless of being in | 91 // If empty is true, the whole cache will be trimmed, regardless of being in |
90 // use. | 92 // use. |
91 void TrimCache(bool empty); | 93 void TrimCache(bool empty); |
92 | 94 |
93 // Handles the used storage count. | 95 // Handles the used storage count. |
94 void AddStorageSize(int32 bytes); | 96 void AddStorageSize(int32 bytes); |
95 void SubstractStorageSize(int32 bytes); | 97 void SubstractStorageSize(int32 bytes); |
96 | 98 |
97 typedef base::hash_map<std::string, MemEntryImpl*> EntryMap; | 99 typedef base::hash_map<std::string, MemEntryImpl*> EntryMap; |
98 | 100 |
99 EntryMap entries_; | 101 EntryMap entries_; |
100 MemRankings rankings_; // Rankings to be able to trim the cache. | 102 MemRankings rankings_; // Rankings to be able to trim the cache. |
101 int32 max_size_; // Maximum data size for this instance. | 103 int32 max_size_; // Maximum data size for this instance. |
102 int32 current_size_; | 104 int32 current_size_; |
103 | 105 |
104 DISALLOW_COPY_AND_ASSIGN(MemBackendImpl); | 106 DISALLOW_COPY_AND_ASSIGN(MemBackendImpl); |
105 }; | 107 }; |
106 | 108 |
107 } // namespace disk_cache | 109 } // namespace disk_cache |
108 | 110 |
109 #endif // NET_DISK_CACHE_MEM_BACKEND_IMPL_H__ | 111 #endif // NET_DISK_CACHE_MEM_BACKEND_IMPL_H__ |
OLD | NEW |