| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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.h" | 12 #include "base/message_loop.h" |
| 13 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
| 14 #include "base/sys_info.h" | 14 #include "base/sys_info.h" |
| 15 #include "base/time.h" | 15 #include "base/time.h" |
| 16 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
| 17 #include "chrome/browser/prefs/pref_service.h" | 17 #include "chrome/browser/prefs/pref_service.h" |
| 18 #include "chrome/common/chrome_constants.h" | 18 #include "chrome/common/chrome_constants.h" |
| 19 #include "chrome/common/chrome_notification_types.h" | 19 #include "chrome/common/chrome_notification_types.h" |
| 20 #include "chrome/common/pref_names.h" | 20 #include "chrome/common/pref_names.h" |
| 21 #include "chrome/common/render_messages.h" | 21 #include "chrome/common/render_messages.h" |
| 22 #include "content/public/browser/notification_service.h" | 22 #include "content/public/browser/notification_service.h" |
| 23 #include "content/public/browser/render_process_host.h" | 23 #include "content/public/browser/render_process_host.h" |
| 24 | 24 |
| 25 using base::Time; | 25 using base::Time; |
| 26 using base::TimeDelta; | 26 using base::TimeDelta; |
| 27 using WebKit::WebCache; | 27 using WebKit::WebCache; |
| 28 | 28 |
| 29 static const unsigned int kReviseAllocationDelayMS = 200 /* milliseconds */; | 29 static const int kReviseAllocationDelayMS = 200; |
| 30 | 30 |
| 31 // The default size limit of the in-memory cache is 8 MB | 31 // The default size limit of the in-memory cache is 8 MB |
| 32 static const int kDefaultMemoryCacheSize = 8 * 1024 * 1024; | 32 static const int kDefaultMemoryCacheSize = 8 * 1024 * 1024; |
| 33 | 33 |
| 34 namespace { | 34 namespace { |
| 35 | 35 |
| 36 int GetDefaultCacheSize() { | 36 int GetDefaultCacheSize() { |
| 37 // Start off with a modest default | 37 // Start off with a modest default |
| 38 int default_cache_size = kDefaultMemoryCacheSize; | 38 int default_cache_size = kDefaultMemoryCacheSize; |
| 39 | 39 |
| (...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 414 } | 414 } |
| 415 } | 415 } |
| 416 | 416 |
| 417 void WebCacheManager::ReviseAllocationStrategyLater() { | 417 void WebCacheManager::ReviseAllocationStrategyLater() { |
| 418 // Ask to be called back in a few milliseconds to actually recompute our | 418 // Ask to be called back in a few milliseconds to actually recompute our |
| 419 // allocation. | 419 // allocation. |
| 420 MessageLoop::current()->PostDelayedTask(FROM_HERE, | 420 MessageLoop::current()->PostDelayedTask(FROM_HERE, |
| 421 base::Bind( | 421 base::Bind( |
| 422 &WebCacheManager::ReviseAllocationStrategy, | 422 &WebCacheManager::ReviseAllocationStrategy, |
| 423 weak_factory_.GetWeakPtr()), | 423 weak_factory_.GetWeakPtr()), |
| 424 kReviseAllocationDelayMS); | 424 base::TimeDelta::FromMilliseconds(kReviseAllocationDelayMS)); |
| 425 } | 425 } |
| 426 | 426 |
| 427 void WebCacheManager::FindInactiveRenderers() { | 427 void WebCacheManager::FindInactiveRenderers() { |
| 428 std::set<int>::const_iterator iter = active_renderers_.begin(); | 428 std::set<int>::const_iterator iter = active_renderers_.begin(); |
| 429 while (iter != active_renderers_.end()) { | 429 while (iter != active_renderers_.end()) { |
| 430 StatsMap::iterator elmt = stats_.find(*iter); | 430 StatsMap::iterator elmt = stats_.find(*iter); |
| 431 DCHECK(elmt != stats_.end()); | 431 DCHECK(elmt != stats_.end()); |
| 432 TimeDelta idle = Time::Now() - elmt->second.access; | 432 TimeDelta idle = Time::Now() - elmt->second.access; |
| 433 if (idle >= TimeDelta::FromMinutes(kRendererInactiveThresholdMinutes)) { | 433 if (idle >= TimeDelta::FromMinutes(kRendererInactiveThresholdMinutes)) { |
| 434 // Moved to inactive status. This invalidates our iterator. | 434 // Moved to inactive status. This invalidates our iterator. |
| 435 inactive_renderers_.insert(*iter); | 435 inactive_renderers_.insert(*iter); |
| 436 active_renderers_.erase(*iter); | 436 active_renderers_.erase(*iter); |
| 437 iter = active_renderers_.begin(); | 437 iter = active_renderers_.begin(); |
| 438 continue; | 438 continue; |
| 439 } | 439 } |
| 440 ++iter; | 440 ++iter; |
| 441 } | 441 } |
| 442 } | 442 } |
| OLD | NEW |