Commit cae84574 authored by Chris Sharp's avatar Chris Sharp Committed by Commit Bot

Revert "base/power_monitor: Add method to query thermal state"

This reverts commit 1e56c551.

Reason for revert: Broke compile on Mac Builder (dbg)

Failure
Step compile failed. Error logs are shown below:
[724/7143] CXX obj/base/base_unittests/power_monitor_device_source_unittest.o
FAILED: obj/base/base_unittests/power_monitor_device_source_unittest.o
/b/s/w/ir/cache/goma/client/gomacc ../../third_party/llvm-build/Release+Asserts/bin/clang++ -MMD -MF...(too long)
../../base/power_monitor/power_monitor_device_source_unittest.cc:32:3: error: use of undeclared identifier 'DVLOG'
DVLOG(1) << PowerMonitorSource::DeviceThermalStateToString(current_state);
^
1 error generated.
More information in raw_io.output[failure_summary]

Original change's description:
> base/power_monitor: Add method to query thermal state
> 
> wip wip
> 
> Add PowerMonitor::GetCurrentThermalState()
> 
> Bug: 1071431
> Change-Id: Id3083e06f16fd2f05e685e77ddee94e274158758
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2248729
> Reviewed-by: Henrik Boström <hbos@chromium.org>
> Reviewed-by: François Doray <fdoray@chromium.org>
> Commit-Queue: Miguel Casas <mcasas@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#781322}

TBR=fdoray@chromium.org,mcasas@chromium.org,hbos@chromium.org

Change-Id: I54bbdc02423890b8443cb2f1deec909b68d87ebf
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 1071431
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2260792Reviewed-by: default avatarChris Sharp <csharp@chromium.org>
Commit-Queue: Chris Sharp <csharp@chromium.org>
Cr-Commit-Position: refs/heads/master@{#781325}
parent 5f3dd76e
...@@ -2743,7 +2743,6 @@ test("base_unittests") { ...@@ -2743,7 +2743,6 @@ test("base_unittests") {
"parameter_pack_unittest.cc", "parameter_pack_unittest.cc",
"path_service_unittest.cc", "path_service_unittest.cc",
"pickle_unittest.cc", "pickle_unittest.cc",
"power_monitor/power_monitor_device_source_unittest.cc",
"power_monitor/power_monitor_unittest.cc", "power_monitor/power_monitor_unittest.cc",
"process/environment_internal_unittest.cc", "process/environment_internal_unittest.cc",
"process/memory_unittest.cc", "process/memory_unittest.cc",
......
...@@ -52,11 +52,6 @@ bool PowerMonitor::IsProcessSuspended() { ...@@ -52,11 +52,6 @@ bool PowerMonitor::IsProcessSuspended() {
return g_is_process_suspended.load(std::memory_order_relaxed); return g_is_process_suspended.load(std::memory_order_relaxed);
} }
PowerObserver::DeviceThermalState PowerMonitor::GetCurrentThermalState() {
DCHECK(IsInitialized());
return GetInstance()->source_->GetCurrentThermalState();
}
void PowerMonitor::NotifyPowerStateChange(bool battery_in_use) { void PowerMonitor::NotifyPowerStateChange(bool battery_in_use) {
DCHECK(IsInitialized()); DCHECK(IsInitialized());
DVLOG(1) << "PowerStateChange: " << (battery_in_use ? "On" : "Off") DVLOG(1) << "PowerStateChange: " << (battery_in_use ? "On" : "Off")
......
...@@ -56,10 +56,6 @@ class BASE_EXPORT PowerMonitor { ...@@ -56,10 +56,6 @@ class BASE_EXPORT PowerMonitor {
// what is the real power state. // what is the real power state.
static bool IsProcessSuspended(); static bool IsProcessSuspended();
// Read the current DeviceThermalState if known. Can be called on any thread.
// May only be called if the PowerMonitor has been initialized.
static PowerObserver::DeviceThermalState GetCurrentThermalState();
// Uninitializes the PowerMonitor. Should be called at the end of any unit // Uninitializes the PowerMonitor. Should be called at the end of any unit
// test that mocks out the PowerMonitor, to avoid affecting subsequent tests. // test that mocks out the PowerMonitor, to avoid affecting subsequent tests.
// There must be no live PowerObservers when invoked. Safe to call even if the // There must be no live PowerObservers when invoked. Safe to call even if the
......
...@@ -47,8 +47,6 @@ class BASE_EXPORT PowerMonitorDeviceSource : public PowerMonitorSource { ...@@ -47,8 +47,6 @@ class BASE_EXPORT PowerMonitorDeviceSource : public PowerMonitorSource {
#endif #endif
private: private:
friend class PowerMonitorDeviceSourceTest;
#if defined(OS_WIN) #if defined(OS_WIN)
// Represents a message-only window for power message handling on Windows. // Represents a message-only window for power message handling on Windows.
// Only allow PowerMonitor to create it. // Only allow PowerMonitor to create it.
...@@ -88,9 +86,6 @@ class BASE_EXPORT PowerMonitorDeviceSource : public PowerMonitorSource { ...@@ -88,9 +86,6 @@ class BASE_EXPORT PowerMonitorDeviceSource : public PowerMonitorSource {
bool IsOnBatteryPowerImpl() override; bool IsOnBatteryPowerImpl() override;
#if defined(OS_MACOSX) && !defined(OS_IOS) #if defined(OS_MACOSX) && !defined(OS_IOS)
// PowerMonitorSource:
PowerObserver::DeviceThermalState GetCurrentThermalState() override;
// Reference to the system IOPMrootDomain port. // Reference to the system IOPMrootDomain port.
io_connect_t power_manager_port_ = IO_OBJECT_NULL; io_connect_t power_manager_port_ = IO_OBJECT_NULL;
......
...@@ -51,14 +51,6 @@ bool PowerMonitorDeviceSource::IsOnBatteryPowerImpl() { ...@@ -51,14 +51,6 @@ bool PowerMonitorDeviceSource::IsOnBatteryPowerImpl() {
return true; return true;
} }
PowerObserver::DeviceThermalState
PowerMonitorDeviceSource::GetCurrentThermalState() {
if (@available(macOS 10.10.3, *)) {
return thermal_state_observer_->GetCurrentThermalState();
};
return PowerObserver::DeviceThermalState::kUnknown;
}
namespace { namespace {
void BatteryEventCallback(void*) { void BatteryEventCallback(void*) {
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/power_monitor/power_monitor_device_source.h"
#include "base/power_monitor/power_monitor.h"
#include "base/power_monitor/power_monitor_source.h"
#include "build/build_config.h"
#include "testing/gtest/include/gtest/gtest.h"
using DeviceThermalState = base::PowerObserver::DeviceThermalState;
namespace base {
class PowerMonitorDeviceSourceTest : public testing::Test {
public:
PowerMonitorDeviceSourceTest() = default;
~PowerMonitorDeviceSourceTest() override = default;
DeviceThermalState GetCurrentThermalState() {
return power_monitor_device_source_.GetCurrentThermalState();
}
PowerMonitorDeviceSource power_monitor_device_source_;
};
TEST_F(PowerMonitorDeviceSourceTest, GetCurrentThermalState) {
const DeviceThermalState current_state = GetCurrentThermalState();
#if defined(OS_MACOSX) && !defined(OS_IOS)
// We cannot make assumptions on |current_state|. Print it out to use the var.
DVLOG(1) << PowerMonitorSource::DeviceThermalStateToString(current_state);
#else
EXPECT_EQ(current_state, DeviceThermalState::kUnknown);
#endif
}
} // namespace base
...@@ -17,10 +17,6 @@ bool PowerMonitorSource::IsOnBatteryPower() { ...@@ -17,10 +17,6 @@ bool PowerMonitorSource::IsOnBatteryPower() {
return on_battery_power_; return on_battery_power_;
} }
PowerObserver::DeviceThermalState PowerMonitorSource::GetCurrentThermalState() {
return PowerObserver::DeviceThermalState::kUnknown;
}
// static // static
void PowerMonitorSource::ProcessPowerEvent(PowerEvent event_id) { void PowerMonitorSource::ProcessPowerEvent(PowerEvent event_id) {
if (!PowerMonitor::IsInitialized()) if (!PowerMonitor::IsInitialized())
......
...@@ -31,10 +31,6 @@ class BASE_EXPORT PowerMonitorSource { ...@@ -31,10 +31,6 @@ class BASE_EXPORT PowerMonitorSource {
// Is the computer currently on battery power. Can be called on any thread. // Is the computer currently on battery power. Can be called on any thread.
bool IsOnBatteryPower(); bool IsOnBatteryPower();
// Reads the current DeviceThermalState, if available on the platform.
// Otherwise, returns kUnknown.
virtual PowerObserver::DeviceThermalState GetCurrentThermalState();
static const char* DeviceThermalStateToString( static const char* DeviceThermalStateToString(
PowerObserver::DeviceThermalState state); PowerObserver::DeviceThermalState state);
......
...@@ -102,7 +102,6 @@ TEST_F(PowerMonitorTest, ThermalThrottling) { ...@@ -102,7 +102,6 @@ TEST_F(PowerMonitorTest, ThermalThrottling) {
for (const auto state : kThermalStates) { for (const auto state : kThermalStates) {
source()->GenerateThermalThrottlingEvent(state); source()->GenerateThermalThrottlingEvent(state);
EXPECT_EQ(state, source()->GetCurrentThermalState());
EXPECT_EQ(observer.last_thermal_state(), state); EXPECT_EQ(observer.last_thermal_state(), state);
} }
......
...@@ -14,9 +14,9 @@ ...@@ -14,9 +14,9 @@
namespace base { namespace base {
// This class is used to listen for the thermal state change notification // This class is used to listen for the thermal state change notification from
// NSProcessInfoThermalStateDidChangeNotification, routing it to // NSProcessInfoThermalStateDidChangeNotification via a fully owned
// PowerMonitorSource. // ThermalStateObserverDelegate, routing the notification to PowerMonitorSource.
class BASE_EXPORT ThermalStateObserverMac { class BASE_EXPORT ThermalStateObserverMac {
public: public:
using StateUpdateCallback = using StateUpdateCallback =
...@@ -25,8 +25,6 @@ class BASE_EXPORT ThermalStateObserverMac { ...@@ -25,8 +25,6 @@ class BASE_EXPORT ThermalStateObserverMac {
explicit ThermalStateObserverMac(StateUpdateCallback state_update_callback); explicit ThermalStateObserverMac(StateUpdateCallback state_update_callback);
~ThermalStateObserverMac(); ~ThermalStateObserverMac();
PowerObserver::DeviceThermalState GetCurrentThermalState();
private: private:
FRIEND_TEST_ALL_PREFIXES(ThermalStateObserverMacTest, StateChange); FRIEND_TEST_ALL_PREFIXES(ThermalStateObserverMacTest, StateChange);
PowerObserver::DeviceThermalState state_for_testing_ = PowerObserver::DeviceThermalState state_for_testing_ =
......
...@@ -63,13 +63,4 @@ ThermalStateObserverMac::~ThermalStateObserverMac() { ...@@ -63,13 +63,4 @@ ThermalStateObserverMac::~ThermalStateObserverMac() {
[[NSNotificationCenter defaultCenter] [[NSNotificationCenter defaultCenter]
removeObserver:thermal_state_update_observer_]; removeObserver:thermal_state_update_observer_];
} }
PowerObserver::DeviceThermalState
ThermalStateObserverMac::GetCurrentThermalState() NS_AVAILABLE_MAC(10_10_3) {
if (state_for_testing_ != PowerObserver::DeviceThermalState::kUnknown)
return state_for_testing_;
NSProcessInfoThermalState nsinfo_state =
[[NSProcessInfo processInfo] thermalState];
return NSProcessInfoThermalStateToDeviceThermalState(nsinfo_state);
}
} }
...@@ -11,18 +11,14 @@ ...@@ -11,18 +11,14 @@
namespace base { namespace base {
PowerMonitorTestSource::PowerMonitorTestSource() { PowerMonitorTestSource::PowerMonitorTestSource()
: test_on_battery_power_(false) {
DCHECK(MessageLoopCurrent::Get()) DCHECK(MessageLoopCurrent::Get())
<< "PowerMonitorTestSource requires a MessageLoop."; << "PowerMonitorTestSource requires a MessageLoop.";
} }
PowerMonitorTestSource::~PowerMonitorTestSource() = default; PowerMonitorTestSource::~PowerMonitorTestSource() = default;
PowerObserver::DeviceThermalState
PowerMonitorTestSource::GetCurrentThermalState() {
return current_thermal_state_;
}
void PowerMonitorTestSource::GeneratePowerStateEvent(bool on_battery_power) { void PowerMonitorTestSource::GeneratePowerStateEvent(bool on_battery_power) {
test_on_battery_power_ = on_battery_power; test_on_battery_power_ = on_battery_power;
ProcessPowerEvent(POWER_STATE_EVENT); ProcessPowerEvent(POWER_STATE_EVENT);
...@@ -46,7 +42,6 @@ bool PowerMonitorTestSource::IsOnBatteryPowerImpl() { ...@@ -46,7 +42,6 @@ bool PowerMonitorTestSource::IsOnBatteryPowerImpl() {
void PowerMonitorTestSource::GenerateThermalThrottlingEvent( void PowerMonitorTestSource::GenerateThermalThrottlingEvent(
PowerObserver::DeviceThermalState new_thermal_state) { PowerObserver::DeviceThermalState new_thermal_state) {
ProcessThermalEvent(new_thermal_state); ProcessThermalEvent(new_thermal_state);
current_thermal_state_ = new_thermal_state;
RunLoop().RunUntilIdle(); RunLoop().RunUntilIdle();
} }
......
...@@ -14,7 +14,6 @@ class PowerMonitorTestSource : public PowerMonitorSource { ...@@ -14,7 +14,6 @@ class PowerMonitorTestSource : public PowerMonitorSource {
public: public:
PowerMonitorTestSource(); PowerMonitorTestSource();
~PowerMonitorTestSource() override; ~PowerMonitorTestSource() override;
PowerObserver::DeviceThermalState GetCurrentThermalState() override;
void GeneratePowerStateEvent(bool on_battery_power); void GeneratePowerStateEvent(bool on_battery_power);
void GenerateSuspendEvent(); void GenerateSuspendEvent();
...@@ -25,9 +24,7 @@ class PowerMonitorTestSource : public PowerMonitorSource { ...@@ -25,9 +24,7 @@ class PowerMonitorTestSource : public PowerMonitorSource {
protected: protected:
bool IsOnBatteryPowerImpl() override; bool IsOnBatteryPowerImpl() override;
bool test_on_battery_power_ = false; bool test_on_battery_power_;
PowerObserver::DeviceThermalState current_thermal_state_ =
PowerObserver::DeviceThermalState::kUnknown;
}; };
class PowerMonitorTestObserver : public PowerObserver { class PowerMonitorTestObserver : public PowerObserver {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment