Shift PowerMonitor to non static
Bug: 346931324 Change-Id: I80fab35a422083c5a9db1d9ee4a2ccd34e11d32f Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5806403 Reviewed-by: Peter Kasting <pkasting@chromium.org> Owners-Override: Peter Kasting <pkasting@chromium.org> Commit-Queue: Peter Kasting <pkasting@chromium.org> Cr-Commit-Position: refs/heads/main@{#1350494}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
ca632a2f83
commit
bcf73217bf
ash/login/ui
base
power_monitor
power_monitor.ccpower_monitor.hpower_monitor_device_source.ccpower_monitor_device_source.hpower_monitor_device_source_android.ccpower_monitor_device_source_chromeos.ccpower_monitor_device_source_ios.mmpower_monitor_device_source_mac.mmpower_monitor_device_source_stub.ccpower_monitor_device_source_win.ccpower_monitor_source.ccpower_monitor_source.hpower_monitor_unittest.ccspeed_limit_observer_win.ccspeed_limit_observer_win.hthermal_state_observer_mac.hthermal_state_observer_mac.mm
task
sequence_manager
test
threading
timer
chrome
browser
ash
login
content_settings
download
extensions
feedback
system_logs
log_sources
media
metrics
perf
tab_stats
usage_scenario
performance_manager
test_support
fake_power_monitor_source.ccfake_power_monitor_source.htest_user_performance_tuning_manager_environment.cc
user_tuning
predictors
smart_card
ui
views
relaunch_notification
web_applications
test
chromeos
ash
components
services
multidevice_setup
dbus
components
download
internal
nacl
loader
power_monitor
viz
service
content
google_apis/gcm/engine
gpu
ios/web/init
media
net
http
socket
services
device
power_monitor
public
media_session
third_party/blink
ui
@ -79,8 +79,8 @@ LockScreenMediaView::LockScreenMediaView(
|
||||
hide_media_view_callback_(hide_media_view_callback) {
|
||||
// Observe power events and if created in power suspended state, post
|
||||
// OnSuspend() call to run after LockContentsView is initialized.
|
||||
if (base::PowerMonitor::AddPowerSuspendObserverAndReturnSuspendedState(
|
||||
this)) {
|
||||
if (base::PowerMonitor::GetInstance()
|
||||
->AddPowerSuspendObserverAndReturnSuspendedState(this)) {
|
||||
base::SingleThreadTaskRunner::GetCurrentDefault()->PostTask(
|
||||
FROM_HERE, base::BindOnce(&LockScreenMediaView::OnSuspend,
|
||||
weak_ptr_factory_.GetWeakPtr()));
|
||||
@ -137,7 +137,7 @@ LockScreenMediaView::LockScreenMediaView(
|
||||
}
|
||||
|
||||
LockScreenMediaView::~LockScreenMediaView() {
|
||||
base::PowerMonitor::RemovePowerSuspendObserver(this);
|
||||
base::PowerMonitor::GetInstance()->RemovePowerSuspendObserver(this);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -16,62 +16,50 @@ namespace base {
|
||||
|
||||
void PowerMonitor::Initialize(std::unique_ptr<PowerMonitorSource> source) {
|
||||
DCHECK(!IsInitialized());
|
||||
PowerMonitor* power_monitor = GetInstance();
|
||||
power_monitor->source_ = std::move(source);
|
||||
source_ = std::move(source);
|
||||
|
||||
// When a power source is associated with the power monitor, ensure the
|
||||
// initial state is propagated to observers, if needed.
|
||||
PowerMonitor::NotifyPowerStateChange(
|
||||
PowerMonitor::Source()->GetBatteryPowerStatus());
|
||||
NotifyPowerStateChange(Source()->GetBatteryPowerStatus());
|
||||
|
||||
PowerMonitor::PowerMonitor::NotifyThermalStateChange(
|
||||
PowerMonitor::Source()->GetCurrentThermalState());
|
||||
NotifyThermalStateChange(Source()->GetCurrentThermalState());
|
||||
|
||||
PowerMonitor::PowerMonitor::NotifySpeedLimitChange(
|
||||
PowerMonitor::Source()->GetInitialSpeedLimit());
|
||||
NotifySpeedLimitChange(Source()->GetInitialSpeedLimit());
|
||||
}
|
||||
|
||||
bool PowerMonitor::IsInitialized() {
|
||||
return GetInstance()->source_.get() != nullptr;
|
||||
bool PowerMonitor::IsInitialized() const {
|
||||
return source_ != nullptr;
|
||||
}
|
||||
|
||||
// static
|
||||
void PowerMonitor::AddPowerSuspendObserver(PowerSuspendObserver* obs) {
|
||||
GetInstance()->power_suspend_observers_->AddObserver(obs);
|
||||
power_suspend_observers_->AddObserver(obs);
|
||||
}
|
||||
|
||||
// static
|
||||
void PowerMonitor::RemovePowerSuspendObserver(PowerSuspendObserver* obs) {
|
||||
GetInstance()->power_suspend_observers_->RemoveObserver(obs);
|
||||
power_suspend_observers_->RemoveObserver(obs);
|
||||
}
|
||||
|
||||
// static
|
||||
void PowerMonitor::AddPowerStateObserver(PowerStateObserver* obs) {
|
||||
GetInstance()->power_state_observers_->AddObserver(obs);
|
||||
power_state_observers_->AddObserver(obs);
|
||||
}
|
||||
|
||||
// static
|
||||
void PowerMonitor::RemovePowerStateObserver(PowerStateObserver* obs) {
|
||||
GetInstance()->power_state_observers_->RemoveObserver(obs);
|
||||
power_state_observers_->RemoveObserver(obs);
|
||||
}
|
||||
|
||||
// static
|
||||
void PowerMonitor::AddPowerThermalObserver(PowerThermalObserver* obs) {
|
||||
GetInstance()->thermal_state_observers_->AddObserver(obs);
|
||||
thermal_state_observers_->AddObserver(obs);
|
||||
}
|
||||
|
||||
// static
|
||||
void PowerMonitor::RemovePowerThermalObserver(PowerThermalObserver* obs) {
|
||||
GetInstance()->thermal_state_observers_->RemoveObserver(obs);
|
||||
thermal_state_observers_->RemoveObserver(obs);
|
||||
}
|
||||
|
||||
// static
|
||||
bool PowerMonitor::AddPowerSuspendObserverAndReturnSuspendedState(
|
||||
PowerSuspendObserver* obs) {
|
||||
PowerMonitor* power_monitor = GetInstance();
|
||||
AutoLock auto_lock(power_monitor->is_system_suspended_lock_);
|
||||
power_monitor->power_suspend_observers_->AddObserver(obs);
|
||||
return power_monitor->is_system_suspended_;
|
||||
AutoLock auto_lock(is_system_suspended_lock_);
|
||||
power_suspend_observers_->AddObserver(obs);
|
||||
return is_system_suspended_;
|
||||
}
|
||||
|
||||
// static
|
||||
@ -84,84 +72,79 @@ bool PowerMonitor::AddPowerStateObserverAndReturnOnBatteryState(
|
||||
PowerStateObserver::BatteryPowerStatus
|
||||
PowerMonitor::AddPowerStateObserverAndReturnBatteryPowerStatus(
|
||||
PowerStateObserver* obs) {
|
||||
PowerMonitor* power_monitor = GetInstance();
|
||||
AutoLock auto_lock(power_monitor->battery_power_status_lock_);
|
||||
power_monitor->power_state_observers_->AddObserver(obs);
|
||||
return power_monitor->battery_power_status_;
|
||||
AutoLock auto_lock(battery_power_status_lock_);
|
||||
power_state_observers_->AddObserver(obs);
|
||||
return battery_power_status_;
|
||||
}
|
||||
|
||||
// static
|
||||
PowerThermalObserver::DeviceThermalState
|
||||
PowerMonitor::AddPowerStateObserverAndReturnPowerThermalState(
|
||||
PowerThermalObserver* obs) {
|
||||
PowerMonitor* power_monitor = GetInstance();
|
||||
AutoLock auto_lock(power_monitor->power_thermal_state_lock_);
|
||||
power_monitor->thermal_state_observers_->AddObserver(obs);
|
||||
return power_monitor->power_thermal_state_;
|
||||
AutoLock auto_lock(power_thermal_state_lock_);
|
||||
thermal_state_observers_->AddObserver(obs);
|
||||
return power_thermal_state_;
|
||||
}
|
||||
|
||||
PowerMonitorSource* PowerMonitor::Source() {
|
||||
return GetInstance()->source_.get();
|
||||
const PowerMonitorSource* PowerMonitor::Source() const {
|
||||
return source_.get();
|
||||
}
|
||||
|
||||
bool PowerMonitor::IsOnBatteryPower() {
|
||||
bool PowerMonitor::IsOnBatteryPower() const {
|
||||
DCHECK(IsInitialized());
|
||||
return GetBatteryPowerStatus() ==
|
||||
PowerStateObserver::BatteryPowerStatus::kBatteryPower;
|
||||
}
|
||||
|
||||
PowerStateObserver::BatteryPowerStatus PowerMonitor::GetBatteryPowerStatus() {
|
||||
PowerStateObserver::BatteryPowerStatus PowerMonitor::GetBatteryPowerStatus()
|
||||
const {
|
||||
DCHECK(IsInitialized());
|
||||
PowerMonitor* power_monitor = GetInstance();
|
||||
AutoLock auto_lock(power_monitor->battery_power_status_lock_);
|
||||
return power_monitor->battery_power_status_;
|
||||
AutoLock auto_lock(battery_power_status_lock_);
|
||||
return battery_power_status_;
|
||||
}
|
||||
|
||||
TimeTicks PowerMonitor::GetLastSystemResumeTime() {
|
||||
PowerMonitor* power_monitor = GetInstance();
|
||||
AutoLock auto_lock(power_monitor->is_system_suspended_lock_);
|
||||
return power_monitor->last_system_resume_time_;
|
||||
TimeTicks PowerMonitor::GetLastSystemResumeTime() const {
|
||||
AutoLock auto_lock(is_system_suspended_lock_);
|
||||
return last_system_resume_time_;
|
||||
}
|
||||
|
||||
void PowerMonitor::ShutdownForTesting() {
|
||||
GetInstance()->source_ = nullptr;
|
||||
source_ = nullptr;
|
||||
|
||||
PowerMonitor* power_monitor = GetInstance();
|
||||
{
|
||||
AutoLock auto_lock(power_monitor->is_system_suspended_lock_);
|
||||
power_monitor->is_system_suspended_ = false;
|
||||
power_monitor->last_system_resume_time_ = TimeTicks();
|
||||
AutoLock auto_lock(is_system_suspended_lock_);
|
||||
is_system_suspended_ = false;
|
||||
last_system_resume_time_ = TimeTicks();
|
||||
}
|
||||
{
|
||||
AutoLock auto_lock(power_monitor->battery_power_status_lock_);
|
||||
power_monitor->battery_power_status_ =
|
||||
AutoLock auto_lock(battery_power_status_lock_);
|
||||
battery_power_status_ =
|
||||
PowerStateObserver::BatteryPowerStatus::kExternalPower;
|
||||
}
|
||||
{
|
||||
AutoLock auto_lock(power_monitor->power_thermal_state_lock_);
|
||||
power_monitor->power_thermal_state_ =
|
||||
PowerThermalObserver::DeviceThermalState::kUnknown;
|
||||
AutoLock auto_lock(power_thermal_state_lock_);
|
||||
power_thermal_state_ = PowerThermalObserver::DeviceThermalState::kUnknown;
|
||||
}
|
||||
}
|
||||
|
||||
// static
|
||||
PowerThermalObserver::DeviceThermalState
|
||||
PowerMonitor::GetCurrentThermalState() {
|
||||
PowerThermalObserver::DeviceThermalState PowerMonitor::GetCurrentThermalState()
|
||||
const {
|
||||
DCHECK(IsInitialized());
|
||||
return GetInstance()->source_->GetCurrentThermalState();
|
||||
return source_->GetCurrentThermalState();
|
||||
}
|
||||
|
||||
// static
|
||||
void PowerMonitor::SetCurrentThermalState(
|
||||
PowerThermalObserver::DeviceThermalState state) {
|
||||
DCHECK(IsInitialized());
|
||||
GetInstance()->source_->SetCurrentThermalState(state);
|
||||
source_->SetCurrentThermalState(state);
|
||||
}
|
||||
|
||||
#if BUILDFLAG(IS_ANDROID)
|
||||
int PowerMonitor::GetRemainingBatteryCapacity() {
|
||||
int PowerMonitor::GetRemainingBatteryCapacity() const {
|
||||
DCHECK(IsInitialized());
|
||||
return PowerMonitor::Source()->GetRemainingBatteryCapacity();
|
||||
return Source()->GetRemainingBatteryCapacity();
|
||||
}
|
||||
#endif // BUILDFLAG(IS_ANDROID)
|
||||
|
||||
@ -188,11 +171,10 @@ void PowerMonitor::NotifyPowerStateChange(
|
||||
<< " battery";
|
||||
}
|
||||
|
||||
PowerMonitor* power_monitor = GetInstance();
|
||||
AutoLock auto_lock(power_monitor->battery_power_status_lock_);
|
||||
if (power_monitor->battery_power_status_ != battery_power_status) {
|
||||
power_monitor->battery_power_status_ = battery_power_status;
|
||||
GetInstance()->power_state_observers_->Notify(
|
||||
AutoLock auto_lock(battery_power_status_lock_);
|
||||
if (battery_power_status_ != battery_power_status) {
|
||||
battery_power_status_ = battery_power_status;
|
||||
power_state_observers_->Notify(
|
||||
FROM_HERE, &PowerStateObserver::OnBatteryPowerStatusChange,
|
||||
battery_power_status);
|
||||
}
|
||||
@ -204,13 +186,12 @@ void PowerMonitor::NotifySuspend() {
|
||||
TRACE_EVENT_SCOPE_PROCESS);
|
||||
DVLOG(1) << "Power Suspending";
|
||||
|
||||
PowerMonitor* power_monitor = GetInstance();
|
||||
AutoLock auto_lock(power_monitor->is_system_suspended_lock_);
|
||||
if (!power_monitor->is_system_suspended_) {
|
||||
power_monitor->is_system_suspended_ = true;
|
||||
power_monitor->last_system_resume_time_ = TimeTicks::Max();
|
||||
GetInstance()->power_suspend_observers_->Notify(
|
||||
FROM_HERE, &PowerSuspendObserver::OnSuspend);
|
||||
AutoLock auto_lock(is_system_suspended_lock_);
|
||||
if (!is_system_suspended_) {
|
||||
is_system_suspended_ = true;
|
||||
last_system_resume_time_ = TimeTicks::Max();
|
||||
power_suspend_observers_->Notify(FROM_HERE,
|
||||
&PowerSuspendObserver::OnSuspend);
|
||||
}
|
||||
}
|
||||
|
||||
@ -222,13 +203,12 @@ void PowerMonitor::NotifyResume() {
|
||||
|
||||
TimeTicks resume_time = TimeTicks::Now();
|
||||
|
||||
PowerMonitor* power_monitor = GetInstance();
|
||||
AutoLock auto_lock(power_monitor->is_system_suspended_lock_);
|
||||
if (power_monitor->is_system_suspended_) {
|
||||
power_monitor->is_system_suspended_ = false;
|
||||
power_monitor->last_system_resume_time_ = resume_time;
|
||||
GetInstance()->power_suspend_observers_->Notify(
|
||||
FROM_HERE, &PowerSuspendObserver::OnResume);
|
||||
AutoLock auto_lock(is_system_suspended_lock_);
|
||||
if (is_system_suspended_) {
|
||||
is_system_suspended_ = false;
|
||||
last_system_resume_time_ = resume_time;
|
||||
power_suspend_observers_->Notify(FROM_HERE,
|
||||
&PowerSuspendObserver::OnResume);
|
||||
}
|
||||
}
|
||||
|
||||
@ -238,11 +218,10 @@ void PowerMonitor::NotifyThermalStateChange(
|
||||
DVLOG(1) << "ThermalStateChange: "
|
||||
<< PowerMonitorSource::DeviceThermalStateToString(new_state);
|
||||
|
||||
PowerMonitor* power_monitor = GetInstance();
|
||||
AutoLock auto_lock(power_monitor->power_thermal_state_lock_);
|
||||
if (power_monitor->power_thermal_state_ != new_state) {
|
||||
power_monitor->power_thermal_state_ = new_state;
|
||||
GetInstance()->thermal_state_observers_->Notify(
|
||||
AutoLock auto_lock(power_thermal_state_lock_);
|
||||
if (power_thermal_state_ != new_state) {
|
||||
power_thermal_state_ = new_state;
|
||||
thermal_state_observers_->Notify(
|
||||
FROM_HERE, &PowerThermalObserver::OnThermalStateChange, new_state);
|
||||
}
|
||||
}
|
||||
@ -251,11 +230,10 @@ void PowerMonitor::NotifySpeedLimitChange(int speed_limit) {
|
||||
DCHECK(IsInitialized());
|
||||
DVLOG(1) << "SpeedLimitChange: " << speed_limit;
|
||||
|
||||
PowerMonitor* power_monitor = GetInstance();
|
||||
AutoLock auto_lock(power_monitor->power_thermal_state_lock_);
|
||||
if (power_monitor->speed_limit_ != speed_limit) {
|
||||
power_monitor->speed_limit_ = speed_limit;
|
||||
GetInstance()->thermal_state_observers_->Notify(
|
||||
AutoLock auto_lock(power_thermal_state_lock_);
|
||||
if (speed_limit_ != speed_limit) {
|
||||
speed_limit_ = speed_limit;
|
||||
thermal_state_observers_->Notify(
|
||||
FROM_HERE, &PowerThermalObserver::OnSpeedLimitChange, speed_limit);
|
||||
}
|
||||
}
|
||||
|
@ -26,11 +26,13 @@ class PowerMonitorSource;
|
||||
// of test contexts where the PowerMonitor global is never created.
|
||||
class BASE_EXPORT PowerMonitor {
|
||||
public:
|
||||
static PowerMonitor* GetInstance();
|
||||
|
||||
// Initializes global PowerMonitor state. Takes ownership of |source|, which
|
||||
// will be leaked on process teardown. May only be called once. Not threadsafe
|
||||
// - no other PowerMonitor methods may be called on any thread while calling
|
||||
// Initialize(). |source| must not be nullptr.
|
||||
static void Initialize(std::unique_ptr<PowerMonitorSource> source);
|
||||
void Initialize(std::unique_ptr<PowerMonitorSource> source);
|
||||
|
||||
PowerMonitor(const PowerMonitor&) = delete;
|
||||
PowerMonitor& operator=(const PowerMonitor&) = delete;
|
||||
@ -38,7 +40,7 @@ class BASE_EXPORT PowerMonitor {
|
||||
// Returns true if Initialize() has been called. Safe to call on any thread,
|
||||
// but must not be called while Initialize() or ShutdownForTesting() is being
|
||||
// invoked.
|
||||
static bool IsInitialized();
|
||||
bool IsInitialized() const;
|
||||
|
||||
// Add and remove an observer.
|
||||
// Can be called from any thread. |observer| is notified on the sequence
|
||||
@ -47,12 +49,12 @@ class BASE_EXPORT PowerMonitor {
|
||||
//
|
||||
// It is safe to add observers before the PowerMonitor is initialized. It is
|
||||
// safe to remove an observer even if it was not added as an observer.
|
||||
static void AddPowerSuspendObserver(PowerSuspendObserver* observer);
|
||||
static void RemovePowerSuspendObserver(PowerSuspendObserver* observer);
|
||||
static void AddPowerStateObserver(PowerStateObserver* observer);
|
||||
static void RemovePowerStateObserver(PowerStateObserver* observer);
|
||||
static void AddPowerThermalObserver(PowerThermalObserver* observer);
|
||||
static void RemovePowerThermalObserver(PowerThermalObserver* observer);
|
||||
void AddPowerSuspendObserver(PowerSuspendObserver* observer);
|
||||
void RemovePowerSuspendObserver(PowerSuspendObserver* observer);
|
||||
void AddPowerStateObserver(PowerStateObserver* observer);
|
||||
void RemovePowerStateObserver(PowerStateObserver* observer);
|
||||
void AddPowerThermalObserver(PowerThermalObserver* observer);
|
||||
void RemovePowerThermalObserver(PowerThermalObserver* observer);
|
||||
|
||||
// Atomically add a PowerSuspendObserver and read the current power suspended
|
||||
// state. This variant must be used to avoid race between adding an observer
|
||||
@ -61,54 +63,53 @@ class BASE_EXPORT PowerMonitor {
|
||||
// if (PowerMonitor::IsSystemSuspended()) { ... }
|
||||
//
|
||||
// Returns true if the system is currently suspended.
|
||||
static bool AddPowerSuspendObserverAndReturnSuspendedState(
|
||||
bool AddPowerSuspendObserverAndReturnSuspendedState(
|
||||
PowerSuspendObserver* observer);
|
||||
// Returns true if the system is on-battery.
|
||||
static bool AddPowerStateObserverAndReturnOnBatteryState(
|
||||
bool AddPowerStateObserverAndReturnOnBatteryState(
|
||||
PowerStateObserver* observer);
|
||||
static PowerStateObserver::BatteryPowerStatus
|
||||
PowerStateObserver::BatteryPowerStatus
|
||||
AddPowerStateObserverAndReturnBatteryPowerStatus(
|
||||
PowerStateObserver* observer);
|
||||
// Returns the power thermal state.
|
||||
static PowerThermalObserver::DeviceThermalState
|
||||
PowerThermalObserver::DeviceThermalState
|
||||
AddPowerStateObserverAndReturnPowerThermalState(
|
||||
PowerThermalObserver* observer);
|
||||
|
||||
// Is the computer currently on battery power. May only be called if the
|
||||
// PowerMonitor has been initialized.
|
||||
static bool IsOnBatteryPower();
|
||||
bool IsOnBatteryPower() const;
|
||||
|
||||
// Returns the current state of the battery power, that can be unknown if the
|
||||
// value isn't initialized yet. May only be called if the PowerMonitor has
|
||||
// been initialized.
|
||||
static PowerStateObserver::BatteryPowerStatus GetBatteryPowerStatus();
|
||||
PowerStateObserver::BatteryPowerStatus GetBatteryPowerStatus() const;
|
||||
|
||||
// Returns the time of the last system resume. If no system suspend/resume was
|
||||
// observed, returns an empty time. If the system is currently suspended,
|
||||
// returns TimeTicks::Max().
|
||||
static TimeTicks GetLastSystemResumeTime();
|
||||
TimeTicks GetLastSystemResumeTime() const;
|
||||
|
||||
// Read the current DeviceThermalState if known. Can be called on any thread.
|
||||
// May only be called if the PowerMonitor has been initialized.
|
||||
static PowerThermalObserver::DeviceThermalState GetCurrentThermalState();
|
||||
PowerThermalObserver::DeviceThermalState GetCurrentThermalState() const;
|
||||
|
||||
// Update the result of thermal state.
|
||||
static void SetCurrentThermalState(
|
||||
PowerThermalObserver::DeviceThermalState state);
|
||||
void SetCurrentThermalState(PowerThermalObserver::DeviceThermalState state);
|
||||
|
||||
#if BUILDFLAG(IS_ANDROID)
|
||||
// Read and return the current remaining battery capacity (microampere-hours).
|
||||
// Only supported with a device power source (i.e. not in child processes in
|
||||
// Chrome) and on devices with Android >= Lollipop as well as a power supply
|
||||
// that supports this counter. Returns 0 if unsupported.
|
||||
static int GetRemainingBatteryCapacity();
|
||||
int GetRemainingBatteryCapacity() const;
|
||||
#endif // BUILDFLAG(IS_ANDROID)
|
||||
|
||||
// Uninitializes the PowerMonitor. Should be called at the end of any unit
|
||||
// test that mocks out the PowerMonitor, to avoid affecting subsequent tests.
|
||||
// There must be no live observers when invoked. Safe to call even if the
|
||||
// PowerMonitor hasn't been initialized.
|
||||
static void ShutdownForTesting();
|
||||
void ShutdownForTesting();
|
||||
|
||||
private:
|
||||
friend class PowerMonitorSource;
|
||||
@ -117,27 +118,25 @@ class BASE_EXPORT PowerMonitor {
|
||||
PowerMonitor();
|
||||
~PowerMonitor();
|
||||
|
||||
static PowerMonitorSource* Source();
|
||||
const PowerMonitorSource* Source() const;
|
||||
|
||||
static void NotifyPowerStateChange(bool on_battery_power);
|
||||
static void NotifyPowerStateChange(
|
||||
void NotifyPowerStateChange(bool on_battery_power);
|
||||
void NotifyPowerStateChange(
|
||||
PowerStateObserver::BatteryPowerStatus battery_power_status);
|
||||
static void NotifySuspend();
|
||||
static void NotifyResume();
|
||||
static void NotifyThermalStateChange(
|
||||
void NotifySuspend();
|
||||
void NotifyResume();
|
||||
void NotifyThermalStateChange(
|
||||
PowerThermalObserver::DeviceThermalState new_state);
|
||||
static void NotifySpeedLimitChange(int speed_limit);
|
||||
|
||||
static PowerMonitor* GetInstance();
|
||||
void NotifySpeedLimitChange(int speed_limit);
|
||||
|
||||
bool is_system_suspended_ GUARDED_BY(is_system_suspended_lock_) = false;
|
||||
Lock is_system_suspended_lock_;
|
||||
mutable Lock is_system_suspended_lock_;
|
||||
TimeTicks last_system_resume_time_ GUARDED_BY(is_system_suspended_lock_);
|
||||
|
||||
PowerStateObserver::BatteryPowerStatus battery_power_status_
|
||||
GUARDED_BY(battery_power_status_lock_) =
|
||||
PowerStateObserver::BatteryPowerStatus::kExternalPower;
|
||||
Lock battery_power_status_lock_;
|
||||
mutable Lock battery_power_status_lock_;
|
||||
|
||||
PowerThermalObserver::DeviceThermalState power_thermal_state_
|
||||
GUARDED_BY(power_thermal_state_lock_) =
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
namespace base {
|
||||
|
||||
bool PowerMonitorDeviceSource::IsOnBatteryPower() {
|
||||
bool PowerMonitorDeviceSource::IsOnBatteryPower() const {
|
||||
return GetBatteryPowerStatus() ==
|
||||
PowerStateObserver::BatteryPowerStatus::kBatteryPower;
|
||||
}
|
||||
|
@ -62,7 +62,8 @@ class BASE_EXPORT PowerMonitorDeviceSource : public PowerMonitorSource {
|
||||
|
||||
// These two methods is used for handling thermal state update requests, such
|
||||
// as asking for initial state when starting lisitening to thermal change.
|
||||
PowerThermalObserver::DeviceThermalState GetCurrentThermalState() override;
|
||||
PowerThermalObserver::DeviceThermalState GetCurrentThermalState()
|
||||
const override;
|
||||
void SetCurrentThermalState(
|
||||
PowerThermalObserver::DeviceThermalState state) override;
|
||||
#endif
|
||||
@ -109,29 +110,31 @@ class BASE_EXPORT PowerMonitorDeviceSource : public PowerMonitorSource {
|
||||
// Platform-specific method to check whether the system is currently
|
||||
// running on battery power. Returns true if running on batteries,
|
||||
// false otherwise.
|
||||
bool IsOnBatteryPower() final;
|
||||
bool IsOnBatteryPower() const final;
|
||||
|
||||
// Platform-specific method to check whether the system is currently
|
||||
// running on battery power. Returns kBatteryPower if running on battery,
|
||||
// kExternalPower if running on external power or kUnknown if the power
|
||||
// state is unknown (for example, during early process lifetime when the
|
||||
// state hasn't been obtained yet).
|
||||
PowerStateObserver::BatteryPowerStatus GetBatteryPowerStatus();
|
||||
PowerStateObserver::BatteryPowerStatus GetBatteryPowerStatus() const;
|
||||
|
||||
#if BUILDFLAG(IS_ANDROID)
|
||||
PowerThermalObserver::DeviceThermalState GetCurrentThermalState() override;
|
||||
int GetRemainingBatteryCapacity() override;
|
||||
PowerThermalObserver::DeviceThermalState GetCurrentThermalState()
|
||||
const override;
|
||||
int GetRemainingBatteryCapacity() const override;
|
||||
#endif // BUILDFLAG(IS_ANDROID)
|
||||
|
||||
#if BUILDFLAG(IS_WIN)
|
||||
// PowerMonitorSource:
|
||||
int GetInitialSpeedLimit() override;
|
||||
int GetInitialSpeedLimit() const override;
|
||||
#endif // BUILDFLAG(IS_WIN)
|
||||
|
||||
#if BUILDFLAG(IS_MAC)
|
||||
// PowerMonitorSource:
|
||||
PowerThermalObserver::DeviceThermalState GetCurrentThermalState() override;
|
||||
int GetInitialSpeedLimit() override;
|
||||
PowerThermalObserver::DeviceThermalState GetCurrentThermalState()
|
||||
const override;
|
||||
int GetInitialSpeedLimit() const override;
|
||||
|
||||
// Retrieves the current battery state to update `is_on_battery_`.
|
||||
void GetBatteryState();
|
||||
|
@ -83,20 +83,20 @@ void JNI_PowerMonitor_OnThermalStatusChanged(JNIEnv* env, int thermal_status) {
|
||||
} // namespace android
|
||||
|
||||
PowerStateObserver::BatteryPowerStatus
|
||||
PowerMonitorDeviceSource::GetBatteryPowerStatus() {
|
||||
PowerMonitorDeviceSource::GetBatteryPowerStatus() const {
|
||||
JNIEnv* env = jni_zero::AttachCurrentThread();
|
||||
int battery_power =
|
||||
base::android::Java_PowerMonitor_getBatteryPowerStatus(env);
|
||||
return static_cast<PowerStateObserver::BatteryPowerStatus>(battery_power);
|
||||
}
|
||||
|
||||
int PowerMonitorDeviceSource::GetRemainingBatteryCapacity() {
|
||||
int PowerMonitorDeviceSource::GetRemainingBatteryCapacity() const {
|
||||
JNIEnv* env = jni_zero::AttachCurrentThread();
|
||||
return base::android::Java_PowerMonitor_getRemainingBatteryCapacity(env);
|
||||
}
|
||||
|
||||
PowerThermalObserver::DeviceThermalState
|
||||
PowerMonitorDeviceSource::GetCurrentThermalState() {
|
||||
PowerMonitorDeviceSource::GetCurrentThermalState() const {
|
||||
JNIEnv* env = jni_zero::AttachCurrentThread();
|
||||
return android::MapToDeviceThermalState(
|
||||
android::Java_PowerMonitor_getCurrentThermalStatus(env));
|
||||
|
@ -38,23 +38,24 @@ void PowerMonitorDeviceSource::HandleSystemResumed() {
|
||||
}
|
||||
|
||||
PowerStateObserver::BatteryPowerStatus
|
||||
PowerMonitorDeviceSource::GetBatteryPowerStatus() {
|
||||
PowerMonitorDeviceSource::GetBatteryPowerStatus() const {
|
||||
return g_battery_power_status;
|
||||
}
|
||||
|
||||
// static
|
||||
void PowerMonitorDeviceSource::ThermalEventReceived(
|
||||
PowerThermalObserver::DeviceThermalState state) {
|
||||
if (!PowerMonitor::IsInitialized()) {
|
||||
PowerMonitor::Initialize(std::make_unique<PowerMonitorDeviceSource>());
|
||||
auto* power_monitor = base::PowerMonitor::GetInstance();
|
||||
if (!power_monitor->IsInitialized()) {
|
||||
power_monitor->Initialize(std::make_unique<PowerMonitorDeviceSource>());
|
||||
}
|
||||
PowerMonitor::SetCurrentThermalState(state);
|
||||
power_monitor->SetCurrentThermalState(state);
|
||||
|
||||
ProcessThermalEvent(state);
|
||||
}
|
||||
|
||||
PowerThermalObserver::DeviceThermalState
|
||||
PowerMonitorDeviceSource::GetCurrentThermalState() {
|
||||
PowerMonitorDeviceSource::GetCurrentThermalState() const {
|
||||
return current_thermal_state_;
|
||||
}
|
||||
|
||||
|
@ -11,7 +11,7 @@
|
||||
namespace base {
|
||||
|
||||
PowerStateObserver::BatteryPowerStatus
|
||||
PowerMonitorDeviceSource::GetBatteryPowerStatus() {
|
||||
PowerMonitorDeviceSource::GetBatteryPowerStatus() const {
|
||||
#if TARGET_IPHONE_SIMULATOR
|
||||
return PowerStateObserver::BatteryPowerStatus::kExternalPower;
|
||||
#else
|
||||
|
@ -20,11 +20,11 @@
|
||||
namespace base {
|
||||
|
||||
PowerThermalObserver::DeviceThermalState
|
||||
PowerMonitorDeviceSource::GetCurrentThermalState() {
|
||||
PowerMonitorDeviceSource::GetCurrentThermalState() const {
|
||||
return thermal_state_observer_->GetCurrentThermalState();
|
||||
}
|
||||
|
||||
int PowerMonitorDeviceSource::GetInitialSpeedLimit() {
|
||||
int PowerMonitorDeviceSource::GetInitialSpeedLimit() const {
|
||||
return thermal_state_observer_->GetCurrentSpeedLimit();
|
||||
}
|
||||
|
||||
@ -96,7 +96,7 @@ void PowerMonitorDeviceSource::PlatformDestroy() {
|
||||
}
|
||||
|
||||
PowerStateObserver::BatteryPowerStatus
|
||||
PowerMonitorDeviceSource::GetBatteryPowerStatus() {
|
||||
PowerMonitorDeviceSource::GetBatteryPowerStatus() const {
|
||||
return battery_power_status_;
|
||||
}
|
||||
|
||||
|
@ -8,7 +8,7 @@
|
||||
namespace base {
|
||||
|
||||
PowerStateObserver::BatteryPowerStatus
|
||||
PowerMonitorDeviceSource::GetBatteryPowerStatus() {
|
||||
PowerMonitorDeviceSource::GetBatteryPowerStatus() const {
|
||||
return PowerStateObserver::BatteryPowerStatus::kExternalPower;
|
||||
}
|
||||
|
||||
|
@ -76,7 +76,7 @@ void PowerMonitorDeviceSource::PlatformDestroy() {
|
||||
}
|
||||
|
||||
PowerStateObserver::BatteryPowerStatus
|
||||
PowerMonitorDeviceSource::GetBatteryPowerStatus() {
|
||||
PowerMonitorDeviceSource::GetBatteryPowerStatus() const {
|
||||
SYSTEM_POWER_STATUS status;
|
||||
if (!::GetSystemPowerStatus(&status)) {
|
||||
DPLOG(ERROR) << "GetSystemPowerStatus failed";
|
||||
@ -87,7 +87,7 @@ PowerMonitorDeviceSource::GetBatteryPowerStatus() {
|
||||
: PowerStateObserver::BatteryPowerStatus::kExternalPower;
|
||||
}
|
||||
|
||||
int PowerMonitorDeviceSource::GetInitialSpeedLimit() {
|
||||
int PowerMonitorDeviceSource::GetInitialSpeedLimit() const {
|
||||
// Returns the maximum value once at start. Subsequent actual values will be
|
||||
// provided asynchronously via callbacks instead.
|
||||
return PowerThermalObserver::kSpeedLimitMax;
|
||||
|
@ -15,11 +15,11 @@ PowerMonitorSource::PowerMonitorSource() = default;
|
||||
PowerMonitorSource::~PowerMonitorSource() = default;
|
||||
|
||||
PowerThermalObserver::DeviceThermalState
|
||||
PowerMonitorSource::GetCurrentThermalState() {
|
||||
PowerMonitorSource::GetCurrentThermalState() const {
|
||||
return PowerThermalObserver::DeviceThermalState::kUnknown;
|
||||
}
|
||||
|
||||
int PowerMonitorSource::GetInitialSpeedLimit() {
|
||||
int PowerMonitorSource::GetInitialSpeedLimit() const {
|
||||
return PowerThermalObserver::kSpeedLimitMax;
|
||||
}
|
||||
|
||||
@ -27,43 +27,47 @@ void PowerMonitorSource::SetCurrentThermalState(
|
||||
PowerThermalObserver::DeviceThermalState state) {}
|
||||
|
||||
#if BUILDFLAG(IS_ANDROID)
|
||||
int PowerMonitorSource::GetRemainingBatteryCapacity() {
|
||||
int PowerMonitorSource::GetRemainingBatteryCapacity() const {
|
||||
return 0;
|
||||
}
|
||||
#endif // BUILDFLAG(IS_ANDROID)
|
||||
|
||||
// static
|
||||
void PowerMonitorSource::ProcessPowerEvent(PowerEvent event_id) {
|
||||
if (!PowerMonitor::IsInitialized())
|
||||
auto* power_monitor = base::PowerMonitor::GetInstance();
|
||||
if (!power_monitor->IsInitialized()) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (event_id) {
|
||||
case POWER_STATE_EVENT:
|
||||
PowerMonitor::NotifyPowerStateChange(
|
||||
PowerMonitor::Source()->GetBatteryPowerStatus());
|
||||
power_monitor->NotifyPowerStateChange(
|
||||
power_monitor->Source()->GetBatteryPowerStatus());
|
||||
break;
|
||||
case RESUME_EVENT:
|
||||
PowerMonitor::NotifyResume();
|
||||
break;
|
||||
power_monitor->NotifyResume();
|
||||
break;
|
||||
case SUSPEND_EVENT:
|
||||
PowerMonitor::NotifySuspend();
|
||||
break;
|
||||
power_monitor->NotifySuspend();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// static
|
||||
void PowerMonitorSource::ProcessThermalEvent(
|
||||
PowerThermalObserver::DeviceThermalState new_thermal_state) {
|
||||
if (!PowerMonitor::IsInitialized())
|
||||
return;
|
||||
PowerMonitor::NotifyThermalStateChange(new_thermal_state);
|
||||
if (auto* power_monitor = base::PowerMonitor::GetInstance();
|
||||
power_monitor->IsInitialized()) {
|
||||
power_monitor->NotifyThermalStateChange(new_thermal_state);
|
||||
}
|
||||
}
|
||||
|
||||
// static
|
||||
void PowerMonitorSource::ProcessSpeedLimitEvent(int speed_limit) {
|
||||
if (!PowerMonitor::IsInitialized())
|
||||
return;
|
||||
PowerMonitor::NotifySpeedLimitChange(speed_limit);
|
||||
if (auto* power_monitor = base::PowerMonitor::GetInstance();
|
||||
power_monitor->IsInitialized()) {
|
||||
power_monitor->NotifySpeedLimitChange(speed_limit);
|
||||
}
|
||||
}
|
||||
|
||||
// static
|
||||
|
@ -31,14 +31,15 @@ class BASE_EXPORT PowerMonitorSource {
|
||||
|
||||
// Reads the current DeviceThermalState, if available on the platform.
|
||||
// Otherwise, returns kUnknown.
|
||||
virtual PowerThermalObserver::DeviceThermalState GetCurrentThermalState();
|
||||
virtual PowerThermalObserver::DeviceThermalState GetCurrentThermalState()
|
||||
const;
|
||||
|
||||
// Reads the initial operating system CPU speed limit, if available on the
|
||||
// platform. Otherwise returns PowerThermalObserver::kSpeedLimitMax.
|
||||
// Only called on the main thread in PowerMonitor::Initialize().
|
||||
// The actual speed limit value will be updated asynchronously via the
|
||||
// ProcessSpeedLimitEvent() if/when the value changes.
|
||||
virtual int GetInitialSpeedLimit();
|
||||
virtual int GetInitialSpeedLimit() const;
|
||||
|
||||
// Update the result of thermal state.
|
||||
virtual void SetCurrentThermalState(
|
||||
@ -46,9 +47,9 @@ class BASE_EXPORT PowerMonitorSource {
|
||||
|
||||
// Platform-specific method to check whether the system is currently
|
||||
// running on battery power.
|
||||
virtual bool IsOnBatteryPower() = 0;
|
||||
virtual bool IsOnBatteryPower() const = 0;
|
||||
|
||||
PowerStateObserver::BatteryPowerStatus GetBatteryPowerStatus() {
|
||||
PowerStateObserver::BatteryPowerStatus GetBatteryPowerStatus() const {
|
||||
return IsOnBatteryPower()
|
||||
? PowerStateObserver::BatteryPowerStatus::kBatteryPower
|
||||
: PowerStateObserver::BatteryPowerStatus::kExternalPower;
|
||||
@ -56,7 +57,7 @@ class BASE_EXPORT PowerMonitorSource {
|
||||
|
||||
#if BUILDFLAG(IS_ANDROID)
|
||||
// Read and return the current remaining battery capacity (microampere-hours).
|
||||
virtual int GetRemainingBatteryCapacity();
|
||||
virtual int GetRemainingBatteryCapacity() const;
|
||||
#endif // BUILDFLAG(IS_ANDROID)
|
||||
|
||||
static const char* DeviceThermalStateToString(
|
||||
|
@ -40,10 +40,11 @@ TEST_F(PowerMonitorTest, PowerNotifications) {
|
||||
PowerMonitorInitialize();
|
||||
|
||||
PowerMonitorTestObserver observers[kObservers];
|
||||
auto* power_monitor = PowerMonitor::GetInstance();
|
||||
for (auto& index : observers) {
|
||||
PowerMonitor::AddPowerSuspendObserver(&index);
|
||||
PowerMonitor::AddPowerStateObserver(&index);
|
||||
PowerMonitor::AddPowerThermalObserver(&index);
|
||||
power_monitor->AddPowerSuspendObserver(&index);
|
||||
power_monitor->AddPowerStateObserver(&index);
|
||||
power_monitor->AddPowerThermalObserver(&index);
|
||||
}
|
||||
|
||||
// Sending resume when not suspended should have no effect.
|
||||
@ -122,15 +123,16 @@ TEST_F(PowerMonitorTest, PowerNotifications) {
|
||||
PowerThermalObserver::DeviceThermalState::kFair);
|
||||
|
||||
for (auto& index : observers) {
|
||||
PowerMonitor::RemovePowerSuspendObserver(&index);
|
||||
PowerMonitor::RemovePowerStateObserver(&index);
|
||||
PowerMonitor::RemovePowerThermalObserver(&index);
|
||||
power_monitor->RemovePowerSuspendObserver(&index);
|
||||
power_monitor->RemovePowerStateObserver(&index);
|
||||
power_monitor->RemovePowerThermalObserver(&index);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(PowerMonitorTest, ThermalThrottling) {
|
||||
PowerMonitorTestObserver observer;
|
||||
PowerMonitor::AddPowerThermalObserver(&observer);
|
||||
auto* power_monitor = PowerMonitor::GetInstance();
|
||||
power_monitor->AddPowerThermalObserver(&observer);
|
||||
|
||||
PowerMonitorInitialize();
|
||||
|
||||
@ -147,20 +149,21 @@ TEST_F(PowerMonitorTest, ThermalThrottling) {
|
||||
EXPECT_EQ(observer.last_thermal_state(), state);
|
||||
}
|
||||
|
||||
PowerMonitor::RemovePowerThermalObserver(&observer);
|
||||
power_monitor->RemovePowerThermalObserver(&observer);
|
||||
}
|
||||
|
||||
TEST_F(PowerMonitorTest, AddPowerSuspendObserverBeforeAndAfterInitialization) {
|
||||
PowerMonitorTestObserver observer1;
|
||||
PowerMonitorTestObserver observer2;
|
||||
auto* power_monitor = PowerMonitor::GetInstance();
|
||||
|
||||
// An observer is added before the PowerMonitor initialization.
|
||||
PowerMonitor::AddPowerSuspendObserver(&observer1);
|
||||
power_monitor->AddPowerSuspendObserver(&observer1);
|
||||
|
||||
PowerMonitorInitialize();
|
||||
|
||||
// An observer is added after the PowerMonitor initialization.
|
||||
PowerMonitor::AddPowerSuspendObserver(&observer2);
|
||||
power_monitor->AddPowerSuspendObserver(&observer2);
|
||||
|
||||
// Simulate suspend/resume notifications.
|
||||
source().GenerateSuspendEvent();
|
||||
@ -173,21 +176,22 @@ TEST_F(PowerMonitorTest, AddPowerSuspendObserverBeforeAndAfterInitialization) {
|
||||
EXPECT_EQ(observer1.resumes(), 1);
|
||||
EXPECT_EQ(observer2.resumes(), 1);
|
||||
|
||||
PowerMonitor::RemovePowerSuspendObserver(&observer1);
|
||||
PowerMonitor::RemovePowerSuspendObserver(&observer2);
|
||||
power_monitor->RemovePowerSuspendObserver(&observer1);
|
||||
power_monitor->RemovePowerSuspendObserver(&observer2);
|
||||
}
|
||||
|
||||
TEST_F(PowerMonitorTest, AddPowerStateObserverBeforeAndAfterInitialization) {
|
||||
PowerMonitorTestObserver observer1;
|
||||
PowerMonitorTestObserver observer2;
|
||||
auto* power_monitor = PowerMonitor::GetInstance();
|
||||
|
||||
// An observer is added before the PowerMonitor initialization.
|
||||
PowerMonitor::AddPowerStateObserver(&observer1);
|
||||
power_monitor->AddPowerStateObserver(&observer1);
|
||||
|
||||
PowerMonitorInitialize();
|
||||
|
||||
// An observer is added after the PowerMonitor initialization.
|
||||
PowerMonitor::AddPowerStateObserver(&observer2);
|
||||
power_monitor->AddPowerStateObserver(&observer2);
|
||||
|
||||
// Simulate power state transitions (e.g. battery on/off).
|
||||
EXPECT_EQ(observer1.power_state_changes(), 0);
|
||||
@ -201,41 +205,43 @@ TEST_F(PowerMonitorTest, AddPowerStateObserverBeforeAndAfterInitialization) {
|
||||
EXPECT_EQ(observer1.power_state_changes(), 2);
|
||||
EXPECT_EQ(observer2.power_state_changes(), 2);
|
||||
|
||||
PowerMonitor::RemovePowerStateObserver(&observer1);
|
||||
PowerMonitor::RemovePowerStateObserver(&observer2);
|
||||
power_monitor->RemovePowerStateObserver(&observer1);
|
||||
power_monitor->RemovePowerStateObserver(&observer2);
|
||||
}
|
||||
|
||||
TEST_F(PowerMonitorTest, SuspendStateReturnedFromAddObserver) {
|
||||
PowerMonitorTestObserver observer1;
|
||||
PowerMonitorTestObserver observer2;
|
||||
auto* power_monitor = PowerMonitor::GetInstance();
|
||||
|
||||
PowerMonitorInitialize();
|
||||
|
||||
EXPECT_FALSE(
|
||||
PowerMonitor::AddPowerSuspendObserverAndReturnSuspendedState(&observer1));
|
||||
EXPECT_FALSE(power_monitor->AddPowerSuspendObserverAndReturnSuspendedState(
|
||||
&observer1));
|
||||
|
||||
source().GenerateSuspendEvent();
|
||||
|
||||
EXPECT_TRUE(
|
||||
PowerMonitor::AddPowerSuspendObserverAndReturnSuspendedState(&observer2));
|
||||
EXPECT_TRUE(power_monitor->AddPowerSuspendObserverAndReturnSuspendedState(
|
||||
&observer2));
|
||||
|
||||
EXPECT_EQ(observer1.suspends(), 1);
|
||||
EXPECT_EQ(observer2.suspends(), 0);
|
||||
EXPECT_EQ(observer1.resumes(), 0);
|
||||
EXPECT_EQ(observer2.resumes(), 0);
|
||||
|
||||
PowerMonitor::RemovePowerSuspendObserver(&observer1);
|
||||
PowerMonitor::RemovePowerSuspendObserver(&observer2);
|
||||
power_monitor->RemovePowerSuspendObserver(&observer1);
|
||||
power_monitor->RemovePowerSuspendObserver(&observer2);
|
||||
}
|
||||
|
||||
TEST_F(PowerMonitorTest, PowerStateReturnedFromAddObserver) {
|
||||
PowerMonitorTestObserver observer1;
|
||||
PowerMonitorTestObserver observer2;
|
||||
auto* power_monitor = PowerMonitor::GetInstance();
|
||||
|
||||
PowerMonitorInitialize();
|
||||
|
||||
// An observer is added before the on-battery notification.
|
||||
EXPECT_NE(PowerMonitor::AddPowerStateObserverAndReturnBatteryPowerStatus(
|
||||
EXPECT_NE(power_monitor->AddPowerStateObserverAndReturnBatteryPowerStatus(
|
||||
&observer1),
|
||||
PowerStateObserver::BatteryPowerStatus::kBatteryPower);
|
||||
|
||||
@ -243,15 +249,15 @@ TEST_F(PowerMonitorTest, PowerStateReturnedFromAddObserver) {
|
||||
PowerStateObserver::BatteryPowerStatus::kBatteryPower);
|
||||
|
||||
// An observer is added after the on-battery notification.
|
||||
EXPECT_EQ(PowerMonitor::AddPowerStateObserverAndReturnBatteryPowerStatus(
|
||||
EXPECT_EQ(power_monitor->AddPowerStateObserverAndReturnBatteryPowerStatus(
|
||||
&observer2),
|
||||
PowerStateObserver::BatteryPowerStatus::kBatteryPower);
|
||||
|
||||
EXPECT_EQ(observer1.power_state_changes(), 1);
|
||||
EXPECT_EQ(observer2.power_state_changes(), 0);
|
||||
|
||||
PowerMonitor::RemovePowerStateObserver(&observer1);
|
||||
PowerMonitor::RemovePowerStateObserver(&observer2);
|
||||
power_monitor->RemovePowerStateObserver(&observer1);
|
||||
power_monitor->RemovePowerStateObserver(&observer2);
|
||||
}
|
||||
|
||||
} // namespace test
|
||||
|
@ -91,7 +91,7 @@ SpeedLimitObserverWin::~SpeedLimitObserverWin() {
|
||||
timer_.Stop();
|
||||
}
|
||||
|
||||
int SpeedLimitObserverWin::GetCurrentSpeedLimit() {
|
||||
int SpeedLimitObserverWin::GetCurrentSpeedLimit() const {
|
||||
const int kSpeedLimitMax = PowerThermalObserver::kSpeedLimitMax;
|
||||
|
||||
int idleness_percent = 0;
|
||||
@ -172,7 +172,7 @@ void SpeedLimitObserverWin::OnTimerTick() {
|
||||
#endif // BUILDFLAG(ENABLE_BASE_TRACING)
|
||||
}
|
||||
|
||||
float SpeedLimitObserverWin::EstimateThrottlingLevel() {
|
||||
float SpeedLimitObserverWin::EstimateThrottlingLevel() const {
|
||||
float throttling_level = 0.f;
|
||||
|
||||
// Populate the PROCESSOR_POWER_INFORMATION structures for all logical CPUs
|
||||
|
@ -34,9 +34,9 @@ class BASE_EXPORT SpeedLimitObserverWin final {
|
||||
~SpeedLimitObserverWin();
|
||||
|
||||
private:
|
||||
int GetCurrentSpeedLimit();
|
||||
int GetCurrentSpeedLimit() const;
|
||||
void OnTimerTick();
|
||||
float EstimateThrottlingLevel();
|
||||
float EstimateThrottlingLevel() const;
|
||||
|
||||
size_t num_cpus() const { return num_cpus_; }
|
||||
|
||||
@ -54,7 +54,7 @@ class BASE_EXPORT SpeedLimitObserverWin final {
|
||||
// sample rate is one sample per seconds but the existing choice is rather
|
||||
// ad-hoc and not based on any deeper analysis into exact frequency
|
||||
// characteristics of the underlying process.
|
||||
MovingAverage<int, int64_t> moving_average_;
|
||||
mutable MovingAverage<int, int64_t> moving_average_;
|
||||
// Max speed-limit value is 100 (%) and it is also used in cases where the
|
||||
// native Windows API(s) fail.
|
||||
int speed_limit_ = PowerThermalObserver::kSpeedLimitMax;
|
||||
|
@ -37,7 +37,7 @@ class BASE_EXPORT ThermalStateObserverMac {
|
||||
~ThermalStateObserverMac();
|
||||
|
||||
PowerThermalObserver::DeviceThermalState GetCurrentThermalState();
|
||||
int GetCurrentSpeedLimit();
|
||||
int GetCurrentSpeedLimit() const;
|
||||
|
||||
private:
|
||||
FRIEND_TEST_ALL_PREFIXES(ThermalStateObserverMacTest, StateChange);
|
||||
|
@ -109,7 +109,7 @@ ThermalStateObserverMac::GetCurrentThermalState() {
|
||||
return NSProcessInfoThermalStateToDeviceThermalState(nsinfo_state);
|
||||
}
|
||||
|
||||
int ThermalStateObserverMac::GetCurrentSpeedLimit() {
|
||||
int ThermalStateObserverMac::GetCurrentSpeedLimit() const {
|
||||
apple::ScopedCFTypeRef<CFDictionaryRef> dictionary;
|
||||
IOReturn result = IOPMCopyCPUPowerStatus(dictionary.InitializeInto());
|
||||
if (result != kIOReturnSuccess) {
|
||||
|
@ -28,18 +28,19 @@ bool g_use_thread_controller_power_monitor_ = false;
|
||||
ThreadControllerPowerMonitor::ThreadControllerPowerMonitor() = default;
|
||||
|
||||
ThreadControllerPowerMonitor::~ThreadControllerPowerMonitor() {
|
||||
PowerMonitor::RemovePowerSuspendObserver(this);
|
||||
PowerMonitor::GetInstance()->RemovePowerSuspendObserver(this);
|
||||
}
|
||||
|
||||
void ThreadControllerPowerMonitor::BindToCurrentThread() {
|
||||
// Occasionally registration happens twice (i.e. when the
|
||||
// ThreadController::SetDefaultTaskRunner() re-initializes the
|
||||
// ThreadController).
|
||||
auto* power_monitor = PowerMonitor::GetInstance();
|
||||
if (is_observer_registered_)
|
||||
PowerMonitor::RemovePowerSuspendObserver(this);
|
||||
power_monitor->RemovePowerSuspendObserver(this);
|
||||
|
||||
// Register the observer to deliver notifications on the current thread.
|
||||
PowerMonitor::AddPowerSuspendObserver(this);
|
||||
power_monitor->AddPowerSuspendObserver(this);
|
||||
is_observer_registered_ = true;
|
||||
}
|
||||
|
||||
|
@ -19,9 +19,10 @@ class PowerMonitorTestSource : public PowerMonitorSource {
|
||||
~PowerMonitorTestSource() override = default;
|
||||
|
||||
// Retrieve current states.
|
||||
PowerThermalObserver::DeviceThermalState GetCurrentThermalState() override;
|
||||
PowerStateObserver::BatteryPowerStatus GetBatteryPowerStatus();
|
||||
bool IsOnBatteryPower() override;
|
||||
PowerThermalObserver::DeviceThermalState GetCurrentThermalState()
|
||||
const override;
|
||||
PowerStateObserver::BatteryPowerStatus GetBatteryPowerStatus() const;
|
||||
bool IsOnBatteryPower() const override;
|
||||
|
||||
// Sends asynchronous notifications to registered observers.
|
||||
void Suspend();
|
||||
@ -51,7 +52,7 @@ class PowerMonitorTestSource : public PowerMonitorSource {
|
||||
};
|
||||
|
||||
PowerThermalObserver::DeviceThermalState
|
||||
PowerMonitorTestSource::GetCurrentThermalState() {
|
||||
PowerMonitorTestSource::GetCurrentThermalState() const {
|
||||
return current_thermal_state_;
|
||||
}
|
||||
|
||||
@ -98,11 +99,11 @@ void PowerMonitorTestSource::GenerateResumeEvent() {
|
||||
}
|
||||
|
||||
PowerStateObserver::BatteryPowerStatus
|
||||
PowerMonitorTestSource::GetBatteryPowerStatus() {
|
||||
PowerMonitorTestSource::GetBatteryPowerStatus() const {
|
||||
return test_power_status_;
|
||||
}
|
||||
|
||||
bool PowerMonitorTestSource::IsOnBatteryPower() {
|
||||
bool PowerMonitorTestSource::IsOnBatteryPower() const {
|
||||
return test_power_status_ ==
|
||||
PowerStateObserver::BatteryPowerStatus::kBatteryPower;
|
||||
}
|
||||
@ -123,24 +124,25 @@ void PowerMonitorTestSource::GenerateSpeedLimitEvent(int speed_limit) {
|
||||
ScopedPowerMonitorTestSource::ScopedPowerMonitorTestSource() {
|
||||
auto power_monitor_test_source = std::make_unique<PowerMonitorTestSource>();
|
||||
power_monitor_test_source_ = power_monitor_test_source.get();
|
||||
base::PowerMonitor::Initialize(std::move(power_monitor_test_source));
|
||||
base::PowerMonitor::GetInstance()->Initialize(
|
||||
std::move(power_monitor_test_source));
|
||||
}
|
||||
|
||||
ScopedPowerMonitorTestSource::~ScopedPowerMonitorTestSource() {
|
||||
base::PowerMonitor::ShutdownForTesting();
|
||||
base::PowerMonitor::GetInstance()->ShutdownForTesting();
|
||||
}
|
||||
|
||||
PowerThermalObserver::DeviceThermalState
|
||||
ScopedPowerMonitorTestSource::GetCurrentThermalState() {
|
||||
ScopedPowerMonitorTestSource::GetCurrentThermalState() const {
|
||||
return power_monitor_test_source_->GetCurrentThermalState();
|
||||
}
|
||||
|
||||
bool ScopedPowerMonitorTestSource::IsOnBatteryPower() {
|
||||
bool ScopedPowerMonitorTestSource::IsOnBatteryPower() const {
|
||||
return power_monitor_test_source_->IsOnBatteryPower();
|
||||
}
|
||||
|
||||
PowerStateObserver::BatteryPowerStatus
|
||||
ScopedPowerMonitorTestSource::GetBatteryPowerStatus() {
|
||||
ScopedPowerMonitorTestSource::GetBatteryPowerStatus() const {
|
||||
return power_monitor_test_source_->GetBatteryPowerStatus();
|
||||
}
|
||||
|
||||
|
@ -37,9 +37,9 @@ class ScopedPowerMonitorTestSource {
|
||||
delete;
|
||||
|
||||
// Retrieve current states.
|
||||
PowerThermalObserver::DeviceThermalState GetCurrentThermalState();
|
||||
bool IsOnBatteryPower();
|
||||
PowerStateObserver::BatteryPowerStatus GetBatteryPowerStatus();
|
||||
PowerThermalObserver::DeviceThermalState GetCurrentThermalState() const;
|
||||
bool IsOnBatteryPower() const;
|
||||
PowerStateObserver::BatteryPowerStatus GetBatteryPowerStatus() const;
|
||||
|
||||
// Sends asynchronous notifications to registered observers.
|
||||
void Suspend();
|
||||
|
@ -561,7 +561,7 @@ std::string HangWatcher::GetTimeSinceLastSystemPowerResumeCrashKeyValue()
|
||||
DCHECK_CALLED_ON_VALID_THREAD(hang_watcher_thread_checker_);
|
||||
|
||||
const TimeTicks last_system_power_resume_time =
|
||||
PowerMonitor::GetLastSystemResumeTime();
|
||||
PowerMonitor::GetInstance()->GetLastSystemResumeTime();
|
||||
if (last_system_power_resume_time.is_null())
|
||||
return "Never suspended";
|
||||
if (last_system_power_resume_time == TimeTicks::Max())
|
||||
|
@ -40,10 +40,11 @@ HighResolutionTimerManager::HighResolutionTimerManager()
|
||||
// we won't receive power state change callbacks and
|
||||
// hi_res_clock_available_ will remain at its initial value.
|
||||
if (HighResolutionTimerAllowed()) {
|
||||
DCHECK(PowerMonitor::IsInitialized());
|
||||
PowerMonitor::AddPowerSuspendObserver(this);
|
||||
auto* power_monitor = base::PowerMonitor::GetInstance();
|
||||
DCHECK(power_monitor->IsInitialized());
|
||||
power_monitor->AddPowerSuspendObserver(this);
|
||||
const bool on_battery =
|
||||
PowerMonitor::AddPowerStateObserverAndReturnOnBatteryState(this);
|
||||
power_monitor->AddPowerStateObserverAndReturnOnBatteryState(this);
|
||||
UseHiResClock(!on_battery);
|
||||
|
||||
// Start polling the high resolution timer usage.
|
||||
@ -55,8 +56,9 @@ HighResolutionTimerManager::HighResolutionTimerManager()
|
||||
|
||||
HighResolutionTimerManager::~HighResolutionTimerManager() {
|
||||
if (HighResolutionTimerAllowed()) {
|
||||
PowerMonitor::RemovePowerSuspendObserver(this);
|
||||
PowerMonitor::RemovePowerStateObserver(this);
|
||||
auto* power_monitor = base::PowerMonitor::GetInstance();
|
||||
power_monitor->RemovePowerSuspendObserver(this);
|
||||
power_monitor->RemovePowerStateObserver(this);
|
||||
UseHiResClock(false);
|
||||
}
|
||||
}
|
||||
|
@ -51,14 +51,14 @@ void WallClockTimer::OnResume() {
|
||||
|
||||
void WallClockTimer::AddObserver() {
|
||||
if (!observer_added_) {
|
||||
PowerMonitor::AddPowerSuspendObserver(this);
|
||||
PowerMonitor::GetInstance()->AddPowerSuspendObserver(this);
|
||||
observer_added_ = true;
|
||||
}
|
||||
}
|
||||
|
||||
void WallClockTimer::RemoveObserver() {
|
||||
if (observer_added_) {
|
||||
PowerMonitor::RemovePowerSuspendObserver(this);
|
||||
PowerMonitor::GetInstance()->RemovePowerSuspendObserver(this);
|
||||
observer_added_ = false;
|
||||
}
|
||||
}
|
||||
|
@ -75,7 +75,7 @@ void OfflineSigninLimiter::SignedIn(UserContext::AuthFlow auth_flow) {
|
||||
base::BindRepeating(&OfflineSigninLimiter::UpdateLockScreenLimit,
|
||||
base::Unretained(this)));
|
||||
// Start listening to power state.
|
||||
base::PowerMonitor::AddPowerSuspendObserver(this);
|
||||
base::PowerMonitor::GetInstance()->AddPowerSuspendObserver(this);
|
||||
|
||||
// Start listening to session lock state
|
||||
auto* session_manager = session_manager::SessionManager::Get();
|
||||
@ -122,7 +122,7 @@ OfflineSigninLimiter::OfflineSigninLimiter(Profile* profile,
|
||||
std::make_unique<base::WallClockTimer>()) {}
|
||||
|
||||
OfflineSigninLimiter::~OfflineSigninLimiter() {
|
||||
base::PowerMonitor::RemovePowerSuspendObserver(this);
|
||||
base::PowerMonitor::GetInstance()->RemovePowerSuspendObserver(this);
|
||||
auto* session_manager = session_manager::SessionManager::Get();
|
||||
if (session_manager) {
|
||||
session_manager->RemoveObserver(this);
|
||||
|
@ -39,11 +39,11 @@ OneTimePermissionProvider::OneTimePermissionProvider(
|
||||
// main function for the browser process is run (which initializes the HCSM).
|
||||
// For this reason, the PowerMonitor is always initialized before the observer
|
||||
// is added here.
|
||||
base::PowerMonitor::AddPowerSuspendObserver(this);
|
||||
base::PowerMonitor::GetInstance()->AddPowerSuspendObserver(this);
|
||||
}
|
||||
|
||||
OneTimePermissionProvider::~OneTimePermissionProvider() {
|
||||
base::PowerMonitor::RemovePowerSuspendObserver(this);
|
||||
base::PowerMonitor::GetInstance()->RemovePowerSuspendObserver(this);
|
||||
}
|
||||
|
||||
// TODO(b/307193732): handle the PartitionKey in all relevant methods, including
|
||||
|
@ -101,11 +101,11 @@ DownloadDisplayController::DownloadDisplayController(
|
||||
if (display) {
|
||||
MaybeShowButtonWhenCreated();
|
||||
}
|
||||
base::PowerMonitor::AddPowerSuspendObserver(this);
|
||||
base::PowerMonitor::GetInstance()->AddPowerSuspendObserver(this);
|
||||
}
|
||||
|
||||
DownloadDisplayController::~DownloadDisplayController() {
|
||||
base::PowerMonitor::RemovePowerSuspendObserver(this);
|
||||
base::PowerMonitor::GetInstance()->RemovePowerSuspendObserver(this);
|
||||
}
|
||||
|
||||
void DownloadDisplayController::OnNewItem(bool show_animation) {
|
||||
|
@ -276,7 +276,7 @@ class ExtensionProtocolsTestBase : public testing::Test,
|
||||
loader_factory_.reset();
|
||||
content_verifier_->Shutdown();
|
||||
// Shut down the PowerMonitor if initialized.
|
||||
base::PowerMonitor::ShutdownForTesting();
|
||||
base::PowerMonitor::GetInstance()->ShutdownForTesting();
|
||||
}
|
||||
|
||||
GetResult RequestOrLoad(const GURL& url,
|
||||
|
@ -64,7 +64,7 @@ class PerformanceLogSourceTest : public BrowserWithTestWindowTest {
|
||||
void SetUp() override { environment_.SetUp(local_state_); }
|
||||
|
||||
void TearDown() override {
|
||||
base::PowerMonitor::ShutdownForTesting();
|
||||
base::PowerMonitor::GetInstance()->ShutdownForTesting();
|
||||
environment_.TearDown();
|
||||
}
|
||||
|
||||
|
@ -300,7 +300,7 @@ void MediaFoundationServiceMonitor::Initialize() {
|
||||
AddGlobalSample(kSignificantPlayback, base::Time::Now());
|
||||
|
||||
content::ServiceProcessHost::AddObserver(this);
|
||||
base::PowerMonitor::AddPowerSuspendObserver(this);
|
||||
base::PowerMonitor::GetInstance()->AddPowerSuspendObserver(this);
|
||||
display::Screen::GetScreen()->AddObserver(this);
|
||||
}
|
||||
|
||||
|
@ -57,7 +57,7 @@ ProfileProvider::ProfileProvider()
|
||||
ProfileProvider::~ProfileProvider() {
|
||||
ash::LoginState::Get()->RemoveObserver(this);
|
||||
chromeos::PowerManagerClient::Get()->RemoveObserver(this);
|
||||
base::PowerMonitor::RemovePowerThermalObserver(this);
|
||||
base::PowerMonitor::GetInstance()->RemovePowerThermalObserver(this);
|
||||
if (jank_monitor_) {
|
||||
jank_monitor_->RemoveObserver(this);
|
||||
jank_monitor_->Destroy();
|
||||
@ -82,7 +82,8 @@ void ProfileProvider::Init() {
|
||||
|
||||
// Register as an observer of thermal state changes.
|
||||
base::PowerThermalObserver::DeviceThermalState thermal_state =
|
||||
base::PowerMonitor::AddPowerStateObserverAndReturnPowerThermalState(this);
|
||||
base::PowerMonitor::GetInstance()
|
||||
->AddPowerStateObserverAndReturnPowerThermalState(this);
|
||||
OnThermalStateChange(thermal_state);
|
||||
|
||||
// Check the login state. At the time of writing, this class is instantiated
|
||||
|
@ -63,12 +63,13 @@ TabStatsTracker* g_tab_stats_tracker_instance = nullptr;
|
||||
|
||||
void UmaHistogramCounts10000WithBatteryStateVariant(const char* histogram_name,
|
||||
size_t value) {
|
||||
DCHECK(base::PowerMonitor::IsInitialized());
|
||||
auto* power_monitor = base::PowerMonitor::GetInstance();
|
||||
DCHECK(power_monitor->IsInitialized());
|
||||
|
||||
base::UmaHistogramCounts10000(histogram_name, value);
|
||||
|
||||
const char* suffix =
|
||||
base::PowerMonitor::IsOnBatteryPower() ? ".OnBattery" : ".PluggedIn";
|
||||
power_monitor->IsOnBatteryPower() ? ".OnBattery" : ".PluggedIn";
|
||||
|
||||
base::UmaHistogramCounts10000(base::StrCat({histogram_name, suffix}), value);
|
||||
}
|
||||
@ -147,7 +148,7 @@ TabStatsTracker::TabStatsTracker(PrefService* pref_service)
|
||||
}
|
||||
|
||||
browser_list->AddObserver(this);
|
||||
base::PowerMonitor::AddPowerSuspendObserver(this);
|
||||
base::PowerMonitor::GetInstance()->AddPowerSuspendObserver(this);
|
||||
|
||||
// Setup daily reporting of the stats aggregated in |tab_stats_data_store|.
|
||||
daily_event_->AddObserver(std::make_unique<TabStatsDailyObserver>(
|
||||
@ -169,7 +170,7 @@ TabStatsTracker::TabStatsTracker(PrefService* pref_service)
|
||||
TabStatsTracker::~TabStatsTracker() {
|
||||
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
|
||||
BrowserList::GetInstance()->RemoveObserver(this);
|
||||
base::PowerMonitor::RemovePowerSuspendObserver(this);
|
||||
base::PowerMonitor::GetInstance()->RemovePowerSuspendObserver(this);
|
||||
g_browser_process->GetTabManager()->RemoveObserver(this);
|
||||
}
|
||||
|
||||
|
@ -35,8 +35,9 @@ namespace {
|
||||
using TabsStats = TabStatsDataStore::TabsStats;
|
||||
|
||||
std::string GetHistogramNameWithBatteryStateSuffix(const char* histogram_name) {
|
||||
const char* suffix =
|
||||
base::PowerMonitor::IsOnBatteryPower() ? ".OnBattery" : ".PluggedIn";
|
||||
const char* suffix = base::PowerMonitor::GetInstance()->IsOnBatteryPower()
|
||||
? ".OnBattery"
|
||||
: ".PluggedIn";
|
||||
|
||||
return base::StrCat({histogram_name, suffix});
|
||||
}
|
||||
|
@ -9,13 +9,17 @@
|
||||
|
||||
SystemEventProvider::SystemEventProvider(UsageScenarioDataStoreImpl* data_store)
|
||||
: data_store_(data_store) {
|
||||
if (base::PowerMonitor::IsInitialized())
|
||||
base::PowerMonitor::AddPowerSuspendObserver(this);
|
||||
if (auto* power_monitor = base::PowerMonitor::GetInstance();
|
||||
power_monitor->IsInitialized()) {
|
||||
power_monitor->AddPowerSuspendObserver(this);
|
||||
}
|
||||
}
|
||||
|
||||
SystemEventProvider::~SystemEventProvider() {
|
||||
if (base::PowerMonitor::IsInitialized())
|
||||
base::PowerMonitor::RemovePowerSuspendObserver(this);
|
||||
if (auto* power_monitor = base::PowerMonitor::GetInstance();
|
||||
power_monitor->IsInitialized()) {
|
||||
power_monitor->RemovePowerSuspendObserver(this);
|
||||
}
|
||||
}
|
||||
|
||||
void SystemEventProvider::OnSuspend() {
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
namespace performance_manager {
|
||||
|
||||
bool FakePowerMonitorSource::IsOnBatteryPower() {
|
||||
bool FakePowerMonitorSource::IsOnBatteryPower() const {
|
||||
return on_battery_power_;
|
||||
}
|
||||
|
||||
|
@ -12,7 +12,7 @@ namespace performance_manager {
|
||||
|
||||
class FakePowerMonitorSource : public base::PowerMonitorSource {
|
||||
public:
|
||||
bool IsOnBatteryPower() override;
|
||||
bool IsOnBatteryPower() const override;
|
||||
void SetOnBatteryPower(bool on_battery_power);
|
||||
|
||||
private:
|
||||
|
4
chrome/browser/performance_manager/test_support/test_user_performance_tuning_manager_environment.cc
4
chrome/browser/performance_manager/test_support/test_user_performance_tuning_manager_environment.cc
@ -72,7 +72,7 @@ void TestUserPerformanceTuningManagerEnvironment::SetUp(
|
||||
#endif
|
||||
auto source = std::make_unique<FakePowerMonitorSource>();
|
||||
power_monitor_source_ = source.get();
|
||||
base::PowerMonitor::Initialize(std::move(source));
|
||||
base::PowerMonitor::GetInstance()->Initialize(std::move(source));
|
||||
|
||||
if (!sampling_event_source) {
|
||||
auto test_sampling_event_source =
|
||||
@ -114,7 +114,7 @@ void TestUserPerformanceTuningManagerEnvironment::TearDown() {
|
||||
user_performance_tuning_manager_.reset();
|
||||
battery_saver_mode_manager_.reset();
|
||||
battery_sampler_.reset();
|
||||
base::PowerMonitor::ShutdownForTesting();
|
||||
base::PowerMonitor::GetInstance()->ShutdownForTesting();
|
||||
#if BUILDFLAG(IS_CHROMEOS_ASH)
|
||||
if (tear_down_power_manager_client_) {
|
||||
chromeos::PowerManagerClient::Shutdown();
|
||||
|
@ -212,7 +212,8 @@ class DesktopBatterySaverProvider
|
||||
base::Unretained(this)));
|
||||
|
||||
on_battery_power_ =
|
||||
base::PowerMonitor::AddPowerStateObserverAndReturnOnBatteryState(this);
|
||||
base::PowerMonitor::GetInstance()
|
||||
->AddPowerStateObserverAndReturnOnBatteryState(this);
|
||||
|
||||
base::BatteryStateSampler* battery_state_sampler =
|
||||
base::BatteryStateSampler::Get();
|
||||
@ -226,7 +227,7 @@ class DesktopBatterySaverProvider
|
||||
}
|
||||
|
||||
~DesktopBatterySaverProvider() override {
|
||||
base::PowerMonitor::RemovePowerStateObserver(this);
|
||||
base::PowerMonitor::GetInstance()->RemovePowerStateObserver(this);
|
||||
}
|
||||
|
||||
// BatterySaverProvider:
|
||||
|
@ -119,7 +119,7 @@ class BatterySaverModeManagerTest : public ::testing::Test {
|
||||
void SetUp() override {
|
||||
auto source = std::make_unique<FakePowerMonitorSource>();
|
||||
power_monitor_source_ = source.get();
|
||||
base::PowerMonitor::Initialize(std::move(source));
|
||||
base::PowerMonitor::GetInstance()->Initialize(std::move(source));
|
||||
|
||||
performance_manager::user_tuning::prefs::RegisterLocalStatePrefs(
|
||||
local_state_.registry());
|
||||
@ -147,7 +147,9 @@ class BatterySaverModeManagerTest : public ::testing::Test {
|
||||
manager()->Start();
|
||||
}
|
||||
|
||||
void TearDown() override { base::PowerMonitor::ShutdownForTesting(); }
|
||||
void TearDown() override {
|
||||
base::PowerMonitor::GetInstance()->ShutdownForTesting();
|
||||
}
|
||||
|
||||
BatterySaverModeManager* manager() {
|
||||
return BatterySaverModeManager::GetInstance();
|
||||
|
@ -93,8 +93,8 @@ bool IsPreconnectExpensive() {
|
||||
#if BUILDFLAG(IS_ANDROID)
|
||||
// Preconnecting is expensive while on battery power and cellular data and
|
||||
// the radio signal is weak.
|
||||
if ((base::PowerMonitor::IsInitialized() &&
|
||||
!base::PowerMonitor::IsOnBatteryPower()) ||
|
||||
if (auto* power_monitor = base::PowerMonitor::GetInstance();
|
||||
(power_monitor->IsInitialized() && !power_monitor->IsOnBatteryPower()) ||
|
||||
(base::android::RadioUtils::GetConnectionType() !=
|
||||
base::android::RadioConnectionType::kCell)) {
|
||||
return false;
|
||||
|
@ -55,11 +55,11 @@ class SmartCardPermissionContext::PowerSuspendObserver
|
||||
public:
|
||||
explicit PowerSuspendObserver(SmartCardPermissionContext& permission_context)
|
||||
: permission_context_(permission_context) {
|
||||
base::PowerMonitor::AddPowerSuspendObserver(this);
|
||||
base::PowerMonitor::GetInstance()->AddPowerSuspendObserver(this);
|
||||
}
|
||||
|
||||
~PowerSuspendObserver() override {
|
||||
base::PowerMonitor::RemovePowerSuspendObserver(this);
|
||||
base::PowerMonitor::GetInstance()->RemovePowerSuspendObserver(this);
|
||||
}
|
||||
|
||||
void OnSuspend() override {
|
||||
|
@ -196,7 +196,7 @@ class RelaunchNotificationControllerTest : public ::testing::Test {
|
||||
// Unittests failed when the system is on battery. This class is using a
|
||||
// mock power monitor source `power_monitor_source_` to ensure no real
|
||||
// power state or power notifications are delivered to the unittests.
|
||||
EXPECT_FALSE(base::PowerMonitor::IsOnBatteryPower());
|
||||
EXPECT_FALSE(base::PowerMonitor::GetInstance()->IsOnBatteryPower());
|
||||
}
|
||||
|
||||
UpgradeDetector* upgrade_detector() { return &upgrade_detector_; }
|
||||
|
@ -109,7 +109,7 @@ WebAppMetrics::WebAppMetrics(Profile* profile)
|
||||
icon_health_checks_(profile),
|
||||
browser_tab_strip_tracker_(this, nullptr) {
|
||||
browser_tab_strip_tracker_.Init();
|
||||
base::PowerMonitor::AddPowerSuspendObserver(this);
|
||||
base::PowerMonitor::GetInstance()->AddPowerSuspendObserver(this);
|
||||
BrowserList::AddObserver(this);
|
||||
// This isn't around on ChromeOS or tests.
|
||||
if (metrics::DesktopSessionDurationTracker::IsInitialized()) {
|
||||
@ -133,7 +133,7 @@ WebAppMetrics::WebAppMetrics(Profile* profile)
|
||||
|
||||
WebAppMetrics::~WebAppMetrics() {
|
||||
BrowserList::RemoveObserver(this);
|
||||
base::PowerMonitor::RemovePowerSuspendObserver(this);
|
||||
base::PowerMonitor::GetInstance()->RemovePowerSuspendObserver(this);
|
||||
if (metrics::DesktopSessionDurationTracker::IsInitialized()) {
|
||||
metrics::DesktopSessionDurationTracker::Get()->RemoveObserver(this);
|
||||
}
|
||||
|
@ -87,7 +87,7 @@ class ChromeUnitTestSuiteInitializer : public testing::EmptyTestEventListener {
|
||||
void OnTestEnd(const testing::TestInfo& test_info) override {
|
||||
TestingBrowserProcess::TearDownAndDeleteInstance();
|
||||
// Some tests cause ChildThreadImpl to initialize a PowerMonitor.
|
||||
base::PowerMonitor::ShutdownForTesting();
|
||||
base::PowerMonitor::GetInstance()->ShutdownForTesting();
|
||||
#if BUILDFLAG(IS_WIN)
|
||||
// Running tests locally on Windows machines with some degree of
|
||||
// accessibility enabled can cause this flag to become implicitly set.
|
||||
|
@ -65,7 +65,7 @@ FeatureUsageMetrics::FeatureUsageMetrics(const std::string& feature_name,
|
||||
// Schedule the first run some time in the future to not overload startup
|
||||
// flow.
|
||||
SetupTimer(kInitialInterval);
|
||||
base::PowerMonitor::AddPowerSuspendObserver(this);
|
||||
base::PowerMonitor::GetInstance()->AddPowerSuspendObserver(this);
|
||||
}
|
||||
|
||||
void FeatureUsageMetrics::SetupTimer(base::TimeDelta delta) {
|
||||
@ -77,7 +77,7 @@ void FeatureUsageMetrics::SetupTimer(base::TimeDelta delta) {
|
||||
|
||||
FeatureUsageMetrics::~FeatureUsageMetrics() {
|
||||
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
|
||||
base::PowerMonitor::RemovePowerSuspendObserver(this);
|
||||
base::PowerMonitor::GetInstance()->RemovePowerSuspendObserver(this);
|
||||
MaybeReportUseTime();
|
||||
}
|
||||
|
||||
|
@ -31,8 +31,9 @@ class FeatureUsageMetricsTest : public ::testing::Test,
|
||||
public FeatureUsageMetrics::Delegate {
|
||||
public:
|
||||
FeatureUsageMetricsTest() {
|
||||
if (!base::PowerMonitor::IsInitialized()) {
|
||||
base::PowerMonitor::Initialize(
|
||||
if (auto* power_monitor = base::PowerMonitor::GetInstance();
|
||||
!power_monitor->IsInitialized()) {
|
||||
power_monitor->Initialize(
|
||||
std::make_unique<base::PowerMonitorDeviceSource>());
|
||||
}
|
||||
|
||||
|
@ -269,7 +269,7 @@ TimeZoneResolver::TimeZoneResolverImpl::TimeZoneResolverImpl(
|
||||
DCHECK(!resolver_->apply_timezone().is_null());
|
||||
DCHECK(!resolver_->delay_network_call().is_null());
|
||||
|
||||
base::PowerMonitor::AddPowerSuspendObserver(this);
|
||||
base::PowerMonitor::GetInstance()->AddPowerSuspendObserver(this);
|
||||
|
||||
const int64_t last_refresh_at_us =
|
||||
resolver_->local_state()->GetInt64(kLastTimeZoneRefreshTime);
|
||||
@ -285,7 +285,7 @@ TimeZoneResolver::TimeZoneResolverImpl::TimeZoneResolverImpl(
|
||||
}
|
||||
|
||||
TimeZoneResolver::TimeZoneResolverImpl::~TimeZoneResolverImpl() {
|
||||
base::PowerMonitor::RemovePowerSuspendObserver(this);
|
||||
base::PowerMonitor::GetInstance()->RemovePowerSuspendObserver(this);
|
||||
}
|
||||
|
||||
void TimeZoneResolver::TimeZoneResolverImpl::Start() {
|
||||
|
@ -80,7 +80,7 @@ WifiSyncNotificationController::WifiSyncNotificationController(
|
||||
delegate_notifier_(delegate_notifier) {
|
||||
if (pref_service_->GetBoolean(kCanShowWifiSyncAnnouncementPrefName)) {
|
||||
session_manager::SessionManager::Get()->AddObserver(this);
|
||||
base::PowerMonitor::AddPowerSuspendObserver(this);
|
||||
base::PowerMonitor::GetInstance()->AddPowerSuspendObserver(this);
|
||||
did_register_session_observers_ = true;
|
||||
}
|
||||
}
|
||||
@ -88,7 +88,7 @@ WifiSyncNotificationController::WifiSyncNotificationController(
|
||||
WifiSyncNotificationController::~WifiSyncNotificationController() {
|
||||
if (did_register_session_observers_) {
|
||||
session_manager::SessionManager::Get()->RemoveObserver(this);
|
||||
base::PowerMonitor::RemovePowerSuspendObserver(this);
|
||||
base::PowerMonitor::GetInstance()->RemovePowerSuspendObserver(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -772,7 +772,7 @@ TEST_F(PowerManagerClientTest, ChangeAmbientColorTemperature) {
|
||||
TEST_F(PowerManagerClientTest, ChangeThermalState) {
|
||||
base::test::ScopedPowerMonitorTestSource power_monitor_source;
|
||||
PowerMonitorTestObserverLocal observer;
|
||||
base::PowerMonitor::AddPowerThermalObserver(&observer);
|
||||
base::PowerMonitor::GetInstance()->AddPowerThermalObserver(&observer);
|
||||
|
||||
typedef struct {
|
||||
power_manager::ThermalEvent::ThermalState dbus_state;
|
||||
@ -810,7 +810,7 @@ TEST_F(PowerManagerClientTest, ChangeThermalState) {
|
||||
EXPECT_EQ(observer.GetThermalState(), p.expected_state);
|
||||
}
|
||||
|
||||
base::PowerMonitor::RemovePowerThermalObserver(&observer);
|
||||
base::PowerMonitor::GetInstance()->RemovePowerThermalObserver(&observer);
|
||||
}
|
||||
|
||||
// Test that |RequestSuspend| calls the DBus method with the same name.
|
||||
|
@ -24,7 +24,7 @@ class BatteryStatusListener {
|
||||
virtual int GetBatteryPercentage() = 0;
|
||||
|
||||
// Is the device is using battery power instead of charging.
|
||||
virtual bool IsOnBatteryPower() = 0;
|
||||
virtual bool IsOnBatteryPower() const = 0;
|
||||
|
||||
// Start/Stop to listen to battery status changes.
|
||||
virtual void Start(Observer* observer) = 0;
|
||||
|
@ -22,21 +22,22 @@ int BatteryStatusListenerImpl::GetBatteryPercentage() {
|
||||
return battery_percentage_;
|
||||
}
|
||||
|
||||
bool BatteryStatusListenerImpl::IsOnBatteryPower() {
|
||||
return base::PowerMonitor::IsOnBatteryPower();
|
||||
bool BatteryStatusListenerImpl::IsOnBatteryPower() const {
|
||||
return base::PowerMonitor::GetInstance()->IsOnBatteryPower();
|
||||
}
|
||||
|
||||
void BatteryStatusListenerImpl::Start(Observer* observer) {
|
||||
observer_ = observer;
|
||||
|
||||
DCHECK(base::PowerMonitor::IsInitialized());
|
||||
base::PowerMonitor::AddPowerStateObserver(this);
|
||||
auto* power_monitor = base::PowerMonitor::GetInstance();
|
||||
DCHECK(power_monitor->IsInitialized());
|
||||
power_monitor->AddPowerStateObserver(this);
|
||||
|
||||
UpdateBatteryPercentage(true);
|
||||
}
|
||||
|
||||
void BatteryStatusListenerImpl::Stop() {
|
||||
base::PowerMonitor::RemovePowerStateObserver(this);
|
||||
base::PowerMonitor::GetInstance()->RemovePowerStateObserver(this);
|
||||
}
|
||||
|
||||
int BatteryStatusListenerImpl::GetBatteryPercentageInternal() {
|
||||
|
@ -33,7 +33,7 @@ class BatteryStatusListenerImpl : public BatteryStatusListener,
|
||||
private:
|
||||
// BatteryStatusListener implementation.
|
||||
int GetBatteryPercentage() override;
|
||||
bool IsOnBatteryPower() override;
|
||||
bool IsOnBatteryPower() const override;
|
||||
void Start(Observer* observer) override;
|
||||
void Stop() override;
|
||||
|
||||
|
@ -14,7 +14,7 @@ int BatteryStatusListenerMac::GetBatteryPercentage() {
|
||||
return 100;
|
||||
}
|
||||
|
||||
bool BatteryStatusListenerMac::IsOnBatteryPower() {
|
||||
bool BatteryStatusListenerMac::IsOnBatteryPower() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,7 @@ class BatteryStatusListenerMac : public BatteryStatusListener {
|
||||
private:
|
||||
// BatteryStatusListener implementation.
|
||||
int GetBatteryPercentage() override;
|
||||
bool IsOnBatteryPower() override;
|
||||
bool IsOnBatteryPower() const override;
|
||||
void Start(Observer* observer) override;
|
||||
void Stop() override;
|
||||
};
|
||||
|
@ -31,7 +31,7 @@ int NaClMain(content::MainFunctionParams parameters) {
|
||||
base::SingleThreadTaskExecutor main_task_executor(base::MessagePumpType::IO);
|
||||
base::PlatformThread::SetName("CrNaClMain");
|
||||
|
||||
base::PowerMonitor::Initialize(MakePowerMonitorDeviceSource());
|
||||
base::PowerMonitor::GetInstance()->Initialize(MakePowerMonitorDeviceSource());
|
||||
base::HighResolutionTimerManager hi_res_timer_manager;
|
||||
|
||||
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID)
|
||||
|
@ -47,7 +47,7 @@ PowerMonitorDeviceSourceLinux::~PowerMonitorDeviceSourceLinux() {
|
||||
ShutdownBus();
|
||||
}
|
||||
|
||||
bool PowerMonitorDeviceSourceLinux::IsOnBatteryPower() {
|
||||
bool PowerMonitorDeviceSourceLinux::IsOnBatteryPower() const {
|
||||
// TODO(crbug.com/40836663): Use org.freedesktop.UPower to check for
|
||||
// OnBattery. One possibility is to connect to the DeviceService's
|
||||
// BatteryMonitor.
|
||||
|
@ -27,7 +27,7 @@ class PowerMonitorDeviceSourceLinux : public base::PowerMonitorSource {
|
||||
~PowerMonitorDeviceSourceLinux() override;
|
||||
|
||||
// base::PowerMonitorSource:
|
||||
bool IsOnBatteryPower() override;
|
||||
bool IsOnBatteryPower() const override;
|
||||
|
||||
private:
|
||||
void ShutdownBus();
|
||||
|
@ -813,8 +813,8 @@ DCLayerOverlayProcessor::DCLayerOverlayProcessor(
|
||||
: has_overlay_support_(skip_initialization_for_testing),
|
||||
allowed_yuv_overlay_count_(allowed_yuv_overlay_count),
|
||||
is_on_battery_power_(
|
||||
base::PowerMonitor::AddPowerStateObserverAndReturnOnBatteryState(
|
||||
this)),
|
||||
base::PowerMonitor::GetInstance()
|
||||
->AddPowerStateObserverAndReturnOnBatteryState(this)),
|
||||
no_undamaged_overlay_promotion_(base::FeatureList::IsEnabled(
|
||||
features::kNoUndamagedOverlayPromotion)) {
|
||||
if (!skip_initialization_for_testing) {
|
||||
@ -829,7 +829,7 @@ DCLayerOverlayProcessor::DCLayerOverlayProcessor(
|
||||
|
||||
DCLayerOverlayProcessor::~DCLayerOverlayProcessor() {
|
||||
gl::DirectCompositionOverlayCapsMonitor::GetInstance()->RemoveObserver(this);
|
||||
base::PowerMonitor::RemovePowerStateObserver(this);
|
||||
base::PowerMonitor::GetInstance()->RemovePowerStateObserver(this);
|
||||
}
|
||||
|
||||
void DCLayerOverlayProcessor::UpdateHasHwOverlaySupport() {
|
||||
|
@ -88,7 +88,7 @@ VizMainImpl::VizMainImpl(Delegate* delegate,
|
||||
// split into separate processes. Until then this is necessary to be able to
|
||||
// run Mushrome (chrome with mus) with Mus running in the browser process.
|
||||
if (dependencies_.power_monitor_source) {
|
||||
base::PowerMonitor::Initialize(
|
||||
base::PowerMonitor::GetInstance()->Initialize(
|
||||
std::move(dependencies_.power_monitor_source));
|
||||
}
|
||||
|
||||
|
@ -74,7 +74,7 @@ class MockPowerMonitorSource : public base::PowerMonitorSource {
|
||||
|
||||
~MockPowerMonitorSource() override { *leak_guard_ = false; }
|
||||
|
||||
bool IsOnBatteryPower() override { return false; }
|
||||
bool IsOnBatteryPower() const override { return false; }
|
||||
|
||||
private:
|
||||
// An external flag to signal as to whether or not this object is still
|
||||
@ -129,8 +129,9 @@ TEST(VizMainImplTest, OopVizDependencyInjection) {
|
||||
builder.Record(recorder);
|
||||
|
||||
// Need to shutdown the |PowerMonitor| infrastructure.
|
||||
EXPECT_TRUE(base::PowerMonitor::IsInitialized());
|
||||
base::PowerMonitor::ShutdownForTesting();
|
||||
auto* power_monitor = base::PowerMonitor::GetInstance();
|
||||
EXPECT_TRUE(power_monitor->IsInitialized());
|
||||
power_monitor->ShutdownForTesting();
|
||||
// Double-check that we're not leaking the MockPowerMonitorSource
|
||||
// instance.
|
||||
ASSERT_FALSE(mock_source_is_alive);
|
||||
|
@ -1248,7 +1248,8 @@ int ContentMainRunnerImpl::RunBrowser(MainFunctionParams main_params,
|
||||
|
||||
// PowerMonitor is needed in reduced mode. BrowserMainLoop will safely skip
|
||||
// initializing it again if it has already been initialized.
|
||||
base::PowerMonitor::Initialize(MakePowerMonitorDeviceSource());
|
||||
base::PowerMonitor::GetInstance()->Initialize(
|
||||
MakePowerMonitorDeviceSource());
|
||||
|
||||
// Ensure the visibility tracker is created on the main thread.
|
||||
ProcessVisibilityTracker::GetInstance();
|
||||
|
@ -182,9 +182,10 @@ AndroidBatteryMetrics::~AndroidBatteryMetrics() {
|
||||
|
||||
void AndroidBatteryMetrics::InitializeOnSequence() {
|
||||
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
|
||||
auto* power_monitor = base::PowerMonitor::GetInstance();
|
||||
on_battery_power_ =
|
||||
base::PowerMonitor::AddPowerStateObserverAndReturnOnBatteryState(this);
|
||||
base::PowerMonitor::AddPowerThermalObserver(this);
|
||||
power_monitor->AddPowerStateObserverAndReturnOnBatteryState(this);
|
||||
power_monitor->AddPowerThermalObserver(this);
|
||||
content::ProcessVisibilityTracker::GetInstance()->AddObserver(this);
|
||||
// TODO(b/339859756): Update this call to take into account the unknown battery
|
||||
// status.
|
||||
@ -234,7 +235,7 @@ void AndroidBatteryMetrics::UpdateMetricsEnabled() {
|
||||
if (should_be_enabled && !metrics_timer_.IsRunning()) {
|
||||
// Capture first capacity measurement and enable the repeating timer.
|
||||
last_remaining_capacity_uah_ =
|
||||
base::PowerMonitor::GetRemainingBatteryCapacity();
|
||||
base::PowerMonitor::GetInstance()->GetRemainingBatteryCapacity();
|
||||
skipped_timers_ = 0;
|
||||
observed_capacity_drops_ = 0;
|
||||
|
||||
@ -252,7 +253,7 @@ void AndroidBatteryMetrics::UpdateMetricsEnabled() {
|
||||
|
||||
void AndroidBatteryMetrics::CaptureAndReportMetrics(bool disabling) {
|
||||
int remaining_capacity_uah =
|
||||
base::PowerMonitor::GetRemainingBatteryCapacity();
|
||||
base::PowerMonitor::GetInstance()->GetRemainingBatteryCapacity();
|
||||
|
||||
if (remaining_capacity_uah >= last_remaining_capacity_uah_) {
|
||||
// No change in battery capacity, or it increased. The latter could happen
|
||||
|
@ -668,8 +668,10 @@ void BrowserMainLoop::PostCreateMainMessageLoop() {
|
||||
}
|
||||
{
|
||||
TRACE_EVENT0("startup", "BrowserMainLoop::Subsystem:PowerMonitor");
|
||||
if (!base::PowerMonitor::IsInitialized())
|
||||
base::PowerMonitor::Initialize(MakePowerMonitorDeviceSource());
|
||||
if (auto* power_monitor = base::PowerMonitor::GetInstance();
|
||||
!power_monitor->IsInitialized()) {
|
||||
power_monitor->Initialize(MakePowerMonitorDeviceSource());
|
||||
}
|
||||
}
|
||||
{
|
||||
TRACE_EVENT0("startup", "BrowserMainLoop::Subsystem:HighResTimerManager");
|
||||
|
@ -51,8 +51,10 @@ void BrowserFeatureProvider::AddFeatures(FeatureVector features,
|
||||
static_cast<int>(net::NetworkChangeNotifier::GetConnectionType()));
|
||||
} else if (desc.name == FeatureLibrary::BatteryPower().name) {
|
||||
bool is_battery = false;
|
||||
if (base::PowerMonitor::IsInitialized())
|
||||
is_battery = base::PowerMonitor::IsOnBatteryPower();
|
||||
if (auto* power_monitor = base::PowerMonitor::GetInstance();
|
||||
power_monitor->IsInitialized()) {
|
||||
is_battery = power_monitor->IsOnBatteryPower();
|
||||
}
|
||||
features[i] = FeatureValue(is_battery);
|
||||
}
|
||||
}
|
||||
|
@ -17,13 +17,15 @@ void SendLogMessage(const std::string& message) {
|
||||
} // namespace
|
||||
|
||||
MediaStreamPowerLogger::MediaStreamPowerLogger() {
|
||||
base::PowerMonitor::AddPowerSuspendObserver(this);
|
||||
base::PowerMonitor::AddPowerThermalObserver(this);
|
||||
auto* power_monitor = base::PowerMonitor::GetInstance();
|
||||
power_monitor->AddPowerSuspendObserver(this);
|
||||
power_monitor->AddPowerThermalObserver(this);
|
||||
}
|
||||
|
||||
MediaStreamPowerLogger::~MediaStreamPowerLogger() {
|
||||
base::PowerMonitor::RemovePowerSuspendObserver(this);
|
||||
base::PowerMonitor::RemovePowerThermalObserver(this);
|
||||
auto* power_monitor = base::PowerMonitor::GetInstance();
|
||||
power_monitor->RemovePowerSuspendObserver(this);
|
||||
power_monitor->RemovePowerThermalObserver(this);
|
||||
}
|
||||
|
||||
void MediaStreamPowerLogger::OnSuspend() {
|
||||
|
@ -75,10 +75,11 @@ PeerConnectionTrackerHost::PeerConnectionTrackerHost(RenderFrameHost* frame)
|
||||
peer_pid_(frame->GetProcess()->GetProcess().Pid()) {
|
||||
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
||||
RegisterHost(this);
|
||||
base::PowerMonitor::AddPowerSuspendObserver(this);
|
||||
auto* power_monitor = base::PowerMonitor::GetInstance();
|
||||
power_monitor->AddPowerSuspendObserver(this);
|
||||
// Ensure that the initial thermal state is known by the |tracker_|.
|
||||
base::PowerThermalObserver::DeviceThermalState initial_thermal_state =
|
||||
base::PowerMonitor::AddPowerStateObserverAndReturnPowerThermalState(this);
|
||||
power_monitor->AddPowerStateObserverAndReturnPowerThermalState(this);
|
||||
|
||||
frame->GetRemoteInterfaces()->GetInterface(
|
||||
tracker_.BindNewPipeAndPassReceiver());
|
||||
@ -91,8 +92,9 @@ PeerConnectionTrackerHost::PeerConnectionTrackerHost(RenderFrameHost* frame)
|
||||
PeerConnectionTrackerHost::~PeerConnectionTrackerHost() {
|
||||
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
||||
RemoveHost(this);
|
||||
base::PowerMonitor::RemovePowerSuspendObserver(this);
|
||||
base::PowerMonitor::RemovePowerThermalObserver(this);
|
||||
auto* power_monitor = base::PowerMonitor::GetInstance();
|
||||
power_monitor->RemovePowerSuspendObserver(this);
|
||||
power_monitor->RemovePowerThermalObserver(this);
|
||||
}
|
||||
|
||||
void PeerConnectionTrackerHost::AddPeerConnection(
|
||||
|
@ -706,12 +706,13 @@ void ChildThreadImpl::Init(const Options& options) {
|
||||
}
|
||||
|
||||
// In single process mode we may already have initialized the power monitor,
|
||||
if (!base::PowerMonitor::IsInitialized()) {
|
||||
if (auto* power_monitor = base::PowerMonitor::GetInstance();
|
||||
!power_monitor->IsInitialized()) {
|
||||
auto power_monitor_source =
|
||||
std::make_unique<device::PowerMonitorBroadcastSource>(
|
||||
GetIOTaskRunner());
|
||||
auto* source_ptr = power_monitor_source.get();
|
||||
base::PowerMonitor::Initialize(std::move(power_monitor_source));
|
||||
power_monitor->Initialize(std::move(power_monitor_source));
|
||||
// The two-phase init is necessary to ensure that the process-wide
|
||||
// PowerMonitor is set before the power monitor source receives incoming
|
||||
// communication from the browser process (see https://crbug.com/821790 for
|
||||
|
@ -84,7 +84,7 @@ ChildThreadImpl::Options GetOptions(
|
||||
|
||||
viz::VizMainImpl::ExternalDependencies CreateVizMainDependencies() {
|
||||
viz::VizMainImpl::ExternalDependencies deps;
|
||||
if (!base::PowerMonitor::IsInitialized()) {
|
||||
if (!base::PowerMonitor::GetInstance()->IsInitialized()) {
|
||||
deps.power_monitor_source =
|
||||
std::make_unique<base::PowerMonitorDeviceSource>();
|
||||
}
|
||||
|
@ -20,11 +20,11 @@ void PowerMonitorTestImpl::MakeSelfOwnedReceiver(
|
||||
}
|
||||
|
||||
PowerMonitorTestImpl::PowerMonitorTestImpl() {
|
||||
base::PowerMonitor::AddPowerStateObserver(this);
|
||||
base::PowerMonitor::GetInstance()->AddPowerStateObserver(this);
|
||||
}
|
||||
|
||||
PowerMonitorTestImpl::~PowerMonitorTestImpl() {
|
||||
base::PowerMonitor::RemovePowerStateObserver(this);
|
||||
base::PowerMonitor::GetInstance()->RemovePowerStateObserver(this);
|
||||
}
|
||||
|
||||
void PowerMonitorTestImpl::QueryNextState(QueryNextStateCallback callback) {
|
||||
|
@ -388,7 +388,7 @@ int UtilityMain(MainFunctionParams parameters) {
|
||||
// base::HighResolutionTimerManager here for future possible usage of high
|
||||
// resolution timer in service utility process.
|
||||
std::optional<base::HighResolutionTimerManager> hi_res_timer_manager;
|
||||
if (base::PowerMonitor::IsInitialized()) {
|
||||
if (base::PowerMonitor::GetInstance()->IsInitialized()) {
|
||||
hi_res_timer_manager.emplace();
|
||||
}
|
||||
|
||||
|
@ -62,7 +62,7 @@ HeartbeatManager::HeartbeatManager(
|
||||
|
||||
HeartbeatManager::~HeartbeatManager() {
|
||||
// Stop listening for system suspend and resume events.
|
||||
base::PowerMonitor::RemovePowerSuspendObserver(this);
|
||||
base::PowerMonitor::GetInstance()->RemovePowerSuspendObserver(this);
|
||||
}
|
||||
|
||||
void HeartbeatManager::Start(
|
||||
@ -74,7 +74,7 @@ void HeartbeatManager::Start(
|
||||
trigger_reconnect_callback_ = trigger_reconnect_callback;
|
||||
|
||||
// Listen for system suspend and resume events.
|
||||
base::PowerMonitor::AddPowerSuspendObserver(this);
|
||||
base::PowerMonitor::GetInstance()->AddPowerSuspendObserver(this);
|
||||
|
||||
// Calculated the heartbeat interval just before we start the timer.
|
||||
UpdateHeartbeatInterval();
|
||||
@ -90,7 +90,7 @@ void HeartbeatManager::Stop() {
|
||||
heartbeat_timer_->Stop();
|
||||
waiting_for_ack_ = false;
|
||||
|
||||
base::PowerMonitor::RemovePowerSuspendObserver(this);
|
||||
base::PowerMonitor::GetInstance()->RemovePowerSuspendObserver(this);
|
||||
}
|
||||
|
||||
void HeartbeatManager::OnHeartbeatAcked() {
|
||||
|
@ -1628,8 +1628,9 @@ wgpu::Adapter WebGPUDecoderImpl::CreatePreferredAdapter(
|
||||
case WebGPUPowerPreference::kNone:
|
||||
if (power_preference == wgpu::PowerPreference::Undefined) {
|
||||
// If on battery power, default to the integrated GPU.
|
||||
if (!base::PowerMonitor::IsInitialized() ||
|
||||
base::PowerMonitor::IsOnBatteryPower()) {
|
||||
if (auto* power_monitor = base::PowerMonitor::GetInstance();
|
||||
!power_monitor->IsInitialized() ||
|
||||
power_monitor->IsOnBatteryPower()) {
|
||||
power_preference = wgpu::PowerPreference::LowPower;
|
||||
} else {
|
||||
power_preference = wgpu::PowerPreference::HighPerformance;
|
||||
|
@ -127,7 +127,7 @@ DCOMPTexture::DCOMPTexture(
|
||||
IPC::ScopedAllowOffSequenceChannelAssociatedBindings allow_binding;
|
||||
receiver_.Bind(std::move(receiver), runner);
|
||||
context_state_->AddContextLostObserver(this);
|
||||
base::PowerMonitor::AddPowerSuspendObserver(this);
|
||||
base::PowerMonitor::GetInstance()->AddPowerSuspendObserver(this);
|
||||
channel_->AddRoute(route_id, sequence_);
|
||||
}
|
||||
|
||||
@ -138,7 +138,7 @@ DCOMPTexture::~DCOMPTexture() {
|
||||
DCHECK(!channel_);
|
||||
|
||||
context_state_->RemoveContextLostObserver(this);
|
||||
base::PowerMonitor::RemovePowerSuspendObserver(this);
|
||||
base::PowerMonitor::GetInstance()->RemovePowerSuspendObserver(this);
|
||||
|
||||
if (window_pos_timer_.IsRunning()) {
|
||||
window_pos_timer_.Stop();
|
||||
|
@ -127,7 +127,7 @@ GpuWatchdogThread::~GpuWatchdogThread() {
|
||||
Stop(); // stop the watchdog thread
|
||||
|
||||
base::CurrentThread::Get()->RemoveTaskObserver(this);
|
||||
base::PowerMonitor::RemovePowerSuspendObserver(this);
|
||||
base::PowerMonitor::GetInstance()->RemovePowerSuspendObserver(this);
|
||||
GpuWatchdogThreadEventHistogram(GpuWatchdogThreadEvent::kGpuWatchdogEnd);
|
||||
#if BUILDFLAG(IS_WIN)
|
||||
if (watched_thread_handle_)
|
||||
@ -343,7 +343,8 @@ void GpuWatchdogThread::AddPowerObserver() {
|
||||
// Adding the Observer to the power monitor is safe even if power monitor is
|
||||
// not yet initialized.
|
||||
bool is_system_suspended =
|
||||
base::PowerMonitor::AddPowerSuspendObserverAndReturnSuspendedState(this);
|
||||
base::PowerMonitor::GetInstance()
|
||||
->AddPowerSuspendObserverAndReturnSuspendedState(this);
|
||||
if (is_system_suspended)
|
||||
StopWatchdogTimeoutTask(kPowerSuspendResume);
|
||||
}
|
||||
|
@ -115,7 +115,7 @@ int WebMainLoop::PreCreateThreads() {
|
||||
// of it?
|
||||
// TODO(crbug.com/40240952): Remove this once we have confidence PowerMonitor
|
||||
// is not needed for iOS
|
||||
base::PowerMonitor::Initialize(
|
||||
base::PowerMonitor::GetInstance()->Initialize(
|
||||
std::make_unique<base::PowerMonitorDeviceSource>());
|
||||
|
||||
return result_code_;
|
||||
|
@ -462,7 +462,7 @@ class AudioManagerMac::AudioPowerObserver : public base::PowerSuspendObserver {
|
||||
public:
|
||||
AudioPowerObserver()
|
||||
: is_suspending_(false),
|
||||
is_monitoring_(base::PowerMonitor::IsInitialized()),
|
||||
is_monitoring_(base::PowerMonitor::GetInstance()->IsInitialized()),
|
||||
num_resume_notifications_(0) {
|
||||
// The PowerMonitor requires significant setup (a CFRunLoop and preallocated
|
||||
// IO ports) so it's not available under unit tests. See the OSX impl of
|
||||
@ -470,7 +470,7 @@ class AudioManagerMac::AudioPowerObserver : public base::PowerSuspendObserver {
|
||||
if (!is_monitoring_) {
|
||||
return;
|
||||
}
|
||||
base::PowerMonitor::AddPowerSuspendObserver(this);
|
||||
base::PowerMonitor::GetInstance()->AddPowerSuspendObserver(this);
|
||||
}
|
||||
|
||||
AudioPowerObserver(const AudioPowerObserver&) = delete;
|
||||
@ -481,7 +481,7 @@ class AudioManagerMac::AudioPowerObserver : public base::PowerSuspendObserver {
|
||||
if (!is_monitoring_) {
|
||||
return;
|
||||
}
|
||||
base::PowerMonitor::RemovePowerSuspendObserver(this);
|
||||
base::PowerMonitor::GetInstance()->RemovePowerSuspendObserver(this);
|
||||
}
|
||||
|
||||
bool IsSuspending() const {
|
||||
@ -500,7 +500,7 @@ class AudioManagerMac::AudioPowerObserver : public base::PowerSuspendObserver {
|
||||
|
||||
bool IsOnBatteryPower() const {
|
||||
DCHECK(thread_checker_.CalledOnValidThread());
|
||||
return base::PowerMonitor::IsOnBatteryPower();
|
||||
return base::PowerMonitor::GetInstance()->IsOnBatteryPower();
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -29,12 +29,12 @@ PowerObserverHelper::PowerObserverHelper(
|
||||
// TODO(grunell): We could be suspending when adding this as observer, and
|
||||
// we won't be notified about that. See if we can add
|
||||
// PowerMonitorSource::IsSuspending() so that this can be checked here.
|
||||
base::PowerMonitor::AddPowerSuspendObserver(this);
|
||||
base::PowerMonitor::GetInstance()->AddPowerSuspendObserver(this);
|
||||
}
|
||||
|
||||
PowerObserverHelper::~PowerObserverHelper() {
|
||||
DCHECK(task_runner_->RunsTasksInCurrentSequence());
|
||||
base::PowerMonitor::RemovePowerSuspendObserver(this);
|
||||
base::PowerMonitor::GetInstance()->RemovePowerSuspendObserver(this);
|
||||
}
|
||||
|
||||
bool PowerObserverHelper::IsSuspending() const {
|
||||
|
@ -83,14 +83,16 @@ AudioRendererImpl::AudioRendererImpl(
|
||||
// won't remove the observer until we're destructed on |task_runner_| so we
|
||||
// must post it here if we're on the wrong thread.
|
||||
if (task_runner_->RunsTasksInCurrentSequence()) {
|
||||
base::PowerMonitor::AddPowerSuspendObserver(this);
|
||||
base::PowerMonitor::GetInstance()->GetInstance()->AddPowerSuspendObserver(
|
||||
this);
|
||||
} else {
|
||||
// Safe to post this without a WeakPtr because this class must be destructed
|
||||
// on the same thread and construction has not completed yet.
|
||||
task_runner_->PostTask(
|
||||
FROM_HERE,
|
||||
base::BindOnce(
|
||||
IgnoreResult(&base::PowerMonitor::AddPowerSuspendObserver), this));
|
||||
base::IgnoreResult(&base::PowerMonitor::AddPowerSuspendObserver),
|
||||
base::Unretained(base::PowerMonitor::GetInstance()), this));
|
||||
}
|
||||
|
||||
// Do not add anything below this line since the above actions are only safe
|
||||
@ -100,7 +102,8 @@ AudioRendererImpl::AudioRendererImpl(
|
||||
AudioRendererImpl::~AudioRendererImpl() {
|
||||
DVLOG(1) << __func__;
|
||||
DCHECK(task_runner_->RunsTasksInCurrentSequence());
|
||||
base::PowerMonitor::RemovePowerSuspendObserver(this);
|
||||
base::PowerMonitor::GetInstance()->GetInstance()->RemovePowerSuspendObserver(
|
||||
this);
|
||||
|
||||
// If Render() is in progress, this call will wait for Render() to finish.
|
||||
// After this call, the |sink_| will not call back into |this| anymore.
|
||||
|
@ -91,10 +91,8 @@ bool NonErrorResponse(int status_code) {
|
||||
}
|
||||
|
||||
bool IsOnBatteryPower() {
|
||||
if (base::PowerMonitor::IsInitialized()) {
|
||||
return base::PowerMonitor::IsOnBatteryPower();
|
||||
}
|
||||
return false;
|
||||
auto* power_monitor = base::PowerMonitor::GetInstance();
|
||||
return power_monitor->IsInitialized() && power_monitor->IsOnBatteryPower();
|
||||
}
|
||||
|
||||
enum ExternallyConditionalizedType {
|
||||
|
@ -26,14 +26,14 @@ HttpNetworkLayer::HttpNetworkLayer(HttpNetworkSession* session)
|
||||
: session_(session) {
|
||||
DCHECK(session_);
|
||||
#if BUILDFLAG(IS_WIN)
|
||||
base::PowerMonitor::AddPowerSuspendObserver(this);
|
||||
base::PowerMonitor::GetInstance()->AddPowerSuspendObserver(this);
|
||||
#endif
|
||||
}
|
||||
|
||||
HttpNetworkLayer::~HttpNetworkLayer() {
|
||||
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
|
||||
#if BUILDFLAG(IS_WIN)
|
||||
base::PowerMonitor::RemovePowerSuspendObserver(this);
|
||||
base::PowerMonitor::GetInstance()->RemovePowerSuspendObserver(this);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -73,7 +73,7 @@ TCPClientSocket::TCPClientSocket(
|
||||
TCPClientSocket::~TCPClientSocket() {
|
||||
Disconnect();
|
||||
#if defined(TCP_CLIENT_SOCKET_OBSERVES_SUSPEND)
|
||||
base::PowerMonitor::RemovePowerSuspendObserver(this);
|
||||
base::PowerMonitor::GetInstance()->RemovePowerSuspendObserver(this);
|
||||
#endif // defined(TCP_CLIENT_SOCKET_OBSERVES_SUSPEND)
|
||||
}
|
||||
|
||||
@ -173,7 +173,7 @@ TCPClientSocket::TCPClientSocket(
|
||||
if (socket_->IsValid())
|
||||
socket_->SetDefaultOptionsForClient();
|
||||
#if defined(TCP_CLIENT_SOCKET_OBSERVES_SUSPEND)
|
||||
base::PowerMonitor::AddPowerSuspendObserver(this);
|
||||
base::PowerMonitor::GetInstance()->AddPowerSuspendObserver(this);
|
||||
#endif // defined(TCP_CLIENT_SOCKET_OBSERVES_SUSPEND)
|
||||
}
|
||||
|
||||
|
@ -60,7 +60,9 @@ class TCPClientSocketTest : public testing::Test {
|
||||
TCPClientSocketTest()
|
||||
: task_environment_(base::test::TaskEnvironment::MainThreadType::IO) {}
|
||||
|
||||
~TCPClientSocketTest() override { base::PowerMonitor::ShutdownForTesting(); }
|
||||
~TCPClientSocketTest() override {
|
||||
base::PowerMonitor::GetInstance()->ShutdownForTesting();
|
||||
}
|
||||
|
||||
void Suspend() { power_monitor_source_.Suspend(); }
|
||||
void Resume() { power_monitor_source_.Resume(); }
|
||||
|
@ -10,13 +10,15 @@
|
||||
namespace device {
|
||||
|
||||
PowerMonitorMessageBroadcaster::PowerMonitorMessageBroadcaster() {
|
||||
base::PowerMonitor::AddPowerSuspendObserver(this);
|
||||
base::PowerMonitor::AddPowerStateObserver(this);
|
||||
auto* power_monitor = base::PowerMonitor::GetInstance();
|
||||
power_monitor->AddPowerSuspendObserver(this);
|
||||
power_monitor->AddPowerStateObserver(this);
|
||||
}
|
||||
|
||||
PowerMonitorMessageBroadcaster::~PowerMonitorMessageBroadcaster() {
|
||||
base::PowerMonitor::RemovePowerSuspendObserver(this);
|
||||
base::PowerMonitor::RemovePowerStateObserver(this);
|
||||
auto* power_monitor = base::PowerMonitor::GetInstance();
|
||||
power_monitor->RemovePowerSuspendObserver(this);
|
||||
power_monitor->RemovePowerStateObserver(this);
|
||||
}
|
||||
|
||||
// static
|
||||
@ -30,11 +32,13 @@ void PowerMonitorMessageBroadcaster::AddClient(
|
||||
power_monitor_client) {
|
||||
mojo::RemoteSetElementId element_id =
|
||||
clients_.Add(std::move(power_monitor_client));
|
||||
auto* power_monitor = base::PowerMonitor::GetInstance();
|
||||
|
||||
if (!base::PowerMonitor::IsInitialized())
|
||||
if (!power_monitor->IsInitialized()) {
|
||||
return;
|
||||
}
|
||||
|
||||
bool on_battery_power = base::PowerMonitor::IsOnBatteryPower();
|
||||
bool on_battery_power = power_monitor->IsOnBatteryPower();
|
||||
|
||||
// If the state has changed since we last checked, update all clients.
|
||||
if (on_battery_power != on_battery_power_) {
|
||||
|
@ -62,7 +62,9 @@ class PowerMonitorMessageBroadcasterTest : public DeviceServiceTestBase {
|
||||
power_monitor_source_.SetOnBatteryPower(on_battery_power);
|
||||
}
|
||||
|
||||
bool IsOnBatteryPower() { return power_monitor_source_.IsOnBatteryPower(); }
|
||||
bool IsOnBatteryPower() const {
|
||||
return power_monitor_source_.IsOnBatteryPower();
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
DestroyDeviceService();
|
||||
|
@ -35,7 +35,7 @@ void PowerMonitorBroadcastSource::Init(
|
||||
}
|
||||
}
|
||||
|
||||
bool PowerMonitorBroadcastSource::IsOnBatteryPower() {
|
||||
bool PowerMonitorBroadcastSource::IsOnBatteryPower() const {
|
||||
return client_->last_reported_on_battery_power_state();
|
||||
}
|
||||
|
||||
|
@ -85,7 +85,7 @@ class PowerMonitorBroadcastSource : public base::PowerMonitorSource {
|
||||
|
||||
Client* client_for_testing() const { return client_.get(); }
|
||||
|
||||
bool IsOnBatteryPower() override;
|
||||
bool IsOnBatteryPower() const override;
|
||||
|
||||
std::unique_ptr<Client> client_;
|
||||
scoped_refptr<base::SequencedTaskRunner> task_runner_;
|
||||
|
@ -29,12 +29,13 @@ class PowerMonitorBroadcastSourceTest : public testing::Test {
|
||||
auto power_monitor_source = std::make_unique<PowerMonitorBroadcastSource>(
|
||||
base::SequencedTaskRunner::GetCurrentDefault());
|
||||
power_monitor_source_ptr_ = power_monitor_source.get();
|
||||
base::PowerMonitor::Initialize(std::move(power_monitor_source));
|
||||
base::PowerMonitor::GetInstance()->Initialize(
|
||||
std::move(power_monitor_source));
|
||||
power_monitor_source_ptr_->Init(mojo::NullRemote());
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
base::PowerMonitor::ShutdownForTesting();
|
||||
base::PowerMonitor::GetInstance()->ShutdownForTesting();
|
||||
base::RunLoop().RunUntilIdle();
|
||||
}
|
||||
|
||||
@ -51,8 +52,9 @@ class PowerMonitorBroadcastSourceTest : public testing::Test {
|
||||
|
||||
TEST_F(PowerMonitorBroadcastSourceTest, PowerMessageReceiveBroadcast) {
|
||||
base::test::PowerMonitorTestObserver observer;
|
||||
base::PowerMonitor::AddPowerSuspendObserver(&observer);
|
||||
base::PowerMonitor::AddPowerStateObserver(&observer);
|
||||
auto* power_monitor = base::PowerMonitor::GetInstance();
|
||||
power_monitor->AddPowerSuspendObserver(&observer);
|
||||
power_monitor->AddPowerStateObserver(&observer);
|
||||
|
||||
// Sending resume when not suspended should have no effect.
|
||||
client()->Resume();
|
||||
@ -103,8 +105,8 @@ TEST_F(PowerMonitorBroadcastSourceTest, PowerMessageReceiveBroadcast) {
|
||||
base::RunLoop().RunUntilIdle();
|
||||
EXPECT_EQ(observer.power_state_changes(), 2);
|
||||
|
||||
base::PowerMonitor::RemovePowerSuspendObserver(&observer);
|
||||
base::PowerMonitor::RemovePowerStateObserver(&observer);
|
||||
power_monitor->RemovePowerSuspendObserver(&observer);
|
||||
power_monitor->RemovePowerStateObserver(&observer);
|
||||
}
|
||||
|
||||
} // namespace device
|
||||
|
@ -39,14 +39,14 @@ class MediaPowerDelegate : public base::PowerSuspendObserver {
|
||||
public:
|
||||
explicit MediaPowerDelegate(base::WeakPtr<AudioFocusManager> owner)
|
||||
: owner_(owner) {
|
||||
base::PowerMonitor::AddPowerSuspendObserver(this);
|
||||
base::PowerMonitor::GetInstance()->AddPowerSuspendObserver(this);
|
||||
}
|
||||
|
||||
MediaPowerDelegate(const MediaPowerDelegate&) = delete;
|
||||
MediaPowerDelegate& operator=(const MediaPowerDelegate&) = delete;
|
||||
|
||||
~MediaPowerDelegate() override {
|
||||
base::PowerMonitor::RemovePowerSuspendObserver(this);
|
||||
base::PowerMonitor::GetInstance()->RemovePowerSuspendObserver(this);
|
||||
}
|
||||
|
||||
// base::PowerSuspendObserver:
|
||||
|
@ -21,9 +21,8 @@ namespace blink {
|
||||
constexpr gfx::Size kMinimumVideoSize = gfx::Size(200, 140);
|
||||
|
||||
static bool IsOnBatteryPower() {
|
||||
if (base::PowerMonitor::IsInitialized())
|
||||
return base::PowerMonitor::IsOnBatteryPower();
|
||||
return false;
|
||||
auto* power_monitor = base::PowerMonitor::GetInstance();
|
||||
return power_monitor->IsInitialized() && power_monitor->IsOnBatteryPower();
|
||||
}
|
||||
|
||||
// Helper function for managing property changes. If the watch time timer is
|
||||
@ -96,7 +95,7 @@ WatchTimeReporter::WatchTimeReporter(
|
||||
if (is_muted_)
|
||||
DCHECK_EQ(volume_, 1.0);
|
||||
|
||||
base::PowerMonitor::AddPowerStateObserver(this);
|
||||
base::PowerMonitor::GetInstance()->AddPowerStateObserver(this);
|
||||
|
||||
provider->AcquireWatchTimeRecorder(properties_->Clone(),
|
||||
recorder_.BindNewPipeAndPassReceiver());
|
||||
@ -146,7 +145,7 @@ WatchTimeReporter::~WatchTimeReporter() {
|
||||
// This is our last chance, so finalize now if there's anything remaining.
|
||||
in_shutdown_ = true;
|
||||
MaybeFinalizeWatchTime(FinalizeTime::IMMEDIATELY);
|
||||
base::PowerMonitor::RemovePowerStateObserver(this);
|
||||
base::PowerMonitor::GetInstance()->RemovePowerStateObserver(this);
|
||||
}
|
||||
|
||||
void WatchTimeReporter::OnPlaying() {
|
||||
|
@ -39,56 +39,70 @@ _CONFIG = [
|
||||
'allowed': [
|
||||
# absl
|
||||
'absl::Cleanup',
|
||||
'absl::MakeInt128',
|
||||
'absl::MakeUint128',
|
||||
'absl::Int128High64',
|
||||
'absl::Int128Low64',
|
||||
'absl::Uint128High64',
|
||||
'absl::Uint128Low64',
|
||||
'absl::get',
|
||||
'absl::get_if',
|
||||
'absl::holds_alternative',
|
||||
'absl::in_place',
|
||||
'absl::in_place_type',
|
||||
'absl::int128',
|
||||
'absl::Int128High64',
|
||||
'absl::Int128Low64',
|
||||
'absl::MakeInt128',
|
||||
'absl::MakeUint128',
|
||||
'absl::monostate',
|
||||
'absl::uint128',
|
||||
'absl::Uint128High64',
|
||||
'absl::Uint128Low64',
|
||||
'absl::variant',
|
||||
'absl::visit',
|
||||
|
||||
# //base constructs that are allowed everywhere
|
||||
'base::(byte_)?span_from_ref',
|
||||
'base::AdoptRef',
|
||||
'base::ApplyMetadataToPastSamples',
|
||||
'base::SampleMetadataScope',
|
||||
'base::as_byte_span',
|
||||
'base::as_byte_span',
|
||||
'base::as_bytes',
|
||||
'base::as_bytes',
|
||||
'base::as_chars',
|
||||
'base::as_chars',
|
||||
'base::as_string_view',
|
||||
'base::as_string_view',
|
||||
'base::as_writable_byte_span',
|
||||
'base::as_writable_bytes',
|
||||
'base::as_writable_bytes',
|
||||
'base::as_writable_chars',
|
||||
'base::AutoReset',
|
||||
'base::Contains',
|
||||
'base::bit_cast',
|
||||
'base::ConditionVariable',
|
||||
'base::Contains',
|
||||
'base::CPU',
|
||||
'base::ValuesEquivalent',
|
||||
'base::Days',
|
||||
'base::DefaultTickClock',
|
||||
'base::ElapsedTimer',
|
||||
'base::EnumSet',
|
||||
'base::HashInts',
|
||||
'base::JobDelegate',
|
||||
'base::JobHandle',
|
||||
'base::PostJob',
|
||||
'base::expected',
|
||||
'base::File',
|
||||
'base::FileErrorOr',
|
||||
'base::FilePath',
|
||||
'base::FunctionRef',
|
||||
'base::GetUniqueIdForProcess',
|
||||
'base::HashingLRUCache',
|
||||
'base::HashInts',
|
||||
'base::HeapArray',
|
||||
'base::HexStringToUInt64',
|
||||
'base::Hours',
|
||||
"base::i18n::TextDirection",
|
||||
"base::i18n::ToChar16Ptr",
|
||||
"base::i18n::ToUCharPtr",
|
||||
'base::i18n::TextDirection',
|
||||
'base::i18n::ToChar16Ptr',
|
||||
'base::i18n::ToUCharPtr',
|
||||
'base::JobDelegate',
|
||||
'base::JobHandle',
|
||||
'base::Location',
|
||||
'base::make_span',
|
||||
'base::MakeRefCounted',
|
||||
'base::MappedReadOnlyRegion',
|
||||
'base::MatchPattern',
|
||||
'base::MatcherStringPattern',
|
||||
'base::MatchPattern',
|
||||
'base::MessagePump',
|
||||
'base::MetricsSubSampler',
|
||||
'base::Microseconds',
|
||||
@ -96,6 +110,7 @@ _CONFIG = [
|
||||
'base::Minutes',
|
||||
'base::Nanoseconds',
|
||||
'base::NotFatalUntil',
|
||||
'base::optional_ref',
|
||||
'base::OptionalFromPtr',
|
||||
'base::OptionalToPtr',
|
||||
'base::Overloaded',
|
||||
@ -103,21 +118,28 @@ _CONFIG = [
|
||||
'base::PersistentHash',
|
||||
'base::PlatformThread',
|
||||
'base::PlatformThreadId',
|
||||
'base::PostJob',
|
||||
'base::PowerMonitor',
|
||||
'base::Process',
|
||||
'base::RadToDeg',
|
||||
'base::RefCountedData',
|
||||
'base::RunLoop',
|
||||
'base::HashingLRUCache',
|
||||
'base::ranges::.+',
|
||||
'base::ReadOnlySharedMemoryMapping',
|
||||
'base::ReadOnlySharedMemoryRegion',
|
||||
'base::RefCountedData',
|
||||
'base::RemoveChars',
|
||||
'base::RepeatingTimer',
|
||||
'base::RunLoop',
|
||||
'base::SampleMetadataScope',
|
||||
'base::ScopedAllowBlocking',
|
||||
'base::ScopedClosureRunner',
|
||||
'base::ScopedFD',
|
||||
'base::Seconds',
|
||||
'base::sequence_manager::TaskTimeObserver',
|
||||
'base::SequencedTaskRunner',
|
||||
'base::SingleThreadTaskRunner',
|
||||
'base::ScopedAllowBlocking',
|
||||
'base::ScopedFD',
|
||||
'base::ScopedClosureRunner',
|
||||
'base::span',
|
||||
'base::span(_with_nul)?_from_cstring',
|
||||
'base::Span(OrSize|Reader|Writer)',
|
||||
'base::StringPiece',
|
||||
'base::SubstringSetMatcher',
|
||||
'base::SupportsWeakPtr',
|
||||
@ -129,41 +151,20 @@ _CONFIG = [
|
||||
'base::Time',
|
||||
'base::TimeDelta',
|
||||
'base::TimeTicks',
|
||||
'base::trace_event::.*',
|
||||
'base::to_underlying',
|
||||
'base::Token',
|
||||
'base::trace_event::.*',
|
||||
'base::unexpected',
|
||||
'base::UnguessableToken',
|
||||
'base::UnguessableTokenHash',
|
||||
'base::UnlocalizedTimeFormatWithPattern',
|
||||
'base::UnsafeSharedMemoryRegion',
|
||||
'base::Uuid',
|
||||
'base::ValuesEquivalent',
|
||||
'base::WeakPtr',
|
||||
'base::WeakPtrFactory',
|
||||
'base::WrapRefCounted',
|
||||
'base::WritableSharedMemoryMapping',
|
||||
'base::as_byte_span',
|
||||
'base::as_bytes',
|
||||
'base::as_chars',
|
||||
'base::as_string_view',
|
||||
'base::as_writable_bytes',
|
||||
'base::bit_cast',
|
||||
'base::expected',
|
||||
'base::make_span',
|
||||
'base::optional_ref',
|
||||
'base::to_underlying',
|
||||
'base::unexpected',
|
||||
'base::ranges::.+',
|
||||
'base::sequence_manager::TaskTimeObserver',
|
||||
'base::span',
|
||||
'base::span(_with_nul)?_from_cstring',
|
||||
'base::Span(OrSize|Reader|Writer)',
|
||||
'base::as_byte_span',
|
||||
'base::as_writable_byte_span',
|
||||
'base::as_bytes',
|
||||
'base::as_writable_bytes',
|
||||
'base::as_chars',
|
||||
'base::as_writable_chars',
|
||||
'base::as_string_view',
|
||||
'base::(byte_)?span_from_ref',
|
||||
'logging::GetVlogLevel',
|
||||
'logging::SetLogItems',
|
||||
|
||||
@ -182,8 +183,8 @@ _CONFIG = [
|
||||
'base::bits::.+',
|
||||
|
||||
# //base/observer_list.h.
|
||||
'base::ObserverList',
|
||||
'base::CheckedObserver',
|
||||
'base::ObserverList',
|
||||
|
||||
# //base/functional/callback_helpers.h.
|
||||
'base::DoNothing',
|
||||
@ -222,60 +223,60 @@ _CONFIG = [
|
||||
'base::LinearHistogram',
|
||||
|
||||
# //base/metrics/field_trial_params.h.
|
||||
'base::GetFieldTrialParamValueByFeature',
|
||||
'base::GetFieldTrialParamByFeatureAsBool',
|
||||
'base::GetFieldTrialParamByFeatureAsDouble',
|
||||
'base::GetFieldTrialParamByFeatureAsInt',
|
||||
'base::GetFieldTrialParamValueByFeature',
|
||||
|
||||
# //base/numerics/safe_conversions.h.
|
||||
'base::as_signed',
|
||||
'base::as_unsigned',
|
||||
'base::checked_cast',
|
||||
'base::saturated_cast',
|
||||
'base::strict_cast',
|
||||
'base::ClampCeil',
|
||||
'base::ClampFloor',
|
||||
'base::ClampRound',
|
||||
'base::IsTypeInRangeForNumericType',
|
||||
'base::IsValueInRangeForNumericType',
|
||||
'base::IsValueNegative',
|
||||
'base::MakeStrictNum',
|
||||
'base::ClampRound',
|
||||
'base::SafeUnsignedAbs',
|
||||
'base::saturated_cast',
|
||||
'base::strict_cast',
|
||||
'base::StrictNumeric',
|
||||
|
||||
# //base/synchronization/lock.h.
|
||||
'base::AutoLock',
|
||||
'base::AutoUnlock',
|
||||
'base::AutoTryLock',
|
||||
'base::AutoUnlock',
|
||||
'base::Lock',
|
||||
|
||||
# //base/synchronization/waitable_event.h.
|
||||
'base::WaitableEvent',
|
||||
|
||||
# //base/numerics/checked_math.h.
|
||||
'base::CheckAdd',
|
||||
'base::CheckAnd',
|
||||
'base::CheckDiv',
|
||||
'base::CheckedNumeric',
|
||||
'base::IsValidForType',
|
||||
'base::ValueOrDieForType',
|
||||
'base::ValueOrDefaultForType',
|
||||
'base::MakeCheckedNum',
|
||||
'base::CheckLsh',
|
||||
'base::CheckMax',
|
||||
'base::CheckMin',
|
||||
'base::CheckAdd',
|
||||
'base::CheckSub',
|
||||
'base::CheckMul',
|
||||
'base::CheckDiv',
|
||||
'base::CheckMod',
|
||||
'base::CheckLsh',
|
||||
'base::CheckRsh',
|
||||
'base::CheckAnd',
|
||||
'base::CheckMul',
|
||||
'base::CheckOr',
|
||||
'base::CheckRsh',
|
||||
'base::CheckSub',
|
||||
'base::CheckXor',
|
||||
'base::IsValidForType',
|
||||
'base::MakeCheckedNum',
|
||||
'base::ValueOrDefaultForType',
|
||||
'base::ValueOrDieForType',
|
||||
|
||||
# //base/numerics/clamped_math.h.
|
||||
'base::ClampAdd',
|
||||
'base::ClampedNumeric',
|
||||
'base::ClampMin',
|
||||
'base::ClampMax',
|
||||
'base::ClampMin',
|
||||
'base::ClampSub',
|
||||
'base::MakeClampedNum',
|
||||
|
||||
@ -291,32 +292,32 @@ _CONFIG = [
|
||||
'base::AtomicSequenceNumber',
|
||||
|
||||
# Task traits
|
||||
'base::TaskTraits',
|
||||
'base::MayBlock',
|
||||
'base::SingleThreadTaskRunnerThreadMode',
|
||||
'base::TaskPriority',
|
||||
'base::TaskShutdownBehavior',
|
||||
'base::WithBaseSyncPrimitives',
|
||||
'base::TaskTraits',
|
||||
'base::ThreadPolicy',
|
||||
'base::ThreadPool',
|
||||
'base::SingleThreadTaskRunnerThreadMode',
|
||||
'base::WithBaseSyncPrimitives',
|
||||
|
||||
# Byte order
|
||||
'base::BigEndian(Reader|Writer)',
|
||||
'base::(numerics::)?((I|U)(8|16|32|64)|(Float|Double))(To|From)(Big|Little|Native)Endian',
|
||||
'base::(numerics::)?ByteSwap',
|
||||
'base::BigEndian(Reader|Writer)',
|
||||
|
||||
# (Cryptographic) random number generation
|
||||
'base::RandUint64',
|
||||
'base::RandInt',
|
||||
'base::RandGenerator',
|
||||
'base::RandDouble',
|
||||
'base::RandBytes',
|
||||
'base::RandBytesAsString',
|
||||
'base::RandDouble',
|
||||
'base::RandGenerator',
|
||||
'base::RandInt',
|
||||
'base::RandUint64',
|
||||
|
||||
# Feature list checking.
|
||||
"base::GetFieldTrial.*",
|
||||
'base::Feature.*',
|
||||
'base::FEATURE_.+',
|
||||
"base::GetFieldTrial.*",
|
||||
'base::features::.+',
|
||||
'features::.+',
|
||||
|
||||
@ -385,9 +386,9 @@ _CONFIG = [
|
||||
'partition_alloc::internal::kAlignment',
|
||||
|
||||
# PartitionAlloc
|
||||
'base::PartitionFree',
|
||||
'base::PartitionAllocZeroFill',
|
||||
'base::PartitionAllocReturnNull',
|
||||
'base::PartitionAllocZeroFill',
|
||||
'base::PartitionFree',
|
||||
|
||||
# For TaskObserver.
|
||||
'base::PendingTask',
|
||||
@ -397,20 +398,20 @@ _CONFIG = [
|
||||
'cc::CategorizedWorkerPool',
|
||||
'cc::ColorFilter',
|
||||
'cc::DrawLooper',
|
||||
'cc::PathEffect',
|
||||
'cc::InspectablePaintRecorder',
|
||||
'cc::InspectableRecordPaintCanvas',
|
||||
'cc::NodeId',
|
||||
'cc::NodeInfo',
|
||||
'cc::PaintCanvas',
|
||||
'cc::PaintFlags',
|
||||
'cc::PaintImage',
|
||||
'cc::PaintImageBuilder',
|
||||
'cc::PaintRecord',
|
||||
'cc::RecordPaintCanvas',
|
||||
'cc::PaintShader',
|
||||
'cc::PaintWorkletInput',
|
||||
'cc::PathEffect',
|
||||
'cc::RecordPaintCanvas',
|
||||
'cc::RefCountedBuffer',
|
||||
'cc::NodeId',
|
||||
'cc::NodeInfo',
|
||||
'cc::UsePaintCache',
|
||||
|
||||
# Chromium geometry types.
|
||||
@ -420,8 +421,8 @@ _CONFIG = [
|
||||
'gfx::Outsets',
|
||||
'gfx::OutsetsF',
|
||||
'gfx::Point',
|
||||
'gfx::PointF',
|
||||
'gfx::Point3F',
|
||||
'gfx::PointF',
|
||||
'gfx::QuadF',
|
||||
'gfx::Quaternion',
|
||||
'gfx::Rect',
|
||||
@ -443,25 +444,25 @@ _CONFIG = [
|
||||
'gfx::DotProduct',
|
||||
'gfx::IntersectRects',
|
||||
'gfx::MapRect',
|
||||
'gfx::MapRect',
|
||||
'gfx::MaximumCoveredRect',
|
||||
'gfx::PointAtOffsetFromOrigin',
|
||||
'gfx::PointFToSkPoint',
|
||||
'gfx::PointToSkIPoint',
|
||||
'gfx::MapRect',
|
||||
'gfx::MaximumCoveredRect',
|
||||
'gfx::RectFToSkRect',
|
||||
'gfx::RectToSkIRect',
|
||||
'gfx::RectToSkRect',
|
||||
'gfx::ScaleInsets',
|
||||
'gfx::ScalePoint',
|
||||
'gfx::ScaleRect',
|
||||
'gfx::ScaleSize',
|
||||
'gfx::ScaleToCeiledSize',
|
||||
'gfx::ScaleToEnclosedRect',
|
||||
'gfx::ScaleToEnclosingRect',
|
||||
'gfx::ScaleToFlooredSize',
|
||||
'gfx::ScaleToRoundedPoint',
|
||||
'gfx::ScaleToRoundedRect',
|
||||
'gfx::ScaleToRoundedSize',
|
||||
'gfx::ScaleRect',
|
||||
'gfx::ScaleSize',
|
||||
'gfx::ScalePoint',
|
||||
'gfx::ScaleToRoundedPoint',
|
||||
'gfx::ScaleVector2d',
|
||||
'gfx::ScaleVector3d',
|
||||
'gfx::SizeFToSkSize',
|
||||
@ -534,17 +535,17 @@ _CONFIG = [
|
||||
'cc::ViewportLayers',
|
||||
|
||||
# cc::Layer helper enums.
|
||||
'cc::HORIZONTAL',
|
||||
'cc::VERTICAL',
|
||||
'cc::THUMB',
|
||||
'cc::TRACK_BUTTONS_TICKMARKS',
|
||||
'cc::BrowserControlsState',
|
||||
'cc::EventListenerClass',
|
||||
'cc::EventListenerProperties',
|
||||
'cc::HitTestOpaqueness',
|
||||
'cc::HORIZONTAL',
|
||||
'cc::THUMB',
|
||||
'cc::TRACK_BUTTONS_TICKMARKS',
|
||||
'cc::VERTICAL',
|
||||
|
||||
# Animation
|
||||
'cc::AnimationHost',
|
||||
"cc::AnimationHost",
|
||||
"cc::AnimationIdProvider",
|
||||
"cc::AnimationTimeline",
|
||||
"cc::FilterKeyframe",
|
||||
@ -568,30 +569,30 @@ _CONFIG = [
|
||||
'cc::PaintHoldingReason',
|
||||
|
||||
# Scrolling
|
||||
'cc::BrowserControlsOffsetTagsInfo',
|
||||
'cc::kManipulationInfoNone',
|
||||
'cc::kManipulationInfoPinchZoom',
|
||||
'cc::kManipulationInfoPrecisionTouchPad',
|
||||
'cc::kManipulationInfoScrollbar',
|
||||
'cc::kManipulationInfoTouch',
|
||||
'cc::kManipulationInfoWheel',
|
||||
'cc::kManipulationInfoScrollbar',
|
||||
'cc::kManipulationInfoNone',
|
||||
'cc::kPixelsPerLineStep',
|
||||
'cc::kMinFractionToStepWhenPaging',
|
||||
'cc::kPercentDeltaForDirectionalScroll',
|
||||
'cc::BrowserControlsOffsetTagsInfo',
|
||||
'cc::kPixelsPerLineStep',
|
||||
'cc::MainThreadScrollingReason',
|
||||
'cc::ManipulationInfo',
|
||||
'cc::ScrollOffsetAnimationCurve',
|
||||
'cc::ScrollSnapAlign',
|
||||
'cc::ScrollSnapType',
|
||||
'cc::ScrollOffsetAnimationCurve',
|
||||
'cc::ScrollStateData',
|
||||
'cc::ScrollUtils',
|
||||
'cc::SnapAlignment',
|
||||
'cc::SnapAreaData',
|
||||
'cc::SnapAxis',
|
||||
'cc::SnapContainerData',
|
||||
'cc::SnappedTargetData',
|
||||
'cc::SnapFlingClient',
|
||||
'cc::SnapFlingController',
|
||||
'cc::SnappedTargetData',
|
||||
'cc::SnapPositionData',
|
||||
'cc::SnapSelectionStrategy',
|
||||
'cc::SnapStrictness',
|
||||
@ -618,6 +619,7 @@ _CONFIG = [
|
||||
'url::.+',
|
||||
|
||||
# Nested namespaces under the blink namespace
|
||||
'[a-z_]+_names::.+',
|
||||
'bindings::.+',
|
||||
'canvas_heuristic_parameters::.+',
|
||||
'compositor_target_property::.+',
|
||||
@ -630,6 +632,7 @@ _CONFIG = [
|
||||
'event_handling_util::.+',
|
||||
'event_util::.+',
|
||||
'file_error::.+',
|
||||
'file_system_access_error::.+',
|
||||
'geometry_util::.+',
|
||||
'inspector_\\w+_event::.+',
|
||||
'inspector_async_task::.+',
|
||||
@ -641,7 +644,6 @@ _CONFIG = [
|
||||
'layout_text_control::.+',
|
||||
'media_constraints_impl::.+',
|
||||
'media_element_parser_helpers::.+',
|
||||
'file_system_access_error::.+',
|
||||
'network_utils::.+',
|
||||
'origin_trials::.+',
|
||||
'paint_filter_builder::.+',
|
||||
@ -656,22 +658,21 @@ _CONFIG = [
|
||||
'touch_action_util::.+',
|
||||
'trace_event::.+',
|
||||
'unicode::.+',
|
||||
'vector_math::.+',
|
||||
'v8_compile_hints::.+',
|
||||
'vector_math::.+',
|
||||
'web_core_test_support::.+',
|
||||
'worker_pool::.+',
|
||||
'xpath::.+',
|
||||
'[a-z_]+_names::.+',
|
||||
|
||||
# Third-party libraries that don't depend on non-Blink Chrome code
|
||||
# are OK.
|
||||
'icu::.+',
|
||||
'inspector_protocol_encoding::.+',
|
||||
'perfetto::.+', # tracing
|
||||
'snappy::.+',
|
||||
'testing::.+', # googlemock / googletest
|
||||
'v8::.+',
|
||||
'v8_inspector::.+',
|
||||
'inspector_protocol_encoding::.+',
|
||||
'snappy::.+',
|
||||
|
||||
# Inspector instrumentation and protocol
|
||||
'probe::.+',
|
||||
@ -691,14 +692,14 @@ _CONFIG = [
|
||||
# CanonicalCookie and related headers
|
||||
'net::CanonicalCookie',
|
||||
'net::CookieInclusionStatus',
|
||||
'net::CookiePriority',
|
||||
'net::CookiePartitionKey',
|
||||
'net::CookiePriority',
|
||||
'net::CookieSameSite',
|
||||
'net::CookieSourceScheme',
|
||||
|
||||
# HTTP status codes
|
||||
'net::HTTP_.+',
|
||||
'net::ERR_.*',
|
||||
'net::HTTP_.+',
|
||||
|
||||
# For ConnectionInfo enumeration
|
||||
'net::HttpConnectionInfo',
|
||||
@ -728,9 +729,9 @@ _CONFIG = [
|
||||
# Note that the Mojo callback helpers are explicitly forbidden:
|
||||
# Blink already has a signal for contexts being destroyed, and
|
||||
# other types of failures should be explicitly signalled.
|
||||
'(?:.+::)?mojom::.+',
|
||||
'mojo::(?!WrapCallback).+',
|
||||
'mojo_base::BigBuffer.*',
|
||||
'(?:.+::)?mojom::.+',
|
||||
'service_manager::InterfaceProvider',
|
||||
|
||||
# STL containers such as std::string and std::vector are discouraged
|
||||
@ -748,10 +749,10 @@ _CONFIG = [
|
||||
'ui::Cursor',
|
||||
|
||||
# UI Pointer and Hover
|
||||
'ui::PointerType',
|
||||
'ui::POINTER_TYPE_.*',
|
||||
'ui::HoverType',
|
||||
'ui::HOVER_TYPE_.*',
|
||||
'ui::HoverType',
|
||||
'ui::POINTER_TYPE_.*',
|
||||
'ui::PointerType',
|
||||
|
||||
# UI Keyconverter
|
||||
'ui::DomCode',
|
||||
@ -760,6 +761,10 @@ _CONFIG = [
|
||||
|
||||
# Accessibility base types and the non-Blink enums they
|
||||
# depend on.
|
||||
'ax::mojom::BoolAttribute',
|
||||
'ax::mojom::HasPopup',
|
||||
'ax::mojom::Restriction',
|
||||
'ax::mojom::State',
|
||||
'ui::AXActionData',
|
||||
'ui::AXEvent',
|
||||
'ui::AXEventIntent',
|
||||
@ -768,21 +773,17 @@ _CONFIG = [
|
||||
'ui::AXRelativeBounds',
|
||||
'ui::AXTreeChecks',
|
||||
'ui::AXTreeData',
|
||||
'ui::AXTreeID',
|
||||
'ui::AXTreeIDUnknown',
|
||||
'ui::AXTreeSerializer',
|
||||
'ui::AXTreeSource',
|
||||
'ui::AXTreeUpdate',
|
||||
'ui::AXTreeID',
|
||||
'ui::AXTreeIDUnknown',
|
||||
'ui::kInvalidAXNodeID',
|
||||
'ui::kFirstGeneratedRendererNodeID',
|
||||
'ui::kLastGeneratedRendererNodeID',
|
||||
'ui::kAXModeBasic',
|
||||
'ui::kAXModeComplete',
|
||||
'ui::kFirstGeneratedRendererNodeID',
|
||||
'ui::kInvalidAXNodeID',
|
||||
'ui::kLastGeneratedRendererNodeID',
|
||||
'ui::ToString',
|
||||
'ax::mojom::BoolAttribute',
|
||||
'ax::mojom::HasPopup',
|
||||
'ax::mojom::State',
|
||||
'ax::mojom::Restriction',
|
||||
|
||||
# Accessibility helper functions - mostly used in Blink for
|
||||
# serialization. Please keep alphabetized.
|
||||
@ -866,9 +867,9 @@ _CONFIG = [
|
||||
'allowed': [
|
||||
# For the script streaming to be able to block when reading from a
|
||||
# mojo datapipe.
|
||||
'base::BlockingType',
|
||||
'base::ScopedAllowBaseSyncPrimitives',
|
||||
'base::ScopedBlockingCall',
|
||||
'base::BlockingType',
|
||||
],
|
||||
},
|
||||
{
|
||||
@ -946,18 +947,18 @@ _CONFIG = [
|
||||
'allowed': [
|
||||
'cc::ActiveFrameSequenceTrackers',
|
||||
'cc::ApplyViewportChangesArgs',
|
||||
'cc::LayerTreeSettings',
|
||||
'cc::PaintBenchmarkResult',
|
||||
'cc::RenderFrameMetadata',
|
||||
'cc::TaskGraphRunner',
|
||||
'cc::ContentLayerClient',
|
||||
'cc::DeadlinePolicy',
|
||||
'cc::DisplayItemList',
|
||||
'cc::DrawColorOp',
|
||||
'cc::DrawImageOp',
|
||||
'cc::LayerTreeSettings',
|
||||
'cc::PaintBenchmarkResult',
|
||||
'cc::RenderFrameMetadata',
|
||||
'cc::RestoreOp',
|
||||
'cc::SaveOp',
|
||||
'cc::ScaleOp',
|
||||
'cc::RestoreOp',
|
||||
'cc::TaskGraphRunner',
|
||||
'cc::TranslateOp',
|
||||
'gfx::DisplayColorSpaces',
|
||||
'gfx::FontRenderParams',
|
||||
@ -1371,17 +1372,17 @@ _CONFIG = [
|
||||
# display-related types.
|
||||
'allowed': [
|
||||
'base::flat_map',
|
||||
'display::Display',
|
||||
'gl::GpuPreference',
|
||||
'gpu::ClientSharedImage',
|
||||
'gpu::SHARED_IMAGE_USAGE_.+',
|
||||
'gpu::gles2::GLES2Interface',
|
||||
'gpu::raster::RasterInterface',
|
||||
'gpu::Mailbox',
|
||||
'gpu::MailboxHolder',
|
||||
'gpu::raster::RasterInterface',
|
||||
'gpu::SHARED_IMAGE_USAGE_.+',
|
||||
'gpu::SharedImageInterface',
|
||||
'gpu::SyncToken',
|
||||
'gpu::webgpu::ReservedTexture',
|
||||
'display::Display',
|
||||
'media::IsOpaque',
|
||||
'media::kNoTransformation',
|
||||
'media::PaintCanvasVideoRenderer',
|
||||
@ -1535,17 +1536,17 @@ _CONFIG = [
|
||||
'third_party/blink/renderer/modules/mediarecorder/',
|
||||
],
|
||||
'allowed': [
|
||||
# TODO(crbug.com/960665): Remove base::queue once it is replaced with a WTF equivalent.
|
||||
'base::queue',
|
||||
'base::ClampMul',
|
||||
'base::MakeFixedFlatMap',
|
||||
'base::NumberToString',
|
||||
# TODO(crbug.com/960665): Remove base::queue once it is replaced with a WTF equivalent.
|
||||
'base::queue',
|
||||
'base::SharedMemory',
|
||||
'base::StringPiece',
|
||||
'base::NumberToString',
|
||||
'base::ThreadTaskRunnerHandle',
|
||||
'media::.+',
|
||||
'libopus::.+',
|
||||
'libyuv::.+',
|
||||
'media::.+',
|
||||
'video_track_recorder::.+',
|
||||
],
|
||||
'inclass_allowed': [
|
||||
@ -1621,8 +1622,8 @@ _CONFIG = [
|
||||
],
|
||||
'allowed': [
|
||||
'base::ClampMul',
|
||||
'base::IsAligned',
|
||||
'base::DoNothingWithBoundArgs',
|
||||
'base::IsAligned',
|
||||
'base::PlatformThreadRef',
|
||||
'base::WrapRefCounted',
|
||||
'cc::kNumYUVPlanes',
|
||||
@ -1630,17 +1631,17 @@ _CONFIG = [
|
||||
'cc::YUVIndex',
|
||||
'cc::YUVSubsampling',
|
||||
'gpu::kNullSurfaceHandle',
|
||||
'gpu::SHARED_IMAGE_.+',
|
||||
'gpu::raster::RasterInterface',
|
||||
'gpu::Mailbox',
|
||||
'gpu::MailboxHolder',
|
||||
'gpu::raster::RasterInterface',
|
||||
'gpu::SHARED_IMAGE_.+',
|
||||
'gpu::SharedImageInterface',
|
||||
'gpu::SyncToken',
|
||||
'viz::RasterContextProvider',
|
||||
'viz::ReleaseCallback',
|
||||
'media::.+',
|
||||
'libgav1::.+',
|
||||
'libyuv::.+',
|
||||
'media::.+',
|
||||
'viz::RasterContextProvider',
|
||||
'viz::ReleaseCallback',
|
||||
]
|
||||
},
|
||||
{
|
||||
|
@ -191,7 +191,7 @@ int DemoMain() {
|
||||
auto context_factory = std::make_unique<ui::InProcessContextFactory>(
|
||||
&host_frame_sink_manager, &frame_sink_manager, /*output_to_window=*/true);
|
||||
|
||||
base::PowerMonitor::Initialize(
|
||||
base::PowerMonitor::GetInstance()->Initialize(
|
||||
std::make_unique<base::PowerMonitorDeviceSource>());
|
||||
|
||||
std::unique_ptr<aura::Env> env = aura::Env::CreateInstance();
|
||||
|
@ -267,8 +267,10 @@ Compositor::Compositor(const viz::FrameSinkId& frame_sink_id,
|
||||
// See: http://crbug.com/956264.
|
||||
host_->SetVisible(true);
|
||||
|
||||
if (base::PowerMonitor::IsInitialized())
|
||||
base::PowerMonitor::AddPowerSuspendObserver(this);
|
||||
if (auto* power_monitor = base::PowerMonitor::GetInstance();
|
||||
power_monitor->IsInitialized()) {
|
||||
power_monitor->AddPowerSuspendObserver(this);
|
||||
}
|
||||
|
||||
if (command_line->HasSwitch(switches::kUISlowAnimations)) {
|
||||
slow_animations_ = std::make_unique<ScopedAnimationDurationScaleMode>(
|
||||
@ -281,8 +283,10 @@ Compositor::Compositor(const viz::FrameSinkId& frame_sink_id,
|
||||
|
||||
Compositor::~Compositor() {
|
||||
TRACE_EVENT0("shutdown,viz", "Compositor::destructor");
|
||||
if (base::PowerMonitor::IsInitialized())
|
||||
base::PowerMonitor::RemovePowerSuspendObserver(this);
|
||||
if (auto* power_monitor = base::PowerMonitor::GetInstance();
|
||||
power_monitor->IsInitialized()) {
|
||||
power_monitor->RemovePowerSuspendObserver(this);
|
||||
}
|
||||
|
||||
for (auto& observer : observer_list_)
|
||||
observer.OnCompositingShuttingDown(this);
|
||||
|
@ -504,11 +504,11 @@ SwapChainPresenter::SwapChainPresenter(
|
||||
d3d11_device_(d3d11_device),
|
||||
dcomp_device_(dcomp_device),
|
||||
is_on_battery_power_(
|
||||
base::PowerMonitor::AddPowerStateObserverAndReturnOnBatteryState(
|
||||
this)) {}
|
||||
base::PowerMonitor::GetInstance()
|
||||
->AddPowerStateObserverAndReturnOnBatteryState(this)) {}
|
||||
|
||||
SwapChainPresenter::~SwapChainPresenter() {
|
||||
base::PowerMonitor::RemovePowerStateObserver(this);
|
||||
base::PowerMonitor::GetInstance()->RemovePowerStateObserver(this);
|
||||
}
|
||||
|
||||
DXGI_FORMAT SwapChainPresenter::GetSwapChainFormat(
|
||||
|
@ -177,8 +177,8 @@ VSyncThreadWin::VSyncThreadWin(Microsoft::WRL::ComPtr<IDXGIDevice> dxgi_device)
|
||||
vsync_provider_(gfx::kNullAcceleratedWidget),
|
||||
dxgi_adapter_(GetAdapter(dxgi_device.Get())),
|
||||
original_adapter_luid_(GetLuid(dxgi_adapter_.Get())) {
|
||||
is_suspended_ =
|
||||
base::PowerMonitor::AddPowerSuspendObserverAndReturnSuspendedState(this);
|
||||
is_suspended_ = base::PowerMonitor::GetInstance()
|
||||
->AddPowerSuspendObserverAndReturnSuspendedState(this);
|
||||
vsync_thread_.StartWithOptions(
|
||||
base::Thread::Options(base::ThreadType::kDisplayCritical));
|
||||
}
|
||||
|
Reference in New Issue
Block a user