OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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 #include "net/disk_cache/mem_backend_impl.h" | 5 #include "net/disk_cache/mem_backend_impl.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/sys_info.h" | 8 #include "base/sys_info.h" |
9 #include "net/disk_cache/cache_util.h" | 9 #include "net/disk_cache/cache_util.h" |
10 #include "net/disk_cache/mem_entry_impl.h" | 10 #include "net/disk_cache/mem_entry_impl.h" |
11 | 11 |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 Entry* entry; | 121 Entry* entry; |
122 if (!OpenEntry(key, &entry)) | 122 if (!OpenEntry(key, &entry)) |
123 return false; | 123 return false; |
124 | 124 |
125 entry->Doom(); | 125 entry->Doom(); |
126 entry->Close(); | 126 entry->Close(); |
127 return true; | 127 return true; |
128 } | 128 } |
129 | 129 |
130 void MemBackendImpl::InternalDoomEntry(MemEntryImpl* entry) { | 130 void MemBackendImpl::InternalDoomEntry(MemEntryImpl* entry) { |
| 131 // Only parent entries can be passed into this method. |
| 132 DCHECK(entry->type() == MemEntryImpl::kParentEntry); |
| 133 |
131 rankings_.Remove(entry); | 134 rankings_.Remove(entry); |
132 EntryMap::iterator it = entries_.find(entry->GetKey()); | 135 EntryMap::iterator it = entries_.find(entry->GetKey()); |
133 if (it != entries_.end()) | 136 if (it != entries_.end()) |
134 entries_.erase(it); | 137 entries_.erase(it); |
135 else | 138 else |
136 NOTREACHED(); | 139 NOTREACHED(); |
137 | 140 |
138 entry->InternalDoom(); | 141 entry->InternalDoom(); |
139 } | 142 } |
140 | 143 |
(...skipping 14 matching lines...) Expand all Loading... |
155 // rankings_ is ordered by last used, this will descend through the cache | 158 // rankings_ is ordered by last used, this will descend through the cache |
156 // and start dooming items before the end_time, and will stop once it reaches | 159 // and start dooming items before the end_time, and will stop once it reaches |
157 // an item used before the initial time. | 160 // an item used before the initial time. |
158 while (next) { | 161 while (next) { |
159 MemEntryImpl* node = next; | 162 MemEntryImpl* node = next; |
160 next = rankings_.GetNext(next); | 163 next = rankings_.GetNext(next); |
161 | 164 |
162 if (node->GetLastUsed() < initial_time) | 165 if (node->GetLastUsed() < initial_time) |
163 break; | 166 break; |
164 | 167 |
165 if (node->GetLastUsed() < end_time) { | 168 if (node->GetLastUsed() < end_time) |
166 node->Doom(); | 169 node->Doom(); |
167 } | |
168 } | 170 } |
169 | 171 |
170 return true; | 172 return true; |
171 } | 173 } |
172 | 174 |
173 // We use OpenNextEntry to retrieve elements from the cache, until we get | |
174 // entries that are too old. | |
175 bool MemBackendImpl::DoomEntriesSince(const Time initial_time) { | 175 bool MemBackendImpl::DoomEntriesSince(const Time initial_time) { |
176 for (;;) { | 176 for (;;) { |
177 Entry* entry; | 177 // Get the entry in the front. |
178 void* iter = NULL; | 178 Entry* entry = rankings_.GetNext(NULL); |
179 if (!OpenNextEntry(&iter, &entry)) | 179 |
| 180 // Break the loop when there are no more entries or the entry is too old. |
| 181 if (!entry || entry->GetLastUsed() < initial_time) |
180 return true; | 182 return true; |
181 | |
182 if (initial_time > entry->GetLastUsed()) { | |
183 entry->Close(); | |
184 EndEnumeration(&iter); | |
185 return true; | |
186 } | |
187 | |
188 entry->Doom(); | 183 entry->Doom(); |
189 entry->Close(); | |
190 EndEnumeration(&iter); // Dooming the entry invalidates the iterator. | |
191 } | 184 } |
192 } | 185 } |
193 | 186 |
194 bool MemBackendImpl::OpenNextEntry(void** iter, Entry** next_entry) { | 187 bool MemBackendImpl::OpenNextEntry(void** iter, Entry** next_entry) { |
195 MemEntryImpl* current = reinterpret_cast<MemEntryImpl*>(*iter); | 188 MemEntryImpl* current = reinterpret_cast<MemEntryImpl*>(*iter); |
196 MemEntryImpl* node = rankings_.GetNext(current); | 189 MemEntryImpl* node = rankings_.GetNext(current); |
| 190 // We should never return a child entry so iterate until we hit a parent |
| 191 // entry. |
| 192 while (node && node->type() != MemEntryImpl::kParentEntry) { |
| 193 node = rankings_.GetNext(node); |
| 194 } |
197 *next_entry = node; | 195 *next_entry = node; |
198 *iter = node; | 196 *iter = node; |
199 | 197 |
200 if (node) | 198 if (node) |
201 node->Open(); | 199 node->Open(); |
202 | 200 |
203 return NULL != node; | 201 return NULL != node; |
204 } | 202 } |
205 | 203 |
206 void MemBackendImpl::EndEnumeration(void** iter) { | 204 void MemBackendImpl::EndEnumeration(void** iter) { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 } | 243 } |
246 | 244 |
247 void MemBackendImpl::UpdateRank(MemEntryImpl* node) { | 245 void MemBackendImpl::UpdateRank(MemEntryImpl* node) { |
248 rankings_.UpdateRank(node); | 246 rankings_.UpdateRank(node); |
249 } | 247 } |
250 | 248 |
251 int MemBackendImpl::MaxFileSize() const { | 249 int MemBackendImpl::MaxFileSize() const { |
252 return max_size_ / 8; | 250 return max_size_ / 8; |
253 } | 251 } |
254 | 252 |
| 253 void MemBackendImpl::InsertIntoRankingList(MemEntryImpl* entry) { |
| 254 rankings_.Insert(entry); |
| 255 } |
| 256 |
| 257 void MemBackendImpl::RemoveFromRankingList(MemEntryImpl* entry) { |
| 258 rankings_.Remove(entry); |
| 259 } |
| 260 |
255 } // namespace disk_cache | 261 } // namespace disk_cache |
OLD | NEW |