Chromium Code Reviews| 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 1740 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1751 | 1751 |
| 1752 if (backgrounded) { | 1752 if (backgrounded) { |
| 1753 renderer_scheduler_->OnRendererBackgrounded(); | 1753 renderer_scheduler_->OnRendererBackgrounded(); |
| 1754 } else { | 1754 } else { |
| 1755 renderer_scheduler_->OnRendererForegrounded(); | 1755 renderer_scheduler_->OnRendererForegrounded(); |
| 1756 // TODO(tasak): after enabling MemoryCoordinator, remove this Notify | 1756 // TODO(tasak): after enabling MemoryCoordinator, remove this Notify |
| 1757 // and follow MemoryCoordinator's request. | 1757 // and follow MemoryCoordinator's request. |
| 1758 if (base::FeatureList::IsEnabled(features::kPurgeAndSuspend)) | 1758 if (base::FeatureList::IsEnabled(features::kPurgeAndSuspend)) |
| 1759 base::MemoryCoordinatorClientRegistry::GetInstance()->Notify( | 1759 base::MemoryCoordinatorClientRegistry::GetInstance()->Notify( |
| 1760 base::MemoryState::NORMAL); | 1760 base::MemoryState::NORMAL); |
| 1761 | |
| 1762 record_purge_suspend_metric_closure_.Cancel(); | |
| 1763 record_purge_suspend_metric_closure_.Reset( | |
| 1764 base::Bind(&RenderThreadImpl::RecordPurgeAndSuspendMetrics, | |
| 1765 base::Unretained(this))); | |
| 1766 is_renderer_suspended_ = false; | |
| 1767 } | 1761 } |
| 1768 } | 1762 } |
| 1769 | 1763 |
| 1770 void RenderThreadImpl::OnProcessPurgeAndSuspend() { | 1764 void RenderThreadImpl::OnProcessPurgeAndSuspend() { |
| 1771 ChildThreadImpl::OnProcessPurgeAndSuspend(); | 1765 ChildThreadImpl::OnProcessPurgeAndSuspend(); |
| 1772 DCHECK(!is_renderer_suspended_); | 1766 DCHECK(!is_renderer_suspended_); |
| 1773 if (!RendererIsHidden()) | 1767 if (!RendererIsHidden()) |
| 1774 return; | 1768 return; |
| 1775 is_renderer_suspended_ = true; | 1769 is_renderer_suspended_ = true; |
| 1776 if (base::FeatureList::IsEnabled(features::kPurgeAndSuspend)) { | 1770 if (base::FeatureList::IsEnabled(features::kPurgeAndSuspend)) { |
| 1777 // TODO(tasak): After enabling MemoryCoordinator, remove this Notify | 1771 // TODO(tasak): After enabling MemoryCoordinator, remove this Notify |
| 1778 // and follow MemoryCoordinator's request. | 1772 // and follow MemoryCoordinator's request. |
| 1779 base::MemoryCoordinatorClientRegistry::GetInstance()->Notify( | 1773 base::MemoryCoordinatorClientRegistry::GetInstance()->Notify( |
| 1780 base::MemoryState::SUSPENDED); | 1774 base::MemoryState::SUSPENDED); |
| 1781 renderer_scheduler_->SuspendRenderer(); | |
| 1782 } | 1775 } |
|
bashi
2016/11/24 07:46:54
ah, Maybe I should add else clause and PostDelayed
bashi
2016/11/24 08:18:50
Chatted offline. We shouldn't record metrics when
| |
| 1783 | |
| 1784 // 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 | |
| 1786 // update purge+suspend UMA histogram. | |
| 1787 // TODO(tasak): use MemoryCoordinator's callback to report purge+suspend | |
| 1788 // UMA when MemoryCoordinator is available. | |
| 1789 GetRendererScheduler()->DefaultTaskRunner()->PostDelayedTask( | |
| 1790 FROM_HERE, record_purge_suspend_metric_closure_.callback(), | |
| 1791 base::TimeDelta::FromSeconds(15)); | |
| 1792 } | 1776 } |
| 1793 | 1777 |
| 1794 // TODO(tasak): Replace the following GetMallocUsage() with memory-infra | 1778 // TODO(tasak): Replace the following GetMallocUsage() with memory-infra |
| 1795 // when it is possible to run memory-infra without tracing. | 1779 // when it is possible to run memory-infra without tracing. |
| 1796 #if defined(OS_WIN) | 1780 #if defined(OS_WIN) |
| 1797 namespace { | 1781 namespace { |
| 1798 | 1782 |
| 1799 static size_t GetMallocUsage() { | 1783 static size_t GetMallocUsage() { |
| 1800 DWORD number_of_heaps = ::GetProcessHeaps(0, NULL); | 1784 DWORD number_of_heaps = ::GetProcessHeaps(0, NULL); |
| 1801 if (number_of_heaps <= 0) | 1785 if (number_of_heaps <= 0) |
| (...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2277 void RenderThreadImpl::OnMemoryStateChange(base::MemoryState state) { | 2261 void RenderThreadImpl::OnMemoryStateChange(base::MemoryState state) { |
| 2278 // TODO(hajimehoshi): Adjust the size of this memory usage according to | 2262 // TODO(hajimehoshi): Adjust the size of this memory usage according to |
| 2279 // |state|. RenderThreadImpl doesn't have a feature to limit memory usage at | 2263 // |state|. RenderThreadImpl doesn't have a feature to limit memory usage at |
| 2280 // present. | 2264 // present. |
| 2281 if (blink_platform_impl_) { | 2265 if (blink_platform_impl_) { |
| 2282 blink::WebMemoryCoordinator::onMemoryStateChange( | 2266 blink::WebMemoryCoordinator::onMemoryStateChange( |
| 2283 static_cast<blink::MemoryState>(state)); | 2267 static_cast<blink::MemoryState>(state)); |
| 2284 } | 2268 } |
| 2285 switch (state) { | 2269 switch (state) { |
| 2286 case base::MemoryState::NORMAL: | 2270 case base::MemoryState::NORMAL: |
| 2271 record_purge_suspend_metric_closure_.Cancel(); | |
| 2272 record_purge_suspend_metric_closure_.Reset( | |
| 2273 base::Bind(&RenderThreadImpl::RecordPurgeAndSuspendMetrics, | |
| 2274 base::Unretained(this))); | |
| 2275 is_renderer_suspended_ = false; | |
| 2287 break; | 2276 break; |
| 2288 case base::MemoryState::THROTTLED: | 2277 case base::MemoryState::THROTTLED: |
| 2289 ReleaseFreeMemory(); | 2278 ReleaseFreeMemory(); |
| 2290 break; | 2279 break; |
| 2291 case base::MemoryState::SUSPENDED: | 2280 case base::MemoryState::SUSPENDED: |
| 2292 OnTrimMemoryImmediately(); | 2281 SuspendRenderer(); |
| 2293 ReleaseFreeMemory(); | |
| 2294 ClearMemory(); | |
| 2295 break; | 2282 break; |
| 2296 case base::MemoryState::UNKNOWN: | 2283 case base::MemoryState::UNKNOWN: |
| 2297 NOTREACHED(); | 2284 NOTREACHED(); |
| 2298 break; | 2285 break; |
| 2299 } | 2286 } |
| 2300 } | 2287 } |
| 2301 | 2288 |
| 2289 void RenderThreadImpl::SuspendRenderer() { | |
| 2290 OnTrimMemoryImmediately(); | |
| 2291 ReleaseFreeMemory(); | |
| 2292 ClearMemory(); | |
| 2293 renderer_scheduler_->SuspendRenderer(); | |
| 2294 // Since purging is not a synchronous task (e.g. v8 GC, oilpan GC, ...), | |
| 2295 // we need to wait until the task is finished. So wait 15 seconds and | |
| 2296 // update purge+suspend UMA histogram. | |
| 2297 // TODO(tasak): use MemoryCoordinator's callback to report purge+suspend | |
| 2298 // UMA when MemoryCoordinator is available. | |
| 2299 GetRendererScheduler()->DefaultTaskRunner()->PostDelayedTask( | |
| 2300 FROM_HERE, record_purge_suspend_metric_closure_.callback(), | |
| 2301 base::TimeDelta::FromSeconds(15)); | |
| 2302 } | |
| 2303 | |
| 2302 void RenderThreadImpl::ClearMemory() { | 2304 void RenderThreadImpl::ClearMemory() { |
| 2303 // Do not call into blink if it is not initialized. | 2305 // Do not call into blink if it is not initialized. |
| 2304 if (blink_platform_impl_) { | 2306 if (blink_platform_impl_) { |
| 2305 // Purge Skia font cache, by setting it to 0 and then again to the | 2307 // Purge Skia font cache, by setting it to 0 and then again to the |
| 2306 // previous limit. | 2308 // previous limit. |
| 2307 size_t font_cache_limit = SkGraphics::SetFontCacheLimit(0); | 2309 size_t font_cache_limit = SkGraphics::SetFontCacheLimit(0); |
| 2308 SkGraphics::SetFontCacheLimit(font_cache_limit); | 2310 SkGraphics::SetFontCacheLimit(font_cache_limit); |
| 2309 } | 2311 } |
| 2310 } | 2312 } |
| 2311 | 2313 |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2489 } | 2491 } |
| 2490 } | 2492 } |
| 2491 | 2493 |
| 2492 void RenderThreadImpl::OnRendererInterfaceRequest( | 2494 void RenderThreadImpl::OnRendererInterfaceRequest( |
| 2493 mojom::RendererAssociatedRequest request) { | 2495 mojom::RendererAssociatedRequest request) { |
| 2494 DCHECK(!renderer_binding_.is_bound()); | 2496 DCHECK(!renderer_binding_.is_bound()); |
| 2495 renderer_binding_.Bind(std::move(request)); | 2497 renderer_binding_.Bind(std::move(request)); |
| 2496 } | 2498 } |
| 2497 | 2499 |
| 2498 } // namespace content | 2500 } // namespace content |
| OLD | NEW |