OLD | NEW |
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 #include "ash/system/chromeos/power/tray_power.h" | 5 #include "ash/system/chromeos/power/tray_power.h" |
6 | 6 |
7 #include "ash/ash_switches.h" | 7 #include "ash/ash_switches.h" |
8 #include "ash/system/chromeos/power/power_status_view.h" | 8 #include "ash/system/chromeos/power/power_status_view.h" |
9 #include "ash/system/date/date_view.h" | 9 #include "ash/system/date/date_view.h" |
10 #include "ash/system/system_notifier.h" | 10 #include "ash/system/system_notifier.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 #include "ui/views/layout/fill_layout.h" | 27 #include "ui/views/layout/fill_layout.h" |
28 #include "ui/views/layout/grid_layout.h" | 28 #include "ui/views/layout/grid_layout.h" |
29 #include "ui/views/view.h" | 29 #include "ui/views/view.h" |
30 #include "ui/views/widget/widget.h" | 30 #include "ui/views/widget/widget.h" |
31 | 31 |
32 using message_center::MessageCenter; | 32 using message_center::MessageCenter; |
33 using message_center::Notification; | 33 using message_center::Notification; |
34 | 34 |
35 namespace ash { | 35 namespace ash { |
36 namespace internal { | 36 namespace internal { |
37 | |
38 namespace { | |
39 // Notification times. | |
40 const int kCriticalSeconds = 5 * 60; | |
41 const int kLowPowerSeconds = 15 * 60; | |
42 const int kNoWarningSeconds = 30 * 60; | |
43 // Notification in battery percentage. | |
44 const double kCriticalPercentage = 5.0; | |
45 const double kLowPowerPercentage = 10.0; | |
46 const double kNoWarningPercentage = 15.0; | |
47 | |
48 } // namespace | |
49 | |
50 namespace tray { | 37 namespace tray { |
51 | 38 |
52 // This view is used only for the tray. | 39 // This view is used only for the tray. |
53 class PowerTrayView : public views::ImageView { | 40 class PowerTrayView : public views::ImageView { |
54 public: | 41 public: |
55 PowerTrayView() { | 42 PowerTrayView() { |
56 UpdateImage(); | 43 UpdateImage(); |
57 } | 44 } |
58 | 45 |
59 virtual ~PowerTrayView() { | 46 virtual ~PowerTrayView() { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 private: | 88 private: |
102 PowerStatusView* power_status_view_; | 89 PowerStatusView* power_status_view_; |
103 | 90 |
104 DISALLOW_COPY_AND_ASSIGN(PowerNotificationView); | 91 DISALLOW_COPY_AND_ASSIGN(PowerNotificationView); |
105 }; | 92 }; |
106 | 93 |
107 } // namespace tray | 94 } // namespace tray |
108 | 95 |
109 using tray::PowerNotificationView; | 96 using tray::PowerNotificationView; |
110 | 97 |
| 98 const int TrayPower::kCriticalMinutes = 5; |
| 99 const int TrayPower::kLowPowerMinutes = 15; |
| 100 const int TrayPower::kNoWarningMinutes = 30; |
| 101 const int TrayPower::kCriticalPercentage = 5; |
| 102 const int TrayPower::kLowPowerPercentage = 10; |
| 103 const int TrayPower::kNoWarningPercentage = 15; |
| 104 |
111 TrayPower::TrayPower(SystemTray* system_tray, MessageCenter* message_center) | 105 TrayPower::TrayPower(SystemTray* system_tray, MessageCenter* message_center) |
112 : SystemTrayItem(system_tray), | 106 : SystemTrayItem(system_tray), |
113 message_center_(message_center), | 107 message_center_(message_center), |
114 power_tray_(NULL), | 108 power_tray_(NULL), |
115 notification_view_(NULL), | 109 notification_view_(NULL), |
116 notification_state_(NOTIFICATION_NONE), | 110 notification_state_(NOTIFICATION_NONE), |
117 usb_charger_was_connected_(false) { | 111 usb_charger_was_connected_(false) { |
118 PowerStatus::Get()->AddObserver(this); | 112 PowerStatus::Get()->AddObserver(this); |
119 } | 113 } |
120 | 114 |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 notification_state_ = NOTIFICATION_NONE; | 222 notification_state_ = NOTIFICATION_NONE; |
229 return false; | 223 return false; |
230 } | 224 } |
231 | 225 |
232 return status.IsUsbChargerConnected() ? | 226 return status.IsUsbChargerConnected() ? |
233 UpdateNotificationStateForRemainingPercentage() : | 227 UpdateNotificationStateForRemainingPercentage() : |
234 UpdateNotificationStateForRemainingTime(); | 228 UpdateNotificationStateForRemainingTime(); |
235 } | 229 } |
236 | 230 |
237 bool TrayPower::UpdateNotificationStateForRemainingTime() { | 231 bool TrayPower::UpdateNotificationStateForRemainingTime() { |
238 const int remaining_seconds = | 232 // The notification includes a rounded minutes value, so round the estimate |
239 PowerStatus::Get()->GetBatteryTimeToEmpty().InSeconds(); | 233 // received from the power manager to match. |
| 234 const int remaining_minutes = static_cast<int>( |
| 235 PowerStatus::Get()->GetBatteryTimeToEmpty().InSecondsF() / 60.0 + 0.5); |
240 | 236 |
241 if (remaining_seconds >= kNoWarningSeconds) { | 237 if (remaining_minutes >= kNoWarningMinutes) { |
242 notification_state_ = NOTIFICATION_NONE; | 238 notification_state_ = NOTIFICATION_NONE; |
243 return false; | 239 return false; |
244 } | 240 } |
245 | 241 |
246 switch (notification_state_) { | 242 switch (notification_state_) { |
247 case NOTIFICATION_NONE: | 243 case NOTIFICATION_NONE: |
248 if (remaining_seconds <= kCriticalSeconds) { | 244 if (remaining_minutes <= kCriticalMinutes) { |
249 notification_state_ = NOTIFICATION_CRITICAL; | 245 notification_state_ = NOTIFICATION_CRITICAL; |
250 return true; | 246 return true; |
251 } | 247 } |
252 if (remaining_seconds <= kLowPowerSeconds) { | 248 if (remaining_minutes <= kLowPowerMinutes) { |
253 notification_state_ = NOTIFICATION_LOW_POWER; | 249 notification_state_ = NOTIFICATION_LOW_POWER; |
254 return true; | 250 return true; |
255 } | 251 } |
256 return false; | 252 return false; |
257 case NOTIFICATION_LOW_POWER: | 253 case NOTIFICATION_LOW_POWER: |
258 if (remaining_seconds <= kCriticalSeconds) { | 254 if (remaining_minutes <= kCriticalMinutes) { |
259 notification_state_ = NOTIFICATION_CRITICAL; | 255 notification_state_ = NOTIFICATION_CRITICAL; |
260 return true; | 256 return true; |
261 } | 257 } |
262 return false; | 258 return false; |
263 case NOTIFICATION_CRITICAL: | 259 case NOTIFICATION_CRITICAL: |
264 return false; | 260 return false; |
265 } | 261 } |
266 NOTREACHED(); | 262 NOTREACHED(); |
267 return false; | 263 return false; |
268 } | 264 } |
269 | 265 |
270 bool TrayPower::UpdateNotificationStateForRemainingPercentage() { | 266 bool TrayPower::UpdateNotificationStateForRemainingPercentage() { |
271 const double remaining_percentage = PowerStatus::Get()->GetBatteryPercent(); | 267 // The notification includes a rounded percentage, so round the value received |
| 268 // from the power manager to match. |
| 269 const int remaining_percentage = |
| 270 PowerStatus::Get()->GetRoundedBatteryPercent(); |
272 | 271 |
273 if (remaining_percentage > kNoWarningPercentage) { | 272 if (remaining_percentage >= kNoWarningPercentage) { |
274 notification_state_ = NOTIFICATION_NONE; | 273 notification_state_ = NOTIFICATION_NONE; |
275 return false; | 274 return false; |
276 } | 275 } |
277 | 276 |
278 switch (notification_state_) { | 277 switch (notification_state_) { |
279 case NOTIFICATION_NONE: | 278 case NOTIFICATION_NONE: |
280 if (remaining_percentage <= kCriticalPercentage) { | 279 if (remaining_percentage <= kCriticalPercentage) { |
281 notification_state_ = NOTIFICATION_CRITICAL; | 280 notification_state_ = NOTIFICATION_CRITICAL; |
282 return true; | 281 return true; |
283 } | 282 } |
(...skipping 10 matching lines...) Expand all Loading... |
294 return false; | 293 return false; |
295 case NOTIFICATION_CRITICAL: | 294 case NOTIFICATION_CRITICAL: |
296 return false; | 295 return false; |
297 } | 296 } |
298 NOTREACHED(); | 297 NOTREACHED(); |
299 return false; | 298 return false; |
300 } | 299 } |
301 | 300 |
302 } // namespace internal | 301 } // namespace internal |
303 } // namespace ash | 302 } // namespace ash |
OLD | NEW |