OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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/renderer/web_cache_render_process_observer.h" | 5 #include "components/web_cache/renderer/web_cache_render_process_observer.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 | 8 |
| 9 #include "base/bind.h" |
9 #include "base/numerics/safe_conversions.h" | 10 #include "base/numerics/safe_conversions.h" |
10 #include "components/web_cache/common/web_cache_messages.h" | 11 #include "content/public/common/service_registry.h" |
| 12 #include "content/public/renderer/render_thread.h" |
11 #include "third_party/WebKit/public/web/WebCache.h" | 13 #include "third_party/WebKit/public/web/WebCache.h" |
12 | 14 |
13 using blink::WebCache; | |
14 | |
15 namespace web_cache { | 15 namespace web_cache { |
16 | 16 |
17 namespace { | 17 namespace { |
18 const size_t kUnitializedCacheCapacity = UINT_MAX; | 18 const size_t kUnitializedCacheCapacity = UINT_MAX; |
19 } | 19 } |
20 | 20 |
21 WebCacheRenderProcessObserver::WebCacheRenderProcessObserver() | 21 WebCacheRenderProcessObserver::WebCacheRenderProcessObserver() |
22 : clear_cache_pending_(false), | 22 : clear_cache_pending_(false), |
23 webkit_initialized_(false), | 23 webkit_initialized_(false), |
24 pending_cache_min_dead_capacity_(0), | 24 pending_cache_min_dead_capacity_(0), |
25 pending_cache_max_dead_capacity_(0), | 25 pending_cache_max_dead_capacity_(0), |
26 pending_cache_capacity_(kUnitializedCacheCapacity) { | 26 pending_cache_capacity_(kUnitializedCacheCapacity) { |
| 27 content::ServiceRegistry* service_registry = |
| 28 content::RenderThread::Get()->GetServiceRegistry(); |
| 29 if (service_registry) { |
| 30 service_registry->AddService(base::Bind( |
| 31 &WebCacheRenderProcessObserver::BindRequest, base::Unretained(this))); |
| 32 } |
27 } | 33 } |
28 | 34 |
29 WebCacheRenderProcessObserver::~WebCacheRenderProcessObserver() { | 35 WebCacheRenderProcessObserver::~WebCacheRenderProcessObserver() { |
30 } | 36 } |
31 | 37 |
| 38 void WebCacheRenderProcessObserver::BindRequest( |
| 39 mojo::InterfaceRequest<mojom::WebCache> web_cache_request) { |
| 40 bindings_.AddBinding(this, std::move(web_cache_request)); |
| 41 } |
| 42 |
32 void WebCacheRenderProcessObserver::ExecutePendingClearCache() { | 43 void WebCacheRenderProcessObserver::ExecutePendingClearCache() { |
33 if (clear_cache_pending_ && webkit_initialized_) { | 44 if (clear_cache_pending_ && webkit_initialized_) { |
34 clear_cache_pending_ = false; | 45 clear_cache_pending_ = false; |
35 WebCache::clear(); | 46 blink::WebCache::clear(); |
36 } | 47 } |
37 } | 48 } |
38 | 49 |
39 bool WebCacheRenderProcessObserver::OnControlMessageReceived( | |
40 const IPC::Message& message) { | |
41 bool handled = true; | |
42 IPC_BEGIN_MESSAGE_MAP(WebCacheRenderProcessObserver, message) | |
43 IPC_MESSAGE_HANDLER(WebCacheMsg_SetCacheCapacities, OnSetCacheCapacities) | |
44 IPC_MESSAGE_HANDLER(WebCacheMsg_ClearCache, OnClearCache) | |
45 IPC_MESSAGE_UNHANDLED(handled = false) | |
46 IPC_END_MESSAGE_MAP() | |
47 return handled; | |
48 } | |
49 | |
50 void WebCacheRenderProcessObserver::WebKitInitialized() { | 50 void WebCacheRenderProcessObserver::WebKitInitialized() { |
51 webkit_initialized_ = true; | 51 webkit_initialized_ = true; |
52 if (pending_cache_capacity_ != kUnitializedCacheCapacity) { | 52 if (pending_cache_capacity_ != kUnitializedCacheCapacity) { |
53 WebCache::setCapacities(pending_cache_min_dead_capacity_, | 53 blink::WebCache::setCapacities(pending_cache_min_dead_capacity_, |
54 pending_cache_max_dead_capacity_, | 54 pending_cache_max_dead_capacity_, |
55 pending_cache_capacity_); | 55 pending_cache_capacity_); |
56 } | 56 } |
57 } | 57 } |
58 | 58 |
59 void WebCacheRenderProcessObserver::OnRenderProcessShutdown() { | 59 void WebCacheRenderProcessObserver::OnRenderProcessShutdown() { |
60 webkit_initialized_ = false; | 60 webkit_initialized_ = false; |
61 } | 61 } |
62 | 62 |
63 void WebCacheRenderProcessObserver::OnSetCacheCapacities( | 63 void WebCacheRenderProcessObserver::SetCacheCapacities( |
64 uint64_t min_dead_capacity, | 64 uint64_t min_dead_capacity, |
65 uint64_t max_dead_capacity, | 65 uint64_t max_dead_capacity, |
66 uint64_t capacity64) { | 66 uint64_t capacity64) { |
67 size_t min_dead_capacity2 = base::checked_cast<size_t>(min_dead_capacity); | 67 size_t min_dead_capacity2 = base::checked_cast<size_t>(min_dead_capacity); |
68 size_t max_dead_capacity2 = base::checked_cast<size_t>(max_dead_capacity); | 68 size_t max_dead_capacity2 = base::checked_cast<size_t>(max_dead_capacity); |
69 size_t capacity = base::checked_cast<size_t>(capacity64); | 69 size_t capacity = base::checked_cast<size_t>(capacity64); |
| 70 |
70 if (!webkit_initialized_) { | 71 if (!webkit_initialized_) { |
71 pending_cache_min_dead_capacity_ = min_dead_capacity2; | 72 pending_cache_min_dead_capacity_ = min_dead_capacity2; |
72 pending_cache_max_dead_capacity_ = max_dead_capacity2; | 73 pending_cache_max_dead_capacity_ = max_dead_capacity2; |
73 pending_cache_capacity_ = capacity; | 74 pending_cache_capacity_ = capacity; |
74 return; | 75 return; |
75 } | 76 } |
76 | 77 |
77 WebCache::setCapacities( | 78 blink::WebCache::setCapacities(min_dead_capacity2, max_dead_capacity2, |
78 min_dead_capacity2, max_dead_capacity2, capacity); | 79 capacity); |
79 } | 80 } |
80 | 81 |
81 void WebCacheRenderProcessObserver::OnClearCache(bool on_navigation) { | 82 void WebCacheRenderProcessObserver::ClearCache(bool on_navigation) { |
82 if (on_navigation || !webkit_initialized_) | 83 if (on_navigation || !webkit_initialized_) |
83 clear_cache_pending_ = true; | 84 clear_cache_pending_ = true; |
84 else | 85 else |
85 WebCache::clear(); | 86 blink::WebCache::clear(); |
86 } | 87 } |
87 | 88 |
88 } // namespace web_cache | 89 } // namespace web_cache |
OLD | NEW |