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
{
24 class BatteryNotification
;
30 class ASH_EXPORT TrayPower
: public SystemTrayItem
,
31 public PowerStatus::Observer
{
33 enum NotificationState
{
36 // Low battery charge.
37 NOTIFICATION_LOW_POWER
,
39 // Critically low battery charge.
40 NOTIFICATION_CRITICAL
,
43 // Time-based notification thresholds when on battery power.
44 static const int kCriticalMinutes
;
45 static const int kLowPowerMinutes
;
46 static const int kNoWarningMinutes
;
48 // Percentage-based notification thresholds when using a low-power charger.
49 static const int kCriticalPercentage
;
50 static const int kLowPowerPercentage
;
51 static const int kNoWarningPercentage
;
53 TrayPower(SystemTray
* system_tray
,
54 message_center::MessageCenter
* message_center
);
55 ~TrayPower() override
;
58 friend class TrayPowerTest
;
60 // This enum is used for histogram. The existing values should not be removed,
61 // and the new values should be added just before CHARGER_TYPE_COUNT.
66 UNCONFIRMED_SPRING_CHARGER
,
71 // Overridden from SystemTrayItem.
72 views::View
* CreateTrayView(user::LoginStatus status
) override
;
73 views::View
* CreateDefaultView(user::LoginStatus status
) override
;
74 void DestroyTrayView() override
;
75 void DestroyDefaultView() override
;
76 void UpdateAfterLoginStatusChange(user::LoginStatus status
) override
;
77 void UpdateAfterShelfAlignmentChange(ShelfAlignment alignment
) override
;
79 // Overridden from PowerStatus::Observer.
80 void OnPowerStatusChanged() override
;
82 // Show a notification that a low-power USB charger has been connected.
83 // Returns true if a notification was shown or explicitly hidden.
84 bool MaybeShowUsbChargerNotification();
86 // Sets |notification_state_|. Returns true if a notification should be shown.
87 bool UpdateNotificationState();
88 bool UpdateNotificationStateForRemainingTime();
89 bool UpdateNotificationStateForRemainingPercentage();
91 message_center::MessageCenter
* message_center_
; // Not owned.
92 tray::PowerTrayView
* power_tray_
;
93 scoped_ptr
<BatteryNotification
> battery_notification_
;
94 NotificationState notification_state_
;
96 // Was a USB charger connected the last time OnPowerStatusChanged() was
98 bool usb_charger_was_connected_
;
100 // Was line power connected the last time onPowerStatusChanged() was called?
101 bool line_power_was_connected_
;
103 DISALLOW_COPY_AND_ASSIGN(TrayPower
);
108 #endif // ASH_SYSTEM_CHROMEOS_POWER_TRAY_POWER_H_