Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(265)

Side by Side Diff: ash/system/chromeos/power/tray_power.h

Issue 17482007: Reland: cros: Show notification when low-power charger connected (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove export macro Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ash/ash_switches.cc ('k') | ash/system/chromeos/power/tray_power.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef ASH_SYSTEM_CHROMEOS_POWER_TRAY_POWER_H_ 5 #ifndef ASH_SYSTEM_CHROMEOS_POWER_TRAY_POWER_H_
6 #define ASH_SYSTEM_CHROMEOS_POWER_TRAY_POWER_H_ 6 #define ASH_SYSTEM_CHROMEOS_POWER_TRAY_POWER_H_
7 7
8 #include "ash/system/tray/system_tray_item.h" 8 #include "ash/system/tray/system_tray_item.h"
9 #include "chromeos/power/power_manager_handler.h" 9 #include "chromeos/power/power_manager_handler.h"
10 10
11 class SkBitmap; 11 class SkBitmap;
12 12
13 namespace gfx { 13 namespace gfx {
14 class Image;
14 class ImageSkia; 15 class ImageSkia;
15 } 16 }
16 17
18 namespace message_center {
19 class MessageCenter;
20 }
21
17 namespace ash { 22 namespace ash {
18 namespace internal { 23 namespace internal {
19 24
20 namespace tray { 25 namespace tray {
21 class PowerNotificationView; 26 class PowerNotificationView;
22 class PowerTrayView; 27 class PowerTrayView;
23 } 28 }
24 29
25 enum IconSet { 30 enum IconSet {
26 ICON_LIGHT, 31 ICON_LIGHT,
27 ICON_DARK 32 ICON_DARK
28 }; 33 };
29 34
30 class TrayPower : public SystemTrayItem, 35 class ASH_EXPORT TrayPower : public SystemTrayItem,
31 public chromeos::PowerManagerHandler::Observer { 36 public chromeos::PowerManagerHandler::Observer {
32 public: 37 public:
33 explicit TrayPower(SystemTray* system_tray); 38 // Visible for testing.
39 enum NotificationState {
40 NOTIFICATION_NONE,
41
42 // Low battery charge.
43 NOTIFICATION_LOW_POWER,
44
45 // Critically low battery charge.
46 NOTIFICATION_CRITICAL,
47 };
48
49 TrayPower(SystemTray* system_tray,
50 message_center::MessageCenter* message_center);
34 virtual ~TrayPower(); 51 virtual ~TrayPower();
35 52
36 // Gets whether battery charging is unreliable for |supply_status|. 53 // Gets whether battery charging is unreliable for |supply_status|.
37 // When a non-standard power supply is connected, the battery may 54 // When a non-standard power supply is connected, the battery may
38 // change from being charged to discharged frequently depending on the 55 // change from being charged to discharged frequently depending on the
39 // charger power and power consumption, i.e usage. In this case we 56 // charger power and power consumption, i.e usage. In this case we
40 // do not want to show either a charging or discharging state. 57 // do not want to show either a charging or discharging state.
41 static bool IsBatteryChargingUnreliable( 58 static bool IsBatteryChargingUnreliable(
42 const chromeos::PowerSupplyStatus& supply_status); 59 const chromeos::PowerSupplyStatus& supply_status);
43 60
44 // Gets the icon index in the battery icon array image based on 61 // Gets the icon index in the battery icon array image based on
45 // |supply_status|. If |supply_status| is uncertain about the power state, 62 // |supply_status|. If |supply_status| is uncertain about the power state,
46 // returns -1. 63 // returns -1.
47 static int GetBatteryImageIndex( 64 static int GetBatteryImageIndex(
48 const chromeos::PowerSupplyStatus& supply_status); 65 const chromeos::PowerSupplyStatus& supply_status);
49 66
50 // Gets the horizontal offset in the battery icon array image based on 67 // Gets the horizontal offset in the battery icon array image based on
51 // |supply_status|. 68 // |supply_status|.
52 static int GetBatteryImageOffset( 69 static int GetBatteryImageOffset(
53 const chromeos::PowerSupplyStatus& supply_status); 70 const chromeos::PowerSupplyStatus& supply_status);
54 71
55 // Looks up the actual icon in the icon array image for |image_index|. 72 // Looks up the actual icon in the icon array image for |image_index|.
56 static gfx::ImageSkia GetBatteryImage(int image_index, 73 static gfx::ImageSkia GetBatteryImage(int image_index,
57 int image_offset, 74 int image_offset,
58 bool charging_unreliable, 75 bool charging_unreliable,
59 IconSet icon_set); 76 IconSet icon_set);
60 77
78 // Returns an icon for the USB charger notification.
79 static gfx::Image GetUsbChargerNotificationImage();
80
61 // Gets the battery accessible string for |supply_status|. 81 // Gets the battery accessible string for |supply_status|.
62 static base::string16 GetAccessibleNameString( 82 static base::string16 GetAccessibleNameString(
63 const chromeos::PowerSupplyStatus& supply_status); 83 const chromeos::PowerSupplyStatus& supply_status);
64 84
65 // Gets rounded battery percentage for |battery_percentage|. 85 // Gets rounded battery percentage for |battery_percentage|.
66 static int GetRoundedBatteryPercentage(double battery_percentage); 86 static int GetRoundedBatteryPercentage(double battery_percentage);
67 87
68 private: 88 private:
69 enum NotificationState { 89 friend class TrayPowerTest;
70 NOTIFICATION_NONE,
71 NOTIFICATION_LOW_POWER,
72 NOTIFICATION_CRITICAL
73 };
74 90
75 // Overridden from SystemTrayItem. 91 // Overridden from SystemTrayItem.
76 virtual views::View* CreateTrayView(user::LoginStatus status) OVERRIDE; 92 virtual views::View* CreateTrayView(user::LoginStatus status) OVERRIDE;
77 virtual views::View* CreateDefaultView(user::LoginStatus status) OVERRIDE; 93 virtual views::View* CreateDefaultView(user::LoginStatus status) OVERRIDE;
78 virtual views::View* CreateNotificationView( 94 virtual views::View* CreateNotificationView(
79 user::LoginStatus status) OVERRIDE; 95 user::LoginStatus status) OVERRIDE;
80 virtual void DestroyTrayView() OVERRIDE; 96 virtual void DestroyTrayView() OVERRIDE;
81 virtual void DestroyDefaultView() OVERRIDE; 97 virtual void DestroyDefaultView() OVERRIDE;
82 virtual void DestroyNotificationView() OVERRIDE; 98 virtual void DestroyNotificationView() OVERRIDE;
83 virtual void UpdateAfterLoginStatusChange(user::LoginStatus status) OVERRIDE; 99 virtual void UpdateAfterLoginStatusChange(user::LoginStatus status) OVERRIDE;
84 virtual void UpdateAfterShelfAlignmentChange( 100 virtual void UpdateAfterShelfAlignmentChange(
85 ShelfAlignment alignment) OVERRIDE; 101 ShelfAlignment alignment) OVERRIDE;
86 102
87 // Overridden from chromeos::PowerManagerHandler::Observer. 103 // Overridden from chromeos::PowerManagerHandler::Observer.
88 virtual void OnPowerStatusChanged( 104 virtual void OnPowerStatusChanged(
89 const chromeos::PowerSupplyStatus& status) OVERRIDE; 105 const chromeos::PowerSupplyStatus& status) OVERRIDE;
90 106
91 // Requests a power status update. 107 // Requests a power status update.
92 void RequestStatusUpdate() const; 108 void RequestStatusUpdate() const;
93 109
110 // Show a notification that a low-power USB charger has been connected.
111 // Returns true if a notification was shown or explicitly hidden.
112 bool MaybeShowUsbChargerNotification(
113 const chromeos::PowerSupplyStatus& old_status,
114 const chromeos::PowerSupplyStatus& new_status);
115
94 // Sets |notification_state_|. Returns true if a notification should be shown. 116 // Sets |notification_state_|. Returns true if a notification should be shown.
95 bool UpdateNotificationState(const chromeos::PowerSupplyStatus& status); 117 bool UpdateNotificationState(const chromeos::PowerSupplyStatus& status);
96 bool UpdateNotificationStateForRemainingTime(int remaining_seconds); 118 bool UpdateNotificationStateForRemainingTime(int remaining_seconds);
97 bool UpdateNotificationStateForRemainingPercentage( 119 bool UpdateNotificationStateForRemainingPercentage(
98 double remaining_percentage); 120 double remaining_percentage);
99 121
122 message_center::MessageCenter* message_center_; // Not owned.
100 tray::PowerTrayView* power_tray_; 123 tray::PowerTrayView* power_tray_;
101 tray::PowerNotificationView* notification_view_; 124 tray::PowerNotificationView* notification_view_;
102 NotificationState notification_state_; 125 NotificationState notification_state_;
103 126
127 // Power supply status at the last update.
128 chromeos::PowerSupplyStatus last_power_supply_status_;
129
104 DISALLOW_COPY_AND_ASSIGN(TrayPower); 130 DISALLOW_COPY_AND_ASSIGN(TrayPower);
105 }; 131 };
106 132
107 } // namespace internal 133 } // namespace internal
108 } // namespace ash 134 } // namespace ash
109 135
110 #endif // ASH_SYSTEM_CHROMEOS_POWER_TRAY_POWER_H_ 136 #endif // ASH_SYSTEM_CHROMEOS_POWER_TRAY_POWER_H_
OLDNEW
« no previous file with comments | « ash/ash_switches.cc ('k') | ash/system/chromeos/power/tray_power.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698