Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(631)

Side by Side Diff: content/renderer/render_thread_impl.cc

Issue 2456073003: Purge memory via MemoryCoordinatorClientRegistry when a backgrounded renderer is suspended. (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/public/common/content_features.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 828 matching lines...) Expand 10 before | Expand all | Expand 10 after
839 media::MediaCodecUtil::IsMediaCodecAvailable()) { 839 media::MediaCodecUtil::IsMediaCodecAvailable()) {
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 base::FeatureList::IsEnabled(features::kPurgeAndSuspend)) {
bashi 2016/10/28 05:45:05 Let's discuss offline how to enable MemoryCoordina
tasak 2016/10/28 06:29:34 According to the discussion, I removed base::Featu
850 // Disable MemoryPressureListener when memory coordinator is enabled. 851 // Disable MemoryPressureListener when memory coordinator is enabled.
851 base::MemoryPressureListener::SetNotificationsSuppressed(true); 852 base::MemoryPressureListener::SetNotificationsSuppressed(true);
852 853
853 // TODO(bashi): Revisit how to manage the lifetime of 854 // TODO(bashi): Revisit how to manage the lifetime of
854 // ChildMemoryCoordinatorImpl. 855 // ChildMemoryCoordinatorImpl.
855 // https://codereview.chromium.org/2094583002/#msg52 856 // https://codereview.chromium.org/2094583002/#msg52
856 mojom::MemoryCoordinatorHandlePtr parent_coordinator; 857 mojom::MemoryCoordinatorHandlePtr parent_coordinator;
857 GetRemoteInterfaces()->GetInterface(mojo::GetProxy(&parent_coordinator)); 858 GetRemoteInterfaces()->GetInterface(mojo::GetProxy(&parent_coordinator));
858 memory_coordinator_ = CreateChildMemoryCoordinator( 859 memory_coordinator_ = CreateChildMemoryCoordinator(
859 std::move(parent_coordinator), this); 860 std::move(parent_coordinator), this);
(...skipping 889 matching lines...) Expand 10 before | Expand all | Expand 10 after
1749 return handled; 1750 return handled;
1750 } 1751 }
1751 1752
1752 void RenderThreadImpl::OnProcessBackgrounded(bool backgrounded) { 1753 void RenderThreadImpl::OnProcessBackgrounded(bool backgrounded) {
1753 ChildThreadImpl::OnProcessBackgrounded(backgrounded); 1754 ChildThreadImpl::OnProcessBackgrounded(backgrounded);
1754 1755
1755 if (backgrounded) { 1756 if (backgrounded) {
1756 renderer_scheduler_->OnRendererBackgrounded(); 1757 renderer_scheduler_->OnRendererBackgrounded();
1757 } else { 1758 } else {
1758 renderer_scheduler_->OnRendererForegrounded(); 1759 renderer_scheduler_->OnRendererForegrounded();
1760 // TODO(tasak): after enabling MemoryCoordinator, remove this Notify
1761 // and follow MemoryCoordinator's request.
1762 if (base::FeatureList::IsEnabled(features::kPurgeAndSuspend))
1763 base::MemoryCoordinatorClientRegistry::GetInstance()->Notify(
1764 base::MemoryState::NORMAL);
1765
1759 record_purge_suspend_metric_closure_.Cancel(); 1766 record_purge_suspend_metric_closure_.Cancel();
1760 record_purge_suspend_metric_closure_.Reset( 1767 record_purge_suspend_metric_closure_.Reset(
1761 base::Bind(&RenderThreadImpl::RecordPurgeAndSuspendMetrics, 1768 base::Bind(&RenderThreadImpl::RecordPurgeAndSuspendMetrics,
1762 base::Unretained(this))); 1769 base::Unretained(this)));
1763 is_renderer_suspended_ = false; 1770 is_renderer_suspended_ = false;
1764 } 1771 }
1765 } 1772 }
1766 1773
1767 void RenderThreadImpl::OnProcessPurgeAndSuspend() { 1774 void RenderThreadImpl::OnProcessPurgeAndSuspend() {
1768 ChildThreadImpl::OnProcessPurgeAndSuspend(); 1775 ChildThreadImpl::OnProcessPurgeAndSuspend();
1769 if (is_renderer_suspended_ || !RendererIsHidden()) 1776 DCHECK(!is_renderer_suspended_);
1777 if (!RendererIsHidden())
1770 return; 1778 return;
1771 // TODO(hajimehoshi): Implement purging e.g. cache (crbug/607077)
1772 is_renderer_suspended_ = true; 1779 is_renderer_suspended_ = true;
1773 renderer_scheduler_->SuspendRenderer(); 1780 if (base::FeatureList::IsEnabled(features::kPurgeAndSuspend)) {
1781 // TODO(tasak): After enabling MemoryCoordinator, remove this Notify
1782 // and follow MemoryCoordinator's request.
1783 base::MemoryCoordinatorClientRegistry::GetInstance()->Notify(
1784 base::MemoryState::SUSPENDED);
1785 renderer_scheduler_->SuspendRenderer();
1786 }
1774 1787
1775 // Since purging is not a synchronous task (e.g. v8 GC, oilpan GC, ...), 1788 // 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 1789 // we need to wait until the task is finished. So wait 15 seconds and
1777 // update purge+suspend UMA histogram. 1790 // update purge+suspend UMA histogram.
1778 // TODO(tasak): use MemoryCoordinator's callback to report purge+suspend 1791 // TODO(tasak): use MemoryCoordinator's callback to report purge+suspend
1779 // UMA when MemoryCoordinator is available. 1792 // UMA when MemoryCoordinator is available.
1780 GetRendererScheduler()->DefaultTaskRunner()->PostDelayedTask( 1793 GetRendererScheduler()->DefaultTaskRunner()->PostDelayedTask(
1781 FROM_HERE, record_purge_suspend_metric_closure_.callback(), 1794 FROM_HERE, record_purge_suspend_metric_closure_.callback(),
1782 base::TimeDelta::FromSeconds(15)); 1795 base::TimeDelta::FromSeconds(15));
1783 } 1796 }
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
1875 blink_stats.blinkGCTotalAllocatedBytes + 1888 blink_stats.blinkGCTotalAllocatedBytes +
1876 malloc_usage + v8_usage + discardable_usage) / 1889 malloc_usage + v8_usage + discardable_usage) /
1877 1024 / 1024); 1890 1024 / 1024);
1878 } 1891 }
1879 1892
1880 void RenderThreadImpl::OnProcessResume() { 1893 void RenderThreadImpl::OnProcessResume() {
1881 ChildThreadImpl::OnProcessResume(); 1894 ChildThreadImpl::OnProcessResume();
1882 1895
1883 DCHECK(is_renderer_suspended_); 1896 DCHECK(is_renderer_suspended_);
1884 is_renderer_suspended_ = false; 1897 is_renderer_suspended_ = false;
1885 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 }
1886 } 1905 }
1887 1906
1888 scoped_refptr<gpu::GpuChannelHost> RenderThreadImpl::EstablishGpuChannelSync() { 1907 scoped_refptr<gpu::GpuChannelHost> RenderThreadImpl::EstablishGpuChannelSync() {
1889 TRACE_EVENT0("gpu", "RenderThreadImpl::EstablishGpuChannelSync"); 1908 TRACE_EVENT0("gpu", "RenderThreadImpl::EstablishGpuChannelSync");
1890 1909
1891 if (gpu_channel_) { 1910 if (gpu_channel_) {
1892 // 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
1893 // establishing one. 1912 // establishing one.
1894 if (!gpu_channel_->IsLost()) 1913 if (!gpu_channel_->IsLost())
1895 return gpu_channel_; 1914 return gpu_channel_;
(...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after
2479 } 2498 }
2480 } 2499 }
2481 2500
2482 void RenderThreadImpl::OnRendererInterfaceRequest( 2501 void RenderThreadImpl::OnRendererInterfaceRequest(
2483 mojom::RendererAssociatedRequest request) { 2502 mojom::RendererAssociatedRequest request) {
2484 DCHECK(!renderer_binding_.is_bound()); 2503 DCHECK(!renderer_binding_.is_bound());
2485 renderer_binding_.Bind(std::move(request)); 2504 renderer_binding_.Bind(std::move(request));
2486 } 2505 }
2487 2506
2488 } // namespace content 2507 } // namespace content
OLDNEW
« no previous file with comments | « content/public/common/content_features.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698