OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/battery_notification.h" | 5 #include "ash/system/chromeos/power/battery_notification.h" |
6 | 6 |
7 #include "ash/system/chromeos/power/power_status.h" | 7 #include "ash/system/chromeos/power/power_status.h" |
8 #include "ash/system/system_notifier.h" | 8 #include "ash/system/system_notifier.h" |
9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 25 matching lines...) Expand all Loading... |
36 } else if (notification_state == TrayPower::NOTIFICATION_CRITICAL) { | 36 } else if (notification_state == TrayPower::NOTIFICATION_CRITICAL) { |
37 resource_id = IDR_AURA_NOTIFICATION_BATTERY_CRITICAL; | 37 resource_id = IDR_AURA_NOTIFICATION_BATTERY_CRITICAL; |
38 } else { | 38 } else { |
39 NOTREACHED(); | 39 NOTREACHED(); |
40 resource_id = 0; | 40 resource_id = 0; |
41 } | 41 } |
42 | 42 |
43 return ui::ResourceBundle::GetSharedInstance().GetImageNamed(resource_id); | 43 return ui::ResourceBundle::GetSharedInstance().GetImageNamed(resource_id); |
44 } | 44 } |
45 | 45 |
46 scoped_ptr<Notification> CreateNotification( | 46 std::unique_ptr<Notification> CreateNotification( |
47 TrayPower::NotificationState notification_state) { | 47 TrayPower::NotificationState notification_state) { |
48 const PowerStatus& status = *PowerStatus::Get(); | 48 const PowerStatus& status = *PowerStatus::Get(); |
49 | 49 |
50 base::string16 message = l10n_util::GetStringFUTF16( | 50 base::string16 message = l10n_util::GetStringFUTF16( |
51 IDS_ASH_STATUS_TRAY_BATTERY_PERCENT, | 51 IDS_ASH_STATUS_TRAY_BATTERY_PERCENT, |
52 base::IntToString16(status.GetRoundedBatteryPercent())); | 52 base::IntToString16(status.GetRoundedBatteryPercent())); |
53 | 53 |
54 const base::TimeDelta time = status.IsBatteryCharging() | 54 const base::TimeDelta time = status.IsBatteryCharging() |
55 ? status.GetBatteryTimeToFull() | 55 ? status.GetBatteryTimeToFull() |
56 : status.GetBatteryTimeToEmpty(); | 56 : status.GetBatteryTimeToEmpty(); |
(...skipping 13 matching lines...) Expand all Loading... |
70 // This is a low battery warning prompting the user in minutes. | 70 // This is a low battery warning prompting the user in minutes. |
71 time_message = ui::TimeFormat::Simple( | 71 time_message = ui::TimeFormat::Simple( |
72 ui::TimeFormat::FORMAT_REMAINING, ui::TimeFormat::LENGTH_LONG, | 72 ui::TimeFormat::FORMAT_REMAINING, ui::TimeFormat::LENGTH_LONG, |
73 base::TimeDelta::FromMinutes(hour * 60 + min)); | 73 base::TimeDelta::FromMinutes(hour * 60 + min)); |
74 } | 74 } |
75 } | 75 } |
76 | 76 |
77 if (!time_message.empty()) | 77 if (!time_message.empty()) |
78 message = message + base::ASCIIToUTF16("\n") + time_message; | 78 message = message + base::ASCIIToUTF16("\n") + time_message; |
79 | 79 |
80 scoped_ptr<Notification> notification(new Notification( | 80 std::unique_ptr<Notification> notification(new Notification( |
81 message_center::NOTIFICATION_TYPE_SIMPLE, kBatteryNotificationId, | 81 message_center::NOTIFICATION_TYPE_SIMPLE, kBatteryNotificationId, |
82 base::string16(), message, GetBatteryImage(notification_state), | 82 base::string16(), message, GetBatteryImage(notification_state), |
83 base::string16(), GURL(), | 83 base::string16(), GURL(), |
84 message_center::NotifierId(message_center::NotifierId::SYSTEM_COMPONENT, | 84 message_center::NotifierId(message_center::NotifierId::SYSTEM_COMPONENT, |
85 system_notifier::kNotifierBattery), | 85 system_notifier::kNotifierBattery), |
86 message_center::RichNotificationData(), NULL)); | 86 message_center::RichNotificationData(), NULL)); |
87 notification->SetSystemPriority(); | 87 notification->SetSystemPriority(); |
88 return notification; | 88 return notification; |
89 } | 89 } |
90 | 90 |
(...skipping 13 matching lines...) Expand all Loading... |
104 | 104 |
105 void BatteryNotification::Update( | 105 void BatteryNotification::Update( |
106 TrayPower::NotificationState notification_state) { | 106 TrayPower::NotificationState notification_state) { |
107 if (message_center_->FindVisibleNotificationById(kBatteryNotificationId)) { | 107 if (message_center_->FindVisibleNotificationById(kBatteryNotificationId)) { |
108 message_center_->UpdateNotification(kBatteryNotificationId, | 108 message_center_->UpdateNotification(kBatteryNotificationId, |
109 CreateNotification(notification_state)); | 109 CreateNotification(notification_state)); |
110 } | 110 } |
111 } | 111 } |
112 | 112 |
113 } // namespace ash | 113 } // namespace ash |
OLD | NEW |