Chromium Code Reviews| Index: content/browser/renderer_host/render_process_host_impl.cc |
| diff --git a/content/browser/renderer_host/render_process_host_impl.cc b/content/browser/renderer_host/render_process_host_impl.cc |
| index b8817c431d67c72ed77b7f21d5cdf3f0b059971e..774766f055ad39f321ccaea76d2e685467754266 100644 |
| --- a/content/browser/renderer_host/render_process_host_impl.cc |
| +++ b/content/browser/renderer_host/render_process_host_impl.cc |
| @@ -707,6 +707,7 @@ RenderProcessHostImpl::RenderProcessHostImpl( |
| never_signaled_(base::WaitableEvent::ResetPolicy::MANUAL, |
| base::WaitableEvent::InitialState::NOT_SIGNALED), |
| #endif |
| + resource_coordinator_binding_(this), |
| instance_weak_factory_( |
| new base::WeakPtrFactory<RenderProcessHostImpl>(this)), |
| weak_factory_(this) { |
| @@ -1553,8 +1554,8 @@ void RenderProcessHostImpl::ShutdownForBadMessage( |
| void RenderProcessHostImpl::WidgetRestored() { |
| visible_widgets_++; |
| - UpdateProcessPriority(); |
| - DCHECK(!is_process_backgrounded_); |
| + // UpdateProcessPriority(); |
| + // DCHECK(!is_process_backgrounded_); |
| } |
| void RenderProcessHostImpl::WidgetHidden() { |
| @@ -1564,8 +1565,8 @@ void RenderProcessHostImpl::WidgetHidden() { |
| --visible_widgets_; |
| if (visible_widgets_ == 0) { |
| - DCHECK(!is_process_backgrounded_); |
| - UpdateProcessPriority(); |
| + // DCHECK(!is_process_backgrounded_); |
| + // UpdateProcessPriority(); |
| } |
| } |
| @@ -1574,14 +1575,35 @@ int RenderProcessHostImpl::VisibleWidgetCount() const { |
| } |
| void RenderProcessHostImpl::OnAudioStreamAdded() { |
| - ++audio_stream_count_; |
| - UpdateProcessPriority(); |
| + if (++audio_stream_count_ == 1) { |
| + GetProcessResourceCoordinator()->SendEvent( |
| + resource_coordinator::mojom::EventType::ON_PROCESS_AUDIO_STARTED); |
|
Sami
2017/03/22 13:51:43
N.B. This notification is fine for what you're doi
|
| + } |
| + // UpdateProcessPriority(); |
| } |
| void RenderProcessHostImpl::OnAudioStreamRemoved() { |
| DCHECK_GT(audio_stream_count_, 0); |
| - --audio_stream_count_; |
| - UpdateProcessPriority(); |
| + if (--audio_stream_count_ == 0) { |
| + GetProcessResourceCoordinator()->SendEvent( |
| + resource_coordinator::mojom::EventType::ON_PROCESS_AUDIO_STOPPED); |
| + } |
| + // UpdateProcessPriority(); |
| +} |
| + |
| +resource_coordinator::ResourceCoordinatorInterface* |
| +RenderProcessHostImpl::GetProcessResourceCoordinator() { |
| + if (!process_resource_coordinator_) { |
| + process_resource_coordinator_ = |
| + base::MakeUnique<resource_coordinator::ResourceCoordinatorInterface>( |
| + ServiceManagerConnection::GetForProcess()->GetConnector(), |
| + resource_coordinator::mojom::IDType::PROCESS); |
| + |
| + process_resource_coordinator_->service()->SetPolicyCallback( |
| + resource_coordinator_binding_.CreateInterfacePtrAndBind()); |
| + } |
| + |
| + return process_resource_coordinator_.get(); |
| } |
| bool RenderProcessHostImpl::IsForGuestsOnly() const { |
| @@ -2729,8 +2751,8 @@ void RenderProcessHostImpl::ProcessDied(bool already_dead, |
| route_provider_binding_.Close(); |
| ResetChannelProxy(); |
| - UpdateProcessPriority(); |
| - DCHECK(!is_process_backgrounded_); |
| + // UpdateProcessPriority(); |
| + // DCHECK(!is_process_backgrounded_); |
| within_process_died_observer_ = true; |
| NotificationService::current()->Notify( |
| @@ -2812,7 +2834,14 @@ void RenderProcessHostImpl::SuddenTerminationChanged(bool enabled) { |
| SetSuddenTerminationAllowed(enabled); |
| } |
| -void RenderProcessHostImpl::UpdateProcessPriority() { |
| +void RenderProcessHostImpl::SetPolicy( |
|
Sami
2017/03/22 13:51:43
What's the latency of these updates? This is all i
|
| + resource_coordinator::mojom::PolicyPtr policy) { |
| + SetProcessPriority(policy->use_background_priority); |
| +} |
| + |
| +void RenderProcessHostImpl::SetProcessPriority(bool should_background) { |
| + LOG(ERROR) << "RenderProcessHostImpl::SetProcessPriority(" |
| + << should_background << ")"; |
| if (!child_process_launcher_.get() || child_process_launcher_->IsStarting()) { |
| is_process_backgrounded_ = false; |
| return; |
| @@ -2823,13 +2852,13 @@ void RenderProcessHostImpl::UpdateProcessPriority() { |
| return; |
| } |
| - // We background a process as soon as it hosts no active audio streams and no |
| - // visible widgets -- the callers must call this function whenever we |
| - // transition in/out of those states. |
| - const bool should_background = |
| - visible_widgets_ == 0 && audio_stream_count_ == 0 && |
| - !base::CommandLine::ForCurrentProcess()->HasSwitch( |
| - switches::kDisableRendererBackgrounding); |
| +// We background a process as soon as it hosts no active audio streams and no |
| +// visible widgets -- the callers must call this function whenever we |
| +// transition in/out of those states. |
| +// const bool should_background = |
| +// visible_widgets_ == 0 && audio_stream_count_ == 0 && |
| +// !base::CommandLine::ForCurrentProcess()->HasSwitch( |
| +// switches::kDisableRendererBackgrounding); |
| // TODO(sebsg): Remove this ifdef when https://crbug.com/537671 is fixed. |
| #if !defined(OS_ANDROID) |
| @@ -2861,6 +2890,7 @@ void RenderProcessHostImpl::UpdateProcessPriority() { |
| // Notify the child process of background state. |
| Send(new ChildProcessMsg_SetProcessBackgrounded(should_background)); |
| + LOG(ERROR) << "RenderProcessHostImpl::SetProcessPriority: SUCCESS!"; |
| } |
| void RenderProcessHostImpl::OnProcessLaunched() { |