| 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 dde83fd48bb4059ecba4525cb58ccaa2330cf29e..ea8e8fa78f6fad04916121a6bef065f656ad8d48 100644
|
| --- a/content/browser/renderer_host/render_process_host_impl.cc
|
| +++ b/content/browser/renderer_host/render_process_host_impl.cc
|
| @@ -947,6 +947,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)),
|
| frame_sink_provider_(id_),
|
| @@ -1814,7 +1815,7 @@ void RenderProcessHostImpl::ShutdownForBadMessage(
|
|
|
| void RenderProcessHostImpl::WidgetRestored() {
|
| visible_widgets_++;
|
| - UpdateProcessPriority();
|
| + // UpdateProcessPriority();
|
| }
|
|
|
| void RenderProcessHostImpl::WidgetHidden() {
|
| @@ -1824,7 +1825,7 @@ void RenderProcessHostImpl::WidgetHidden() {
|
|
|
| --visible_widgets_;
|
| if (visible_widgets_ == 0) {
|
| - UpdateProcessPriority();
|
| + // UpdateProcessPriority();
|
| }
|
| }
|
|
|
| @@ -1833,14 +1834,35 @@ int RenderProcessHostImpl::VisibleWidgetCount() const {
|
| }
|
|
|
| void RenderProcessHostImpl::OnAudioStreamAdded() {
|
| - ++audio_stream_count_;
|
| - UpdateProcessPriority();
|
| + if (++audio_stream_count_ == 1) {
|
| + GetProcessResourceCoordinator()->SendEvent(
|
| + resource_coordinator::EventType::kOnProcessAudioStarted);
|
| + }
|
| + // UpdateProcessPriority();
|
| }
|
|
|
| void RenderProcessHostImpl::OnAudioStreamRemoved() {
|
| DCHECK_GT(audio_stream_count_, 0);
|
| - --audio_stream_count_;
|
| - UpdateProcessPriority();
|
| + if (--audio_stream_count_ == 0) {
|
| + GetProcessResourceCoordinator()->SendEvent(
|
| + resource_coordinator::EventType::kOnProcessAudioStopped);
|
| + }
|
| + // UpdateProcessPriority();
|
| +}
|
| +
|
| +resource_coordinator::ResourceCoordinatorInterface*
|
| +RenderProcessHostImpl::GetProcessResourceCoordinator() {
|
| + if (!process_resource_coordinator_) {
|
| + process_resource_coordinator_ =
|
| + base::MakeUnique<resource_coordinator::ResourceCoordinatorInterface>(
|
| + ServiceManagerConnection::GetForProcess()->GetConnector(),
|
| + resource_coordinator::CoordinationUnitType::kProcess);
|
| +
|
| + process_resource_coordinator_->service()->SetCoordinationPolicyCallback(
|
| + resource_coordinator_binding_.CreateInterfacePtrAndBind());
|
| + }
|
| +
|
| + return process_resource_coordinator_.get();
|
| }
|
|
|
| void RenderProcessHostImpl::set_render_process_host_factory(
|
| @@ -2618,13 +2640,13 @@ void RenderProcessHostImpl::Cleanup() {
|
|
|
| void RenderProcessHostImpl::AddPendingView() {
|
| pending_views_++;
|
| - UpdateProcessPriority();
|
| + // UpdateProcessPriority();
|
| }
|
|
|
| void RenderProcessHostImpl::RemovePendingView() {
|
| DCHECK(pending_views_);
|
| pending_views_--;
|
| - UpdateProcessPriority();
|
| + // UpdateProcessPriority();
|
| }
|
|
|
| void RenderProcessHostImpl::AddWidget(RenderWidgetHost* widget) {
|
| @@ -3151,7 +3173,7 @@ void RenderProcessHostImpl::ProcessDied(bool already_dead,
|
| associated_interfaces_.reset();
|
| ResetChannelProxy();
|
|
|
| - UpdateProcessPriority();
|
| + // UpdateProcessPriority();
|
|
|
| within_process_died_observer_ = true;
|
| NotificationService::current()->Notify(
|
| @@ -3244,7 +3266,14 @@ void RenderProcessHostImpl::SuddenTerminationChanged(bool enabled) {
|
| SetSuddenTerminationAllowed(enabled);
|
| }
|
|
|
| -void RenderProcessHostImpl::UpdateProcessPriority() {
|
| +void RenderProcessHostImpl::SetCoordinationPolicy(
|
| + resource_coordinator::mojom::CoordinationPolicyPtr 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_ = kLaunchingProcessIsBackgrounded;
|
| boost_priority_for_pending_views_ =
|
| @@ -3260,10 +3289,10 @@ void RenderProcessHostImpl::UpdateProcessPriority() {
|
| // 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);
|
| + // const bool should_background =
|
| + // visible_widgets_ == 0 && audio_stream_count_ == 0 &&
|
| + // !base::CommandLine::ForCurrentProcess()->HasSwitch(
|
| + // switches::kDisableRendererBackgrounding);
|
| const bool should_background_changed =
|
| is_process_backgrounded_ != should_background;
|
| const bool has_pending_views = !!pending_views_;
|
| @@ -3301,8 +3330,10 @@ void RenderProcessHostImpl::UpdateProcessPriority() {
|
| // Notify the child process of background state. Note
|
| // |boost_priority_for_pending_views_| state is not sent to renderer simply
|
| // due to lack of need.
|
| - if (should_background_changed)
|
| + if (should_background_changed) {
|
| Send(new ChildProcessMsg_SetProcessBackgrounded(should_background));
|
| + LOG(ERROR) << "RenderProcessHostImpl::SetProcessPriority: SUCCESS!";
|
| + }
|
| }
|
|
|
| void RenderProcessHostImpl::OnProcessLaunched() {
|
|
|