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/shell.h" |
8 #include "ash/system/chromeos/power/power_status_view.h" | 9 #include "ash/system/chromeos/power/power_status_view.h" |
9 #include "ash/system/date/date_view.h" | 10 #include "ash/system/date/date_view.h" |
10 #include "ash/system/system_notifier.h" | 11 #include "ash/system/system_notifier.h" |
| 12 #include "ash/system/tray/system_tray_delegate.h" |
11 #include "ash/system/tray/tray_constants.h" | 13 #include "ash/system/tray/tray_constants.h" |
12 #include "ash/system/tray/tray_notification_view.h" | 14 #include "ash/system/tray/tray_notification_view.h" |
13 #include "ash/system/tray/tray_utils.h" | 15 #include "ash/system/tray/tray_utils.h" |
14 #include "base/command_line.h" | 16 #include "base/command_line.h" |
| 17 #include "base/metrics/histogram.h" |
15 #include "grit/ash_resources.h" | 18 #include "grit/ash_resources.h" |
16 #include "grit/ash_strings.h" | 19 #include "grit/ash_strings.h" |
17 #include "third_party/icu/source/i18n/unicode/fieldpos.h" | 20 #include "third_party/icu/source/i18n/unicode/fieldpos.h" |
18 #include "third_party/icu/source/i18n/unicode/fmtable.h" | 21 #include "third_party/icu/source/i18n/unicode/fmtable.h" |
19 #include "ui/base/accessibility/accessible_view_state.h" | 22 #include "ui/base/accessibility/accessible_view_state.h" |
20 #include "ui/base/resource/resource_bundle.h" | 23 #include "ui/base/resource/resource_bundle.h" |
21 #include "ui/message_center/message_center.h" | 24 #include "ui/message_center/message_center.h" |
22 #include "ui/message_center/notification.h" | 25 #include "ui/message_center/notification.h" |
23 #include "ui/views/controls/button/button.h" | 26 #include "ui/views/controls/button/button.h" |
24 #include "ui/views/controls/image_view.h" | 27 #include "ui/views/controls/image_view.h" |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 const int TrayPower::kCriticalPercentage = 5; | 104 const int TrayPower::kCriticalPercentage = 5; |
102 const int TrayPower::kLowPowerPercentage = 10; | 105 const int TrayPower::kLowPowerPercentage = 10; |
103 const int TrayPower::kNoWarningPercentage = 15; | 106 const int TrayPower::kNoWarningPercentage = 15; |
104 | 107 |
105 TrayPower::TrayPower(SystemTray* system_tray, MessageCenter* message_center) | 108 TrayPower::TrayPower(SystemTray* system_tray, MessageCenter* message_center) |
106 : SystemTrayItem(system_tray), | 109 : SystemTrayItem(system_tray), |
107 message_center_(message_center), | 110 message_center_(message_center), |
108 power_tray_(NULL), | 111 power_tray_(NULL), |
109 notification_view_(NULL), | 112 notification_view_(NULL), |
110 notification_state_(NOTIFICATION_NONE), | 113 notification_state_(NOTIFICATION_NONE), |
111 usb_charger_was_connected_(false) { | 114 usb_charger_was_connected_(false), |
| 115 line_power_was_connected_(false) { |
112 PowerStatus::Get()->AddObserver(this); | 116 PowerStatus::Get()->AddObserver(this); |
113 } | 117 } |
114 | 118 |
115 TrayPower::~TrayPower() { | 119 TrayPower::~TrayPower() { |
116 PowerStatus::Get()->RemoveObserver(this); | 120 PowerStatus::Get()->RemoveObserver(this); |
117 } | 121 } |
118 | 122 |
119 views::View* TrayPower::CreateTrayView(user::LoginStatus status) { | 123 views::View* TrayPower::CreateTrayView(user::LoginStatus status) { |
120 // There may not be enough information when this is created about whether | 124 // There may not be enough information when this is created about whether |
121 // there is a battery or not. So always create this, and adjust visibility as | 125 // there is a battery or not. So always create this, and adjust visibility as |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 } | 159 } |
156 | 160 |
157 void TrayPower::UpdateAfterLoginStatusChange(user::LoginStatus status) { | 161 void TrayPower::UpdateAfterLoginStatusChange(user::LoginStatus status) { |
158 } | 162 } |
159 | 163 |
160 void TrayPower::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) { | 164 void TrayPower::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) { |
161 SetTrayImageItemBorder(power_tray_, alignment); | 165 SetTrayImageItemBorder(power_tray_, alignment); |
162 } | 166 } |
163 | 167 |
164 void TrayPower::OnPowerStatusChanged() { | 168 void TrayPower::OnPowerStatusChanged() { |
| 169 RecordChargerType(); |
| 170 |
| 171 if (PowerStatus::Get()->IsOriginalSpringChargerConnected()) { |
| 172 ash::Shell::GetInstance()->system_tray_delegate()-> |
| 173 ShowSpringChargerReplacementDialog(); |
| 174 } |
| 175 |
165 bool battery_alert = UpdateNotificationState(); | 176 bool battery_alert = UpdateNotificationState(); |
166 if (power_tray_) | 177 if (power_tray_) |
167 power_tray_->UpdateStatus(battery_alert); | 178 power_tray_->UpdateStatus(battery_alert); |
168 if (notification_view_) | 179 if (notification_view_) |
169 notification_view_->UpdateStatus(); | 180 notification_view_->UpdateStatus(); |
170 | 181 |
171 // Factory testing may place the battery into unusual states. | 182 // Factory testing may place the battery into unusual states. |
172 if (CommandLine::ForCurrentProcess()->HasSwitch( | 183 if (CommandLine::ForCurrentProcess()->HasSwitch( |
173 ash::switches::kAshHideNotificationsForFactory)) | 184 ash::switches::kAshHideNotificationsForFactory)) |
174 return; | 185 return; |
175 | 186 |
176 if (ash::switches::UseUsbChargerNotification()) | 187 if (ash::switches::UseUsbChargerNotification()) |
177 MaybeShowUsbChargerNotification(); | 188 MaybeShowUsbChargerNotification(); |
178 | 189 |
179 if (battery_alert) | 190 if (battery_alert) |
180 ShowNotificationView(); | 191 ShowNotificationView(); |
181 else if (notification_state_ == NOTIFICATION_NONE) | 192 else if (notification_state_ == NOTIFICATION_NONE) |
182 HideNotificationView(); | 193 HideNotificationView(); |
183 | 194 |
184 usb_charger_was_connected_ = PowerStatus::Get()->IsUsbChargerConnected(); | 195 usb_charger_was_connected_ = PowerStatus::Get()->IsUsbChargerConnected(); |
| 196 line_power_was_connected_ = PowerStatus::Get()->IsLinePowerConnected(); |
185 } | 197 } |
186 | 198 |
187 bool TrayPower::MaybeShowUsbChargerNotification() { | 199 bool TrayPower::MaybeShowUsbChargerNotification() { |
188 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 200 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
189 const char kNotificationId[] = "usb-charger"; | 201 const char kNotificationId[] = "usb-charger"; |
190 bool usb_charger_is_connected = PowerStatus::Get()->IsUsbChargerConnected(); | 202 bool usb_charger_is_connected = PowerStatus::Get()->IsUsbChargerConnected(); |
191 | 203 |
192 // Check for a USB charger being connected. | 204 // Check for a USB charger being connected. |
193 if (usb_charger_is_connected && !usb_charger_was_connected_) { | 205 if (usb_charger_is_connected && !usb_charger_was_connected_) { |
194 scoped_ptr<Notification> notification(new Notification( | 206 scoped_ptr<Notification> notification(new Notification( |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 return true; | 306 return true; |
295 } | 307 } |
296 return false; | 308 return false; |
297 case NOTIFICATION_CRITICAL: | 309 case NOTIFICATION_CRITICAL: |
298 return false; | 310 return false; |
299 } | 311 } |
300 NOTREACHED(); | 312 NOTREACHED(); |
301 return false; | 313 return false; |
302 } | 314 } |
303 | 315 |
| 316 void TrayPower::RecordChargerType() { |
| 317 if (!PowerStatus::Get()->IsLinePowerConnected() || |
| 318 line_power_was_connected_) |
| 319 return; |
| 320 |
| 321 ChargerType current_charger = UNKNOWN_CHARGER; |
| 322 if (PowerStatus::Get()->IsMainsChargerConnected()) { |
| 323 current_charger = MAINS_CHARGER; |
| 324 } else if (PowerStatus::Get()->IsUsbChargerConnected()) { |
| 325 current_charger = USB_CHARGER; |
| 326 } else if (PowerStatus::Get()->IsOriginalSpringChargerConnected()) { |
| 327 current_charger = |
| 328 ash::Shell::GetInstance()->system_tray_delegate()-> |
| 329 HasUserConfirmedSafeSpringCharger() ? |
| 330 SAFE_SPRING_CHARGER : UNCONFIRMED_SPRING_CHARGER; |
| 331 } |
| 332 |
| 333 if (current_charger != UNKNOWN_CHARGER) { |
| 334 UMA_HISTOGRAM_ENUMERATION("Power.ChargerType", |
| 335 current_charger, |
| 336 CHARGER_TYPE_COUNT); |
| 337 } |
| 338 } |
| 339 |
304 } // namespace internal | 340 } // namespace internal |
305 } // namespace ash | 341 } // namespace ash |
OLD | NEW |