1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef ASH_SYSTEM_CHROMEOS_POWER_TRAY_POWER_H_
6 #define ASH_SYSTEM_CHROMEOS_POWER_TRAY_POWER_H_
8 #include "ash/system/chromeos/power/power_status.h"
9 #include "ash/system/tray/system_tray_item.h"
18 namespace message_center {
26 class PowerNotificationView;
30 class ASH_EXPORT TrayPower : public SystemTrayItem,
31 public PowerStatus::Observer {
33 // Visible for testing.
34 enum NotificationState {
37 // Low battery charge.
38 NOTIFICATION_LOW_POWER,
40 // Critically low battery charge.
41 NOTIFICATION_CRITICAL,
44 // Time-based notification thresholds when on battery power.
45 static const int kCriticalMinutes;
46 static const int kLowPowerMinutes;
47 static const int kNoWarningMinutes;
49 // Percentage-based notification thresholds when using a low-power charger.
50 static const int kCriticalPercentage;
51 static const int kLowPowerPercentage;
52 static const int kNoWarningPercentage;
54 TrayPower(SystemTray* system_tray,
55 message_center::MessageCenter* message_center);
59 friend class TrayPowerTest;
61 // Overridden from SystemTrayItem.
62 virtual views::View* CreateTrayView(user::LoginStatus status) OVERRIDE;
63 virtual views::View* CreateDefaultView(user::LoginStatus status) OVERRIDE;
64 virtual views::View* CreateNotificationView(
65 user::LoginStatus status) OVERRIDE;
66 virtual void DestroyTrayView() OVERRIDE;
67 virtual void DestroyDefaultView() OVERRIDE;
68 virtual void DestroyNotificationView() OVERRIDE;
69 virtual void UpdateAfterLoginStatusChange(user::LoginStatus status) OVERRIDE;
70 virtual void UpdateAfterShelfAlignmentChange(
71 ShelfAlignment alignment) OVERRIDE;
73 // Overridden from PowerStatus::Observer.
74 virtual void OnPowerStatusChanged() OVERRIDE;
76 // Show a notification that a low-power USB charger has been connected.
77 // Returns true if a notification was shown or explicitly hidden.
78 bool MaybeShowUsbChargerNotification();
80 // Sets |notification_state_|. Returns true if a notification should be shown.
81 bool UpdateNotificationState();
82 bool UpdateNotificationStateForRemainingTime();
83 bool UpdateNotificationStateForRemainingPercentage();
85 message_center::MessageCenter* message_center_; // Not owned.
86 tray::PowerTrayView* power_tray_;
87 tray::PowerNotificationView* notification_view_;
88 NotificationState notification_state_;
90 // Was a USB charger connected the last time OnPowerStatusChanged() was
92 bool usb_charger_was_connected_;
94 DISALLOW_COPY_AND_ASSIGN(TrayPower);
97 } // namespace internal
100 #endif // ASH_SYSTEM_CHROMEOS_POWER_TRAY_POWER_H_