| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "chrome/common/chrome_switches.h" | 9 #include "chrome/common/chrome_switches.h" |
| 10 #include "chrome/browser/renderer_host/backing_store.h" | 10 #include "chrome/browser/renderer_host/backing_store.h" |
| 11 #include "chrome/browser/renderer_host/render_widget_host.h" | 11 #include "chrome/browser/renderer_host/render_widget_host.h" |
| 12 #include "chrome/browser/renderer_host/render_widget_host_painting_observer.h" | |
| 13 #include "chrome/common/chrome_constants.h" | 12 #include "chrome/common/chrome_constants.h" |
| 14 #include "chrome/common/mru_cache.h" | 13 #include "chrome/common/mru_cache.h" |
| 14 #include "chrome/common/notification_service.h" |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 // There are two separate caches, |large_cache| and |small_cache|. large_cache | 18 // There are two separate caches, |large_cache| and |small_cache|. large_cache |
| 19 // is meant for large items (tabs, popup windows), while small_cache is meant | 19 // is meant for large items (tabs, popup windows), while small_cache is meant |
| 20 // for small items (extension toolstrips and buttons, etc.). The idea is that | 20 // for small items (extension toolstrips and buttons, etc.). The idea is that |
| 21 // we'll almost always try to evict from large_cache first since small_cache | 21 // we'll almost always try to evict from large_cache first since small_cache |
| 22 // items will tend to be visible more of the time. | 22 // items will tend to be visible more of the time. |
| 23 typedef OwningMRUCache<RenderWidgetHost*, BackingStore*> BackingStoreCache; | 23 typedef OwningMRUCache<RenderWidgetHost*, BackingStore*> BackingStoreCache; |
| 24 static BackingStoreCache* large_cache = NULL; | 24 static BackingStoreCache* large_cache = NULL; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 | 62 |
| 63 // The maximum about of memory to use for all BackingStoreCache object combined. | 63 // The maximum about of memory to use for all BackingStoreCache object combined. |
| 64 static size_t MaxBackingStoreMemory() { | 64 static size_t MaxBackingStoreMemory() { |
| 65 // Compute in terms of the number of large monitor's worth of backing-store. | 65 // Compute in terms of the number of large monitor's worth of backing-store. |
| 66 return MaxNumberOfBackingStores() * kMemoryMultiplier; | 66 return MaxNumberOfBackingStores() * kMemoryMultiplier; |
| 67 } | 67 } |
| 68 | 68 |
| 69 // Expires the given |backing_store| from |cache|. | 69 // Expires the given |backing_store| from |cache|. |
| 70 void ExpireBackingStoreAt(BackingStoreCache* cache, | 70 void ExpireBackingStoreAt(BackingStoreCache* cache, |
| 71 BackingStoreCache::iterator backing_store) { | 71 BackingStoreCache::iterator backing_store) { |
| 72 RenderWidgetHost* rwh = backing_store->second->render_widget_host(); | 72 NotificationService::current()->Notify( |
| 73 if (rwh->painting_observer()) { | 73 NotificationType::RENDER_WIDGET_HOST_WILL_DESTROY_BACKING_STORE, |
| 74 rwh->painting_observer()->WidgetWillDestroyBackingStore( | 74 Source<RenderWidgetHost>(backing_store->first), |
| 75 backing_store->first, | 75 Details<BackingStore>(backing_store->second)); |
| 76 backing_store->second); | |
| 77 } | |
| 78 cache->Erase(backing_store); | 76 cache->Erase(backing_store); |
| 79 } | 77 } |
| 80 | 78 |
| 81 size_t ExpireLastBackingStore(BackingStoreCache* cache) { | 79 size_t ExpireLastBackingStore(BackingStoreCache* cache) { |
| 82 if (cache->size() < 1) | 80 if (cache->size() < 1) |
| 83 return 0; | 81 return 0; |
| 84 | 82 |
| 85 // Crazy C++ alert: rbegin.base() is a forward iterator pointing to end(), | 83 // Crazy C++ alert: rbegin.base() is a forward iterator pointing to end(), |
| 86 // so we need to do -- to move one back to the actual last item. | 84 // so we need to do -- to move one back to the actual last item. |
| 87 BackingStoreCache::iterator entry = --cache->rbegin().base(); | 85 BackingStoreCache::iterator entry = --cache->rbegin().base(); |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 size_t mem = 0; | 277 size_t mem = 0; |
| 280 BackingStoreCache::iterator it; | 278 BackingStoreCache::iterator it; |
| 281 for (it = large_cache->begin(); it != large_cache->end(); ++it) | 279 for (it = large_cache->begin(); it != large_cache->end(); ++it) |
| 282 mem += it->second->MemorySize(); | 280 mem += it->second->MemorySize(); |
| 283 | 281 |
| 284 for (it = small_cache->begin(); it != small_cache->end(); ++it) | 282 for (it = small_cache->begin(); it != small_cache->end(); ++it) |
| 285 mem += it->second->MemorySize(); | 283 mem += it->second->MemorySize(); |
| 286 | 284 |
| 287 return mem; | 285 return mem; |
| 288 } | 286 } |
| OLD | NEW |