Chromium Code Reviews| Index: content/browser/memory/memory_coordinator_impl.cc |
| diff --git a/content/browser/memory/memory_coordinator_impl.cc b/content/browser/memory/memory_coordinator_impl.cc |
| index de5b783a0a4ecd7febe6b1c62f7aa455f4c0b5cb..ce3eef9abf3864582a1712211b0e4cde473b5e82 100644 |
| --- a/content/browser/memory/memory_coordinator_impl.cc |
| +++ b/content/browser/memory/memory_coordinator_impl.cc |
| @@ -27,6 +27,7 @@ using MemoryState = base::MemoryState; |
| namespace { |
| const int kDefaultMinimumTransitionPeriodSeconds = 30; |
| +const int kDefaultTabDiscardingIntervalSeconds = 5; |
| mojom::MemoryState ToMojomMemoryState(MemoryState state) { |
| switch (state) { |
| @@ -155,6 +156,11 @@ MemoryCoordinatorImpl::MemoryCoordinatorImpl( |
| kDefaultMinimumTransitionPeriodSeconds)) { |
| DCHECK(memory_monitor_.get()); |
| base::MemoryCoordinatorProxy::SetMemoryCoordinator(this); |
| + |
| + tab_discarding_closure_ = |
| + base::Bind(&MemoryCoordinatorImpl::DiscardTab, base::Unretained(this)); |
| + tab_discarding_interval_ = |
| + base::TimeDelta::FromSeconds(kDefaultTabDiscardingIntervalSeconds); |
| } |
| MemoryCoordinatorImpl::~MemoryCoordinatorImpl() { |
| @@ -281,6 +287,7 @@ MemoryState MemoryCoordinatorImpl::GetStateForProcess( |
| void MemoryCoordinatorImpl::UpdateConditionIfNeeded( |
| MemoryCondition next_condition) { |
| DCHECK(CalledOnValidThread()); |
| + |
| if (memory_condition_ == next_condition) |
| return; |
| @@ -313,15 +320,14 @@ void MemoryCoordinatorImpl::UpdateConditionIfNeeded( |
| // Set THROTTLED state to all clients/processes. |
| UpdateBrowserStateAndNotifyStateToClients(MemoryState::THROTTLED); |
| NotifyStateToChildren(MemoryState::THROTTLED); |
| - // Idea: Start discarding tabs. |
| + // Start discarding tabs. |
| + if (delegate_) { |
| + base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, |
| + tab_discarding_closure_); |
| + } |
| } |
| } |
| -void MemoryCoordinatorImpl::DiscardTab() { |
| - if (delegate_) |
| - delegate_->DiscardTab(); |
| -} |
| - |
| RenderProcessHost* MemoryCoordinatorImpl::GetRenderProcessHost( |
| int render_process_id) { |
| return RenderProcessHost::FromID(render_process_id); |
| @@ -441,6 +447,19 @@ void MemoryCoordinatorImpl::NotifyStateToChildren(MemoryState state) { |
| SetChildMemoryState(iter.first, state); |
| } |
| +void MemoryCoordinatorImpl::DiscardTab() { |
| + DCHECK(delegate_); |
| + if (memory_condition_ != MemoryCondition::CRITICAL) |
|
haraken
2017/03/07 08:04:57
Don't we need to update the memory condition befor
bashi
2017/03/07 08:14:08
Yeah, if we want to use up-to-date condition we wo
|
| + return; |
| + |
| + // Keep scheduling tab discarding task while memory condition is CRITICAL. |
|
haraken
2017/03/07 08:04:57
a tab discarding task while the memory condition i
|
| + bool success = delegate_->DiscardTab(); |
| + if (success) { |
| + base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
|
haraken
2017/03/07 08:04:57
Maybe it's nicer to check memory_condition_ again
bashi
2017/03/07 08:14:08
Maybe, but I guess the cost wouldn't be so differe
|
| + FROM_HERE, tab_discarding_closure_, tab_discarding_interval_); |
| + } |
| +} |
| + |
| MemoryCoordinatorImpl::ChildInfo::ChildInfo() {} |
| MemoryCoordinatorImpl::ChildInfo::ChildInfo(const ChildInfo& rhs) { |