| 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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 } // namespace tray | 114 } // namespace tray |
| 112 | 115 |
| 113 using tray::PowerNotificationView; | 116 using tray::PowerNotificationView; |
| 114 | 117 |
| 115 TrayPower::TrayPower(SystemTray* system_tray, MessageCenter* message_center) | 118 TrayPower::TrayPower(SystemTray* system_tray, MessageCenter* message_center) |
| 116 : SystemTrayItem(system_tray), | 119 : SystemTrayItem(system_tray), |
| 117 message_center_(message_center), | 120 message_center_(message_center), |
| 118 power_tray_(NULL), | 121 power_tray_(NULL), |
| 119 notification_view_(NULL), | 122 notification_view_(NULL), |
| 120 notification_state_(NOTIFICATION_NONE), | 123 notification_state_(NOTIFICATION_NONE), |
| 121 usb_charger_was_connected_(false) { | 124 usb_charger_was_connected_(false), |
| 125 line_power_was_connected_(false) { |
| 122 PowerStatus::Get()->AddObserver(this); | 126 PowerStatus::Get()->AddObserver(this); |
| 123 } | 127 } |
| 124 | 128 |
| 125 TrayPower::~TrayPower() { | 129 TrayPower::~TrayPower() { |
| 126 PowerStatus::Get()->RemoveObserver(this); | 130 PowerStatus::Get()->RemoveObserver(this); |
| 127 } | 131 } |
| 128 | 132 |
| 129 views::View* TrayPower::CreateTrayView(user::LoginStatus status) { | 133 views::View* TrayPower::CreateTrayView(user::LoginStatus status) { |
| 130 // There may not be enough information when this is created about whether | 134 // There may not be enough information when this is created about whether |
| 131 // there is a battery or not. So always create this, and adjust visibility as | 135 // 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... |
| 165 } | 169 } |
| 166 | 170 |
| 167 void TrayPower::UpdateAfterLoginStatusChange(user::LoginStatus status) { | 171 void TrayPower::UpdateAfterLoginStatusChange(user::LoginStatus status) { |
| 168 } | 172 } |
| 169 | 173 |
| 170 void TrayPower::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) { | 174 void TrayPower::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) { |
| 171 SetTrayImageItemBorder(power_tray_, alignment); | 175 SetTrayImageItemBorder(power_tray_, alignment); |
| 172 } | 176 } |
| 173 | 177 |
| 174 void TrayPower::OnPowerStatusChanged() { | 178 void TrayPower::OnPowerStatusChanged() { |
| 179 RecordChargerType(); |
| 180 |
| 181 if (PowerStatus::Get()->IsOriginalSpringChargerConnected()) { |
| 182 ash::Shell::GetInstance()->system_tray_delegate()-> |
| 183 ShowSpringChargerReplacementDialog(); |
| 184 } |
| 185 |
| 175 bool battery_alert = UpdateNotificationState(); | 186 bool battery_alert = UpdateNotificationState(); |
| 176 if (power_tray_) | 187 if (power_tray_) |
| 177 power_tray_->UpdateStatus(battery_alert); | 188 power_tray_->UpdateStatus(battery_alert); |
| 178 if (notification_view_) | 189 if (notification_view_) |
| 179 notification_view_->UpdateStatus(); | 190 notification_view_->UpdateStatus(); |
| 180 | 191 |
| 181 // Factory testing may place the battery into unusual states. | 192 // Factory testing may place the battery into unusual states. |
| 182 if (CommandLine::ForCurrentProcess()->HasSwitch( | 193 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 183 ash::switches::kAshHideNotificationsForFactory)) | 194 ash::switches::kAshHideNotificationsForFactory)) |
| 184 return; | 195 return; |
| 185 | 196 |
| 186 if (ash::switches::UseUsbChargerNotification()) | 197 if (ash::switches::UseUsbChargerNotification()) |
| 187 MaybeShowUsbChargerNotification(); | 198 MaybeShowUsbChargerNotification(); |
| 188 | 199 |
| 189 if (battery_alert) | 200 if (battery_alert) |
| 190 ShowNotificationView(); | 201 ShowNotificationView(); |
| 191 else if (notification_state_ == NOTIFICATION_NONE) | 202 else if (notification_state_ == NOTIFICATION_NONE) |
| 192 HideNotificationView(); | 203 HideNotificationView(); |
| 193 | 204 |
| 194 usb_charger_was_connected_ = PowerStatus::Get()->IsUsbChargerConnected(); | 205 usb_charger_was_connected_ = PowerStatus::Get()->IsUsbChargerConnected(); |
| 206 line_power_was_connected_ = PowerStatus::Get()->IsLinePowerConnected(); |
| 195 } | 207 } |
| 196 | 208 |
| 197 bool TrayPower::MaybeShowUsbChargerNotification() { | 209 bool TrayPower::MaybeShowUsbChargerNotification() { |
| 198 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 210 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 199 const char kNotificationId[] = "usb-charger"; | 211 const char kNotificationId[] = "usb-charger"; |
| 200 bool usb_charger_is_connected = PowerStatus::Get()->IsUsbChargerConnected(); | 212 bool usb_charger_is_connected = PowerStatus::Get()->IsUsbChargerConnected(); |
| 201 | 213 |
| 202 // Check for a USB charger being connected. | 214 // Check for a USB charger being connected. |
| 203 if (usb_charger_is_connected && !usb_charger_was_connected_) { | 215 if (usb_charger_is_connected && !usb_charger_was_connected_) { |
| 204 scoped_ptr<Notification> notification(new Notification( | 216 scoped_ptr<Notification> notification(new Notification( |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 return true; | 309 return true; |
| 298 } | 310 } |
| 299 return false; | 311 return false; |
| 300 case NOTIFICATION_CRITICAL: | 312 case NOTIFICATION_CRITICAL: |
| 301 return false; | 313 return false; |
| 302 } | 314 } |
| 303 NOTREACHED(); | 315 NOTREACHED(); |
| 304 return false; | 316 return false; |
| 305 } | 317 } |
| 306 | 318 |
| 319 void TrayPower::RecordChargerType() { |
| 320 if (!PowerStatus::Get()->IsLinePowerConnected() || |
| 321 line_power_was_connected_) |
| 322 return; |
| 323 |
| 324 ChargerType current_charger = UNKNOWN_CHARGER; |
| 325 if (PowerStatus::Get()->IsMainsChargerConnected()) { |
| 326 current_charger = MAINS_CHARGER; |
| 327 } else if (PowerStatus::Get()->IsUsbChargerConnected()) { |
| 328 current_charger = USB_CHARGER; |
| 329 } else if (PowerStatus::Get()->IsOriginalSpringChargerConnected()) { |
| 330 current_charger = |
| 331 ash::Shell::GetInstance()->system_tray_delegate()-> |
| 332 HasUserConfirmedSafeSpringCharger() ? |
| 333 SAFE_SPRING_CHARGER : UNCONFIRMED_SPRING_CHARGER; |
| 334 } |
| 335 |
| 336 if (current_charger != UNKNOWN_CHARGER) { |
| 337 UMA_HISTOGRAM_ENUMERATION("Power.ChargerType", |
| 338 current_charger, |
| 339 CHARGER_TYPE_COUNT); |
| 340 } |
| 341 } |
| 342 |
| 307 } // namespace internal | 343 } // namespace internal |
| 308 } // namespace ash | 344 } // namespace ash |
| OLD | NEW |