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

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: Address comments from PS3 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
« no previous file with comments | « base/trace_event/memory_usage_estimator.h ('k') | net/disk_cache/memory/mem_entry_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // Entries in lru_list_ will be counted by EMU but not in entries_ since
288 return 0; 289 // they're pointers.
290 return base::trace_event::EstimateMemoryUsage(lru_list_) +
291 base::trace_event::EstimateMemoryUsage(entries_);
289 } 292 }
290 293
291 void MemBackendImpl::EvictIfNeeded() { 294 void MemBackendImpl::EvictIfNeeded() {
292 if (current_size_ <= max_size_) 295 if (current_size_ <= max_size_)
293 return; 296 return;
294 297
295 int target_size = std::max(0, max_size_ - kDefaultEvictionSize); 298 int target_size = std::max(0, max_size_ - kDefaultEvictionSize);
296 299
297 base::LinkNode<MemEntryImpl>* entry = lru_list_.head(); 300 base::LinkNode<MemEntryImpl>* entry = lru_list_.head();
298 while (current_size_ > target_size && entry != lru_list_.end()) { 301 while (current_size_ > target_size && entry != lru_list_.end()) {
299 MemEntryImpl* to_doom = entry->value(); 302 MemEntryImpl* to_doom = entry->value();
300 entry = entry->next(); 303 entry = entry->next();
301 if (!to_doom->InUse()) 304 if (!to_doom->InUse())
302 to_doom->Doom(); 305 to_doom->Doom();
303 } 306 }
304 } 307 }
305 308
306 } // namespace disk_cache 309 } // namespace disk_cache
OLDNEW
« no previous file with comments | « base/trace_event/memory_usage_estimator.h ('k') | net/disk_cache/memory/mem_entry_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698