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/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/memory/singleton.h" | 10 #include "base/memory/singleton.h" |
11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
12 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
13 #include "base/sys_info.h" | 13 #include "base/sys_info.h" |
14 #include "base/time.h" | 14 #include "base/time.h" |
15 #include "chrome/browser/browser_process.h" | 15 #include "chrome/browser/browser_process.h" |
16 #include "chrome/browser/prefs/pref_service.h" | 16 #include "chrome/browser/prefs/pref_service.h" |
17 #include "chrome/common/chrome_constants.h" | 17 #include "chrome/common/chrome_constants.h" |
18 #include "chrome/common/chrome_notification_types.h" | 18 #include "chrome/common/chrome_notification_types.h" |
19 #include "chrome/common/pref_names.h" | 19 #include "chrome/common/pref_names.h" |
20 #include "chrome/common/render_messages.h" | 20 #include "chrome/common/render_messages.h" |
21 #include "content/browser/renderer_host/browser_render_process_host.h" | 21 #include "content/browser/renderer_host/browser_render_process_host.h" |
22 #include "content/common/notification_service.h" | 22 #include "content/public/browser/notification_service.h" |
23 | 23 |
24 using base::Time; | 24 using base::Time; |
25 using base::TimeDelta; | 25 using base::TimeDelta; |
26 using WebKit::WebCache; | 26 using WebKit::WebCache; |
27 | 27 |
28 static const unsigned int kReviseAllocationDelayMS = 200 /* milliseconds */; | 28 static const unsigned int kReviseAllocationDelayMS = 200 /* milliseconds */; |
29 | 29 |
30 // The default size limit of the in-memory cache is 8 MB | 30 // The default size limit of the in-memory cache is 8 MB |
31 static const int kDefaultMemoryCacheSize = 8 * 1024 * 1024; | 31 static const int kDefaultMemoryCacheSize = 8 * 1024 * 1024; |
32 | 32 |
(...skipping 25 matching lines...) Expand all Loading... |
58 | 58 |
59 // static | 59 // static |
60 WebCacheManager* WebCacheManager::GetInstance() { | 60 WebCacheManager* WebCacheManager::GetInstance() { |
61 return Singleton<WebCacheManager>::get(); | 61 return Singleton<WebCacheManager>::get(); |
62 } | 62 } |
63 | 63 |
64 WebCacheManager::WebCacheManager() | 64 WebCacheManager::WebCacheManager() |
65 : global_size_limit_(GetDefaultGlobalSizeLimit()), | 65 : global_size_limit_(GetDefaultGlobalSizeLimit()), |
66 ALLOW_THIS_IN_INITIALIZER_LIST(revise_allocation_factory_(this)) { | 66 ALLOW_THIS_IN_INITIALIZER_LIST(revise_allocation_factory_(this)) { |
67 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CREATED, | 67 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CREATED, |
68 NotificationService::AllBrowserContextsAndSources()); | 68 content::NotificationService::AllBrowserContextsAndSources()); |
69 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, | 69 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, |
70 NotificationService::AllBrowserContextsAndSources()); | 70 content::NotificationService::AllBrowserContextsAndSources()); |
71 } | 71 } |
72 | 72 |
73 WebCacheManager::~WebCacheManager() { | 73 WebCacheManager::~WebCacheManager() { |
74 } | 74 } |
75 | 75 |
76 void WebCacheManager::Add(int renderer_id) { | 76 void WebCacheManager::Add(int renderer_id) { |
77 DCHECK(inactive_renderers_.count(renderer_id) == 0); | 77 DCHECK(inactive_renderers_.count(renderer_id) == 0); |
78 | 78 |
79 // It is tempting to make the following DCHECK here, but it fails when a new | 79 // It is tempting to make the following DCHECK here, but it fails when a new |
80 // tab is created as we observe activity from that tab because the | 80 // tab is created as we observe activity from that tab because the |
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
429 if (idle >= TimeDelta::FromMinutes(kRendererInactiveThresholdMinutes)) { | 429 if (idle >= TimeDelta::FromMinutes(kRendererInactiveThresholdMinutes)) { |
430 // Moved to inactive status. This invalidates our iterator. | 430 // Moved to inactive status. This invalidates our iterator. |
431 inactive_renderers_.insert(*iter); | 431 inactive_renderers_.insert(*iter); |
432 active_renderers_.erase(*iter); | 432 active_renderers_.erase(*iter); |
433 iter = active_renderers_.begin(); | 433 iter = active_renderers_.begin(); |
434 continue; | 434 continue; |
435 } | 435 } |
436 ++iter; | 436 ++iter; |
437 } | 437 } |
438 } | 438 } |
OLD | NEW |