Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(51)

Side by Side Diff: net/disk_cache/memory/mem_backend_impl.cc

Issue 542733002: Remove void** from disk_cache interface. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: narrower Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #include "net/disk_cache/memory/mem_backend_impl.h" 5 #include "net/disk_cache/memory/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/base/net_errors.h" 9 #include "net/base/net_errors.h"
10 #include "net/disk_cache/cache_util.h" 10 #include "net/disk_cache/cache_util.h"
(...skipping 11 matching lines...) Expand all
22 return 0; 22 return 0;
23 23
24 return high_water - kCleanUpMargin; 24 return high_water - kCleanUpMargin;
25 } 25 }
26 26
27 } // namespace 27 } // namespace
28 28
29 namespace disk_cache { 29 namespace disk_cache {
30 30
31 MemBackendImpl::MemBackendImpl(net::NetLog* net_log) 31 MemBackendImpl::MemBackendImpl(net::NetLog* net_log)
32 : max_size_(0), current_size_(0), net_log_(net_log) {} 32 : max_size_(0), current_size_(0), net_log_(net_log), weak_factory_(this) {}
rvargas (doing something else) 2014/09/18 02:32:12 not a single line anymore ({})
gavinp 2014/09/18 18:13:04 Done.
33 33
34 MemBackendImpl::~MemBackendImpl() { 34 MemBackendImpl::~MemBackendImpl() {
35 EntryMap::iterator it = entries_.begin(); 35 EntryMap::iterator it = entries_.begin();
36 while (it != entries_.end()) { 36 while (it != entries_.end()) {
37 it->second->Doom(); 37 it->second->Doom();
38 it = entries_.begin(); 38 it = entries_.begin();
39 } 39 }
40 DCHECK(!current_size_); 40 DCHECK(!current_size_);
41 } 41 }
42 42
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 } 173 }
174 174
175 int MemBackendImpl::DoomEntriesSince(const base::Time initial_time, 175 int MemBackendImpl::DoomEntriesSince(const base::Time initial_time,
176 const CompletionCallback& callback) { 176 const CompletionCallback& callback) {
177 if (DoomEntriesSince(initial_time)) 177 if (DoomEntriesSince(initial_time))
178 return net::OK; 178 return net::OK;
179 179
180 return net::ERR_FAILED; 180 return net::ERR_FAILED;
181 } 181 }
182 182
183 int MemBackendImpl::OpenNextEntry(void** iter, Entry** next_entry, 183 class MemBackendImpl::MemIterator : public Backend::Iterator {
184 const CompletionCallback& callback) { 184 public:
185 if (OpenNextEntry(iter, next_entry)) 185 explicit MemIterator(base::WeakPtr<MemBackendImpl> backend)
186 return net::OK; 186 : backend_(backend), current_(NULL) {}
187 187
188 return net::ERR_FAILED; 188 virtual int OpenNextEntry(Entry** next_entry,
189 } 189 const CompletionCallback& callback) OVERRIDE {
190 if (!backend_)
191 return net::ERR_FAILED;
190 192
191 void MemBackendImpl::EndEnumeration(void** iter) { 193 MemEntryImpl* node = backend_->rankings_.GetNext(current_);
192 *iter = NULL; 194 // We should never return a child entry so iterate until we hit a parent
195 // entry.
196 while (node && node->type() != MemEntryImpl::kParentEntry)
197 node = backend_->rankings_.GetNext(node);
198 *next_entry = node;
199 current_ = node;
200
201 if (node) {
202 node->Open();
203 return net::OK;
204 }
205 return net::ERR_FAILED;
206 }
207
208 private:
209 base::WeakPtr<MemBackendImpl> backend_;
210 MemEntryImpl* current_;
211 };
212
213 scoped_ptr<Backend::Iterator> MemBackendImpl::CreateIterator() {
214 return scoped_ptr<Backend::Iterator>(
215 new MemIterator(weak_factory_.GetWeakPtr()));
193 } 216 }
194 217
195 void MemBackendImpl::OnExternalCacheHit(const std::string& key) { 218 void MemBackendImpl::OnExternalCacheHit(const std::string& key) {
196 EntryMap::iterator it = entries_.find(key); 219 EntryMap::iterator it = entries_.find(key);
197 if (it != entries_.end()) { 220 if (it != entries_.end()) {
198 UpdateRank(it->second); 221 UpdateRank(it->second);
199 } 222 }
200 } 223 }
201 224
202 bool MemBackendImpl::OpenEntry(const std::string& key, Entry** entry) { 225 bool MemBackendImpl::OpenEntry(const std::string& key, Entry** entry) {
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 // Get the entry in the front. 303 // Get the entry in the front.
281 Entry* entry = rankings_.GetNext(NULL); 304 Entry* entry = rankings_.GetNext(NULL);
282 305
283 // Break the loop when there are no more entries or the entry is too old. 306 // Break the loop when there are no more entries or the entry is too old.
284 if (!entry || entry->GetLastUsed() < initial_time) 307 if (!entry || entry->GetLastUsed() < initial_time)
285 return true; 308 return true;
286 entry->Doom(); 309 entry->Doom();
287 } 310 }
288 } 311 }
289 312
290 bool MemBackendImpl::OpenNextEntry(void** iter, Entry** next_entry) {
291 MemEntryImpl* current = reinterpret_cast<MemEntryImpl*>(*iter);
292 MemEntryImpl* node = rankings_.GetNext(current);
293 // We should never return a child entry so iterate until we hit a parent
294 // entry.
295 while (node && node->type() != MemEntryImpl::kParentEntry) {
296 node = rankings_.GetNext(node);
297 }
298 *next_entry = node;
299 *iter = node;
300
301 if (node)
302 node->Open();
303
304 return NULL != node;
305 }
306
307 void MemBackendImpl::TrimCache(bool empty) { 313 void MemBackendImpl::TrimCache(bool empty) {
308 MemEntryImpl* next = rankings_.GetPrev(NULL); 314 MemEntryImpl* next = rankings_.GetPrev(NULL);
309 if (!next) 315 if (!next)
310 return; 316 return;
311 317
312 int target_size = empty ? 0 : LowWaterAdjust(max_size_); 318 int target_size = empty ? 0 : LowWaterAdjust(max_size_);
313 while (current_size_ > target_size && next) { 319 while (current_size_ > target_size && next) {
314 MemEntryImpl* node = next; 320 MemEntryImpl* node = next;
315 next = rankings_.GetPrev(next); 321 next = rankings_.GetPrev(next);
316 if (!node->InUse() || empty) { 322 if (!node->InUse() || empty) {
(...skipping 11 matching lines...) Expand all
328 if (current_size_ > max_size_) 334 if (current_size_ > max_size_)
329 TrimCache(false); 335 TrimCache(false);
330 } 336 }
331 337
332 void MemBackendImpl::SubstractStorageSize(int32 bytes) { 338 void MemBackendImpl::SubstractStorageSize(int32 bytes) {
333 current_size_ -= bytes; 339 current_size_ -= bytes;
334 DCHECK_GE(current_size_, 0); 340 DCHECK_GE(current_size_, 0);
335 } 341 }
336 342
337 } // namespace disk_cache 343 } // namespace disk_cache
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698