Switch global error menu icon to vectorized MD asset
[chromium-blink-merge.git] / components / web_cache / renderer / web_cache_render_process_observer.cc
blobc57325b1746f26e8479268337cb46a92c095babe
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "components/web_cache/renderer/web_cache_render_process_observer.h"
7 #include <limits>
9 #include "base/thread_task_runner_handle.h"
10 #include "base/trace_event/memory_dump_manager.h"
11 #include "components/web_cache/common/web_cache_messages.h"
12 #include "components/web_cache/renderer/web_cache_memory_dump_provider.h"
13 #include "third_party/WebKit/public/web/WebCache.h"
15 using blink::WebCache;
17 namespace web_cache {
19 namespace {
20 const size_t kUnitializedCacheCapacity = UINT_MAX;
23 WebCacheRenderProcessObserver::WebCacheRenderProcessObserver()
24 : clear_cache_pending_(false),
25 webkit_initialized_(false),
26 pending_cache_min_dead_capacity_(0),
27 pending_cache_max_dead_capacity_(0),
28 pending_cache_capacity_(kUnitializedCacheCapacity) {
31 WebCacheRenderProcessObserver::~WebCacheRenderProcessObserver() {
34 void WebCacheRenderProcessObserver::ExecutePendingClearCache() {
35 if (clear_cache_pending_ && webkit_initialized_) {
36 clear_cache_pending_ = false;
37 WebCache::clear();
41 bool WebCacheRenderProcessObserver::OnControlMessageReceived(
42 const IPC::Message& message) {
43 bool handled = true;
44 IPC_BEGIN_MESSAGE_MAP(WebCacheRenderProcessObserver, message)
45 IPC_MESSAGE_HANDLER(WebCacheMsg_SetCacheCapacities, OnSetCacheCapacities)
46 IPC_MESSAGE_HANDLER(WebCacheMsg_ClearCache, OnClearCache)
47 IPC_MESSAGE_UNHANDLED(handled = false)
48 IPC_END_MESSAGE_MAP()
49 return handled;
52 void WebCacheRenderProcessObserver::WebKitInitialized() {
53 webkit_initialized_ = true;
54 if (pending_cache_capacity_ != kUnitializedCacheCapacity) {
55 WebCache::setCapacities(pending_cache_min_dead_capacity_,
56 pending_cache_max_dead_capacity_,
57 pending_cache_capacity_);
60 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider(
61 web_cache::WebCacheMemoryDumpProvider::GetInstance(),
62 base::ThreadTaskRunnerHandle::Get());
65 void WebCacheRenderProcessObserver::OnRenderProcessShutdown() {
66 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider(
67 web_cache::WebCacheMemoryDumpProvider::GetInstance());
68 webkit_initialized_ = false;
71 void WebCacheRenderProcessObserver::OnSetCacheCapacities(
72 size_t min_dead_capacity,
73 size_t max_dead_capacity,
74 size_t capacity) {
75 if (!webkit_initialized_) {
76 pending_cache_min_dead_capacity_ = min_dead_capacity;
77 pending_cache_max_dead_capacity_ = max_dead_capacity;
78 pending_cache_capacity_ = capacity;
79 return;
82 WebCache::setCapacities(
83 min_dead_capacity, max_dead_capacity, capacity);
86 void WebCacheRenderProcessObserver::OnClearCache(bool on_navigation) {
87 if (on_navigation || !webkit_initialized_)
88 clear_cache_pending_ = true;
89 else
90 WebCache::clear();
93 } // namespace web_cache