Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / ash / system / chromeos / power / tray_power.h
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 tray {
24 class PowerNotificationView;
25 class PowerTrayView;
26 }
27
28 class 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_