Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(797)

Side by Side Diff: chrome/browser/renderer_host/web_cache_manager.cc

Issue 8515027: Define the public version of the browser side RenderProcessHost interface. This interface is not ... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/browser/renderer_host/browser_render_process_host.h"
23 #include "content/public/browser/notification_service.h" 22 #include "content/public/browser/notification_service.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 unsigned int kReviseAllocationDelayMS = 200 /* milliseconds */;
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
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 // the user navigates to a new website. 156 // the user navigates to a new website.
157 ClearRendederCache(active_renderers_, ON_NAVIGATION); 157 ClearRendederCache(active_renderers_, ON_NAVIGATION);
158 ClearRendederCache(inactive_renderers_, ON_NAVIGATION); 158 ClearRendederCache(inactive_renderers_, ON_NAVIGATION);
159 } 159 }
160 160
161 void WebCacheManager::Observe(int type, 161 void WebCacheManager::Observe(int type,
162 const content::NotificationSource& source, 162 const content::NotificationSource& source,
163 const content::NotificationDetails& details) { 163 const content::NotificationDetails& details) {
164 switch (type) { 164 switch (type) {
165 case content::NOTIFICATION_RENDERER_PROCESS_CREATED: { 165 case content::NOTIFICATION_RENDERER_PROCESS_CREATED: {
166 RenderProcessHost* process = 166 content::RenderProcessHost* process =
167 content::Source<RenderProcessHost>(source).ptr(); 167 content::Source<content::RenderProcessHost>(source).ptr();
168 Add(process->id()); 168 Add(process->GetID());
169 break; 169 break;
170 } 170 }
171 case content::NOTIFICATION_RENDERER_PROCESS_TERMINATED: { 171 case content::NOTIFICATION_RENDERER_PROCESS_TERMINATED: {
172 RenderProcessHost* process = 172 content::RenderProcessHost* process =
173 content::Source<RenderProcessHost>(source).ptr(); 173 content::Source<content::RenderProcessHost>(source).ptr();
174 Remove(process->id()); 174 Remove(process->GetID());
175 break; 175 break;
176 } 176 }
177 default: 177 default:
178 NOTREACHED(); 178 NOTREACHED();
179 break; 179 break;
180 } 180 }
181 } 181 }
182 182
183 // static 183 // static
184 size_t WebCacheManager::GetDefaultGlobalSizeLimit() { 184 size_t WebCacheManager::GetDefaultGlobalSizeLimit() {
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 // Record the allocation in our strategy. 301 // Record the allocation in our strategy.
302 strategy->push_back(Allocation(*iter, cache_size)); 302 strategy->push_back(Allocation(*iter, cache_size));
303 ++iter; 303 ++iter;
304 } 304 }
305 } 305 }
306 306
307 void WebCacheManager::EnactStrategy(const AllocationStrategy& strategy) { 307 void WebCacheManager::EnactStrategy(const AllocationStrategy& strategy) {
308 // Inform each render process of its cache allocation. 308 // Inform each render process of its cache allocation.
309 AllocationStrategy::const_iterator allocation = strategy.begin(); 309 AllocationStrategy::const_iterator allocation = strategy.begin();
310 while (allocation != strategy.end()) { 310 while (allocation != strategy.end()) {
311 RenderProcessHost* host = RenderProcessHost::FromID(allocation->first); 311 content::RenderProcessHost* host =
312 content::RenderProcessHost::FromID(allocation->first);
312 if (host) { 313 if (host) {
313 // This is the capacity this renderer has been allocated. 314 // This is the capacity this renderer has been allocated.
314 size_t capacity = allocation->second; 315 size_t capacity = allocation->second;
315 316
316 // We don't reserve any space for dead objects in the cache. Instead, we 317 // We don't reserve any space for dead objects in the cache. Instead, we
317 // prefer to keep live objects around. There is probably some performance 318 // prefer to keep live objects around. There is probably some performance
318 // tuning to be done here. 319 // tuning to be done here.
319 size_t min_dead_capacity = 0; 320 size_t min_dead_capacity = 0;
320 321
321 // We allow the dead objects to consume all of the cache, if the renderer 322 // We allow the dead objects to consume all of the cache, if the renderer
322 // so desires. If we wanted this memory, we would have set the total 323 // so desires. If we wanted this memory, we would have set the total
323 // capacity lower. 324 // capacity lower.
324 size_t max_dead_capacity = capacity; 325 size_t max_dead_capacity = capacity;
325 326
326 host->Send(new ChromeViewMsg_SetCacheCapacities(min_dead_capacity, 327 host->Send(new ChromeViewMsg_SetCacheCapacities(min_dead_capacity,
327 max_dead_capacity, 328 max_dead_capacity,
328 capacity)); 329 capacity));
329 } 330 }
330 ++allocation; 331 ++allocation;
331 } 332 }
332 } 333 }
333 334
334 void WebCacheManager::ClearRendederCache( 335 void WebCacheManager::ClearRendederCache(
335 const std::set<int>& renderers, 336 const std::set<int>& renderers,
336 WebCacheManager::ClearCacheOccasion occasion) { 337 WebCacheManager::ClearCacheOccasion occasion) {
337 std::set<int>::const_iterator iter = renderers.begin(); 338 std::set<int>::const_iterator iter = renderers.begin();
338 for (; iter != renderers.end(); ++iter) { 339 for (; iter != renderers.end(); ++iter) {
339 RenderProcessHost* host = RenderProcessHost::FromID(*iter); 340 content::RenderProcessHost* host =
341 content::RenderProcessHost::FromID(*iter);
340 if (host) 342 if (host)
341 host->Send(new ChromeViewMsg_ClearCache(occasion == ON_NAVIGATION)); 343 host->Send(new ChromeViewMsg_ClearCache(occasion == ON_NAVIGATION));
342 } 344 }
343 } 345 }
344 346
345 void WebCacheManager::ReviseAllocationStrategy() { 347 void WebCacheManager::ReviseAllocationStrategy() {
346 DCHECK(stats_.size() <= 348 DCHECK(stats_.size() <=
347 active_renderers_.size() + inactive_renderers_.size()); 349 active_renderers_.size() + inactive_renderers_.size());
348 350
349 // Check if renderers have gone inactive. 351 // Check if renderers have gone inactive.
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 if (idle >= TimeDelta::FromMinutes(kRendererInactiveThresholdMinutes)) { 433 if (idle >= TimeDelta::FromMinutes(kRendererInactiveThresholdMinutes)) {
432 // Moved to inactive status. This invalidates our iterator. 434 // Moved to inactive status. This invalidates our iterator.
433 inactive_renderers_.insert(*iter); 435 inactive_renderers_.insert(*iter);
434 active_renderers_.erase(*iter); 436 active_renderers_.erase(*iter);
435 iter = active_renderers_.begin(); 437 iter = active_renderers_.begin();
436 continue; 438 continue;
437 } 439 }
438 ++iter; 440 ++iter;
439 } 441 }
440 } 442 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698