Chromium Code Reviews| Index: content/renderer/render_thread_impl.cc |
| diff --git a/content/renderer/render_thread_impl.cc b/content/renderer/render_thread_impl.cc |
| index 5426e8aa67a192bfd5a4f6cd25242ab1ecd53418..8474383bc86044f4fa4e242ca47975432d367623 100644 |
| --- a/content/renderer/render_thread_impl.cc |
| +++ b/content/renderer/render_thread_impl.cc |
| @@ -1758,12 +1758,6 @@ void RenderThreadImpl::OnProcessBackgrounded(bool backgrounded) { |
| if (base::FeatureList::IsEnabled(features::kPurgeAndSuspend)) |
| base::MemoryCoordinatorClientRegistry::GetInstance()->Notify( |
| base::MemoryState::NORMAL); |
| - |
| - record_purge_suspend_metric_closure_.Cancel(); |
| - record_purge_suspend_metric_closure_.Reset( |
| - base::Bind(&RenderThreadImpl::RecordPurgeAndSuspendMetrics, |
| - base::Unretained(this))); |
| - is_renderer_suspended_ = false; |
| } |
| } |
| @@ -1778,17 +1772,7 @@ void RenderThreadImpl::OnProcessPurgeAndSuspend() { |
| // and follow MemoryCoordinator's request. |
| base::MemoryCoordinatorClientRegistry::GetInstance()->Notify( |
| base::MemoryState::SUSPENDED); |
| - renderer_scheduler_->SuspendRenderer(); |
| } |
|
bashi
2016/11/24 07:46:54
ah, Maybe I should add else clause and PostDelayed
bashi
2016/11/24 08:18:50
Chatted offline. We shouldn't record metrics when
|
| - |
| - // Since purging is not a synchronous task (e.g. v8 GC, oilpan GC, ...), |
| - // we need to wait until the task is finished. So wait 15 seconds and |
| - // update purge+suspend UMA histogram. |
| - // TODO(tasak): use MemoryCoordinator's callback to report purge+suspend |
| - // UMA when MemoryCoordinator is available. |
| - GetRendererScheduler()->DefaultTaskRunner()->PostDelayedTask( |
| - FROM_HERE, record_purge_suspend_metric_closure_.callback(), |
| - base::TimeDelta::FromSeconds(15)); |
| } |
| // TODO(tasak): Replace the following GetMallocUsage() with memory-infra |
| @@ -2284,14 +2268,17 @@ void RenderThreadImpl::OnMemoryStateChange(base::MemoryState state) { |
| } |
| switch (state) { |
| case base::MemoryState::NORMAL: |
| + record_purge_suspend_metric_closure_.Cancel(); |
| + record_purge_suspend_metric_closure_.Reset( |
| + base::Bind(&RenderThreadImpl::RecordPurgeAndSuspendMetrics, |
| + base::Unretained(this))); |
| + is_renderer_suspended_ = false; |
| break; |
| case base::MemoryState::THROTTLED: |
| ReleaseFreeMemory(); |
| break; |
| case base::MemoryState::SUSPENDED: |
| - OnTrimMemoryImmediately(); |
| - ReleaseFreeMemory(); |
| - ClearMemory(); |
| + SuspendRenderer(); |
| break; |
| case base::MemoryState::UNKNOWN: |
| NOTREACHED(); |
| @@ -2299,6 +2286,21 @@ void RenderThreadImpl::OnMemoryStateChange(base::MemoryState state) { |
| } |
| } |
| +void RenderThreadImpl::SuspendRenderer() { |
| + OnTrimMemoryImmediately(); |
| + ReleaseFreeMemory(); |
| + ClearMemory(); |
| + renderer_scheduler_->SuspendRenderer(); |
| + // Since purging is not a synchronous task (e.g. v8 GC, oilpan GC, ...), |
| + // we need to wait until the task is finished. So wait 15 seconds and |
| + // update purge+suspend UMA histogram. |
| + // TODO(tasak): use MemoryCoordinator's callback to report purge+suspend |
| + // UMA when MemoryCoordinator is available. |
| + GetRendererScheduler()->DefaultTaskRunner()->PostDelayedTask( |
| + FROM_HERE, record_purge_suspend_metric_closure_.callback(), |
| + base::TimeDelta::FromSeconds(15)); |
| +} |
| + |
| void RenderThreadImpl::ClearMemory() { |
| // Do not call into blink if it is not initialized. |
| if (blink_platform_impl_) { |