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

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

Issue 2723553002: Keep track of byte usage of the memory cache backend (Closed)
Patch Set: Created 3 years, 9 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 <algorithm> 7 #include <algorithm>
8 #include <functional> 8 #include <functional>
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/memory/ptr_util.h" 12 #include "base/memory/ptr_util.h"
13 #include "base/sys_info.h" 13 #include "base/sys_info.h"
14 #include "base/trace_event/memory_usage_estimator.h"
14 #include "net/base/net_errors.h" 15 #include "net/base/net_errors.h"
15 #include "net/disk_cache/cache_util.h" 16 #include "net/disk_cache/cache_util.h"
16 #include "net/disk_cache/memory/mem_entry_impl.h" 17 #include "net/disk_cache/memory/mem_entry_impl.h"
17 18
18 using base::Time; 19 using base::Time;
19 20
20 namespace disk_cache { 21 namespace disk_cache {
21 22
22 namespace { 23 namespace {
23 24
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 new MemIterator(weak_factory_.GetWeakPtr())); 278 new MemIterator(weak_factory_.GetWeakPtr()));
278 } 279 }
279 280
280 void MemBackendImpl::OnExternalCacheHit(const std::string& key) { 281 void MemBackendImpl::OnExternalCacheHit(const std::string& key) {
281 EntryMap::iterator it = entries_.find(key); 282 EntryMap::iterator it = entries_.find(key);
282 if (it != entries_.end()) 283 if (it != entries_.end())
283 it->second->UpdateStateOnUse(MemEntryImpl::ENTRY_WAS_NOT_MODIFIED); 284 it->second->UpdateStateOnUse(MemEntryImpl::ENTRY_WAS_NOT_MODIFIED);
284 } 285 }
285 286
286 size_t MemBackendImpl::EstimateMemoryUsage() const { 287 size_t MemBackendImpl::EstimateMemoryUsage() const {
287 // TODO(xunjieli): Implement this. crbug.com/669108. 288 return base::trace_event::EstimateMemoryUsage(lru_list_);
DmitrySkiba 2017/02/27 19:17:42 I think this should also include EMU(entries_).
jkarlin 2017/02/28 13:10:50 entries_ contains pointers to the same set of reso
DmitrySkiba 2017/02/28 16:44:52 Yes, but EMU(entries_) will estimate size take by
jkarlin 2017/02/28 17:20:34 Done.
288 return 0;
289 } 289 }
290 290
291 void MemBackendImpl::EvictIfNeeded() { 291 void MemBackendImpl::EvictIfNeeded() {
292 if (current_size_ <= max_size_) 292 if (current_size_ <= max_size_)
293 return; 293 return;
294 294
295 int target_size = std::max(0, max_size_ - kDefaultEvictionSize); 295 int target_size = std::max(0, max_size_ - kDefaultEvictionSize);
296 296
297 base::LinkNode<MemEntryImpl>* entry = lru_list_.head(); 297 base::LinkNode<MemEntryImpl>* entry = lru_list_.head();
298 while (current_size_ > target_size && entry != lru_list_.end()) { 298 while (current_size_ > target_size && entry != lru_list_.end()) {
299 MemEntryImpl* to_doom = entry->value(); 299 MemEntryImpl* to_doom = entry->value();
300 entry = entry->next(); 300 entry = entry->next();
301 if (!to_doom->InUse()) 301 if (!to_doom->InUse())
302 to_doom->Doom(); 302 to_doom->Doom();
303 } 303 }
304 } 304 }
305 305
306 } // namespace disk_cache 306 } // namespace disk_cache
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698