OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #ifndef ASH_SYSTEM_POWER_TRAY_POWER_H_ | |
6 #define ASH_SYSTEM_POWER_TRAY_POWER_H_ | |
7 | |
8 #include <memory> | |
9 | |
10 #include "ash/system/power/power_status.h" | |
11 #include "ash/system/tray/system_tray_item.h" | |
12 #include "base/macros.h" | |
13 | |
14 namespace message_center { | |
15 class MessageCenter; | |
16 } | |
17 | |
18 namespace ash { | |
19 | |
20 class BatteryNotification; | |
21 class DualRoleNotification; | |
22 | |
23 namespace tray { | |
24 class PowerTrayView; | |
25 } | |
26 | |
27 class ASH_EXPORT TrayPower : public SystemTrayItem, | |
28 public PowerStatus::Observer { | |
29 public: | |
30 enum NotificationState { | |
31 NOTIFICATION_NONE, | |
32 | |
33 // Low battery charge. | |
34 NOTIFICATION_LOW_POWER, | |
35 | |
36 // Critically low battery charge. | |
37 NOTIFICATION_CRITICAL, | |
38 }; | |
39 | |
40 // Time-based notification thresholds when on battery power. | |
41 static const int kCriticalMinutes; | |
42 static const int kLowPowerMinutes; | |
43 static const int kNoWarningMinutes; | |
44 | |
45 // Percentage-based notification thresholds when using a low-power charger. | |
46 static const int kCriticalPercentage; | |
47 static const int kLowPowerPercentage; | |
48 static const int kNoWarningPercentage; | |
49 | |
50 static const char kUsbNotificationId[]; | |
51 | |
52 TrayPower(SystemTray* system_tray, | |
53 message_center::MessageCenter* message_center); | |
54 ~TrayPower() override; | |
55 | |
56 void NotifyUsbNotificationClosedByUser(); | |
57 | |
58 private: | |
59 friend class TrayPowerTest; | |
60 | |
61 // This enum is used for histogram. The existing values should not be removed, | |
62 // and the new values should be added just before CHARGER_TYPE_COUNT. | |
63 enum ChargerType { | |
64 UNKNOWN_CHARGER, | |
65 MAINS_CHARGER, | |
66 USB_CHARGER, | |
67 UNCONFIRMED_SPRING_CHARGER, | |
68 SAFE_SPRING_CHARGER, | |
69 CHARGER_TYPE_COUNT, | |
70 }; | |
71 | |
72 // Overridden from SystemTrayItem. | |
73 views::View* CreateTrayView(LoginStatus status) override; | |
74 views::View* CreateDefaultView(LoginStatus status) override; | |
75 void DestroyTrayView() override; | |
76 void DestroyDefaultView() override; | |
77 void UpdateAfterLoginStatusChange(LoginStatus status) override; | |
78 void UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) override; | |
79 | |
80 // Overridden from PowerStatus::Observer. | |
81 void OnPowerStatusChanged() override; | |
82 | |
83 // Shows a notification that a low-power USB charger has been connected. | |
84 // Returns true if a notification was shown or explicitly hidden. | |
85 bool MaybeShowUsbChargerNotification(); | |
86 | |
87 // Shows a notification when dual-role devices are connected. | |
88 void MaybeShowDualRoleNotification(); | |
89 | |
90 // Sets |notification_state_|. Returns true if a notification should be shown. | |
91 bool UpdateNotificationState(); | |
92 bool UpdateNotificationStateForRemainingTime(); | |
93 bool UpdateNotificationStateForRemainingPercentage(); | |
94 | |
95 message_center::MessageCenter* message_center_; // Not owned. | |
96 tray::PowerTrayView* power_tray_; | |
97 std::unique_ptr<BatteryNotification> battery_notification_; | |
98 std::unique_ptr<DualRoleNotification> dual_role_notification_; | |
99 NotificationState notification_state_; | |
100 | |
101 // Was a USB charger connected the last time OnPowerStatusChanged() was | |
102 // called? | |
103 bool usb_charger_was_connected_; | |
104 | |
105 // Was line power connected the last time onPowerStatusChanged() was called? | |
106 bool line_power_was_connected_; | |
107 | |
108 // Has the user already dismissed a low-power notification? Should be set | |
109 // back to false when all power sources are disconnected. | |
110 bool usb_notification_dismissed_; | |
111 | |
112 DISALLOW_COPY_AND_ASSIGN(TrayPower); | |
113 }; | |
114 | |
115 } // namespace ash | |
116 | |
117 #endif // ASH_SYSTEM_POWER_TRAY_POWER_H_ | |
OLD | NEW |