| 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 829 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 840 media::EnablePlatformDecoderSupport(); | 840 media::EnablePlatformDecoderSupport(); |
| 841 } | 841 } |
| 842 #endif | 842 #endif |
| 843 | 843 |
| 844 memory_pressure_listener_.reset(new base::MemoryPressureListener( | 844 memory_pressure_listener_.reset(new base::MemoryPressureListener( |
| 845 base::Bind(&RenderThreadImpl::OnMemoryPressure, base::Unretained(this)), | 845 base::Bind(&RenderThreadImpl::OnMemoryPressure, base::Unretained(this)), |
| 846 base::Bind(&RenderThreadImpl::OnSyncMemoryPressure, | 846 base::Bind(&RenderThreadImpl::OnSyncMemoryPressure, |
| 847 base::Unretained(this)))); | 847 base::Unretained(this)))); |
| 848 | 848 |
| 849 if (base::FeatureList::IsEnabled(features::kMemoryCoordinator)) { | 849 if (base::FeatureList::IsEnabled(features::kMemoryCoordinator)) { |
| 850 // Currently it is not possible to enable both PurgeAndSuspend and |
| 851 // MemoryCoordinator at the same time. |
| 852 DCHECK(!base::FeatureList::IsEnabled(features::kPurgeAndSuspend)); |
| 853 |
| 850 // Disable MemoryPressureListener when memory coordinator is enabled. | 854 // Disable MemoryPressureListener when memory coordinator is enabled. |
| 851 base::MemoryPressureListener::SetNotificationsSuppressed(true); | 855 base::MemoryPressureListener::SetNotificationsSuppressed(true); |
| 852 | 856 |
| 853 // TODO(bashi): Revisit how to manage the lifetime of | 857 // TODO(bashi): Revisit how to manage the lifetime of |
| 854 // ChildMemoryCoordinatorImpl. | 858 // ChildMemoryCoordinatorImpl. |
| 855 // https://codereview.chromium.org/2094583002/#msg52 | 859 // https://codereview.chromium.org/2094583002/#msg52 |
| 856 mojom::MemoryCoordinatorHandlePtr parent_coordinator; | 860 mojom::MemoryCoordinatorHandlePtr parent_coordinator; |
| 857 GetRemoteInterfaces()->GetInterface(mojo::GetProxy(&parent_coordinator)); | 861 GetRemoteInterfaces()->GetInterface(mojo::GetProxy(&parent_coordinator)); |
| 858 memory_coordinator_ = CreateChildMemoryCoordinator( | 862 memory_coordinator_ = CreateChildMemoryCoordinator( |
| 859 std::move(parent_coordinator), this); | 863 std::move(parent_coordinator), this); |
| (...skipping 885 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1745 return handled; | 1749 return handled; |
| 1746 } | 1750 } |
| 1747 | 1751 |
| 1748 void RenderThreadImpl::OnProcessBackgrounded(bool backgrounded) { | 1752 void RenderThreadImpl::OnProcessBackgrounded(bool backgrounded) { |
| 1749 ChildThreadImpl::OnProcessBackgrounded(backgrounded); | 1753 ChildThreadImpl::OnProcessBackgrounded(backgrounded); |
| 1750 | 1754 |
| 1751 if (backgrounded) { | 1755 if (backgrounded) { |
| 1752 renderer_scheduler_->OnRendererBackgrounded(); | 1756 renderer_scheduler_->OnRendererBackgrounded(); |
| 1753 } else { | 1757 } else { |
| 1754 renderer_scheduler_->OnRendererForegrounded(); | 1758 renderer_scheduler_->OnRendererForegrounded(); |
| 1759 // TODO(tasak): after enabling MemoryCoordinator, remove this Notify |
| 1760 // and follow MemoryCoordinator's request. |
| 1761 if (base::FeatureList::IsEnabled(features::kPurgeAndSuspend)) |
| 1762 base::MemoryCoordinatorClientRegistry::GetInstance()->Notify( |
| 1763 base::MemoryState::NORMAL); |
| 1764 |
| 1755 record_purge_suspend_metric_closure_.Cancel(); | 1765 record_purge_suspend_metric_closure_.Cancel(); |
| 1756 record_purge_suspend_metric_closure_.Reset( | 1766 record_purge_suspend_metric_closure_.Reset( |
| 1757 base::Bind(&RenderThreadImpl::RecordPurgeAndSuspendMetrics, | 1767 base::Bind(&RenderThreadImpl::RecordPurgeAndSuspendMetrics, |
| 1758 base::Unretained(this))); | 1768 base::Unretained(this))); |
| 1759 is_renderer_suspended_ = false; | 1769 is_renderer_suspended_ = false; |
| 1760 } | 1770 } |
| 1761 } | 1771 } |
| 1762 | 1772 |
| 1763 void RenderThreadImpl::OnProcessPurgeAndSuspend() { | 1773 void RenderThreadImpl::OnProcessPurgeAndSuspend() { |
| 1764 ChildThreadImpl::OnProcessPurgeAndSuspend(); | 1774 ChildThreadImpl::OnProcessPurgeAndSuspend(); |
| 1765 if (is_renderer_suspended_ || !RendererIsHidden()) | 1775 DCHECK(!is_renderer_suspended_); |
| 1776 if (!RendererIsHidden()) |
| 1766 return; | 1777 return; |
| 1767 // TODO(hajimehoshi): Implement purging e.g. cache (crbug/607077) | |
| 1768 is_renderer_suspended_ = true; | 1778 is_renderer_suspended_ = true; |
| 1769 renderer_scheduler_->SuspendRenderer(); | 1779 if (base::FeatureList::IsEnabled(features::kPurgeAndSuspend)) { |
| 1780 // TODO(tasak): After enabling MemoryCoordinator, remove this Notify |
| 1781 // and follow MemoryCoordinator's request. |
| 1782 base::MemoryCoordinatorClientRegistry::GetInstance()->Notify( |
| 1783 base::MemoryState::SUSPENDED); |
| 1784 renderer_scheduler_->SuspendRenderer(); |
| 1785 } |
| 1770 | 1786 |
| 1771 // Since purging is not a synchronous task (e.g. v8 GC, oilpan GC, ...), | 1787 // Since purging is not a synchronous task (e.g. v8 GC, oilpan GC, ...), |
| 1772 // we need to wait until the task is finished. So wait 15 seconds and | 1788 // we need to wait until the task is finished. So wait 15 seconds and |
| 1773 // update purge+suspend UMA histogram. | 1789 // update purge+suspend UMA histogram. |
| 1774 // TODO(tasak): use MemoryCoordinator's callback to report purge+suspend | 1790 // TODO(tasak): use MemoryCoordinator's callback to report purge+suspend |
| 1775 // UMA when MemoryCoordinator is available. | 1791 // UMA when MemoryCoordinator is available. |
| 1776 GetRendererScheduler()->DefaultTaskRunner()->PostDelayedTask( | 1792 GetRendererScheduler()->DefaultTaskRunner()->PostDelayedTask( |
| 1777 FROM_HERE, record_purge_suspend_metric_closure_.callback(), | 1793 FROM_HERE, record_purge_suspend_metric_closure_.callback(), |
| 1778 base::TimeDelta::FromSeconds(15)); | 1794 base::TimeDelta::FromSeconds(15)); |
| 1779 } | 1795 } |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1872 blink_stats.blinkGCTotalAllocatedBytes + | 1888 blink_stats.blinkGCTotalAllocatedBytes + |
| 1873 malloc_usage + v8_usage + discardable_usage) / | 1889 malloc_usage + v8_usage + discardable_usage) / |
| 1874 1024 / 1024); | 1890 1024 / 1024); |
| 1875 } | 1891 } |
| 1876 | 1892 |
| 1877 void RenderThreadImpl::OnProcessResume() { | 1893 void RenderThreadImpl::OnProcessResume() { |
| 1878 ChildThreadImpl::OnProcessResume(); | 1894 ChildThreadImpl::OnProcessResume(); |
| 1879 | 1895 |
| 1880 DCHECK(is_renderer_suspended_); | 1896 DCHECK(is_renderer_suspended_); |
| 1881 is_renderer_suspended_ = false; | 1897 is_renderer_suspended_ = false; |
| 1882 renderer_scheduler_->ResumeRenderer(); | 1898 if (base::FeatureList::IsEnabled(features::kPurgeAndSuspend)) { |
| 1899 // TODO(tasak): after enabling MemoryCoordinator, remove this Notify |
| 1900 // and follow MemoryCoordinator's request. |
| 1901 base::MemoryCoordinatorClientRegistry::GetInstance()->Notify( |
| 1902 base::MemoryState::NORMAL); |
| 1903 renderer_scheduler_->ResumeRenderer(); |
| 1904 } |
| 1883 } | 1905 } |
| 1884 | 1906 |
| 1885 scoped_refptr<gpu::GpuChannelHost> RenderThreadImpl::EstablishGpuChannelSync() { | 1907 scoped_refptr<gpu::GpuChannelHost> RenderThreadImpl::EstablishGpuChannelSync() { |
| 1886 TRACE_EVENT0("gpu", "RenderThreadImpl::EstablishGpuChannelSync"); | 1908 TRACE_EVENT0("gpu", "RenderThreadImpl::EstablishGpuChannelSync"); |
| 1887 | 1909 |
| 1888 if (gpu_channel_) { | 1910 if (gpu_channel_) { |
| 1889 // Do nothing if we already have a GPU channel or are already | 1911 // Do nothing if we already have a GPU channel or are already |
| 1890 // establishing one. | 1912 // establishing one. |
| 1891 if (!gpu_channel_->IsLost()) | 1913 if (!gpu_channel_->IsLost()) |
| 1892 return gpu_channel_; | 1914 return gpu_channel_; |
| (...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2479 } | 2501 } |
| 2480 } | 2502 } |
| 2481 | 2503 |
| 2482 void RenderThreadImpl::OnRendererInterfaceRequest( | 2504 void RenderThreadImpl::OnRendererInterfaceRequest( |
| 2483 mojom::RendererAssociatedRequest request) { | 2505 mojom::RendererAssociatedRequest request) { |
| 2484 DCHECK(!renderer_binding_.is_bound()); | 2506 DCHECK(!renderer_binding_.is_bound()); |
| 2485 renderer_binding_.Bind(std::move(request)); | 2507 renderer_binding_.Bind(std::move(request)); |
| 2486 } | 2508 } |
| 2487 | 2509 |
| 2488 } // namespace content | 2510 } // namespace content |
| OLD | NEW |