| 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 797 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 808 media::EnablePlatformDecoderSupport(); | 808 media::EnablePlatformDecoderSupport(); |
| 809 } | 809 } |
| 810 #endif | 810 #endif |
| 811 | 811 |
| 812 memory_pressure_listener_.reset(new base::MemoryPressureListener( | 812 memory_pressure_listener_.reset(new base::MemoryPressureListener( |
| 813 base::Bind(&RenderThreadImpl::OnMemoryPressure, base::Unretained(this)), | 813 base::Bind(&RenderThreadImpl::OnMemoryPressure, base::Unretained(this)), |
| 814 base::Bind(&RenderThreadImpl::OnSyncMemoryPressure, | 814 base::Bind(&RenderThreadImpl::OnSyncMemoryPressure, |
| 815 base::Unretained(this)))); | 815 base::Unretained(this)))); |
| 816 | 816 |
| 817 if (base::FeatureList::IsEnabled(features::kMemoryCoordinator)) { | 817 if (base::FeatureList::IsEnabled(features::kMemoryCoordinator)) { |
| 818 // Currently it is not possible to enable both PurgeAndSuspend and | |
| 819 // MemoryCoordinator at the same time. | |
| 820 DCHECK(!base::FeatureList::IsEnabled(features::kPurgeAndSuspend)); | |
| 821 | |
| 822 // Disable MemoryPressureListener when memory coordinator is enabled. | 818 // Disable MemoryPressureListener when memory coordinator is enabled. |
| 823 base::MemoryPressureListener::SetNotificationsSuppressed(true); | 819 base::MemoryPressureListener::SetNotificationsSuppressed(true); |
| 824 | 820 |
| 825 // TODO(bashi): Revisit how to manage the lifetime of | 821 // TODO(bashi): Revisit how to manage the lifetime of |
| 826 // ChildMemoryCoordinatorImpl. | 822 // ChildMemoryCoordinatorImpl. |
| 827 // https://codereview.chromium.org/2094583002/#msg52 | 823 // https://codereview.chromium.org/2094583002/#msg52 |
| 828 mojom::MemoryCoordinatorHandlePtr parent_coordinator; | 824 mojom::MemoryCoordinatorHandlePtr parent_coordinator; |
| 829 GetRemoteInterfaces()->GetInterface(mojo::MakeRequest(&parent_coordinator)); | 825 GetRemoteInterfaces()->GetInterface(mojo::MakeRequest(&parent_coordinator)); |
| 830 memory_coordinator_ = CreateChildMemoryCoordinator( | 826 memory_coordinator_ = CreateChildMemoryCoordinator( |
| 831 std::move(parent_coordinator), this); | 827 std::move(parent_coordinator), this); |
| (...skipping 795 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1627 } | 1623 } |
| 1628 | 1624 |
| 1629 void RenderThreadImpl::OnProcessBackgrounded(bool backgrounded) { | 1625 void RenderThreadImpl::OnProcessBackgrounded(bool backgrounded) { |
| 1630 ChildThreadImpl::OnProcessBackgrounded(backgrounded); | 1626 ChildThreadImpl::OnProcessBackgrounded(backgrounded); |
| 1631 | 1627 |
| 1632 if (backgrounded) { | 1628 if (backgrounded) { |
| 1633 renderer_scheduler_->OnRendererBackgrounded(); | 1629 renderer_scheduler_->OnRendererBackgrounded(); |
| 1634 needs_to_record_first_active_paint_ = false; | 1630 needs_to_record_first_active_paint_ = false; |
| 1635 } else { | 1631 } else { |
| 1636 renderer_scheduler_->OnRendererForegrounded(); | 1632 renderer_scheduler_->OnRendererForegrounded(); |
| 1637 // TODO(tasak): after enabling MemoryCoordinator, remove this Notify | |
| 1638 // and follow MemoryCoordinator's request. | |
| 1639 if (base::FeatureList::IsEnabled(features::kPurgeAndSuspend)) | |
| 1640 base::MemoryCoordinatorClientRegistry::GetInstance()->Notify( | |
| 1641 base::MemoryState::NORMAL); | |
| 1642 | 1633 |
| 1643 record_purge_suspend_metric_closure_.Cancel(); | 1634 record_purge_suspend_metric_closure_.Cancel(); |
| 1644 record_purge_suspend_metric_closure_.Reset( | 1635 record_purge_suspend_metric_closure_.Reset( |
| 1645 base::Bind(&RenderThreadImpl::RecordPurgeAndSuspendMetrics, | 1636 base::Bind(&RenderThreadImpl::RecordPurgeAndSuspendMetrics, |
| 1646 base::Unretained(this))); | 1637 base::Unretained(this))); |
| 1647 record_purge_suspend_growth_metric_closure_.Cancel(); | 1638 record_purge_suspend_growth_metric_closure_.Cancel(); |
| 1648 record_purge_suspend_growth_metric_closure_.Reset( | 1639 record_purge_suspend_growth_metric_closure_.Reset( |
| 1649 base::Bind(&RenderThreadImpl::RecordPurgeAndSuspendMemoryGrowthMetrics, | 1640 base::Bind(&RenderThreadImpl::RecordPurgeAndSuspendMemoryGrowthMetrics, |
| 1650 base::Unretained(this))); | 1641 base::Unretained(this))); |
| 1651 } | 1642 } |
| 1652 } | 1643 } |
| 1653 | 1644 |
| 1654 void RenderThreadImpl::OnProcessPurgeAndSuspend() { | 1645 void RenderThreadImpl::OnProcessPurgeAndSuspend() { |
| 1655 ChildThreadImpl::OnProcessPurgeAndSuspend(); | 1646 ChildThreadImpl::OnProcessPurgeAndSuspend(); |
| 1656 if (!RendererIsHidden()) | 1647 if (!RendererIsHidden()) |
| 1657 return; | 1648 return; |
| 1658 | 1649 |
| 1659 // TODO(bashi): Enable the tab suspension when MemoryCoordinator is enabled. | |
| 1660 if (base::FeatureList::IsEnabled(features::kMemoryCoordinator)) | |
| 1661 return; | |
| 1662 | |
| 1663 if (base::FeatureList::IsEnabled(features::kPurgeAndSuspend)) { | 1650 if (base::FeatureList::IsEnabled(features::kPurgeAndSuspend)) { |
| 1664 // TODO(tasak): After enabling MemoryCoordinator, remove this Notify | |
| 1665 // and follow MemoryCoordinator's request. | |
| 1666 base::MemoryCoordinatorClientRegistry::GetInstance()->PurgeMemory(); | 1651 base::MemoryCoordinatorClientRegistry::GetInstance()->PurgeMemory(); |
| 1667 } | 1652 } |
| 1668 // Since purging is not a synchronous task (e.g. v8 GC, oilpan GC, ...), | 1653 // Since purging is not a synchronous task (e.g. v8 GC, oilpan GC, ...), |
| 1669 // we need to wait until the task is finished. So wait 15 seconds and | 1654 // we need to wait until the task is finished. So wait 15 seconds and |
| 1670 // update purge+suspend UMA histogram. | 1655 // update purge+suspend UMA histogram. |
| 1671 // TODO(tasak): use MemoryCoordinator's callback to report purge+suspend | 1656 // TODO(tasak): use MemoryCoordinator's callback to report purge+suspend |
| 1672 // UMA when MemoryCoordinator is available. | 1657 // UMA when MemoryCoordinator is available. |
| 1673 GetRendererScheduler()->DefaultTaskRunner()->PostDelayedTask( | 1658 GetRendererScheduler()->DefaultTaskRunner()->PostDelayedTask( |
| 1674 FROM_HERE, record_purge_suspend_metric_closure_.callback(), | 1659 FROM_HERE, record_purge_suspend_metric_closure_.callback(), |
| 1675 base::TimeDelta::FromSeconds(15)); | 1660 base::TimeDelta::FromSeconds(15)); |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1828 UMA_HISTOGRAM_MEMORY_KB( | 1813 UMA_HISTOGRAM_MEMORY_KB( |
| 1829 "PurgeAndSuspend.Experimental.MemoryGrowth.V8MainThreadIsolateKB", | 1814 "PurgeAndSuspend.Experimental.MemoryGrowth.V8MainThreadIsolateKB", |
| 1830 GET_MEMORY_GROWTH(memory_metrics, purge_and_suspend_memory_metrics_, | 1815 GET_MEMORY_GROWTH(memory_metrics, purge_and_suspend_memory_metrics_, |
| 1831 v8_main_thread_isolate_mb) * 1024); | 1816 v8_main_thread_isolate_mb) * 1024); |
| 1832 UMA_HISTOGRAM_MEMORY_KB( | 1817 UMA_HISTOGRAM_MEMORY_KB( |
| 1833 "PurgeAndSuspend.Experimental.MemoryGrowth.TotalAllocatedKB", | 1818 "PurgeAndSuspend.Experimental.MemoryGrowth.TotalAllocatedKB", |
| 1834 GET_MEMORY_GROWTH(memory_metrics, purge_and_suspend_memory_metrics_, | 1819 GET_MEMORY_GROWTH(memory_metrics, purge_and_suspend_memory_metrics_, |
| 1835 total_allocated_mb) * 1024); | 1820 total_allocated_mb) * 1024); |
| 1836 } | 1821 } |
| 1837 | 1822 |
| 1838 void RenderThreadImpl::OnProcessResume() { | |
| 1839 ChildThreadImpl::OnProcessResume(); | |
| 1840 | |
| 1841 if (!RendererIsHidden()) | |
| 1842 return; | |
| 1843 | |
| 1844 // TODO(bashi): Enable the tab suspension when MemoryCoordinator is enabled. | |
| 1845 if (base::FeatureList::IsEnabled(features::kMemoryCoordinator)) | |
| 1846 return; | |
| 1847 | |
| 1848 if (base::FeatureList::IsEnabled(features::kPurgeAndSuspend)) { | |
| 1849 // TODO(tasak): after enabling MemoryCoordinator, remove this Notify | |
| 1850 // and follow MemoryCoordinator's request. | |
| 1851 base::MemoryCoordinatorClientRegistry::GetInstance()->Notify( | |
| 1852 base::MemoryState::NORMAL); | |
| 1853 } | |
| 1854 } | |
| 1855 | |
| 1856 scoped_refptr<gpu::GpuChannelHost> RenderThreadImpl::EstablishGpuChannelSync() { | 1823 scoped_refptr<gpu::GpuChannelHost> RenderThreadImpl::EstablishGpuChannelSync() { |
| 1857 TRACE_EVENT0("gpu", "RenderThreadImpl::EstablishGpuChannelSync"); | 1824 TRACE_EVENT0("gpu", "RenderThreadImpl::EstablishGpuChannelSync"); |
| 1858 | 1825 |
| 1859 if (gpu_channel_) { | 1826 if (gpu_channel_) { |
| 1860 // Do nothing if we already have a GPU channel or are already | 1827 // Do nothing if we already have a GPU channel or are already |
| 1861 // establishing one. | 1828 // establishing one. |
| 1862 if (!gpu_channel_->IsLost()) | 1829 if (!gpu_channel_->IsLost()) |
| 1863 return gpu_channel_; | 1830 return gpu_channel_; |
| 1864 | 1831 |
| 1865 // Recreate the channel if it has been lost. | 1832 // Recreate the channel if it has been lost. |
| (...skipping 547 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2413 } | 2380 } |
| 2414 } | 2381 } |
| 2415 | 2382 |
| 2416 void RenderThreadImpl::OnRendererInterfaceRequest( | 2383 void RenderThreadImpl::OnRendererInterfaceRequest( |
| 2417 mojom::RendererAssociatedRequest request) { | 2384 mojom::RendererAssociatedRequest request) { |
| 2418 DCHECK(!renderer_binding_.is_bound()); | 2385 DCHECK(!renderer_binding_.is_bound()); |
| 2419 renderer_binding_.Bind(std::move(request)); | 2386 renderer_binding_.Bind(std::move(request)); |
| 2420 } | 2387 } |
| 2421 | 2388 |
| 2422 } // namespace content | 2389 } // namespace content |
| OLD | NEW |