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"
9 #include "components/web_cache/common/web_cache_messages.h"
10 #include "third_party/WebKit/public/web/WebCache.h"
12 using blink::WebCache
;
17 const size_t kUnitializedCacheCapacity
= UINT_MAX
;
20 WebCacheRenderProcessObserver::WebCacheRenderProcessObserver()
21 : clear_cache_pending_(false),
22 webkit_initialized_(false),
23 pending_cache_min_dead_capacity_(0),
24 pending_cache_max_dead_capacity_(0),
25 pending_cache_capacity_(kUnitializedCacheCapacity
) {
28 WebCacheRenderProcessObserver::~WebCacheRenderProcessObserver() {
31 void WebCacheRenderProcessObserver::ExecutePendingClearCache() {
32 if (clear_cache_pending_
&& webkit_initialized_
) {
33 clear_cache_pending_
= false;
38 bool WebCacheRenderProcessObserver::OnControlMessageReceived(
39 const IPC::Message
& message
) {
41 IPC_BEGIN_MESSAGE_MAP(WebCacheRenderProcessObserver
, message
)
42 IPC_MESSAGE_HANDLER(WebCacheMsg_SetCacheCapacities
, OnSetCacheCapacities
)
43 IPC_MESSAGE_HANDLER(WebCacheMsg_ClearCache
, OnClearCache
)
44 IPC_MESSAGE_UNHANDLED(handled
= false)
49 void WebCacheRenderProcessObserver::WebKitInitialized() {
50 webkit_initialized_
= true;
51 if (pending_cache_capacity_
!= kUnitializedCacheCapacity
) {
52 WebCache::setCapacities(pending_cache_min_dead_capacity_
,
53 pending_cache_max_dead_capacity_
,
54 pending_cache_capacity_
);
58 void WebCacheRenderProcessObserver::OnRenderProcessShutdown() {
59 webkit_initialized_
= false;
62 void WebCacheRenderProcessObserver::OnSetCacheCapacities(
63 size_t min_dead_capacity
,
64 size_t max_dead_capacity
,
66 if (!webkit_initialized_
) {
67 pending_cache_min_dead_capacity_
= min_dead_capacity
;
68 pending_cache_max_dead_capacity_
= max_dead_capacity
;
69 pending_cache_capacity_
= capacity
;
73 WebCache::setCapacities(
74 min_dead_capacity
, max_dead_capacity
, capacity
);
77 void WebCacheRenderProcessObserver::OnClearCache(bool on_navigation
) {
78 if (on_navigation
|| !webkit_initialized_
)
79 clear_cache_pending_
= true;
84 } // namespace web_cache