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/pref_names.h" | 19 #include "chrome/common/pref_names.h" |
19 #include "chrome/common/render_messages.h" | 20 #include "chrome/common/render_messages.h" |
20 #include "content/browser/renderer_host/browser_render_process_host.h" | 21 #include "content/browser/renderer_host/browser_render_process_host.h" |
21 #include "content/common/notification_service.h" | 22 #include "content/common/notification_service.h" |
22 | 23 |
23 using base::Time; | 24 using base::Time; |
24 using base::TimeDelta; | 25 using base::TimeDelta; |
25 using WebKit::WebCache; | 26 using WebKit::WebCache; |
26 | 27 |
27 static const unsigned int kReviseAllocationDelayMS = 200 /* milliseconds */; | 28 static const unsigned int kReviseAllocationDelayMS = 200 /* milliseconds */; |
(...skipping 28 matching lines...) Expand all Loading... |
56 } | 57 } |
57 | 58 |
58 // static | 59 // static |
59 WebCacheManager* WebCacheManager::GetInstance() { | 60 WebCacheManager* WebCacheManager::GetInstance() { |
60 return Singleton<WebCacheManager>::get(); | 61 return Singleton<WebCacheManager>::get(); |
61 } | 62 } |
62 | 63 |
63 WebCacheManager::WebCacheManager() | 64 WebCacheManager::WebCacheManager() |
64 : global_size_limit_(GetDefaultGlobalSizeLimit()), | 65 : global_size_limit_(GetDefaultGlobalSizeLimit()), |
65 ALLOW_THIS_IN_INITIALIZER_LIST(revise_allocation_factory_(this)) { | 66 ALLOW_THIS_IN_INITIALIZER_LIST(revise_allocation_factory_(this)) { |
66 registrar_.Add(this, NotificationType::RENDERER_PROCESS_CREATED, | 67 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CREATED, |
67 NotificationService::AllSources()); | 68 NotificationService::AllSources()); |
68 registrar_.Add(this, NotificationType::RENDERER_PROCESS_TERMINATED, | 69 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, |
69 NotificationService::AllSources()); | 70 NotificationService::AllSources()); |
70 } | 71 } |
71 | 72 |
72 WebCacheManager::~WebCacheManager() { | 73 WebCacheManager::~WebCacheManager() { |
73 } | 74 } |
74 | 75 |
75 void WebCacheManager::Add(int renderer_id) { | 76 void WebCacheManager::Add(int renderer_id) { |
76 DCHECK(inactive_renderers_.count(renderer_id) == 0); | 77 DCHECK(inactive_renderers_.count(renderer_id) == 0); |
77 | 78 |
78 // 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 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 entry->second.deadSize = stats.deadSize; | 136 entry->second.deadSize = stats.deadSize; |
136 entry->second.liveSize = stats.liveSize; | 137 entry->second.liveSize = stats.liveSize; |
137 entry->second.maxDeadCapacity = stats.maxDeadCapacity; | 138 entry->second.maxDeadCapacity = stats.maxDeadCapacity; |
138 entry->second.minDeadCapacity = stats.minDeadCapacity; | 139 entry->second.minDeadCapacity = stats.minDeadCapacity; |
139 | 140 |
140 // trigger notification | 141 // trigger notification |
141 WebCache::UsageStats stats_details(stats); | 142 WebCache::UsageStats stats_details(stats); |
142 // &stats_details is only valid during the notification. | 143 // &stats_details is only valid during the notification. |
143 // See notification_types.h. | 144 // See notification_types.h. |
144 NotificationService::current()->Notify( | 145 NotificationService::current()->Notify( |
145 NotificationType::WEB_CACHE_STATS_OBSERVED, | 146 chrome::NOTIFICATION_WEB_CACHE_STATS_OBSERVED, |
146 Source<RenderProcessHost>(RenderProcessHost::FromID(renderer_id)), | 147 Source<RenderProcessHost>(RenderProcessHost::FromID(renderer_id)), |
147 Details<WebCache::UsageStats>(&stats_details)); | 148 Details<WebCache::UsageStats>(&stats_details)); |
148 } | 149 } |
149 | 150 |
150 void WebCacheManager::SetGlobalSizeLimit(size_t bytes) { | 151 void WebCacheManager::SetGlobalSizeLimit(size_t bytes) { |
151 global_size_limit_ = bytes; | 152 global_size_limit_ = bytes; |
152 ReviseAllocationStrategyLater(); | 153 ReviseAllocationStrategyLater(); |
153 } | 154 } |
154 | 155 |
155 void WebCacheManager::ClearCache() { | 156 void WebCacheManager::ClearCache() { |
156 // Tell each renderer process to clear the cache. | 157 // Tell each renderer process to clear the cache. |
157 ClearRendederCache(active_renderers_); | 158 ClearRendederCache(active_renderers_); |
158 ClearRendederCache(inactive_renderers_); | 159 ClearRendederCache(inactive_renderers_); |
159 } | 160 } |
160 | 161 |
161 void WebCacheManager::Observe(NotificationType type, | 162 void WebCacheManager::Observe(int type, |
162 const NotificationSource& source, | 163 const NotificationSource& source, |
163 const NotificationDetails& details) { | 164 const NotificationDetails& details) { |
164 switch (type.value) { | 165 switch (type) { |
165 case NotificationType::RENDERER_PROCESS_CREATED: { | 166 case content::NOTIFICATION_RENDERER_PROCESS_CREATED: { |
166 RenderProcessHost* process = Source<RenderProcessHost>(source).ptr(); | 167 RenderProcessHost* process = Source<RenderProcessHost>(source).ptr(); |
167 Add(process->id()); | 168 Add(process->id()); |
168 break; | 169 break; |
169 } | 170 } |
170 case NotificationType::RENDERER_PROCESS_TERMINATED: { | 171 case content::NOTIFICATION_RENDERER_PROCESS_TERMINATED: { |
171 RenderProcessHost* process = Source<RenderProcessHost>(source).ptr(); | 172 RenderProcessHost* process = Source<RenderProcessHost>(source).ptr(); |
172 Remove(process->id()); | 173 Remove(process->id()); |
173 break; | 174 break; |
174 } | 175 } |
175 default: | 176 default: |
176 NOTREACHED(); | 177 NOTREACHED(); |
177 break; | 178 break; |
178 } | 179 } |
179 } | 180 } |
180 | 181 |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
426 if (idle >= TimeDelta::FromMinutes(kRendererInactiveThresholdMinutes)) { | 427 if (idle >= TimeDelta::FromMinutes(kRendererInactiveThresholdMinutes)) { |
427 // Moved to inactive status. This invalidates our iterator. | 428 // Moved to inactive status. This invalidates our iterator. |
428 inactive_renderers_.insert(*iter); | 429 inactive_renderers_.insert(*iter); |
429 active_renderers_.erase(*iter); | 430 active_renderers_.erase(*iter); |
430 iter = active_renderers_.begin(); | 431 iter = active_renderers_.begin(); |
431 continue; | 432 continue; |
432 } | 433 } |
433 ++iter; | 434 ++iter; |
434 } | 435 } |
435 } | 436 } |
OLD | NEW |