Commit 1801762b authored by Etienne Bergeron's avatar Etienne Bergeron Committed by Commit Bot

Fix registration of PowerController for ThreadControllers.

The CL is fixing the issue where the IO-Thread was not receiving the
power manager notifications.

The observer list doesn't register observers without a sequence
being set.

  void AddObserver(ObserverType* observer) {
    // TODO(fdoray): Change this to a DCHECK once all call sites have a
    // SequencedTaskRunnerHandle.
    if (!SequencedTaskRunnerHandle::IsSet())
      return;

Previously, these observers were not registered and notifications
were not received.

Currently, the thread controller bind to the current thread but has
conditional code depending if the task runner is set.

  see: ThreadControllerWithMessagePumpImpl::BindToCurrentThread

  if (task_runner_)
      InitializeThreadTaskRunnerHandle();


The function InitializeThreadTaskRunnerHandle(...) is the place to make
the link between the PowerMonitor and the Controller since a
task_runner is required for power notifications.


Bug: 1074332
Change-Id: If3e652e6516fdc3df4e3ea8ace909389d668e690
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2225627Reviewed-by: default avatarFrançois Doray <fdoray@chromium.org>
Reviewed-by: default avatarGabriel Charette <gab@chromium.org>
Commit-Queue: Etienne Bergeron <etienneb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#774722}
parent 1eeaa11d
......@@ -30,13 +30,15 @@ ThreadControllerPowerMonitor::~ThreadControllerPowerMonitor() {
}
void ThreadControllerPowerMonitor::BindToCurrentThread() {
#if DCHECK_IS_ON()
DCHECK(!is_observer_registered_);
is_observer_registered_ = true;
#endif
// Occasionally registration happens twice (i.e. when the deprecated
// ThreadController::SetDefaultTaskRunner() re-initializes the
// ThreadController).
if (is_observer_registered_)
PowerMonitor::RemoveObserver(this);
// Register the observer to deliver notifications on the current thread.
PowerMonitor::AddObserver(this);
is_observer_registered_ = true;
}
bool ThreadControllerPowerMonitor::IsProcessInPowerSuspendState() {
......
......@@ -5,8 +5,6 @@
#ifndef BASE_TASK_SEQUENCE_MANAGER_THREAD_CONTROLLER_POWER_MONITOR_H_
#define BASE_TASK_SEQUENCE_MANAGER_THREAD_CONTROLLER_POWER_MONITOR_H_
#include "base/check.h"
#include "base/macros.h"
#include "base/power_monitor/power_observer.h"
namespace base {
......@@ -47,10 +45,8 @@ class BASE_EXPORT ThreadControllerPowerMonitor : public PowerObserver {
// Power state based on notifications delivered to this observer.
bool is_power_suspended_ = false;
#if DCHECK_IS_ON()
// Whether PowerMonitor observer is registered.
bool is_observer_registered_ = false;
#endif
};
} // namespace internal
......
......@@ -100,7 +100,6 @@ void ThreadControllerWithMessagePumpImpl::BindToCurrentThread(
ShouldScheduleWork::kScheduleImmediate) {
pump_->ScheduleWork();
}
power_monitor_.BindToCurrentThread();
}
void ThreadControllerWithMessagePumpImpl::SetWorkBatchSize(
......@@ -179,6 +178,9 @@ void ThreadControllerWithMessagePumpImpl::InitializeThreadTaskRunnerHandle() {
main_thread_only().thread_task_runner_handle.reset();
main_thread_only().thread_task_runner_handle =
std::make_unique<ThreadTaskRunnerHandle>(task_runner_);
// When the task runner is known, bind the power manager. Power notifications
// are received through that sequence.
power_monitor_.BindToCurrentThread();
}
scoped_refptr<SingleThreadTaskRunner>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment