Commit 74710cee authored by Thanh Nguyen's avatar Thanh Nguyen Committed by Commit Bot

[smart-charging] Trigger logging event for shutdown and suspend

This CL:
1. Adds an function to notify observers for shutdown events.
2. Trigger logging event for shutdown and suspend.

Design doc: go/cros-smart-charging-logging

Bug: 1028853
Change-Id: I8f3a16d21882e70d6863a3d949936e834bdee867
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1949809
Commit-Queue: Thanh Nguyen <thanhdng@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Reviewed-by: default avatarTony Yeoman <tby@chromium.org>
Reviewed-by: default avatarJia Meng <jiameng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#724098}
parent 94a8a5f8
...@@ -138,6 +138,7 @@ void SmartChargingManager::PowerChanged( ...@@ -138,6 +138,7 @@ void SmartChargingManager::PowerChanged(
} }
void SmartChargingManager::PowerManagerBecameAvailable(bool available) { void SmartChargingManager::PowerManagerBecameAvailable(bool available) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (!available) { if (!available) {
return; return;
} }
...@@ -147,6 +148,18 @@ void SmartChargingManager::PowerManagerBecameAvailable(bool available) { ...@@ -147,6 +148,18 @@ void SmartChargingManager::PowerManagerBecameAvailable(bool available) {
weak_ptr_factory_.GetWeakPtr())); weak_ptr_factory_.GetWeakPtr()));
} }
void SmartChargingManager::ShutdownRequested(
power_manager::RequestShutdownReason reason) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
LogEvent(UserChargingEvent::Event::SHUTDOWN);
}
void SmartChargingManager::SuspendImminent(
power_manager::SuspendImminent::Reason reason) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
LogEvent(UserChargingEvent::Event::SUSPEND);
}
void SmartChargingManager::PopulateUserChargingEventProto( void SmartChargingManager::PopulateUserChargingEventProto(
UserChargingEvent* proto) { UserChargingEvent* proto) {
auto& features = *proto->mutable_features(); auto& features = *proto->mutable_features();
......
...@@ -47,6 +47,8 @@ class SmartChargingManager : public ui::UserActivityObserver, ...@@ -47,6 +47,8 @@ class SmartChargingManager : public ui::UserActivityObserver,
const power_manager::BacklightBrightnessChange& change) override; const power_manager::BacklightBrightnessChange& change) override;
void PowerChanged(const power_manager::PowerSupplyProperties& proto) override; void PowerChanged(const power_manager::PowerSupplyProperties& proto) override;
void PowerManagerBecameAvailable(bool available) override; void PowerManagerBecameAvailable(bool available) override;
void ShutdownRequested(power_manager::RequestShutdownReason reason) override;
void SuspendImminent(power_manager::SuspendImminent::Reason reason) override;
private: private:
friend class SmartChargingManagerTest; friend class SmartChargingManagerTest;
......
...@@ -72,6 +72,16 @@ class SmartChargingManagerTest : public ChromeRenderViewHostTestHarness { ...@@ -72,6 +72,16 @@ class SmartChargingManagerTest : public ChromeRenderViewHostTestHarness {
smart_charging_manager_->ScreenBrightnessChanged(change); smart_charging_manager_->ScreenBrightnessChanged(change);
} }
void ReportShutdownEvent() {
smart_charging_manager_->ShutdownRequested(
power_manager::RequestShutdownReason::REQUEST_SHUTDOWN_FOR_USER);
}
void ReportSuspendEvent() {
smart_charging_manager_->SuspendImminent(
power_manager::SuspendImminent::LID_CLOSED);
}
void FireTimer() { smart_charging_manager_->OnTimerFired(); } void FireTimer() { smart_charging_manager_->OnTimerFired(); }
void InitializeBrightness(const double level) { void InitializeBrightness(const double level) {
...@@ -194,5 +204,23 @@ TEST_F(SmartChargingManagerTest, UserEventCounts) { ...@@ -194,5 +204,23 @@ TEST_F(SmartChargingManagerTest, UserEventCounts) {
EXPECT_EQ(proto.features().num_recent_stylus_events(), 4); EXPECT_EQ(proto.features().num_recent_stylus_events(), 4);
} }
TEST_F(SmartChargingManagerTest, ShutdownAndSuspend) {
ReportPowerChangeEvent(power_manager::PowerSupplyProperties::DISCONNECTED,
25.0f);
// Suspend.
ReportSuspendEvent();
EXPECT_EQ(GetUserChargingEvent().features().battery_percentage(), 25);
EXPECT_EQ(GetUserChargingEvent().event().event_id(), 0);
EXPECT_EQ(GetUserChargingEvent().event().reason(),
UserChargingEvent::Event::SUSPEND);
// Shutdown.
ReportShutdownEvent();
EXPECT_EQ(GetUserChargingEvent().features().battery_percentage(), 25);
EXPECT_EQ(GetUserChargingEvent().event().event_id(), 1);
EXPECT_EQ(GetUserChargingEvent().event().reason(),
UserChargingEvent::Event::SHUTDOWN);
}
} // namespace power } // namespace power
} // namespace chromeos } // namespace chromeos
...@@ -346,6 +346,8 @@ class PowerManagerClientImpl : public PowerManagerClient { ...@@ -346,6 +346,8 @@ class PowerManagerClientImpl : public PowerManagerClient {
const std::string& description) override { const std::string& description) override {
POWER_LOG(USER) << "RequestShutdown: " << reason << " (" << description POWER_LOG(USER) << "RequestShutdown: " << reason << " (" << description
<< ")"; << ")";
for (auto& observer : observers_)
observer.ShutdownRequested(reason);
dbus::MethodCall method_call(power_manager::kPowerManagerInterface, dbus::MethodCall method_call(power_manager::kPowerManagerInterface,
power_manager::kRequestShutdownMethod); power_manager::kRequestShutdownMethod);
dbus::MessageWriter writer(&method_call); dbus::MessageWriter writer(&method_call);
......
...@@ -137,6 +137,12 @@ class COMPONENT_EXPORT(DBUS_POWER) PowerManagerClient { ...@@ -137,6 +137,12 @@ class COMPONENT_EXPORT(DBUS_POWER) PowerManagerClient {
// observer is ready for suspend. // observer is ready for suspend.
virtual void DarkSuspendImminent() {} virtual void DarkSuspendImminent() {}
// Called when the browser is about to request shutdown. Shutdown is
// deferred until all observers' implementations of this method have
// finished running.
virtual void ShutdownRequested(
power_manager::RequestShutdownReason reason) {}
// Called when the power button is pressed or released. // Called when the power button is pressed or released.
virtual void PowerButtonEventReceived(bool down, virtual void PowerButtonEventReceived(bool down,
const base::TimeTicks& timestamp) {} const base::TimeTicks& timestamp) {}
......
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