Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(718)

Side by Side Diff: components/web_cache/renderer/web_cache_render_process_observer.cc

Issue 1706603004: Replace web_cache_messages.h with Mojo service. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed Ken's comments Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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; 15 using blink::WebCache;
14 16
15 namespace web_cache { 17 namespace web_cache {
16 18
17 namespace { 19 namespace {
18 const size_t kUnitializedCacheCapacity = UINT_MAX; 20 const size_t kUnitializedCacheCapacity = UINT_MAX;
19 } 21 }
20 22
21 WebCacheRenderProcessObserver::WebCacheRenderProcessObserver() 23 WebCacheRenderProcessObserver::WebCacheRenderProcessObserver()
22 : clear_cache_pending_(false), 24 : clear_cache_pending_(false),
23 webkit_initialized_(false), 25 webkit_initialized_(false),
24 pending_cache_min_dead_capacity_(0), 26 pending_cache_min_dead_capacity_(0),
25 pending_cache_max_dead_capacity_(0), 27 pending_cache_max_dead_capacity_(0),
26 pending_cache_capacity_(kUnitializedCacheCapacity) { 28 pending_cache_capacity_(kUnitializedCacheCapacity) {
29 content::ServiceRegistry* service_registry =
30 content::RenderThread::Get()->GetServiceRegistry();
31 if (service_registry) {
32 service_registry->AddService<WebCacheService>(base::Bind(
33 &WebCacheRenderProcessObserver::BindRequest, base::Unretained(this)));
34 }
27 } 35 }
28 36
29 WebCacheRenderProcessObserver::~WebCacheRenderProcessObserver() { 37 WebCacheRenderProcessObserver::~WebCacheRenderProcessObserver() {
30 } 38 }
31 39
40 void WebCacheRenderProcessObserver::BindRequest(
41 mojo::InterfaceRequest<WebCacheService> web_cache_request) {
42 bindings_.AddBinding(this, std::move(web_cache_request));
43 }
44
32 void WebCacheRenderProcessObserver::ExecutePendingClearCache() { 45 void WebCacheRenderProcessObserver::ExecutePendingClearCache() {
33 if (clear_cache_pending_ && webkit_initialized_) { 46 if (clear_cache_pending_ && webkit_initialized_) {
34 clear_cache_pending_ = false; 47 clear_cache_pending_ = false;
35 WebCache::clear(); 48 WebCache::clear();
36 } 49 }
37 } 50 }
38 51
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() { 52 void WebCacheRenderProcessObserver::WebKitInitialized() {
51 webkit_initialized_ = true; 53 webkit_initialized_ = true;
52 if (pending_cache_capacity_ != kUnitializedCacheCapacity) { 54 if (pending_cache_capacity_ != kUnitializedCacheCapacity) {
53 WebCache::setCapacities(pending_cache_min_dead_capacity_, 55 WebCache::setCapacities(pending_cache_min_dead_capacity_,
54 pending_cache_max_dead_capacity_, 56 pending_cache_max_dead_capacity_,
55 pending_cache_capacity_); 57 pending_cache_capacity_);
56 } 58 }
57 } 59 }
58 60
59 void WebCacheRenderProcessObserver::OnRenderProcessShutdown() { 61 void WebCacheRenderProcessObserver::OnRenderProcessShutdown() {
60 webkit_initialized_ = false; 62 webkit_initialized_ = false;
61 } 63 }
62 64
63 void WebCacheRenderProcessObserver::OnSetCacheCapacities( 65 void WebCacheRenderProcessObserver::SetCacheCapacities(
64 uint64_t min_dead_capacity, 66 uint64_t min_dead_capacity,
65 uint64_t max_dead_capacity, 67 uint64_t max_dead_capacity,
66 uint64_t capacity64) { 68 uint64_t capacity64) {
67 size_t min_dead_capacity2 = base::checked_cast<size_t>(min_dead_capacity); 69 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); 70 size_t max_dead_capacity2 = base::checked_cast<size_t>(max_dead_capacity);
69 size_t capacity = base::checked_cast<size_t>(capacity64); 71 size_t capacity = base::checked_cast<size_t>(capacity64);
72
70 if (!webkit_initialized_) { 73 if (!webkit_initialized_) {
71 pending_cache_min_dead_capacity_ = min_dead_capacity2; 74 pending_cache_min_dead_capacity_ = min_dead_capacity2;
72 pending_cache_max_dead_capacity_ = max_dead_capacity2; 75 pending_cache_max_dead_capacity_ = max_dead_capacity2;
73 pending_cache_capacity_ = capacity; 76 pending_cache_capacity_ = capacity;
74 return; 77 return;
75 } 78 }
76 79
77 WebCache::setCapacities( 80 WebCache::setCapacities(
78 min_dead_capacity2, max_dead_capacity2, capacity); 81 min_dead_capacity2, max_dead_capacity2, capacity);
79 } 82 }
80 83
81 void WebCacheRenderProcessObserver::OnClearCache(bool on_navigation) { 84 void WebCacheRenderProcessObserver::ClearCache(bool on_navigation) {
82 if (on_navigation || !webkit_initialized_) 85 if (on_navigation || !webkit_initialized_)
83 clear_cache_pending_ = true; 86 clear_cache_pending_ = true;
84 else 87 else
85 WebCache::clear(); 88 WebCache::clear();
86 } 89 }
87 90
88 } // namespace web_cache 91 } // namespace web_cache
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698