| 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 879 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 890 ChildThreadImpl::current()->SetThreadPriority( | 890 ChildThreadImpl::current()->SetThreadPriority( |
| 891 categorized_worker_pool_->background_worker_thread_id(), | 891 categorized_worker_pool_->background_worker_thread_id(), |
| 892 base::ThreadPriority::BACKGROUND); | 892 base::ThreadPriority::BACKGROUND); |
| 893 #endif | 893 #endif |
| 894 | 894 |
| 895 record_purge_suspend_metric_closure_.Reset(base::Bind( | 895 record_purge_suspend_metric_closure_.Reset(base::Bind( |
| 896 &RenderThreadImpl::RecordPurgeAndSuspendMetrics, base::Unretained(this))); | 896 &RenderThreadImpl::RecordPurgeAndSuspendMetrics, base::Unretained(this))); |
| 897 record_purge_suspend_growth_metric_closure_.Reset( | 897 record_purge_suspend_growth_metric_closure_.Reset( |
| 898 base::Bind(&RenderThreadImpl::RecordPurgeAndSuspendMemoryGrowthMetrics, | 898 base::Bind(&RenderThreadImpl::RecordPurgeAndSuspendMemoryGrowthMetrics, |
| 899 base::Unretained(this))); | 899 base::Unretained(this))); |
| 900 needs_to_record_first_active_paint_ = false; |
| 900 | 901 |
| 901 base::MemoryCoordinatorClientRegistry::GetInstance()->Register(this); | 902 base::MemoryCoordinatorClientRegistry::GetInstance()->Register(this); |
| 902 | 903 |
| 903 // If this renderer doesn't run inside the browser process, enable | 904 // If this renderer doesn't run inside the browser process, enable |
| 904 // SequencedWorkerPool. Otherwise, it should already have been enabled. | 905 // SequencedWorkerPool. Otherwise, it should already have been enabled. |
| 905 // TODO(fdoray): Remove this once the SequencedWorkerPool to TaskScheduler | 906 // TODO(fdoray): Remove this once the SequencedWorkerPool to TaskScheduler |
| 906 // redirection experiment concludes https://crbug.com/622400. | 907 // redirection experiment concludes https://crbug.com/622400. |
| 907 if (!command_line.HasSwitch(switches::kSingleProcess)) | 908 if (!command_line.HasSwitch(switches::kSingleProcess)) |
| 908 base::SequencedWorkerPool::EnableForProcess(); | 909 base::SequencedWorkerPool::EnableForProcess(); |
| 909 } | 910 } |
| (...skipping 724 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1634 IPC_MESSAGE_UNHANDLED(handled = false) | 1635 IPC_MESSAGE_UNHANDLED(handled = false) |
| 1635 IPC_END_MESSAGE_MAP() | 1636 IPC_END_MESSAGE_MAP() |
| 1636 return handled; | 1637 return handled; |
| 1637 } | 1638 } |
| 1638 | 1639 |
| 1639 void RenderThreadImpl::OnProcessBackgrounded(bool backgrounded) { | 1640 void RenderThreadImpl::OnProcessBackgrounded(bool backgrounded) { |
| 1640 ChildThreadImpl::OnProcessBackgrounded(backgrounded); | 1641 ChildThreadImpl::OnProcessBackgrounded(backgrounded); |
| 1641 | 1642 |
| 1642 if (backgrounded) { | 1643 if (backgrounded) { |
| 1643 renderer_scheduler_->OnRendererBackgrounded(); | 1644 renderer_scheduler_->OnRendererBackgrounded(); |
| 1645 needs_to_record_first_active_paint_ = false; |
| 1644 } else { | 1646 } else { |
| 1645 renderer_scheduler_->OnRendererForegrounded(); | 1647 renderer_scheduler_->OnRendererForegrounded(); |
| 1646 // TODO(tasak): after enabling MemoryCoordinator, remove this Notify | 1648 // TODO(tasak): after enabling MemoryCoordinator, remove this Notify |
| 1647 // and follow MemoryCoordinator's request. | 1649 // and follow MemoryCoordinator's request. |
| 1648 if (base::FeatureList::IsEnabled(features::kPurgeAndSuspend)) | 1650 if (base::FeatureList::IsEnabled(features::kPurgeAndSuspend)) |
| 1649 base::MemoryCoordinatorClientRegistry::GetInstance()->Notify( | 1651 base::MemoryCoordinatorClientRegistry::GetInstance()->Notify( |
| 1650 base::MemoryState::NORMAL); | 1652 base::MemoryState::NORMAL); |
| 1651 | 1653 |
| 1652 record_purge_suspend_metric_closure_.Cancel(); | 1654 record_purge_suspend_metric_closure_.Cancel(); |
| 1653 record_purge_suspend_metric_closure_.Reset( | 1655 record_purge_suspend_metric_closure_.Reset( |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1673 memory_coordinator_->PurgeMemory(); | 1675 memory_coordinator_->PurgeMemory(); |
| 1674 } | 1676 } |
| 1675 // Since purging is not a synchronous task (e.g. v8 GC, oilpan GC, ...), | 1677 // Since purging is not a synchronous task (e.g. v8 GC, oilpan GC, ...), |
| 1676 // we need to wait until the task is finished. So wait 15 seconds and | 1678 // we need to wait until the task is finished. So wait 15 seconds and |
| 1677 // update purge+suspend UMA histogram. | 1679 // update purge+suspend UMA histogram. |
| 1678 // TODO(tasak): use MemoryCoordinator's callback to report purge+suspend | 1680 // TODO(tasak): use MemoryCoordinator's callback to report purge+suspend |
| 1679 // UMA when MemoryCoordinator is available. | 1681 // UMA when MemoryCoordinator is available. |
| 1680 GetRendererScheduler()->DefaultTaskRunner()->PostDelayedTask( | 1682 GetRendererScheduler()->DefaultTaskRunner()->PostDelayedTask( |
| 1681 FROM_HERE, record_purge_suspend_metric_closure_.callback(), | 1683 FROM_HERE, record_purge_suspend_metric_closure_.callback(), |
| 1682 base::TimeDelta::FromSeconds(15)); | 1684 base::TimeDelta::FromSeconds(15)); |
| 1685 needs_to_record_first_active_paint_ = true; |
| 1683 } | 1686 } |
| 1684 | 1687 |
| 1685 // TODO(tasak): Replace the following GetMallocUsage() with memory-infra | 1688 // TODO(tasak): Replace the following GetMallocUsage() with memory-infra |
| 1686 // when it is possible to run memory-infra without tracing. | 1689 // when it is possible to run memory-infra without tracing. |
| 1687 #if defined(OS_WIN) | 1690 #if defined(OS_WIN) |
| 1688 namespace { | 1691 namespace { |
| 1689 | 1692 |
| 1690 static size_t GetMallocUsage() { | 1693 static size_t GetMallocUsage() { |
| 1691 // Iterate through whichever heap the CRT is using. | 1694 // Iterate through whichever heap the CRT is using. |
| 1692 HANDLE crt_heap = reinterpret_cast<HANDLE>(_get_heap_handle()); | 1695 HANDLE crt_heap = reinterpret_cast<HANDLE>(_get_heap_handle()); |
| (...skipping 744 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2437 } | 2440 } |
| 2438 } | 2441 } |
| 2439 | 2442 |
| 2440 void RenderThreadImpl::OnRendererInterfaceRequest( | 2443 void RenderThreadImpl::OnRendererInterfaceRequest( |
| 2441 mojom::RendererAssociatedRequest request) { | 2444 mojom::RendererAssociatedRequest request) { |
| 2442 DCHECK(!renderer_binding_.is_bound()); | 2445 DCHECK(!renderer_binding_.is_bound()); |
| 2443 renderer_binding_.Bind(std::move(request)); | 2446 renderer_binding_.Bind(std::move(request)); |
| 2444 } | 2447 } |
| 2445 | 2448 |
| 2446 } // namespace content | 2449 } // namespace content |
| OLD | NEW |