Commit 04d6ce0b authored by Tetsui Ohkubo's avatar Tetsui Ohkubo Committed by Commit Bot

Generate power notification outside tray.

Power/battery related notifications were generated in TrayPower, whixh
is a SystemTrayItem.

We're going to get rid of SystemTrayItems as UnifiedSystemTray will
replace them, so we should generate the notification outside system
tray.

TEST=PowerNotificationControllerTest
BUG=none

Change-Id: Ie707770cd86964f496651d5ed840198890362b40
Reviewed-on: https://chromium-review.googlesource.com/1013784Reviewed-by: default avatarSteven Bennetts <stevenjb@chromium.org>
Reviewed-by: default avatarJames Cook <jamescook@chromium.org>
Commit-Queue: Tetsui Ohkubo <tetsui@chromium.org>
Cr-Commit-Position: refs/heads/master@{#551517}
parent 327666c6
...@@ -678,6 +678,8 @@ component("ash") { ...@@ -678,6 +678,8 @@ component("ash") {
"system/power/power_button_screenshot_controller.h", "system/power/power_button_screenshot_controller.h",
"system/power/power_event_observer.cc", "system/power/power_event_observer.cc",
"system/power/power_event_observer.h", "system/power/power_event_observer.h",
"system/power/power_notification_controller.cc",
"system/power/power_notification_controller.h",
"system/power/power_prefs.cc", "system/power/power_prefs.cc",
"system/power/power_prefs.h", "system/power/power_prefs.h",
"system/power/power_status.cc", "system/power/power_status.cc",
...@@ -1634,10 +1636,10 @@ test("ash_unittests") { ...@@ -1634,10 +1636,10 @@ test("ash_unittests") {
"system/power/power_button_controller_unittest.cc", "system/power/power_button_controller_unittest.cc",
"system/power/power_button_screenshot_controller_unittest.cc", "system/power/power_button_screenshot_controller_unittest.cc",
"system/power/power_event_observer_unittest.cc", "system/power/power_event_observer_unittest.cc",
"system/power/power_notification_controller_unittest.cc",
"system/power/power_prefs_unittest.cc", "system/power/power_prefs_unittest.cc",
"system/power/power_status_unittest.cc", "system/power/power_status_unittest.cc",
"system/power/power_status_view_unittest.cc", "system/power/power_status_view_unittest.cc",
"system/power/tray_power_unittest.cc",
"system/power/video_activity_notifier_unittest.cc", "system/power/video_activity_notifier_unittest.cc",
"system/rotation/rotation_lock_feature_pod_controller_unittest.cc", "system/rotation/rotation_lock_feature_pod_controller_unittest.cc",
"system/rotation/tray_rotation_lock_unittest.cc", "system/rotation/tray_rotation_lock_unittest.cc",
......
...@@ -99,6 +99,7 @@ ...@@ -99,6 +99,7 @@
#include "ash/system/power/peripheral_battery_notifier.h" #include "ash/system/power/peripheral_battery_notifier.h"
#include "ash/system/power/power_button_controller.h" #include "ash/system/power/power_button_controller.h"
#include "ash/system/power/power_event_observer.h" #include "ash/system/power/power_event_observer.h"
#include "ash/system/power/power_notification_controller.h"
#include "ash/system/power/power_prefs.h" #include "ash/system/power/power_prefs.h"
#include "ash/system/power/power_status.h" #include "ash/system/power/power_status.h"
#include "ash/system/power/video_activity_notifier.h" #include "ash/system/power/video_activity_notifier.h"
...@@ -195,6 +196,7 @@ ...@@ -195,6 +196,7 @@
#include "ui/keyboard/keyboard_switches.h" #include "ui/keyboard/keyboard_switches.h"
#include "ui/keyboard/keyboard_ui.h" #include "ui/keyboard/keyboard_ui.h"
#include "ui/keyboard/keyboard_util.h" #include "ui/keyboard/keyboard_util.h"
#include "ui/message_center/message_center.h"
#include "ui/views/corewm/tooltip_aura.h" #include "ui/views/corewm/tooltip_aura.h"
#include "ui/views/corewm/tooltip_controller.h" #include "ui/views/corewm/tooltip_controller.h"
#include "ui/views/focus/focus_manager_factory.h" #include "ui/views/focus/focus_manager_factory.h"
...@@ -829,6 +831,7 @@ Shell::~Shell() { ...@@ -829,6 +831,7 @@ Shell::~Shell() {
screen_pinning_controller_.reset(); screen_pinning_controller_.reset();
caps_lock_notification_controller_.reset(); caps_lock_notification_controller_.reset();
power_notification_controller_.reset();
resolution_notification_controller_.reset(); resolution_notification_controller_.reset();
screen_security_notification_controller_.reset(); screen_security_notification_controller_.reset();
screenshot_controller_.reset(); screenshot_controller_.reset();
...@@ -944,6 +947,9 @@ void Shell::Init(ui::ContextFactory* context_factory, ...@@ -944,6 +947,9 @@ void Shell::Init(ui::ContextFactory* context_factory,
detachable_base_notification_controller_ = detachable_base_notification_controller_ =
std::make_unique<DetachableBaseNotificationController>( std::make_unique<DetachableBaseNotificationController>(
detachable_base_handler_.get()); detachable_base_handler_.get());
power_notification_controller_ =
std::make_unique<PowerNotificationController>(
message_center::MessageCenter::Get());
screen_security_notification_controller_ = screen_security_notification_controller_ =
std::make_unique<ScreenSecurityNotificationController>(); std::make_unique<ScreenSecurityNotificationController>();
supervised_notification_controller_ = supervised_notification_controller_ =
......
...@@ -138,6 +138,7 @@ class PeripheralBatteryNotifier; ...@@ -138,6 +138,7 @@ class PeripheralBatteryNotifier;
class PersistentWindowController; class PersistentWindowController;
class PowerButtonController; class PowerButtonController;
class PowerEventObserver; class PowerEventObserver;
class PowerNotificationController;
class PowerPrefs; class PowerPrefs;
class ProjectingObserver; class ProjectingObserver;
class ResizeShadowController; class ResizeShadowController;
...@@ -717,6 +718,7 @@ class ASH_EXPORT Shell : public SessionObserver, ...@@ -717,6 +718,7 @@ class ASH_EXPORT Shell : public SessionObserver,
std::unique_ptr<SessionController> session_controller_; std::unique_ptr<SessionController> session_controller_;
std::unique_ptr<NightLightController> night_light_controller_; std::unique_ptr<NightLightController> night_light_controller_;
std::unique_ptr<NoteTakingController> note_taking_controller_; std::unique_ptr<NoteTakingController> note_taking_controller_;
std::unique_ptr<PowerNotificationController> power_notification_controller_;
std::unique_ptr<ScreenSecurityNotificationController> std::unique_ptr<ScreenSecurityNotificationController>
screen_security_notification_controller_; screen_security_notification_controller_;
std::unique_ptr<SupervisedNotificationController> std::unique_ptr<SupervisedNotificationController>
......
...@@ -29,12 +29,14 @@ const char kBatteryNotificationId[] = "battery"; ...@@ -29,12 +29,14 @@ const char kBatteryNotificationId[] = "battery";
const char kNotifierBattery[] = "ash.battery"; const char kNotifierBattery[] = "ash.battery";
const gfx::VectorIcon& GetBatteryImageMD( const gfx::VectorIcon& GetBatteryImageMD(
TrayPower::NotificationState notification_state) { PowerNotificationController::NotificationState notification_state) {
if (PowerStatus::Get()->IsUsbChargerConnected()) { if (PowerStatus::Get()->IsUsbChargerConnected()) {
return kNotificationBatteryFluctuatingIcon; return kNotificationBatteryFluctuatingIcon;
} else if (notification_state == TrayPower::NOTIFICATION_LOW_POWER) { } else if (notification_state ==
PowerNotificationController::NOTIFICATION_LOW_POWER) {
return kNotificationBatteryLowIcon; return kNotificationBatteryLowIcon;
} else if (notification_state == TrayPower::NOTIFICATION_CRITICAL) { } else if (notification_state ==
PowerNotificationController::NOTIFICATION_CRITICAL) {
return kNotificationBatteryCriticalIcon; return kNotificationBatteryCriticalIcon;
} else { } else {
NOTREACHED(); NOTREACHED();
...@@ -43,12 +45,14 @@ const gfx::VectorIcon& GetBatteryImageMD( ...@@ -43,12 +45,14 @@ const gfx::VectorIcon& GetBatteryImageMD(
} }
message_center::SystemNotificationWarningLevel GetWarningLevelMD( message_center::SystemNotificationWarningLevel GetWarningLevelMD(
TrayPower::NotificationState notification_state) { PowerNotificationController::NotificationState notification_state) {
if (PowerStatus::Get()->IsUsbChargerConnected()) { if (PowerStatus::Get()->IsUsbChargerConnected()) {
return message_center::SystemNotificationWarningLevel::WARNING; return message_center::SystemNotificationWarningLevel::WARNING;
} else if (notification_state == TrayPower::NOTIFICATION_LOW_POWER) { } else if (notification_state ==
PowerNotificationController::NOTIFICATION_LOW_POWER) {
return message_center::SystemNotificationWarningLevel::WARNING; return message_center::SystemNotificationWarningLevel::WARNING;
} else if (notification_state == TrayPower::NOTIFICATION_CRITICAL) { } else if (notification_state ==
PowerNotificationController::NOTIFICATION_CRITICAL) {
return message_center::SystemNotificationWarningLevel::CRITICAL_WARNING; return message_center::SystemNotificationWarningLevel::CRITICAL_WARNING;
} else { } else {
NOTREACHED(); NOTREACHED();
...@@ -57,7 +61,7 @@ message_center::SystemNotificationWarningLevel GetWarningLevelMD( ...@@ -57,7 +61,7 @@ message_center::SystemNotificationWarningLevel GetWarningLevelMD(
} }
std::unique_ptr<Notification> CreateNotification( std::unique_ptr<Notification> CreateNotification(
TrayPower::NotificationState notification_state) { PowerNotificationController::NotificationState notification_state) {
const PowerStatus& status = *PowerStatus::Get(); const PowerStatus& status = *PowerStatus::Get();
base::string16 message = base::i18n::MessageFormatter::FormatWithNumberedArgs( base::string16 message = base::i18n::MessageFormatter::FormatWithNumberedArgs(
...@@ -106,7 +110,7 @@ std::unique_ptr<Notification> CreateNotification( ...@@ -106,7 +110,7 @@ std::unique_ptr<Notification> CreateNotification(
BatteryNotification::BatteryNotification( BatteryNotification::BatteryNotification(
MessageCenter* message_center, MessageCenter* message_center,
TrayPower::NotificationState notification_state) PowerNotificationController::NotificationState notification_state)
: message_center_(message_center) { : message_center_(message_center) {
message_center_->AddNotification(CreateNotification(notification_state)); message_center_->AddNotification(CreateNotification(notification_state));
} }
...@@ -117,7 +121,7 @@ BatteryNotification::~BatteryNotification() { ...@@ -117,7 +121,7 @@ BatteryNotification::~BatteryNotification() {
} }
void BatteryNotification::Update( void BatteryNotification::Update(
TrayPower::NotificationState notification_state) { PowerNotificationController::NotificationState notification_state) {
if (message_center_->FindVisibleNotificationById(kBatteryNotificationId)) { if (message_center_->FindVisibleNotificationById(kBatteryNotificationId)) {
message_center_->UpdateNotification(kBatteryNotificationId, message_center_->UpdateNotification(kBatteryNotificationId,
CreateNotification(notification_state)); CreateNotification(notification_state));
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
#define ASH_SYSTEM_POWER_BATTERY_NOTIFICATION_H_ #define ASH_SYSTEM_POWER_BATTERY_NOTIFICATION_H_
#include "ash/ash_export.h" #include "ash/ash_export.h"
#include "ash/system/power/tray_power.h" #include "ash/system/power/power_notification_controller.h"
#include "base/macros.h" #include "base/macros.h"
namespace message_center { namespace message_center {
...@@ -18,12 +18,14 @@ namespace ash { ...@@ -18,12 +18,14 @@ namespace ash {
// Class for showing and hiding a MessageCenter low battery notification. // Class for showing and hiding a MessageCenter low battery notification.
class ASH_EXPORT BatteryNotification { class ASH_EXPORT BatteryNotification {
public: public:
BatteryNotification(message_center::MessageCenter* message_center, BatteryNotification(
TrayPower::NotificationState notification_state); message_center::MessageCenter* message_center,
PowerNotificationController::NotificationState notification_state);
~BatteryNotification(); ~BatteryNotification();
// Updates the notification if it still exists. // Updates the notification if it still exists.
void Update(TrayPower::NotificationState notification_state); void Update(
PowerNotificationController::NotificationState notification_state);
private: private:
message_center::MessageCenter* message_center_; message_center::MessageCenter* message_center_;
......
// Copyright 2018 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 "ash/system/power/power_notification_controller.h"
#include "ash/public/cpp/ash_switches.h"
#include "ash/resources/vector_icons/vector_icons.h"
#include "ash/strings/grit/ash_strings.h"
#include "ash/system/power/battery_notification.h"
#include "ash/system/power/dual_role_notification.h"
#include "base/command_line.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/chromeos/devicetype_utils.h"
#include "ui/message_center/message_center.h"
#include "ui/message_center/public/cpp/notification.h"
#include "ui/message_center/public/cpp/notification_delegate.h"
using message_center::MessageCenter;
using message_center::Notification;
namespace ash {
namespace {
const char kNotifierPower[] = "ash.power";
// Informs the PowerNotificationController when a USB notification is closed.
class UsbNotificationDelegate : public message_center::NotificationDelegate {
public:
explicit UsbNotificationDelegate(PowerNotificationController* controller)
: controller_(controller) {}
// Overridden from message_center::NotificationDelegate.
void Close(bool by_user) override {
if (by_user)
controller_->NotifyUsbNotificationClosedByUser();
}
private:
~UsbNotificationDelegate() override = default;
PowerNotificationController* const controller_;
DISALLOW_COPY_AND_ASSIGN(UsbNotificationDelegate);
};
std::string GetNotificationStateString(
PowerNotificationController::NotificationState notification_state) {
switch (notification_state) {
case PowerNotificationController::NOTIFICATION_NONE:
return "none";
case PowerNotificationController::NOTIFICATION_LOW_POWER:
return "low power";
case PowerNotificationController::NOTIFICATION_CRITICAL:
return "critical power";
}
NOTREACHED() << "Unknown state " << notification_state;
return "Unknown state";
}
void LogBatteryForUsbCharger(
PowerNotificationController::NotificationState state,
int battery_percent) {
VLOG(1) << "Showing " << GetNotificationStateString(state)
<< " notification. USB charger is connected. "
<< "Battery percentage: " << battery_percent << "%.";
}
void LogBatteryForNoCharger(
PowerNotificationController::NotificationState state,
int remaining_minutes) {
VLOG(1) << "Showing " << GetNotificationStateString(state)
<< " notification. No charger connected."
<< " Remaining time: " << remaining_minutes << " minutes.";
}
} // namespace
const char PowerNotificationController::kUsbNotificationId[] = "usb-charger";
PowerNotificationController::PowerNotificationController(
message_center::MessageCenter* message_center)
: message_center_(message_center) {
PowerStatus::Get()->AddObserver(this);
}
PowerNotificationController::~PowerNotificationController() {
PowerStatus::Get()->RemoveObserver(this);
message_center_->RemoveNotification(kUsbNotificationId, false);
}
void PowerNotificationController::OnPowerStatusChanged() {
bool battery_alert = UpdateNotificationState();
// Factory testing may place the battery into unusual states.
if (base::CommandLine::ForCurrentProcess()->HasSwitch(
ash::switches::kAshHideNotificationsForFactory)) {
return;
}
MaybeShowUsbChargerNotification();
MaybeShowDualRoleNotification();
if (battery_alert) {
// Remove any existing notification so it's dismissed before adding a new
// one. Otherwise we might update a "low battery" notification to "critical"
// without it being shown again.
battery_notification_.reset();
battery_notification_.reset(
new BatteryNotification(message_center_, notification_state_));
} else if (notification_state_ == NOTIFICATION_NONE) {
battery_notification_.reset();
} else if (battery_notification_.get()) {
battery_notification_->Update(notification_state_);
}
battery_was_full_ = PowerStatus::Get()->IsBatteryFull();
usb_charger_was_connected_ = PowerStatus::Get()->IsUsbChargerConnected();
line_power_was_connected_ = PowerStatus::Get()->IsLinePowerConnected();
}
bool PowerNotificationController::MaybeShowUsbChargerNotification() {
const PowerStatus& status = *PowerStatus::Get();
// We show the notification if a USB charger is connected but the battery
// isn't full (since some ECs may choose to use a lower power rail when the
// battery is full even when a high-power charger is connected).
const bool show = status.IsUsbChargerConnected() && !status.IsBatteryFull();
// Check if the notification needs to be created.
if (show && !usb_charger_was_connected_ && !usb_notification_dismissed_) {
std::unique_ptr<Notification> notification =
Notification::CreateSystemNotification(
message_center::NOTIFICATION_TYPE_SIMPLE, kUsbNotificationId,
l10n_util::GetStringUTF16(
IDS_ASH_STATUS_TRAY_LOW_POWER_CHARGER_TITLE),
ui::SubstituteChromeOSDeviceType(
IDS_ASH_STATUS_TRAY_LOW_POWER_CHARGER_MESSAGE_SHORT),
gfx::Image(), base::string16(), GURL(),
message_center::NotifierId(
message_center::NotifierId::SYSTEM_COMPONENT, kNotifierPower),
message_center::RichNotificationData(),
new UsbNotificationDelegate(this), kNotificationLowPowerChargerIcon,
message_center::SystemNotificationWarningLevel::WARNING);
notification->set_priority(message_center::SYSTEM_PRIORITY);
message_center_->AddNotification(std::move(notification));
return true;
}
if (!show && usb_charger_was_connected_ && !battery_was_full_) {
// USB charger was unplugged or identified as a different type or battery
// reached the full state while the notification was showing.
message_center_->RemoveNotification(kUsbNotificationId, false);
if (!status.IsLinePowerConnected())
usb_notification_dismissed_ = false;
return true;
}
return false;
}
void PowerNotificationController::MaybeShowDualRoleNotification() {
const PowerStatus& status = *PowerStatus::Get();
if (!status.HasDualRoleDevices()) {
dual_role_notification_.reset();
return;
}
if (!dual_role_notification_)
dual_role_notification_.reset(new DualRoleNotification(message_center_));
dual_role_notification_->Update();
}
bool PowerNotificationController::UpdateNotificationState() {
const PowerStatus& status = *PowerStatus::Get();
if (!status.IsBatteryPresent() || status.IsBatteryTimeBeingCalculated() ||
status.IsMainsChargerConnected()) {
notification_state_ = NOTIFICATION_NONE;
return false;
}
return status.IsUsbChargerConnected()
? UpdateNotificationStateForRemainingPercentage()
: UpdateNotificationStateForRemainingTime();
}
bool PowerNotificationController::UpdateNotificationStateForRemainingTime() {
// The notification includes a rounded minutes value, so round the estimate
// received from the power manager to match.
const int remaining_minutes = static_cast<int>(
PowerStatus::Get()->GetBatteryTimeToEmpty().InSecondsF() / 60.0 + 0.5);
if (remaining_minutes >= kNoWarningMinutes ||
PowerStatus::Get()->IsBatteryFull()) {
notification_state_ = NOTIFICATION_NONE;
return false;
}
switch (notification_state_) {
case NOTIFICATION_NONE:
if (remaining_minutes <= kCriticalMinutes) {
notification_state_ = NOTIFICATION_CRITICAL;
LogBatteryForNoCharger(notification_state_, remaining_minutes);
return true;
}
if (remaining_minutes <= kLowPowerMinutes) {
notification_state_ = NOTIFICATION_LOW_POWER;
LogBatteryForNoCharger(notification_state_, remaining_minutes);
return true;
}
return false;
case NOTIFICATION_LOW_POWER:
if (remaining_minutes <= kCriticalMinutes) {
notification_state_ = NOTIFICATION_CRITICAL;
LogBatteryForNoCharger(notification_state_, remaining_minutes);
return true;
}
return false;
case NOTIFICATION_CRITICAL:
return false;
}
NOTREACHED();
return false;
}
bool PowerNotificationController::
UpdateNotificationStateForRemainingPercentage() {
// The notification includes a rounded percentage, so round the value received
// from the power manager to match.
const int remaining_percentage =
PowerStatus::Get()->GetRoundedBatteryPercent();
if (remaining_percentage >= kNoWarningPercentage ||
PowerStatus::Get()->IsBatteryFull()) {
notification_state_ = NOTIFICATION_NONE;
return false;
}
switch (notification_state_) {
case NOTIFICATION_NONE:
if (remaining_percentage <= kCriticalPercentage) {
notification_state_ = NOTIFICATION_CRITICAL;
LogBatteryForUsbCharger(notification_state_, remaining_percentage);
return true;
}
if (remaining_percentage <= kLowPowerPercentage) {
notification_state_ = NOTIFICATION_LOW_POWER;
LogBatteryForUsbCharger(notification_state_, remaining_percentage);
return true;
}
return false;
case NOTIFICATION_LOW_POWER:
if (remaining_percentage <= kCriticalPercentage) {
notification_state_ = NOTIFICATION_CRITICAL;
LogBatteryForUsbCharger(notification_state_, remaining_percentage);
return true;
}
return false;
case NOTIFICATION_CRITICAL:
return false;
}
NOTREACHED();
return false;
}
void PowerNotificationController::NotifyUsbNotificationClosedByUser() {
usb_notification_dismissed_ = true;
}
} // namespace ash
// Copyright 2018 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.
#ifndef ASH_SYSTEM_POWER_POWER_NOTIFICATION_CONTROLLER_H_
#define ASH_SYSTEM_POWER_POWER_NOTIFICATION_CONTROLLER_H_
#include <memory>
#include "ash/system/power/power_status.h"
#include "base/macros.h"
namespace message_center {
class MessageCenter;
} // namespace message_center
namespace ash {
class BatteryNotification;
class DualRoleNotification;
// Controller class to manage power/battery notifications.
class ASH_EXPORT PowerNotificationController : public PowerStatus::Observer {
public:
enum NotificationState {
NOTIFICATION_NONE,
// Low battery charge.
NOTIFICATION_LOW_POWER,
// Critically low battery charge.
NOTIFICATION_CRITICAL,
};
explicit PowerNotificationController(
message_center::MessageCenter* message_center);
~PowerNotificationController() override;
void NotifyUsbNotificationClosedByUser();
private:
FRIEND_TEST_ALL_PREFIXES(PowerNotificationControllerTest,
MaybeShowUsbChargerNotification);
FRIEND_TEST_ALL_PREFIXES(PowerNotificationControllerTest,
UpdateNotificationState);
friend class PowerNotificationControllerTest;
// Overridden from PowerStatus::Observer.
void OnPowerStatusChanged() override;
// Shows a notification that a low-power USB charger has been connected.
// Returns true if a notification was shown or explicitly hidden.
bool MaybeShowUsbChargerNotification();
// Shows a notification when dual-role devices are connected.
void MaybeShowDualRoleNotification();
// Sets |notification_state_|. Returns true if a notification should be shown.
bool UpdateNotificationState();
bool UpdateNotificationStateForRemainingTime();
bool UpdateNotificationStateForRemainingPercentage();
// Time-based notification thresholds when on battery power.
static constexpr int kCriticalMinutes = 5;
static constexpr int kLowPowerMinutes = 15;
static constexpr int kNoWarningMinutes = 30;
// Percentage-based notification thresholds when using a low-power charger.
static constexpr int kCriticalPercentage = 5;
static constexpr int kLowPowerPercentage = 10;
static constexpr int kNoWarningPercentage = 15;
static const char kUsbNotificationId[];
message_center::MessageCenter* const message_center_; // Unowned.
std::unique_ptr<BatteryNotification> battery_notification_;
std::unique_ptr<DualRoleNotification> dual_role_notification_;
NotificationState notification_state_ = NOTIFICATION_NONE;
// Was the battery full the last time OnPowerStatusChanged() was called?
bool battery_was_full_ = false;
// Was a USB charger connected the last time OnPowerStatusChanged() was
// called?
bool usb_charger_was_connected_ = false;
// Was line power connected the last time onPowerStatusChanged() was called?
bool line_power_was_connected_ = false;
// Has the user already dismissed a low-power notification? Should be set
// back to false when all power sources are disconnected.
bool usb_notification_dismissed_ = false;
DISALLOW_COPY_AND_ASSIGN(PowerNotificationController);
};
} // namespace ash
#endif // ASH_SYSTEM_POWER_POWER_NOTIFICATION_CONTROLLER_H_
This diff is collapsed.
...@@ -11,15 +11,8 @@ ...@@ -11,15 +11,8 @@
#include "ash/system/tray/system_tray_item.h" #include "ash/system/tray/system_tray_item.h"
#include "base/macros.h" #include "base/macros.h"
namespace message_center {
class MessageCenter;
}
namespace ash { namespace ash {
class BatteryNotification;
class DualRoleNotification;
namespace tray { namespace tray {
class PowerTrayView; class PowerTrayView;
} }
...@@ -27,37 +20,10 @@ class PowerTrayView; ...@@ -27,37 +20,10 @@ class PowerTrayView;
class ASH_EXPORT TrayPower : public SystemTrayItem, class ASH_EXPORT TrayPower : public SystemTrayItem,
public PowerStatus::Observer { public PowerStatus::Observer {
public: public:
enum NotificationState { explicit TrayPower(SystemTray* system_tray);
NOTIFICATION_NONE,
// Low battery charge.
NOTIFICATION_LOW_POWER,
// Critically low battery charge.
NOTIFICATION_CRITICAL,
};
// Time-based notification thresholds when on battery power.
static const int kCriticalMinutes;
static const int kLowPowerMinutes;
static const int kNoWarningMinutes;
// Percentage-based notification thresholds when using a low-power charger.
static const int kCriticalPercentage;
static const int kLowPowerPercentage;
static const int kNoWarningPercentage;
static const char kUsbNotificationId[];
TrayPower(SystemTray* system_tray,
message_center::MessageCenter* message_center);
~TrayPower() override; ~TrayPower() override;
void NotifyUsbNotificationClosedByUser();
private: private:
friend class TrayPowerTest;
// This enum is used for histogram. The existing values should not be removed, // This enum is used for histogram. The existing values should not be removed,
// and the new values should be added just before CHARGER_TYPE_COUNT. // and the new values should be added just before CHARGER_TYPE_COUNT.
enum ChargerType { enum ChargerType {
...@@ -77,37 +43,7 @@ class ASH_EXPORT TrayPower : public SystemTrayItem, ...@@ -77,37 +43,7 @@ class ASH_EXPORT TrayPower : public SystemTrayItem,
// Overridden from PowerStatus::Observer. // Overridden from PowerStatus::Observer.
void OnPowerStatusChanged() override; void OnPowerStatusChanged() override;
// Shows a notification that a low-power USB charger has been connected.
// Returns true if a notification was shown or explicitly hidden.
bool MaybeShowUsbChargerNotification();
// Shows a notification when dual-role devices are connected.
void MaybeShowDualRoleNotification();
// Sets |notification_state_|. Returns true if a notification should be shown.
bool UpdateNotificationState();
bool UpdateNotificationStateForRemainingTime();
bool UpdateNotificationStateForRemainingPercentage();
message_center::MessageCenter* message_center_ = nullptr; // Not owned.
tray::PowerTrayView* power_tray_ = nullptr; tray::PowerTrayView* power_tray_ = nullptr;
std::unique_ptr<BatteryNotification> battery_notification_;
std::unique_ptr<DualRoleNotification> dual_role_notification_;
NotificationState notification_state_ = NOTIFICATION_NONE;
// Was the battery full the last time OnPowerStatusChanged() was called?
bool battery_was_full_ = false;
// Was a USB charger connected the last time OnPowerStatusChanged() was
// called?
bool usb_charger_was_connected_ = false;
// Was line power connected the last time onPowerStatusChanged() was called?
bool line_power_was_connected_ = false;
// Has the user already dismissed a low-power notification? Should be set
// back to false when all power sources are disconnected.
bool usb_notification_dismissed_ = false;
DISALLOW_COPY_AND_ASSIGN(TrayPower); DISALLOW_COPY_AND_ASSIGN(TrayPower);
}; };
......
...@@ -268,8 +268,7 @@ void SystemTray::CreateItems() { ...@@ -268,8 +268,7 @@ void SystemTray::CreateItems() {
AddTrayItem(base::WrapUnique(tray_accessibility_)); AddTrayItem(base::WrapUnique(tray_accessibility_));
tray_tracing_ = new TrayTracing(this); tray_tracing_ = new TrayTracing(this);
AddTrayItem(base::WrapUnique(tray_tracing_)); AddTrayItem(base::WrapUnique(tray_tracing_));
AddTrayItem( AddTrayItem(std::make_unique<TrayPower>(this));
std::make_unique<TrayPower>(this, message_center::MessageCenter::Get()));
tray_network_ = new TrayNetwork(this); tray_network_ = new TrayNetwork(this);
AddTrayItem(base::WrapUnique(tray_network_)); AddTrayItem(base::WrapUnique(tray_network_));
tray_vpn_ = new TrayVPN(this); tray_vpn_ = new TrayVPN(this);
......
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