Roll src/third_party/WebKit 9f7fb92:f103b33 (svn 202621:202622)
[chromium-blink-merge.git] / components / web_cache / renderer / web_cache_render_process_observer.cc
bloba273817a2c0d957d798930a0a6ad65ddfa1947f1
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 "components/web_cache/common/web_cache_messages.h"
10 #include "third_party/WebKit/public/web/WebCache.h"
12 using blink::WebCache;
14 namespace web_cache {
16 namespace {
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;
34 WebCache::clear();
38 bool WebCacheRenderProcessObserver::OnControlMessageReceived(
39 const IPC::Message& message) {
40 bool handled = true;
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)
45 IPC_END_MESSAGE_MAP()
46 return handled;
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,
65 size_t 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;
70 return;
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;
80 else
81 WebCache::clear();
84 } // namespace web_cache