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 1760 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1771 record_purge_suspend_metric_closure_.Reset( | 1771 record_purge_suspend_metric_closure_.Reset( |
1772 base::Bind(&RenderThreadImpl::RecordPurgeAndSuspendMetrics, | 1772 base::Bind(&RenderThreadImpl::RecordPurgeAndSuspendMetrics, |
1773 base::Unretained(this))); | 1773 base::Unretained(this))); |
1774 } | 1774 } |
1775 } | 1775 } |
1776 | 1776 |
1777 void RenderThreadImpl::OnProcessPurgeAndSuspend() { | 1777 void RenderThreadImpl::OnProcessPurgeAndSuspend() { |
1778 ChildThreadImpl::OnProcessPurgeAndSuspend(); | 1778 ChildThreadImpl::OnProcessPurgeAndSuspend(); |
1779 if (!RendererIsHidden()) | 1779 if (!RendererIsHidden()) |
1780 return; | 1780 return; |
| 1781 |
| 1782 // TODO(bashi): Enable the tab suspension when MemoryCoordinator is enabled. |
| 1783 if (base::FeatureList::IsEnabled(features::kMemoryCoordinator)) |
| 1784 return; |
| 1785 |
1781 if (base::FeatureList::IsEnabled(features::kPurgeAndSuspend)) { | 1786 if (base::FeatureList::IsEnabled(features::kPurgeAndSuspend)) { |
1782 // TODO(tasak,bashi): After enabling MemoryCoordinator, stop calling | 1787 // TODO(tasak): After enabling MemoryCoordinator, remove this Notify |
1783 // SuspendRenderer() here. | 1788 // and follow MemoryCoordinator's request. |
1784 SuspendRenderer(); | 1789 base::MemoryCoordinatorClientRegistry::GetInstance()->Notify( |
| 1790 base::MemoryState::SUSPENDED); |
1785 } | 1791 } |
1786 // Since purging is not a synchronous task (e.g. v8 GC, oilpan GC, ...), | 1792 // Since purging is not a synchronous task (e.g. v8 GC, oilpan GC, ...), |
1787 // we need to wait until the task is finished. So wait 15 seconds and | 1793 // we need to wait until the task is finished. So wait 15 seconds and |
1788 // update purge+suspend UMA histogram. | 1794 // update purge+suspend UMA histogram. |
1789 // TODO(tasak): use MemoryCoordinator's callback to report purge+suspend | 1795 // TODO(tasak): use MemoryCoordinator's callback to report purge+suspend |
1790 // UMA when MemoryCoordinator is available. | 1796 // UMA when MemoryCoordinator is available. |
1791 GetRendererScheduler()->DefaultTaskRunner()->PostDelayedTask( | 1797 GetRendererScheduler()->DefaultTaskRunner()->PostDelayedTask( |
1792 FROM_HERE, record_purge_suspend_metric_closure_.callback(), | 1798 FROM_HERE, record_purge_suspend_metric_closure_.callback(), |
1793 base::TimeDelta::FromSeconds(15)); | 1799 base::TimeDelta::FromSeconds(15)); |
1794 } | 1800 } |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1881 blink_stats.blinkGCTotalAllocatedBytes + | 1887 blink_stats.blinkGCTotalAllocatedBytes + |
1882 malloc_usage + v8_usage + discardable_usage) / | 1888 malloc_usage + v8_usage + discardable_usage) / |
1883 1024 / 1024); | 1889 1024 / 1024); |
1884 } | 1890 } |
1885 | 1891 |
1886 void RenderThreadImpl::OnProcessResume() { | 1892 void RenderThreadImpl::OnProcessResume() { |
1887 ChildThreadImpl::OnProcessResume(); | 1893 ChildThreadImpl::OnProcessResume(); |
1888 | 1894 |
1889 if (!RendererIsHidden()) | 1895 if (!RendererIsHidden()) |
1890 return; | 1896 return; |
| 1897 |
| 1898 // TODO(bashi): Enable the tab suspension when MemoryCoordinator is enabled. |
| 1899 if (base::FeatureList::IsEnabled(features::kMemoryCoordinator)) |
| 1900 return; |
| 1901 |
1891 if (base::FeatureList::IsEnabled(features::kPurgeAndSuspend)) { | 1902 if (base::FeatureList::IsEnabled(features::kPurgeAndSuspend)) { |
1892 // TODO(tasak,bashi): After enabling MemoryCoordinator, stop calling | 1903 // TODO(tasak): after enabling MemoryCoordinator, remove this Notify |
1893 // ResumeRenderer() here. | 1904 // and follow MemoryCoordinator's request. |
1894 ResumeRenderer(); | 1905 base::MemoryCoordinatorClientRegistry::GetInstance()->Notify( |
| 1906 base::MemoryState::NORMAL); |
1895 } | 1907 } |
1896 } | 1908 } |
1897 | 1909 |
1898 scoped_refptr<gpu::GpuChannelHost> RenderThreadImpl::EstablishGpuChannelSync() { | 1910 scoped_refptr<gpu::GpuChannelHost> RenderThreadImpl::EstablishGpuChannelSync() { |
1899 TRACE_EVENT0("gpu", "RenderThreadImpl::EstablishGpuChannelSync"); | 1911 TRACE_EVENT0("gpu", "RenderThreadImpl::EstablishGpuChannelSync"); |
1900 | 1912 |
1901 if (gpu_channel_) { | 1913 if (gpu_channel_) { |
1902 // 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 |
1903 // establishing one. | 1915 // establishing one. |
1904 if (!gpu_channel_->IsLost()) | 1916 if (!gpu_channel_->IsLost()) |
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2251 void RenderThreadImpl::OnMemoryStateChange(base::MemoryState state) { | 2263 void RenderThreadImpl::OnMemoryStateChange(base::MemoryState state) { |
2252 // TODO(hajimehoshi): Adjust the size of this memory usage according to | 2264 // TODO(hajimehoshi): Adjust the size of this memory usage according to |
2253 // |state|. RenderThreadImpl doesn't have a feature to limit memory usage at | 2265 // |state|. RenderThreadImpl doesn't have a feature to limit memory usage at |
2254 // present. | 2266 // present. |
2255 if (blink_platform_impl_) { | 2267 if (blink_platform_impl_) { |
2256 blink::WebMemoryCoordinator::onMemoryStateChange( | 2268 blink::WebMemoryCoordinator::onMemoryStateChange( |
2257 static_cast<blink::MemoryState>(state)); | 2269 static_cast<blink::MemoryState>(state)); |
2258 } | 2270 } |
2259 switch (state) { | 2271 switch (state) { |
2260 case base::MemoryState::NORMAL: | 2272 case base::MemoryState::NORMAL: |
2261 // TODO(bashi): When the renderer is suspended, resume it. | 2273 ResumeRenderer(); |
2262 break; | 2274 break; |
2263 case base::MemoryState::THROTTLED: | 2275 case base::MemoryState::THROTTLED: |
2264 // TODO(bashi): When the renderer is suspended, resume it. | 2276 ResumeRenderer(); |
2265 // TODO(bashi): Figure out what kind of strategy is suitable on | 2277 // TODO(bashi): Figure out what kind of strategy is suitable on |
2266 // THROTTLED state. crbug.com/674815 | 2278 // THROTTLED state. crbug.com/674815 |
2267 #if defined(OS_ANDROID) | 2279 #if defined(OS_ANDROID) |
2268 OnTrimMemoryImmediately(); | 2280 OnTrimMemoryImmediately(); |
2269 #else | 2281 #else |
2270 OnSyncMemoryPressure( | 2282 OnSyncMemoryPressure( |
2271 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE); | 2283 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE); |
2272 #endif | 2284 #endif |
2273 ReleaseFreeMemory(); | 2285 ReleaseFreeMemory(); |
2274 break; | 2286 break; |
2275 case base::MemoryState::SUSPENDED: | 2287 case base::MemoryState::SUSPENDED: |
2276 // TODO(bashi): Suspend the renderer. | 2288 SuspendRenderer(); |
2277 OnTrimMemoryImmediately(); | |
2278 ReleaseFreeMemory(); | |
2279 ClearMemory(); | |
2280 break; | 2289 break; |
2281 case base::MemoryState::UNKNOWN: | 2290 case base::MemoryState::UNKNOWN: |
2282 NOTREACHED(); | 2291 NOTREACHED(); |
2283 break; | 2292 break; |
2284 } | 2293 } |
2285 } | 2294 } |
2286 | 2295 |
2287 void RenderThreadImpl::SuspendRenderer() { | 2296 void RenderThreadImpl::SuspendRenderer() { |
2288 DCHECK(IsMainThread()); | 2297 DCHECK(IsMainThread()); |
2289 OnTrimMemoryImmediately(); | 2298 OnTrimMemoryImmediately(); |
2290 ReleaseFreeMemory(); | 2299 ReleaseFreeMemory(); |
2291 ClearMemory(); | 2300 ClearMemory(); |
2292 renderer_scheduler_->SuspendRenderer(); | 2301 // TODO(bashi): Enable the tab suspension when MemoryCoordinator is enabled. |
| 2302 if (!base::FeatureList::IsEnabled(features::kMemoryCoordinator) && |
| 2303 base::FeatureList::IsEnabled(features::kPurgeAndSuspend)) |
| 2304 renderer_scheduler_->SuspendRenderer(); |
2293 } | 2305 } |
2294 | 2306 |
2295 void RenderThreadImpl::ResumeRenderer() { | 2307 void RenderThreadImpl::ResumeRenderer() { |
2296 DCHECK(IsMainThread()); | 2308 DCHECK(IsMainThread()); |
2297 renderer_scheduler_->ResumeRenderer(); | 2309 // TODO(bashi): Enable the tab suspension when MemoryCoordinator is enabled. |
| 2310 if (!base::FeatureList::IsEnabled(features::kMemoryCoordinator) && |
| 2311 base::FeatureList::IsEnabled(features::kPurgeAndSuspend)) |
| 2312 renderer_scheduler_->ResumeRenderer(); |
2298 } | 2313 } |
2299 | 2314 |
2300 void RenderThreadImpl::ClearMemory() { | 2315 void RenderThreadImpl::ClearMemory() { |
2301 // Do not call into blink if it is not initialized. | 2316 // Do not call into blink if it is not initialized. |
2302 if (blink_platform_impl_) { | 2317 if (blink_platform_impl_) { |
2303 // Purge Skia font cache, by setting it to 0 and then again to the | 2318 // Purge Skia font cache, by setting it to 0 and then again to the |
2304 // previous limit. | 2319 // previous limit. |
2305 size_t font_cache_limit = SkGraphics::SetFontCacheLimit(0); | 2320 size_t font_cache_limit = SkGraphics::SetFontCacheLimit(0); |
2306 SkGraphics::SetFontCacheLimit(font_cache_limit); | 2321 SkGraphics::SetFontCacheLimit(font_cache_limit); |
2307 } | 2322 } |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2487 } | 2502 } |
2488 } | 2503 } |
2489 | 2504 |
2490 void RenderThreadImpl::OnRendererInterfaceRequest( | 2505 void RenderThreadImpl::OnRendererInterfaceRequest( |
2491 mojom::RendererAssociatedRequest request) { | 2506 mojom::RendererAssociatedRequest request) { |
2492 DCHECK(!renderer_binding_.is_bound()); | 2507 DCHECK(!renderer_binding_.is_bound()); |
2493 renderer_binding_.Bind(std::move(request)); | 2508 renderer_binding_.Bind(std::move(request)); |
2494 } | 2509 } |
2495 | 2510 |
2496 } // namespace content | 2511 } // namespace content |
OLD | NEW |