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

Side by Side Diff: chrome/browser/renderer_host/backing_store_manager.cc

Issue 176037: Fix a DCHECK corner case. Allow (current + new == max) case.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | 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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 "chrome/browser/renderer_host/backing_store_manager.h" 5 #include "chrome/browser/renderer_host/backing_store_manager.h"
6 6
7 #include "base/sys_info.h" 7 #include "base/sys_info.h"
8 #include "chrome/browser/renderer_host/backing_store.h" 8 #include "chrome/browser/renderer_host/backing_store.h"
9 #include "chrome/browser/renderer_host/render_widget_host.h" 9 #include "chrome/browser/renderer_host/render_widget_host.h"
10 #include "chrome/browser/renderer_host/render_widget_host_painting_observer.h" 10 #include "chrome/browser/renderer_host/render_widget_host_painting_observer.h"
(...skipping 28 matching lines...) Expand all
39 // The maximum number of large BackingStoreCache objects (tabs) to use. 39 // The maximum number of large BackingStoreCache objects (tabs) to use.
40 // Use a minimum of 2, and add one for each 256MB of physical memory you have. 40 // Use a minimum of 2, and add one for each 256MB of physical memory you have.
41 // Cap at 5, the thinking being that even if you have a gigantic amount of 41 // Cap at 5, the thinking being that even if you have a gigantic amount of
42 // RAM, there's a limit to how much caching helps beyond a certain number 42 // RAM, there's a limit to how much caching helps beyond a certain number
43 // of tabs. 43 // of tabs.
44 static size_t MaxNumberOfBackingStores() { 44 static size_t MaxNumberOfBackingStores() {
45 return std::min(5, 2 + (base::SysInfo::AmountOfPhysicalMemoryMB() / 256)); 45 return std::min(5, 2 + (base::SysInfo::AmountOfPhysicalMemoryMB() / 256));
46 } 46 }
47 47
48 // The maximum about of memory to use for all BackingStoreCache object combined. 48 // The maximum about of memory to use for all BackingStoreCache object combined.
49 // We use this
50 static size_t MaxBackingStoreMemory() { 49 static size_t MaxBackingStoreMemory() {
51 // Compute in terms of the number of large monitor's worth of backing-store. 50 // Compute in terms of the number of large monitor's worth of backing-store.
52 return MaxNumberOfBackingStores() * kMemoryMultiplier; 51 return MaxNumberOfBackingStores() * kMemoryMultiplier;
53 } 52 }
54 53
55 // Expires the given |backing_store| from |cache|. 54 // Expires the given |backing_store| from |cache|.
56 void ExpireBackingStoreAt(BackingStoreCache* cache, 55 void ExpireBackingStoreAt(BackingStoreCache* cache,
57 BackingStoreCache::iterator backing_store) { 56 BackingStoreCache::iterator backing_store) {
58 RenderWidgetHost* rwh = backing_store->second->render_widget_host(); 57 RenderWidgetHost* rwh = backing_store->second->render_widget_host();
59 if (rwh->painting_observer()) { 58 if (rwh->painting_observer()) {
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 size_t max_mem = MaxBackingStoreMemory(); 111 size_t max_mem = MaxBackingStoreMemory();
113 DCHECK(new_mem < max_mem); 112 DCHECK(new_mem < max_mem);
114 if (current_mem + new_mem > max_mem) { 113 if (current_mem + new_mem > max_mem) {
115 // Need to remove old backing stores to make room for the new one. We 114 // Need to remove old backing stores to make room for the new one. We
116 // don't want to do this when the backing store is being replace by a new 115 // don't want to do this when the backing store is being replace by a new
117 // one for the same tab, but this case won't get called then: we'll have 116 // one for the same tab, but this case won't get called then: we'll have
118 // removed the old one in the RemoveBackingStore above, and the cache 117 // removed the old one in the RemoveBackingStore above, and the cache
119 // won't be over-sized. 118 // won't be over-sized.
120 CreateCacheSpace((current_mem + new_mem) - max_mem); 119 CreateCacheSpace((current_mem + new_mem) - max_mem);
121 } 120 }
122 DCHECK((BackingStoreManager::MemorySize() + new_mem) < max_mem); 121 DCHECK((BackingStoreManager::MemorySize() + new_mem) <= max_mem);
123 122
124 BackingStoreCache* cache; 123 BackingStoreCache* cache;
125 if (new_mem > kSmallThreshold) { 124 if (new_mem > kSmallThreshold) {
126 // Limit the number of large backing stores (tabs) to the memory tier number 125 // Limit the number of large backing stores (tabs) to the memory tier number
127 // (between 2-5). While we allow a larger amount of memory for people who 126 // (between 2-5). While we allow a larger amount of memory for people who
128 // have large windows, this means that those who use small browser windows 127 // have large windows, this means that those who use small browser windows
129 // won't ever cache more than 5 tabs, so they pay a smaller memory cost. 128 // won't ever cache more than 5 tabs, so they pay a smaller memory cost.
130 if (large_cache->size() >= MaxNumberOfBackingStores()) 129 if (large_cache->size() >= MaxNumberOfBackingStores())
131 ExpireLastBackingStore(large_cache); 130 ExpireLastBackingStore(large_cache);
132 cache = large_cache; 131 cache = large_cache;
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 size_t mem = 0; 236 size_t mem = 0;
238 BackingStoreCache::iterator it; 237 BackingStoreCache::iterator it;
239 for (it = large_cache->begin(); it != large_cache->end(); ++it) 238 for (it = large_cache->begin(); it != large_cache->end(); ++it)
240 mem += it->second->MemorySize(); 239 mem += it->second->MemorySize();
241 240
242 for (it = small_cache->begin(); it != small_cache->end(); ++it) 241 for (it = small_cache->begin(); it != small_cache->end(); ++it)
243 mem += it->second->MemorySize(); 242 mem += it->second->MemorySize();
244 243
245 return mem; 244 return mem;
246 } 245 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698