| OLD | NEW |
| 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 "content/browser/renderer_host/backing_store_manager.h" | 5 #include "content/browser/renderer_host/backing_store_manager.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/memory/mru_cache.h" | 9 #include "base/memory/mru_cache.h" |
| 10 #include "base/sys_info.h" | 10 #include "base/sys_info.h" |
| 11 #include "content/browser/renderer_host/backing_store.h" | 11 #include "content/browser/renderer_host/backing_store.h" |
| 12 #include "content/browser/renderer_host/render_widget_host_impl.h" | 12 #include "content/browser/renderer_host/render_widget_host_impl.h" |
| 13 #include "content/public/common/content_switches.h" | 13 #include "content/public/common/content_switches.h" |
| 14 | 14 |
| 15 using content::RenderWidgetHost; |
| 16 |
| 15 namespace { | 17 namespace { |
| 16 | 18 |
| 17 // There are two separate caches, |large_cache| and |small_cache|. large_cache | 19 // There are two separate caches, |large_cache| and |small_cache|. large_cache |
| 18 // is meant for large items (tabs, popup windows), while small_cache is meant | 20 // is meant for large items (tabs, popup windows), while small_cache is meant |
| 19 // for small items (extension popups, HTML5 notifications). The idea is that | 21 // for small items (extension popups, HTML5 notifications). The idea is that |
| 20 // we'll almost always try to evict from large_cache first since small_cache | 22 // we'll almost always try to evict from large_cache first since small_cache |
| 21 // items will tend to be visible more of the time. | 23 // items will tend to be visible more of the time. |
| 22 typedef base::OwningMRUCache<RenderWidgetHost*, BackingStore*> | 24 typedef base::OwningMRUCache<RenderWidgetHost*, BackingStore*> |
| 23 BackingStoreCache; | 25 BackingStoreCache; |
| 24 static BackingStoreCache* large_cache = NULL; | 26 static BackingStoreCache* large_cache = NULL; |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 // Limit the number of large backing stores (tabs) to the memory tier number | 140 // Limit the number of large backing stores (tabs) to the memory tier number |
| 139 // (between 2-5). While we allow a larger amount of memory for people who | 141 // (between 2-5). While we allow a larger amount of memory for people who |
| 140 // have large windows, this means that those who use small browser windows | 142 // have large windows, this means that those who use small browser windows |
| 141 // won't ever cache more than 5 tabs, so they pay a smaller memory cost. | 143 // won't ever cache more than 5 tabs, so they pay a smaller memory cost. |
| 142 if (large_cache->size() >= MaxNumberOfBackingStores()) | 144 if (large_cache->size() >= MaxNumberOfBackingStores()) |
| 143 ExpireLastBackingStore(large_cache); | 145 ExpireLastBackingStore(large_cache); |
| 144 cache = large_cache; | 146 cache = large_cache; |
| 145 } else { | 147 } else { |
| 146 cache = small_cache; | 148 cache = small_cache; |
| 147 } | 149 } |
| 148 BackingStore* backing_store = | 150 BackingStore* backing_store = content::RenderWidgetHostImpl::From( |
| 149 RenderWidgetHostImpl::From(host)->AllocBackingStore(backing_store_size); | 151 host)->AllocBackingStore(backing_store_size); |
| 150 if (backing_store) | 152 if (backing_store) |
| 151 cache->Put(host, backing_store); | 153 cache->Put(host, backing_store); |
| 152 return backing_store; | 154 return backing_store; |
| 153 } | 155 } |
| 154 | 156 |
| 155 int ComputeTotalArea(const std::vector<gfx::Rect>& rects) { | 157 int ComputeTotalArea(const std::vector<gfx::Rect>& rects) { |
| 156 // We assume that the given rects are non-overlapping, which is a property of | 158 // We assume that the given rects are non-overlapping, which is a property of |
| 157 // the paint rects generated by the PaintAggregator. | 159 // the paint rects generated by the PaintAggregator. |
| 158 #ifndef NDEBUG | 160 #ifndef NDEBUG |
| 159 for (size_t i = 0; i < rects.size(); ++i) { | 161 for (size_t i = 0; i < rects.size(); ++i) { |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 size_t mem = 0; | 271 size_t mem = 0; |
| 270 BackingStoreCache::iterator it; | 272 BackingStoreCache::iterator it; |
| 271 for (it = large_cache->begin(); it != large_cache->end(); ++it) | 273 for (it = large_cache->begin(); it != large_cache->end(); ++it) |
| 272 mem += it->second->MemorySize(); | 274 mem += it->second->MemorySize(); |
| 273 | 275 |
| 274 for (it = small_cache->begin(); it != small_cache->end(); ++it) | 276 for (it = small_cache->begin(); it != small_cache->end(); ++it) |
| 275 mem += it->second->MemorySize(); | 277 mem += it->second->MemorySize(); |
| 276 | 278 |
| 277 return mem; | 279 return mem; |
| 278 } | 280 } |
| OLD | NEW |