| 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..45254e5537d6be8e01c5e5b31e9d779898bcb0f8 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,7 +1554,7 @@ void RenderProcessHostImpl::ShutdownForBadMessage(
|
|
|
| void RenderProcessHostImpl::WidgetRestored() {
|
| visible_widgets_++;
|
| - UpdateProcessPriority();
|
| + // UpdateProcessPriority();
|
| DCHECK(!is_process_backgrounded_);
|
| }
|
|
|
| @@ -1565,7 +1566,7 @@ void RenderProcessHostImpl::WidgetHidden() {
|
| --visible_widgets_;
|
| if (visible_widgets_ == 0) {
|
| DCHECK(!is_process_backgrounded_);
|
| - UpdateProcessPriority();
|
| + // 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);
|
| + }
|
| + // 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,7 +2751,7 @@ void RenderProcessHostImpl::ProcessDied(bool already_dead,
|
| route_provider_binding_.Close();
|
| ResetChannelProxy();
|
|
|
| - UpdateProcessPriority();
|
| + // UpdateProcessPriority();
|
| DCHECK(!is_process_backgrounded_);
|
|
|
| within_process_died_observer_ = true;
|
| @@ -2812,7 +2834,14 @@ void RenderProcessHostImpl::SuddenTerminationChanged(bool enabled) {
|
| SetSuddenTerminationAllowed(enabled);
|
| }
|
|
|
| -void RenderProcessHostImpl::UpdateProcessPriority() {
|
| +void RenderProcessHostImpl::SetPolicy(
|
| + 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() {
|
|
|