| 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 "chrome/browser/renderer_host/web_cache_manager.h" | 5 #include "chrome/browser/renderer_host/web_cache_manager.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 11 #include "base/memory/singleton.h" | 11 #include "base/memory/singleton.h" |
| 12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
| 13 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
| 14 #include "base/prefs/pref_registry_simple.h" | 14 #include "base/prefs/pref_registry_simple.h" |
| 15 #include "base/prefs/pref_service.h" | 15 #include "base/prefs/pref_service.h" |
| 16 #include "base/sys_info.h" | 16 #include "base/sys_info.h" |
| 17 #include "base/sys_utils.h" |
| 17 #include "base/time/time.h" | 18 #include "base/time/time.h" |
| 18 #include "chrome/browser/browser_process.h" | 19 #include "chrome/browser/browser_process.h" |
| 19 #include "chrome/browser/chrome_notification_types.h" | 20 #include "chrome/browser/chrome_notification_types.h" |
| 20 #include "chrome/common/chrome_constants.h" | 21 #include "chrome/common/chrome_constants.h" |
| 21 #include "chrome/common/pref_names.h" | 22 #include "chrome/common/pref_names.h" |
| 22 #include "chrome/common/render_messages.h" | 23 #include "chrome/common/render_messages.h" |
| 23 #include "content/public/browser/notification_service.h" | 24 #include "content/public/browser/notification_service.h" |
| 24 #include "content/public/browser/render_process_host.h" | 25 #include "content/public/browser/render_process_host.h" |
| 25 | 26 |
| 26 #if defined(OS_ANDROID) | |
| 27 #include "base/android/sys_utils.h" | |
| 28 #endif | |
| 29 | |
| 30 using base::Time; | 27 using base::Time; |
| 31 using base::TimeDelta; | 28 using base::TimeDelta; |
| 32 using blink::WebCache; | 29 using blink::WebCache; |
| 33 | 30 |
| 34 static const int kReviseAllocationDelayMS = 200; | 31 static const int kReviseAllocationDelayMS = 200; |
| 35 | 32 |
| 36 // The default size limit of the in-memory cache is 8 MB | 33 // The default size limit of the in-memory cache is 8 MB |
| 37 static const int kDefaultMemoryCacheSize = 8 * 1024 * 1024; | 34 static const int kDefaultMemoryCacheSize = 8 * 1024 * 1024; |
| 38 | 35 |
| 39 namespace { | 36 namespace { |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 size_t capacity = allocation->second; | 317 size_t capacity = allocation->second; |
| 321 | 318 |
| 322 // We don't reserve any space for dead objects in the cache. Instead, we | 319 // We don't reserve any space for dead objects in the cache. Instead, we |
| 323 // prefer to keep live objects around. There is probably some performance | 320 // prefer to keep live objects around. There is probably some performance |
| 324 // tuning to be done here. | 321 // tuning to be done here. |
| 325 size_t min_dead_capacity = 0; | 322 size_t min_dead_capacity = 0; |
| 326 | 323 |
| 327 // We allow the dead objects to consume up to half of the cache capacity. | 324 // We allow the dead objects to consume up to half of the cache capacity. |
| 328 size_t max_dead_capacity = capacity / 2; | 325 size_t max_dead_capacity = capacity / 2; |
| 329 #if defined(OS_ANDROID) | 326 #if defined(OS_ANDROID) |
| 330 if (base::android::SysUtils::IsLowEndDevice()) | 327 if (base::SysUtils::IsLowEndDevice()) |
| 331 max_dead_capacity = std::min(512 * 1024U, max_dead_capacity); | 328 max_dead_capacity = std::min(512 * 1024U, max_dead_capacity); |
| 332 #endif | 329 #endif |
| 333 | 330 |
| 334 host->Send(new ChromeViewMsg_SetCacheCapacities(min_dead_capacity, | 331 host->Send(new ChromeViewMsg_SetCacheCapacities(min_dead_capacity, |
| 335 max_dead_capacity, | 332 max_dead_capacity, |
| 336 capacity)); | 333 capacity)); |
| 337 } | 334 } |
| 338 ++allocation; | 335 ++allocation; |
| 339 } | 336 } |
| 340 } | 337 } |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 if (idle >= TimeDelta::FromMinutes(kRendererInactiveThresholdMinutes)) { | 437 if (idle >= TimeDelta::FromMinutes(kRendererInactiveThresholdMinutes)) { |
| 441 // Moved to inactive status. This invalidates our iterator. | 438 // Moved to inactive status. This invalidates our iterator. |
| 442 inactive_renderers_.insert(*iter); | 439 inactive_renderers_.insert(*iter); |
| 443 active_renderers_.erase(*iter); | 440 active_renderers_.erase(*iter); |
| 444 iter = active_renderers_.begin(); | 441 iter = active_renderers_.begin(); |
| 445 continue; | 442 continue; |
| 446 } | 443 } |
| 447 ++iter; | 444 ++iter; |
| 448 } | 445 } |
| 449 } | 446 } |
| OLD | NEW |