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
11class SkBitmap;
12
13namespace gfx {
14class Image;
15class ImageSkia;
16}
17
18namespace message_center {
19class MessageCenter;
20}
21
22namespace ash {
23namespace tray {
24class PowerNotificationView;
25class PowerTrayView;
26}
27
28class ASH_EXPORT TrayPower : public SystemTrayItem,
29                             public PowerStatus::Observer {
30 public:
31  // Visible for testing.
32  enum NotificationState {
33    NOTIFICATION_NONE,
34
35    // Low battery charge.
36    NOTIFICATION_LOW_POWER,
37
38    // Critically low battery charge.
39    NOTIFICATION_CRITICAL,
40  };
41
42  // Time-based notification thresholds when on battery power.
43  static const int kCriticalMinutes;
44  static const int kLowPowerMinutes;
45  static const int kNoWarningMinutes;
46
47  // Percentage-based notification thresholds when using a low-power charger.
48  static const int kCriticalPercentage;
49  static const int kLowPowerPercentage;
50  static const int kNoWarningPercentage;
51
52  TrayPower(SystemTray* system_tray,
53            message_center::MessageCenter* message_center);
54  virtual ~TrayPower();
55
56 private:
57  friend class TrayPowerTest;
58
59  // This enum is used for histogram. The existing values should not be removed,
60  // and the new values should be added just before CHARGER_TYPE_COUNT.
61  enum ChargerType{
62    UNKNOWN_CHARGER,
63    MAINS_CHARGER,
64    USB_CHARGER,
65    UNCONFIRMED_SPRING_CHARGER,
66    SAFE_SPRING_CHARGER,
67    CHARGER_TYPE_COUNT,
68  };
69
70  // Overridden from SystemTrayItem.
71  virtual views::View* CreateTrayView(user::LoginStatus status) OVERRIDE;
72  virtual views::View* CreateDefaultView(user::LoginStatus status) OVERRIDE;
73  virtual views::View* CreateNotificationView(
74      user::LoginStatus status) OVERRIDE;
75  virtual void DestroyTrayView() OVERRIDE;
76  virtual void DestroyDefaultView() OVERRIDE;
77  virtual void DestroyNotificationView() OVERRIDE;
78  virtual void UpdateAfterLoginStatusChange(user::LoginStatus status) OVERRIDE;
79  virtual void UpdateAfterShelfAlignmentChange(
80      ShelfAlignment alignment) OVERRIDE;
81
82  // Overridden from PowerStatus::Observer.
83  virtual void OnPowerStatusChanged() OVERRIDE;
84
85  // Show a notification that a low-power USB charger has been connected.
86  // Returns true if a notification was shown or explicitly hidden.
87  bool MaybeShowUsbChargerNotification();
88
89  // Sets |notification_state_|. Returns true if a notification should be shown.
90  bool UpdateNotificationState();
91  bool UpdateNotificationStateForRemainingTime();
92  bool UpdateNotificationStateForRemainingPercentage();
93
94  // Records the charger type in UMA.
95  void RecordChargerType();
96
97  message_center::MessageCenter* message_center_;  // Not owned.
98  tray::PowerTrayView* power_tray_;
99  tray::PowerNotificationView* notification_view_;
100  NotificationState notification_state_;
101
102  // Was a USB charger connected the last time OnPowerStatusChanged() was
103  // called?
104  bool usb_charger_was_connected_;
105
106  // Was line power connected the last time onPowerStatusChanged() was called?
107  bool line_power_was_connected_;
108
109  DISALLOW_COPY_AND_ASSIGN(TrayPower);
110};
111
112}  // namespace ash
113
114#endif  // ASH_SYSTEM_CHROMEOS_POWER_TRAY_POWER_H_
115