| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/renderer/render_thread_impl.h" | 5 #include "content/renderer/render_thread_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 #include <map> | 9 #include <map> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 1760 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1771 ChildThreadImpl::OnProcessPurgeAndSuspend(); | 1771 ChildThreadImpl::OnProcessPurgeAndSuspend(); |
| 1772 DCHECK(!is_renderer_suspended_); | 1772 DCHECK(!is_renderer_suspended_); |
| 1773 if (!RendererIsHidden()) | 1773 if (!RendererIsHidden()) |
| 1774 return; | 1774 return; |
| 1775 is_renderer_suspended_ = true; | 1775 is_renderer_suspended_ = true; |
| 1776 if (base::FeatureList::IsEnabled(features::kPurgeAndSuspend)) { | 1776 if (base::FeatureList::IsEnabled(features::kPurgeAndSuspend)) { |
| 1777 // TODO(tasak): After enabling MemoryCoordinator, remove this Notify | 1777 // TODO(tasak): After enabling MemoryCoordinator, remove this Notify |
| 1778 // and follow MemoryCoordinator's request. | 1778 // and follow MemoryCoordinator's request. |
| 1779 base::MemoryCoordinatorClientRegistry::GetInstance()->Notify( | 1779 base::MemoryCoordinatorClientRegistry::GetInstance()->Notify( |
| 1780 base::MemoryState::SUSPENDED); | 1780 base::MemoryState::SUSPENDED); |
| 1781 renderer_scheduler_->SuspendRenderer(); | |
| 1782 } | 1781 } |
| 1783 | |
| 1784 // Since purging is not a synchronous task (e.g. v8 GC, oilpan GC, ...), | 1782 // Since purging is not a synchronous task (e.g. v8 GC, oilpan GC, ...), |
| 1785 // we need to wait until the task is finished. So wait 15 seconds and | 1783 // we need to wait until the task is finished. So wait 15 seconds and |
| 1786 // update purge+suspend UMA histogram. | 1784 // update purge+suspend UMA histogram. |
| 1787 // TODO(tasak): use MemoryCoordinator's callback to report purge+suspend | 1785 // TODO(tasak): use MemoryCoordinator's callback to report purge+suspend |
| 1788 // UMA when MemoryCoordinator is available. | 1786 // UMA when MemoryCoordinator is available. |
| 1789 GetRendererScheduler()->DefaultTaskRunner()->PostDelayedTask( | 1787 GetRendererScheduler()->DefaultTaskRunner()->PostDelayedTask( |
| 1790 FROM_HERE, record_purge_suspend_metric_closure_.callback(), | 1788 FROM_HERE, record_purge_suspend_metric_closure_.callback(), |
| 1791 base::TimeDelta::FromSeconds(15)); | 1789 base::TimeDelta::FromSeconds(15)); |
| 1792 } | 1790 } |
| 1793 | 1791 |
| (...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2282 blink::WebMemoryCoordinator::onMemoryStateChange( | 2280 blink::WebMemoryCoordinator::onMemoryStateChange( |
| 2283 static_cast<blink::MemoryState>(state)); | 2281 static_cast<blink::MemoryState>(state)); |
| 2284 } | 2282 } |
| 2285 switch (state) { | 2283 switch (state) { |
| 2286 case base::MemoryState::NORMAL: | 2284 case base::MemoryState::NORMAL: |
| 2287 break; | 2285 break; |
| 2288 case base::MemoryState::THROTTLED: | 2286 case base::MemoryState::THROTTLED: |
| 2289 ReleaseFreeMemory(); | 2287 ReleaseFreeMemory(); |
| 2290 break; | 2288 break; |
| 2291 case base::MemoryState::SUSPENDED: | 2289 case base::MemoryState::SUSPENDED: |
| 2292 OnTrimMemoryImmediately(); | 2290 SuspendRenderer(); |
| 2293 ReleaseFreeMemory(); | |
| 2294 ClearMemory(); | |
| 2295 break; | 2291 break; |
| 2296 case base::MemoryState::UNKNOWN: | 2292 case base::MemoryState::UNKNOWN: |
| 2297 NOTREACHED(); | 2293 NOTREACHED(); |
| 2298 break; | 2294 break; |
| 2299 } | 2295 } |
| 2300 } | 2296 } |
| 2301 | 2297 |
| 2298 void RenderThreadImpl::SuspendRenderer() { |
| 2299 OnTrimMemoryImmediately(); |
| 2300 ReleaseFreeMemory(); |
| 2301 ClearMemory(); |
| 2302 renderer_scheduler_->SuspendRenderer(); |
| 2303 } |
| 2304 |
| 2302 void RenderThreadImpl::ClearMemory() { | 2305 void RenderThreadImpl::ClearMemory() { |
| 2303 // Do not call into blink if it is not initialized. | 2306 // Do not call into blink if it is not initialized. |
| 2304 if (blink_platform_impl_) { | 2307 if (blink_platform_impl_) { |
| 2305 // Purge Skia font cache, by setting it to 0 and then again to the | 2308 // Purge Skia font cache, by setting it to 0 and then again to the |
| 2306 // previous limit. | 2309 // previous limit. |
| 2307 size_t font_cache_limit = SkGraphics::SetFontCacheLimit(0); | 2310 size_t font_cache_limit = SkGraphics::SetFontCacheLimit(0); |
| 2308 SkGraphics::SetFontCacheLimit(font_cache_limit); | 2311 SkGraphics::SetFontCacheLimit(font_cache_limit); |
| 2309 } | 2312 } |
| 2310 } | 2313 } |
| 2311 | 2314 |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2489 } | 2492 } |
| 2490 } | 2493 } |
| 2491 | 2494 |
| 2492 void RenderThreadImpl::OnRendererInterfaceRequest( | 2495 void RenderThreadImpl::OnRendererInterfaceRequest( |
| 2493 mojom::RendererAssociatedRequest request) { | 2496 mojom::RendererAssociatedRequest request) { |
| 2494 DCHECK(!renderer_binding_.is_bound()); | 2497 DCHECK(!renderer_binding_.is_bound()); |
| 2495 renderer_binding_.Bind(std::move(request)); | 2498 renderer_binding_.Bind(std::move(request)); |
| 2496 } | 2499 } |
| 2497 | 2500 |
| 2498 } // namespace content | 2501 } // namespace content |
| OLD | NEW |