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