Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | |
|
James Cook
2014/09/05 16:53:18
nit: no (c)
Xi Han
2014/09/05 19:39:25
Removed.
| |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "components/web_cache/renderer/web_cache_render_process_observer.h" | |
| 6 | |
| 7 #include <limits> | |
| 8 | |
| 9 #include "components/web_cache/common/web_cache_messages.h" | |
| 10 #include "third_party/WebKit/public/web/WebCache.h" | |
| 11 | |
| 12 using blink::WebCache; | |
|
James Cook
2014/09/05 16:53:18
I like "using" declarations. :-)
Xi Han
2014/09/05 19:39:25
Me too:)
| |
| 13 | |
| 14 namespace web_cache { | |
| 15 | |
| 16 const size_t kUnitializedCacheCapacity = UINT_MAX; | |
|
James Cook
2014/09/05 16:53:18
wrap in namespace { }, it helps the linker, also "
Xi Han
2014/09/05 19:39:25
Added.
| |
| 17 | |
| 18 WebCacheRenderProcessObserver::WebCacheRenderProcessObserver() | |
| 19 : clear_cache_pending_(false), | |
| 20 webkit_initialized_(false), | |
| 21 pending_cache_min_dead_capacity_(0), | |
| 22 pending_cache_max_dead_capacity_(0), | |
| 23 pending_cache_capacity_(kUnitializedCacheCapacity) { | |
| 24 } | |
| 25 | |
| 26 WebCacheRenderProcessObserver::~WebCacheRenderProcessObserver() { | |
| 27 } | |
| 28 | |
| 29 void WebCacheRenderProcessObserver::ExecutePendingClearCache() { | |
| 30 if (clear_cache_pending_ && webkit_initialized_) { | |
| 31 clear_cache_pending_ = false; | |
| 32 WebCache::clear(); | |
| 33 } | |
| 34 } | |
| 35 | |
| 36 bool WebCacheRenderProcessObserver::OnControlMessageReceived( | |
| 37 const IPC::Message& message) { | |
| 38 bool handled = true; | |
| 39 IPC_BEGIN_MESSAGE_MAP(WebCacheRenderProcessObserver, message) | |
| 40 IPC_MESSAGE_HANDLER(WebCacheMsg_SetCacheCapacities, OnSetCacheCapacities) | |
| 41 IPC_MESSAGE_HANDLER(WebCacheMsg_ClearCache, OnClearCache) | |
| 42 IPC_MESSAGE_UNHANDLED(handled = false) | |
| 43 IPC_END_MESSAGE_MAP() | |
| 44 return handled; | |
| 45 } | |
| 46 | |
| 47 void WebCacheRenderProcessObserver::WebKitInitialized() { | |
| 48 webkit_initialized_ = true; | |
| 49 if (pending_cache_capacity_ != kUnitializedCacheCapacity) { | |
| 50 WebCache::setCapacities(pending_cache_min_dead_capacity_, | |
| 51 pending_cache_max_dead_capacity_, | |
| 52 pending_cache_capacity_); | |
| 53 } | |
| 54 } | |
| 55 | |
| 56 void WebCacheRenderProcessObserver::OnRenderProcessShutdown() { | |
| 57 webkit_initialized_ = false; | |
| 58 } | |
| 59 | |
| 60 void WebCacheRenderProcessObserver::OnSetCacheCapacities( | |
| 61 size_t min_dead_capacity, | |
| 62 size_t max_dead_capacity, | |
| 63 size_t capacity) { | |
| 64 if (!webkit_initialized_) { | |
| 65 pending_cache_min_dead_capacity_ = min_dead_capacity; | |
| 66 pending_cache_max_dead_capacity_ = max_dead_capacity; | |
| 67 pending_cache_capacity_ = capacity; | |
| 68 return; | |
| 69 } | |
| 70 | |
| 71 WebCache::setCapacities( | |
| 72 min_dead_capacity, max_dead_capacity, capacity); | |
| 73 } | |
| 74 | |
| 75 void WebCacheRenderProcessObserver::OnClearCache(bool on_navigation) { | |
| 76 if (on_navigation || !webkit_initialized_) { | |
| 77 clear_cache_pending_ = true; | |
| 78 } else { | |
| 79 WebCache::clear(); | |
| 80 } | |
| 81 } | |
| 82 | |
| 83 } // namespace web_cache | |
| OLD | NEW |