Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(161)

Unified Diff: ash/system/chromeos/power/tray_power.cc

Issue 1014753003: Move low battery notification to Message Center. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Made suggested changes Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ash/system/chromeos/power/tray_power.cc
diff --git a/ash/system/chromeos/power/tray_power.cc b/ash/system/chromeos/power/tray_power.cc
index 969a1ddf75a4859e86035db897e1455603d4aeb4..1e03397e7ba4bd6c98330f085c236cc9d6aace6c 100644
--- a/ash/system/chromeos/power/tray_power.cc
+++ b/ash/system/chromeos/power/tray_power.cc
@@ -7,32 +7,23 @@
#include "ash/accessibility_delegate.h"
#include "ash/ash_switches.h"
#include "ash/shell.h"
-#include "ash/system/chromeos/power/power_status_view.h"
+#include "ash/system/chromeos/power/battery_notification.h"
#include "ash/system/date/date_view.h"
#include "ash/system/system_notifier.h"
#include "ash/system/tray/system_tray_delegate.h"
#include "ash/system/tray/tray_constants.h"
-#include "ash/system/tray/tray_notification_view.h"
#include "ash/system/tray/tray_utils.h"
#include "base/command_line.h"
#include "base/metrics/histogram.h"
#include "base/time/time.h"
#include "grit/ash_resources.h"
#include "grit/ash_strings.h"
-#include "third_party/icu/source/i18n/unicode/fieldpos.h"
-#include "third_party/icu/source/i18n/unicode/fmtable.h"
#include "ui/accessibility/ax_view_state.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/message_center/message_center.h"
#include "ui/message_center/notification.h"
-#include "ui/views/controls/button/button.h"
#include "ui/views/controls/image_view.h"
-#include "ui/views/controls/label.h"
-#include "ui/views/layout/box_layout.h"
-#include "ui/views/layout/fill_layout.h"
-#include "ui/views/layout/grid_layout.h"
#include "ui/views/view.h"
-#include "ui/views/widget/widget.h"
using message_center::MessageCenter;
using message_center::Notification;
@@ -75,29 +66,8 @@ class PowerTrayView : public views::ImageView {
DISALLOW_COPY_AND_ASSIGN(PowerTrayView);
};
-class PowerNotificationView : public TrayNotificationView {
- public:
- explicit PowerNotificationView(TrayPower* owner)
- : TrayNotificationView(owner, 0) {
- power_status_view_ =
- new PowerStatusView(PowerStatusView::VIEW_NOTIFICATION, true);
- InitView(power_status_view_);
- }
-
- void UpdateStatus() {
- SetIconImage(PowerStatus::Get()->GetBatteryImage(PowerStatus::ICON_DARK));
- }
-
- private:
- PowerStatusView* power_status_view_;
-
- DISALLOW_COPY_AND_ASSIGN(PowerNotificationView);
-};
-
} // namespace tray
-using tray::PowerNotificationView;
-
const int TrayPower::kCriticalMinutes = 5;
const int TrayPower::kLowPowerMinutes = 15;
const int TrayPower::kNoWarningMinutes = 30;
@@ -109,7 +79,6 @@ TrayPower::TrayPower(SystemTray* system_tray, MessageCenter* message_center)
: SystemTrayItem(system_tray),
message_center_(message_center),
power_tray_(NULL),
- notification_view_(NULL),
notification_state_(NOTIFICATION_NONE),
usb_charger_was_connected_(false),
line_power_was_connected_(false) {
@@ -136,17 +105,6 @@ views::View* TrayPower::CreateDefaultView(user::LoginStatus status) {
return NULL;
}
-views::View* TrayPower::CreateNotificationView(user::LoginStatus status) {
- CHECK(notification_view_ == NULL);
- if (!PowerStatus::Get()->IsBatteryPresent())
- return NULL;
-
- notification_view_ = new PowerNotificationView(this);
- notification_view_->UpdateStatus();
-
- return notification_view_;
-}
-
void TrayPower::DestroyTrayView() {
power_tray_ = NULL;
}
@@ -154,10 +112,6 @@ void TrayPower::DestroyTrayView() {
void TrayPower::DestroyDefaultView() {
}
-void TrayPower::DestroyNotificationView() {
- notification_view_ = NULL;
-}
-
void TrayPower::UpdateAfterLoginStatusChange(user::LoginStatus status) {
}
@@ -169,8 +123,6 @@ void TrayPower::OnPowerStatusChanged() {
bool battery_alert = UpdateNotificationState();
if (power_tray_)
power_tray_->UpdateStatus(battery_alert);
- if (notification_view_)
- notification_view_->UpdateStatus();
// Factory testing may place the battery into unusual states.
if (base::CommandLine::ForCurrentProcess()->HasSwitch(
@@ -179,10 +131,18 @@ void TrayPower::OnPowerStatusChanged() {
MaybeShowUsbChargerNotification();
- if (battery_alert)
- ShowNotificationView();
- else if (notification_state_ == NOTIFICATION_NONE)
- HideNotificationView();
+ 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_);
+ }
usb_charger_was_connected_ = PowerStatus::Get()->IsUsbChargerConnected();
line_power_was_connected_ = PowerStatus::Get()->IsLinePowerConnected();

Powered by Google App Engine
This is Rietveld 408576698