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

Side by Side Diff: components/web_cache/browser/web_cache_manager.cc

Issue 1706603004: Replace web_cache_messages.h with Mojo service. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed Ken's comments Created 4 years, 10 months 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
OLDNEW
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 "components/web_cache/browser/web_cache_manager.h" 5 #include "components/web_cache/browser/web_cache_manager.h"
6 6
7 #include <string.h> 7 #include <string.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/compiler_specific.h" 12 #include "base/compiler_specific.h"
13 #include "base/location.h" 13 #include "base/location.h"
14 #include "base/memory/singleton.h" 14 #include "base/memory/singleton.h"
15 #include "base/metrics/histogram_macros.h" 15 #include "base/metrics/histogram_macros.h"
16 #include "base/single_thread_task_runner.h" 16 #include "base/single_thread_task_runner.h"
17 #include "base/sys_info.h" 17 #include "base/sys_info.h"
18 #include "base/thread_task_runner_handle.h" 18 #include "base/thread_task_runner_handle.h"
19 #include "base/time/time.h" 19 #include "base/time/time.h"
20 #include "components/prefs/pref_registry_simple.h" 20 #include "components/prefs/pref_registry_simple.h"
21 #include "components/prefs/pref_service.h" 21 #include "components/prefs/pref_service.h"
22 #include "components/web_cache/common/web_cache_messages.h"
23 #include "content/public/browser/notification_service.h" 22 #include "content/public/browser/notification_service.h"
24 #include "content/public/browser/notification_types.h" 23 #include "content/public/browser/notification_types.h"
25 #include "content/public/browser/render_process_host.h" 24 #include "content/public/browser/render_process_host.h"
25 #include "content/public/common/service_registry.h"
26 26
27 using base::Time; 27 using base::Time;
28 using base::TimeDelta; 28 using base::TimeDelta;
29 29
30 namespace web_cache { 30 namespace web_cache {
31 31
32 static const int kReviseAllocationDelayMS = 200; 32 static const int kReviseAllocationDelayMS = 200;
33 33
34 // The default size limit of the in-memory cache is 8 MB 34 // The default size limit of the in-memory cache is 8 MB
35 static const int kDefaultMemoryCacheSize = 8 * 1024 * 1024; 35 static const int kDefaultMemoryCacheSize = 8 * 1024 * 1024;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 // 83 //
84 // However, there doesn't seem to be much harm in receiving the calls in this 84 // However, there doesn't seem to be much harm in receiving the calls in this
85 // order. 85 // order.
86 86
87 active_renderers_.insert(renderer_id); 87 active_renderers_.insert(renderer_id);
88 88
89 RendererInfo* stats = &(stats_[renderer_id]); 89 RendererInfo* stats = &(stats_[renderer_id]);
90 memset(stats, 0, sizeof(*stats)); 90 memset(stats, 0, sizeof(*stats));
91 stats->access = Time::Now(); 91 stats->access = Time::Now();
92 92
93 WebCacheServicePtr service;
94 content::RenderProcessHost* host =
95 content::RenderProcessHost::FromID(renderer_id);
96 DCHECK(host);
97 host->GetServiceRegistry()->ConnectToRemoteService(mojo::GetProxy(&service));
98
99 web_cache_services_[renderer_id] = std::move(service);
100
93 // Revise our allocation strategy to account for this new renderer. 101 // Revise our allocation strategy to account for this new renderer.
94 ReviseAllocationStrategyLater(); 102 ReviseAllocationStrategyLater();
95 } 103 }
96 104
97 void WebCacheManager::Remove(int renderer_id) { 105 void WebCacheManager::Remove(int renderer_id) {
98 // Erase all knowledge of this renderer 106 // Erase all knowledge of this renderer
99 active_renderers_.erase(renderer_id); 107 active_renderers_.erase(renderer_id);
100 inactive_renderers_.erase(renderer_id); 108 inactive_renderers_.erase(renderer_id);
101 stats_.erase(renderer_id); 109 stats_.erase(renderer_id);
102 110
111 web_cache_services_.erase(renderer_id);
112
103 // Reallocate the resources used by this renderer 113 // Reallocate the resources used by this renderer
104 ReviseAllocationStrategyLater(); 114 ReviseAllocationStrategyLater();
105 } 115 }
106 116
107 void WebCacheManager::ObserveActivity(int renderer_id) { 117 void WebCacheManager::ObserveActivity(int renderer_id) {
108 StatsMap::iterator item = stats_.find(renderer_id); 118 StatsMap::iterator item = stats_.find(renderer_id);
109 if (item == stats_.end()) 119 if (item == stats_.end())
110 return; // We might see stats for a renderer that has been destroyed. 120 return; // We might see stats for a renderer that has been destroyed.
111 121
112 // Record activity. 122 // Record activity.
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 // tuning to be done here. 332 // tuning to be done here.
323 uint64_t min_dead_capacity = 0; 333 uint64_t min_dead_capacity = 0;
324 334
325 // We allow the dead objects to consume up to half of the cache capacity. 335 // We allow the dead objects to consume up to half of the cache capacity.
326 uint64_t max_dead_capacity = capacity / 2; 336 uint64_t max_dead_capacity = capacity / 2;
327 if (base::SysInfo::IsLowEndDevice()) { 337 if (base::SysInfo::IsLowEndDevice()) {
328 max_dead_capacity = std::min(static_cast<uint64_t>(512 * 1024u), 338 max_dead_capacity = std::min(static_cast<uint64_t>(512 * 1024u),
329 max_dead_capacity); 339 max_dead_capacity);
330 } 340 }
331 341
332 host->Send(new WebCacheMsg_SetCacheCapacities(min_dead_capacity, 342 const WebCacheServicePtr& service =
333 max_dead_capacity, 343 web_cache_services_[allocation->first];
334 capacity)); 344 DCHECK(service.get());
Anand Mistry (off Chromium) 2016/02/18 12:33:57 I think you should be able to do: DCHECK(service);
leonhsl(Using Gerrit) 2016/02/19 08:37:41 Done.
345 service->SetCacheCapacities(min_dead_capacity, max_dead_capacity,
346 capacity);
335 } 347 }
336 ++allocation; 348 ++allocation;
337 } 349 }
338 } 350 }
339 351
340 void WebCacheManager::ClearCacheForProcess(int render_process_id) { 352 void WebCacheManager::ClearCacheForProcess(int render_process_id) {
341 std::set<int> renderers; 353 std::set<int> renderers;
342 renderers.insert(render_process_id); 354 renderers.insert(render_process_id);
343 ClearRendererCache(renderers, INSTANTLY); 355 ClearRendererCache(renderers, INSTANTLY);
344 } 356 }
345 357
346 void WebCacheManager::ClearRendererCache( 358 void WebCacheManager::ClearRendererCache(
347 const std::set<int>& renderers, 359 const std::set<int>& renderers,
348 WebCacheManager::ClearCacheOccasion occasion) { 360 WebCacheManager::ClearCacheOccasion occasion) {
349 std::set<int>::const_iterator iter = renderers.begin(); 361 std::set<int>::const_iterator iter = renderers.begin();
350 for (; iter != renderers.end(); ++iter) { 362 for (; iter != renderers.end(); ++iter) {
351 content::RenderProcessHost* host = 363 content::RenderProcessHost* host =
352 content::RenderProcessHost::FromID(*iter); 364 content::RenderProcessHost::FromID(*iter);
353 if (host) 365 if (host) {
354 host->Send(new WebCacheMsg_ClearCache(occasion == ON_NAVIGATION)); 366 const WebCacheServicePtr& service = web_cache_services_[*iter];
367 DCHECK(service.get());
368 service->ClearCache(occasion == ON_NAVIGATION);
369 }
355 } 370 }
356 } 371 }
357 372
358 void WebCacheManager::ReviseAllocationStrategy() { 373 void WebCacheManager::ReviseAllocationStrategy() {
359 DCHECK(stats_.size() <= 374 DCHECK(stats_.size() <=
360 active_renderers_.size() + inactive_renderers_.size()); 375 active_renderers_.size() + inactive_renderers_.size());
361 376
362 // Check if renderers have gone inactive. 377 // Check if renderers have gone inactive.
363 FindInactiveRenderers(); 378 FindInactiveRenderers();
364 379
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 inactive_renderers_.insert(*iter); 468 inactive_renderers_.insert(*iter);
454 active_renderers_.erase(*iter); 469 active_renderers_.erase(*iter);
455 iter = active_renderers_.begin(); 470 iter = active_renderers_.begin();
456 continue; 471 continue;
457 } 472 }
458 ++iter; 473 ++iter;
459 } 474 }
460 } 475 }
461 476
462 } // namespace web_cache 477 } // namespace web_cache
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698