15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "ash/system/chromeos/power/tray_power.h"
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
75d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ash/accessibility_delegate.h"
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/ash_switches.h"
95d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ash/shell.h"
1090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "ash/system/chromeos/power/power_status_view.h"
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/system/date/date_view.h"
12424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)#include "ash/system/system_notifier.h"
135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ash/system/tray/system_tray_delegate.h"
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/system/tray/tray_constants.h"
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/system/tray/tray_notification_view.h"
16c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "ash/system/tray/tray_utils.h"
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/command_line.h"
185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/metrics/histogram.h"
195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/time/time.h"
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "grit/ash_resources.h"
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "grit/ash_strings.h"
22ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch#include "third_party/icu/source/i18n/unicode/fieldpos.h"
23ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch#include "third_party/icu/source/i18n/unicode/fmtable.h"
24a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ui/accessibility/ax_view_state.h"
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/base/resource/resource_bundle.h"
26eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "ui/message_center/message_center.h"
27eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "ui/message_center/notification.h"
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/views/controls/button/button.h"
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/views/controls/image_view.h"
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/views/controls/label.h"
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/views/layout/box_layout.h"
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/views/layout/fill_layout.h"
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/views/layout/grid_layout.h"
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/views/view.h"
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/views/widget/widget.h"
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
37eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochusing message_center::MessageCenter;
38eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochusing message_center::Notification;
3990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace ash {
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace tray {
425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)namespace {
435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)const int kMaxSpringChargerAccessibilityNotifyCount = 3;
455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)const int kSpringChargerAccessibilityTimerFirstTimeNotifyInSeconds = 30;
465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)const int kSpringChargerAccessibilityTimerRepeatInMinutes = 5;
475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// This view is used only for the tray.
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class PowerTrayView : public views::ImageView {
525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  PowerTrayView()
545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      : spring_charger_spoken_notification_count_(0) {
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    UpdateImage();
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual ~PowerTrayView() {
595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
61c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Overriden from views::View.
62a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  virtual void GetAccessibleState(ui::AXViewState* state) OVERRIDE {
63c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    state->name = accessible_name_;
64a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    state->role = ui::AX_ROLE_BUTTON;
65c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  }
66c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
67eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  void UpdateStatus(bool battery_alert) {
685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    UpdateImage();
69eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    SetVisible(PowerStatus::Get()->IsBatteryPresent());
70c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
71c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    if (battery_alert) {
725f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)      accessible_name_ = PowerStatus::Get()->GetAccessibleNameString(true);
73a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      NotifyAccessibilityEvent(ui::AX_EVENT_ALERT, true);
74c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    }
755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  void SetupNotifyBadCharger() {
785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    // Poll with a shorter duration timer to notify the charger issue
795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    // for the first time after the charger dialog is displayed.
805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    spring_charger_accessility_timer_.Start(
815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        FROM_HERE, base::TimeDelta::FromSeconds(
825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)            kSpringChargerAccessibilityTimerFirstTimeNotifyInSeconds),
835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        this, &PowerTrayView::NotifyChargerIssue);
845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  }
855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private:
875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void UpdateImage() {
88eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    SetImage(PowerStatus::Get()->GetBatteryImage(PowerStatus::ICON_LIGHT));
895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  void NotifyChargerIssue() {
925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    if (!Shell::GetInstance()->accessibility_delegate()->
935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)            IsSpokenFeedbackEnabled())
945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      return;
955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    if (!Shell::GetInstance()->system_tray_delegate()->
975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)            IsSpringChargerReplacementDialogVisible()) {
985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      spring_charger_accessility_timer_.Stop();
995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      return;
1005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    }
1015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    accessible_name_ =  ui::ResourceBundle::GetSharedInstance().
1035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        GetLocalizedString(IDS_CHARGER_REPLACEMENT_ACCESSIBILTY_NOTIFICATION);
104a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    NotifyAccessibilityEvent(ui::AX_EVENT_ALERT, true);
1055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    ++spring_charger_spoken_notification_count_;
1065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    if (spring_charger_spoken_notification_count_ == 1) {
1085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      // After notify the charger issue for the first time, repeat the
1095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      // notification with a longer duration timer.
1105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      spring_charger_accessility_timer_.Stop();
1115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      spring_charger_accessility_timer_.Start(
1125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)          FROM_HERE, base::TimeDelta::FromMinutes(
1135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)              kSpringChargerAccessibilityTimerRepeatInMinutes),
1145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)          this, &PowerTrayView::NotifyChargerIssue);
1155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    } else if (spring_charger_spoken_notification_count_ >=
1165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        kMaxSpringChargerAccessibilityNotifyCount) {
1175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      spring_charger_accessility_timer_.Stop();
1185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    }
1195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  }
1205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
121c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  base::string16 accessible_name_;
1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Tracks how many times the original spring charger accessibility
1245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // notification has been spoken.
1255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  int spring_charger_spoken_notification_count_;
1265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  base::RepeatingTimer<PowerTrayView> spring_charger_accessility_timer_;
1285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(PowerTrayView);
1305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
1315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class PowerNotificationView : public TrayNotificationView {
1335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
1342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  explicit PowerNotificationView(TrayPower* owner)
135eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      : TrayNotificationView(owner, 0) {
1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    power_status_view_ =
1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        new PowerStatusView(PowerStatusView::VIEW_NOTIFICATION, true);
1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    InitView(power_status_view_);
1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
1405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
141eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  void UpdateStatus() {
142eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    SetIconImage(PowerStatus::Get()->GetBatteryImage(PowerStatus::ICON_DARK));
1435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
1445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private:
1465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  PowerStatusView* power_status_view_;
1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(PowerNotificationView);
1495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
1505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace tray
1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)using tray::PowerNotificationView;
1545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1551e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)const int TrayPower::kCriticalMinutes = 5;
1561e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)const int TrayPower::kLowPowerMinutes = 15;
1571e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)const int TrayPower::kNoWarningMinutes = 30;
1581e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)const int TrayPower::kCriticalPercentage = 5;
1591e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)const int TrayPower::kLowPowerPercentage = 10;
1601e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)const int TrayPower::kNoWarningPercentage = 15;
1611e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
162eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen MurdochTrayPower::TrayPower(SystemTray* system_tray, MessageCenter* message_center)
1632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    : SystemTrayItem(system_tray),
164eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      message_center_(message_center),
1652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      power_tray_(NULL),
1665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      notification_view_(NULL),
167eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      notification_state_(NOTIFICATION_NONE),
1685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      usb_charger_was_connected_(false),
1695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      line_power_was_connected_(false) {
170eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  PowerStatus::Get()->AddObserver(this);
1715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TrayPower::~TrayPower() {
174eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  PowerStatus::Get()->RemoveObserver(this);
175c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}
176c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
1775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)views::View* TrayPower::CreateTrayView(user::LoginStatus status) {
1785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // There may not be enough information when this is created about whether
1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // there is a battery or not. So always create this, and adjust visibility as
1805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // necessary.
1815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  CHECK(power_tray_ == NULL);
1825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  power_tray_ = new tray::PowerTrayView();
183eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  power_tray_->UpdateStatus(false);
1845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return power_tray_;
1855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)views::View* TrayPower::CreateDefaultView(user::LoginStatus status) {
1885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Make sure icon status is up-to-date. (Also triggers stub activation).
189eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  PowerStatus::Get()->RequestStatusUpdate();
1905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return NULL;
1915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)views::View* TrayPower::CreateNotificationView(user::LoginStatus status) {
1945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  CHECK(notification_view_ == NULL);
195eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  if (!PowerStatus::Get()->IsBatteryPresent())
1965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return NULL;
1975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  notification_view_ = new PowerNotificationView(this);
199eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  notification_view_->UpdateStatus();
2005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return notification_view_;
2025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void TrayPower::DestroyTrayView() {
2055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  power_tray_ = NULL;
2065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void TrayPower::DestroyDefaultView() {
2095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void TrayPower::DestroyNotificationView() {
2125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  notification_view_ = NULL;
2135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void TrayPower::UpdateAfterLoginStatusChange(user::LoginStatus status) {
2165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void TrayPower::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) {
2195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SetTrayImageItemBorder(power_tray_, alignment);
2205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
222eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochvoid TrayPower::OnPowerStatusChanged() {
2235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  RecordChargerType();
2245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
2255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (PowerStatus::Get()->IsOriginalSpringChargerConnected()) {
2265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    if (ash::Shell::GetInstance()->system_tray_delegate()->
2275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)            ShowSpringChargerReplacementDialog()) {
2285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      power_tray_->SetupNotifyBadCharger();
2295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    }
2305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  }
2315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
232eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  bool battery_alert = UpdateNotificationState();
2335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (power_tray_)
234eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    power_tray_->UpdateStatus(battery_alert);
2355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (notification_view_)
236eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    notification_view_->UpdateStatus();
2375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2387d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  // Factory testing may place the battery into unusual states.
2397d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  if (CommandLine::ForCurrentProcess()->HasSwitch(
2407d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)          ash::switches::kAshHideNotificationsForFactory))
2417d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    return;
2427d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
243a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  MaybeShowUsbChargerNotification();
244eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
245c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  if (battery_alert)
2465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    ShowNotificationView();
2475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  else if (notification_state_ == NOTIFICATION_NONE)
2485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    HideNotificationView();
249eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
250eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  usb_charger_was_connected_ = PowerStatus::Get()->IsUsbChargerConnected();
2515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  line_power_was_connected_ = PowerStatus::Get()->IsLinePowerConnected();
2525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
254eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochbool TrayPower::MaybeShowUsbChargerNotification() {
255eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
256eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  const char kNotificationId[] = "usb-charger";
257eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  bool usb_charger_is_connected = PowerStatus::Get()->IsUsbChargerConnected();
258eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
259eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // Check for a USB charger being connected.
260eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  if (usb_charger_is_connected && !usb_charger_was_connected_) {
261eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    scoped_ptr<Notification> notification(new Notification(
262eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch        message_center::NOTIFICATION_TYPE_SIMPLE,
263eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch        kNotificationId,
264eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch        rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_LOW_POWER_CHARGER_TITLE),
265f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)        rb.GetLocalizedString(
266f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)            IDS_ASH_STATUS_TRAY_LOW_POWER_CHARGER_MESSAGE_SHORT),
267eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch        rb.GetImageNamed(IDR_AURA_NOTIFICATION_LOW_POWER_CHARGER),
268eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch        base::string16(),
269a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)        message_center::NotifierId(
270a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)            message_center::NotifierId::SYSTEM_COMPONENT,
271a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)            system_notifier::kNotifierPower),
272eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch        message_center::RichNotificationData(),
273eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch        NULL));
274eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    message_center_->AddNotification(notification.Pass());
275eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    return true;
276eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  }
277eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
278eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // Check for unplug of a USB charger while the USB charger notification is
279eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  // showing.
280eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  if (!usb_charger_is_connected && usb_charger_was_connected_) {
281eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    message_center_->RemoveNotification(kNotificationId, false);
282eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    return true;
283eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  }
284eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  return false;
28590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}
28690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
287eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochbool TrayPower::UpdateNotificationState() {
288eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  const PowerStatus& status = *PowerStatus::Get();
289eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  if (!status.IsBatteryPresent() ||
290eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      status.IsBatteryTimeBeingCalculated() ||
2915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      status.IsMainsChargerConnected() ||
2925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      status.IsOriginalSpringChargerConnected()) {
2935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    notification_state_ = NOTIFICATION_NONE;
2945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return false;
2955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
2965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
297eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  return status.IsUsbChargerConnected() ?
298eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      UpdateNotificationStateForRemainingPercentage() :
299eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      UpdateNotificationStateForRemainingTime();
300a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)}
301a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
302eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochbool TrayPower::UpdateNotificationStateForRemainingTime() {
3031e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // The notification includes a rounded minutes value, so round the estimate
3041e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // received from the power manager to match.
3051e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  const int remaining_minutes = static_cast<int>(
3061e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      PowerStatus::Get()->GetBatteryTimeToEmpty().InSecondsF() / 60.0 + 0.5);
307eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
3085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (remaining_minutes >= kNoWarningMinutes ||
3095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      PowerStatus::Get()->IsBatteryFull()) {
3105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    notification_state_ = NOTIFICATION_NONE;
3115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return false;
3125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
3135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  switch (notification_state_) {
3155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    case NOTIFICATION_NONE:
3161e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      if (remaining_minutes <= kCriticalMinutes) {
3175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        notification_state_ = NOTIFICATION_CRITICAL;
3185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        return true;
319eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      }
3201e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      if (remaining_minutes <= kLowPowerMinutes) {
3215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        notification_state_ = NOTIFICATION_LOW_POWER;
3225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        return true;
3235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      }
3245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      return false;
3255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    case NOTIFICATION_LOW_POWER:
3261e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      if (remaining_minutes <= kCriticalMinutes) {
3275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        notification_state_ = NOTIFICATION_CRITICAL;
3285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        return true;
3295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      }
3305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      return false;
3315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    case NOTIFICATION_CRITICAL:
3325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      return false;
3335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
3345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  NOTREACHED();
3355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return false;
3365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
3375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
338eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochbool TrayPower::UpdateNotificationStateForRemainingPercentage() {
3391e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // The notification includes a rounded percentage, so round the value received
3401e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // from the power manager to match.
3411e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  const int remaining_percentage =
3421e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      PowerStatus::Get()->GetRoundedBatteryPercent();
343eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
3445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (remaining_percentage >= kNoWarningPercentage ||
3455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      PowerStatus::Get()->IsBatteryFull()) {
346a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    notification_state_ = NOTIFICATION_NONE;
347a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    return false;
348a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  }
349a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
350a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  switch (notification_state_) {
351a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    case NOTIFICATION_NONE:
352a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      if (remaining_percentage <= kCriticalPercentage) {
353a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)        notification_state_ = NOTIFICATION_CRITICAL;
354a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)        return true;
355a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      }
356a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      if (remaining_percentage <= kLowPowerPercentage) {
357a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)        notification_state_ = NOTIFICATION_LOW_POWER;
358a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)        return true;
359a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      }
360a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      return false;
361a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    case NOTIFICATION_LOW_POWER:
362a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      if (remaining_percentage <= kCriticalPercentage) {
363a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)        notification_state_ = NOTIFICATION_CRITICAL;
364a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)        return true;
365a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      }
366a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      return false;
367a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    case NOTIFICATION_CRITICAL:
368a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      return false;
369a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  }
370a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  NOTREACHED();
371a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  return false;
372a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)}
373a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
3745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void TrayPower::RecordChargerType() {
3755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (!PowerStatus::Get()->IsLinePowerConnected() ||
3765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      line_power_was_connected_)
3775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    return;
3785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
3795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  ChargerType current_charger = UNKNOWN_CHARGER;
3805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (PowerStatus::Get()->IsMainsChargerConnected()) {
3815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    current_charger = MAINS_CHARGER;
3825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  } else if (PowerStatus::Get()->IsUsbChargerConnected()) {
3835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    current_charger = USB_CHARGER;
3845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  } else if (PowerStatus::Get()->IsOriginalSpringChargerConnected()) {
3855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    current_charger =
3865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        ash::Shell::GetInstance()->system_tray_delegate()->
3875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)            HasUserConfirmedSafeSpringCharger() ?
3885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        SAFE_SPRING_CHARGER : UNCONFIRMED_SPRING_CHARGER;
3895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  }
3905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
3915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  if (current_charger != UNKNOWN_CHARGER) {
3925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    UMA_HISTOGRAM_ENUMERATION("Power.ChargerType",
3935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                              current_charger,
3945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                              CHARGER_TYPE_COUNT);
3955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  }
3965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
3975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
3985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace ash
399