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