• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_CHROMEOS_POWER_TRAY_POWER_H_
6 #define ASH_SYSTEM_CHROMEOS_POWER_TRAY_POWER_H_
7 
8 #include "ash/system/chromeos/power/power_status.h"
9 #include "ash/system/tray/system_tray_item.h"
10 
11 class SkBitmap;
12 
13 namespace gfx {
14 class Image;
15 class ImageSkia;
16 }
17 
18 namespace message_center {
19 class MessageCenter;
20 }
21 
22 namespace ash {
23 namespace internal {
24 
25 namespace tray {
26 class PowerNotificationView;
27 class PowerTrayView;
28 }
29 
30 class ASH_EXPORT TrayPower : public SystemTrayItem,
31                              public PowerStatus::Observer {
32  public:
33   // Visible for testing.
34   enum NotificationState {
35     NOTIFICATION_NONE,
36 
37     // Low battery charge.
38     NOTIFICATION_LOW_POWER,
39 
40     // Critically low battery charge.
41     NOTIFICATION_CRITICAL,
42   };
43 
44   // Time-based notification thresholds when on battery power.
45   static const int kCriticalMinutes;
46   static const int kLowPowerMinutes;
47   static const int kNoWarningMinutes;
48 
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;
53 
54   TrayPower(SystemTray* system_tray,
55             message_center::MessageCenter* message_center);
56   virtual ~TrayPower();
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   virtual views::View* CreateTrayView(user::LoginStatus status) OVERRIDE;
74   virtual views::View* CreateDefaultView(user::LoginStatus status) OVERRIDE;
75   virtual views::View* CreateNotificationView(
76       user::LoginStatus status) OVERRIDE;
77   virtual void DestroyTrayView() OVERRIDE;
78   virtual void DestroyDefaultView() OVERRIDE;
79   virtual void DestroyNotificationView() OVERRIDE;
80   virtual void UpdateAfterLoginStatusChange(user::LoginStatus status) OVERRIDE;
81   virtual void UpdateAfterShelfAlignmentChange(
82       ShelfAlignment alignment) OVERRIDE;
83 
84   // Overridden from PowerStatus::Observer.
85   virtual void OnPowerStatusChanged() OVERRIDE;
86 
87   // Show a notification that a low-power USB charger has been connected.
88   // Returns true if a notification was shown or explicitly hidden.
89   bool MaybeShowUsbChargerNotification();
90 
91   // Sets |notification_state_|. Returns true if a notification should be shown.
92   bool UpdateNotificationState();
93   bool UpdateNotificationStateForRemainingTime();
94   bool UpdateNotificationStateForRemainingPercentage();
95 
96   // Records the charger type in UMA.
97   void RecordChargerType();
98 
99   message_center::MessageCenter* message_center_;  // Not owned.
100   tray::PowerTrayView* power_tray_;
101   tray::PowerNotificationView* notification_view_;
102   NotificationState notification_state_;
103 
104   // Was a USB charger connected the last time OnPowerStatusChanged() was
105   // called?
106   bool usb_charger_was_connected_;
107 
108   // Was line power connected the last time onPowerStatusChanged() was called?
109   bool line_power_was_connected_;
110 
111   DISALLOW_COPY_AND_ASSIGN(TrayPower);
112 };
113 
114 }  // namespace internal
115 }  // namespace ash
116 
117 #endif  // ASH_SYSTEM_CHROMEOS_POWER_TRAY_POWER_H_
118