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 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 889 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1749 return handled; | 1753 return handled; |
| 1750 } | 1754 } |
| 1751 | 1755 |
| 1752 void RenderThreadImpl::OnProcessBackgrounded(bool backgrounded) { | 1756 void RenderThreadImpl::OnProcessBackgrounded(bool backgrounded) { |
| 1753 ChildThreadImpl::OnProcessBackgrounded(backgrounded); | 1757 ChildThreadImpl::OnProcessBackgrounded(backgrounded); |
| 1754 | 1758 |
| 1755 if (backgrounded) { | 1759 if (backgrounded) { |
| 1756 renderer_scheduler_->OnRendererBackgrounded(); | 1760 renderer_scheduler_->OnRendererBackgrounded(); |
| 1757 } else { | 1761 } else { |
| 1758 renderer_scheduler_->OnRendererForegrounded(); | 1762 renderer_scheduler_->OnRendererForegrounded(); |
| 1763 // TODO(tasak): after enabling MemoryCoordinator, remove this Notify | |
| 1764 // and follow MemoryCoordinator's request. | |
| 1765 if (base::FeatureList::IsEnabled(features::kPurgeAndSuspend)) | |
| 1766 base::MemoryCoordinatorClientRegistry::GetInstance()->Notify( | |
| 1767 base::MemoryState::NORMAL); | |
| 1768 | |
| 1759 record_purge_suspend_metric_closure_.Cancel(); | 1769 record_purge_suspend_metric_closure_.Cancel(); |
| 1760 record_purge_suspend_metric_closure_.Reset( | 1770 record_purge_suspend_metric_closure_.Reset( |
| 1761 base::Bind(&RenderThreadImpl::RecordPurgeAndSuspendMetrics, | 1771 base::Bind(&RenderThreadImpl::RecordPurgeAndSuspendMetrics, |
| 1762 base::Unretained(this))); | 1772 base::Unretained(this))); |
| 1763 is_renderer_suspended_ = false; | 1773 is_renderer_suspended_ = false; |
| 1764 } | 1774 } |
| 1765 } | 1775 } |
| 1766 | 1776 |
| 1767 void RenderThreadImpl::OnProcessPurgeAndSuspend() { | 1777 void RenderThreadImpl::OnProcessPurgeAndSuspend() { |
| 1768 ChildThreadImpl::OnProcessPurgeAndSuspend(); | 1778 ChildThreadImpl::OnProcessPurgeAndSuspend(); |
| 1769 if (is_renderer_suspended_ || !RendererIsHidden()) | 1779 DCHECK(!is_renderer_suspended_); |
|
tasak
2016/10/28 06:31:33
This needs https://codereview.chromium.org/2462513
| |
| 1780 if (!RendererIsHidden()) | |
| 1770 return; | 1781 return; |
| 1771 // TODO(hajimehoshi): Implement purging e.g. cache (crbug/607077) | |
| 1772 is_renderer_suspended_ = true; | 1782 is_renderer_suspended_ = true; |
| 1773 renderer_scheduler_->SuspendRenderer(); | 1783 if (base::FeatureList::IsEnabled(features::kPurgeAndSuspend)) { |
| 1784 // TODO(tasak): After enabling MemoryCoordinator, remove this Notify | |
| 1785 // and follow MemoryCoordinator's request. | |
| 1786 base::MemoryCoordinatorClientRegistry::GetInstance()->Notify( | |
| 1787 base::MemoryState::SUSPENDED); | |
| 1788 renderer_scheduler_->SuspendRenderer(); | |
| 1789 } | |
| 1774 | 1790 |
| 1775 // Since purging is not a synchronous task (e.g. v8 GC, oilpan GC, ...), | 1791 // Since purging is not a synchronous task (e.g. v8 GC, oilpan GC, ...), |
| 1776 // we need to wait until the task is finished. So wait 15 seconds and | 1792 // we need to wait until the task is finished. So wait 15 seconds and |
| 1777 // update purge+suspend UMA histogram. | 1793 // update purge+suspend UMA histogram. |
| 1778 // TODO(tasak): use MemoryCoordinator's callback to report purge+suspend | 1794 // TODO(tasak): use MemoryCoordinator's callback to report purge+suspend |
| 1779 // UMA when MemoryCoordinator is available. | 1795 // UMA when MemoryCoordinator is available. |
| 1780 GetRendererScheduler()->DefaultTaskRunner()->PostDelayedTask( | 1796 GetRendererScheduler()->DefaultTaskRunner()->PostDelayedTask( |
| 1781 FROM_HERE, record_purge_suspend_metric_closure_.callback(), | 1797 FROM_HERE, record_purge_suspend_metric_closure_.callback(), |
| 1782 base::TimeDelta::FromSeconds(15)); | 1798 base::TimeDelta::FromSeconds(15)); |
| 1783 } | 1799 } |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1875 blink_stats.blinkGCTotalAllocatedBytes + | 1891 blink_stats.blinkGCTotalAllocatedBytes + |
| 1876 malloc_usage + v8_usage + discardable_usage) / | 1892 malloc_usage + v8_usage + discardable_usage) / |
| 1877 1024 / 1024); | 1893 1024 / 1024); |
| 1878 } | 1894 } |
| 1879 | 1895 |
| 1880 void RenderThreadImpl::OnProcessResume() { | 1896 void RenderThreadImpl::OnProcessResume() { |
| 1881 ChildThreadImpl::OnProcessResume(); | 1897 ChildThreadImpl::OnProcessResume(); |
| 1882 | 1898 |
| 1883 DCHECK(is_renderer_suspended_); | 1899 DCHECK(is_renderer_suspended_); |
| 1884 is_renderer_suspended_ = false; | 1900 is_renderer_suspended_ = false; |
| 1885 renderer_scheduler_->ResumeRenderer(); | 1901 if (base::FeatureList::IsEnabled(features::kPurgeAndSuspend)) { |
| 1902 // TODO(tasak): after enabling MemoryCoordinator, remove this Notify | |
| 1903 // and follow MemoryCoordinator's request. | |
| 1904 base::MemoryCoordinatorClientRegistry::GetInstance()->Notify( | |
| 1905 base::MemoryState::NORMAL); | |
|
haraken
2016/10/28 07:49:41
I'm not sure if this should be NORMAL. It could be
chrisha
2016/11/01 21:24:38
Ditto. This seems fine for now.
| |
| 1906 renderer_scheduler_->ResumeRenderer(); | |
| 1907 } | |
| 1886 } | 1908 } |
| 1887 | 1909 |
| 1888 scoped_refptr<gpu::GpuChannelHost> RenderThreadImpl::EstablishGpuChannelSync() { | 1910 scoped_refptr<gpu::GpuChannelHost> RenderThreadImpl::EstablishGpuChannelSync() { |
| 1889 TRACE_EVENT0("gpu", "RenderThreadImpl::EstablishGpuChannelSync"); | 1911 TRACE_EVENT0("gpu", "RenderThreadImpl::EstablishGpuChannelSync"); |
| 1890 | 1912 |
| 1891 if (gpu_channel_) { | 1913 if (gpu_channel_) { |
| 1892 // Do nothing if we already have a GPU channel or are already | 1914 // Do nothing if we already have a GPU channel or are already |
| 1893 // establishing one. | 1915 // establishing one. |
| 1894 if (!gpu_channel_->IsLost()) | 1916 if (!gpu_channel_->IsLost()) |
| 1895 return gpu_channel_; | 1917 return gpu_channel_; |
| (...skipping 583 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 |