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