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/dual_role_notification.h" | 5 #include "ash/system/chromeos/power/dual_role_notification.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
10 #include "ash/system/chromeos/power/power_status.h" | 10 #include "ash/system/chromeos/power/power_status.h" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 if (message_center_->FindVisibleNotificationById(kDualRoleNotificationId)) | 57 if (message_center_->FindVisibleNotificationById(kDualRoleNotificationId)) |
58 message_center_->RemoveNotification(kDualRoleNotificationId, false); | 58 message_center_->RemoveNotification(kDualRoleNotificationId, false); |
59 } | 59 } |
60 | 60 |
61 void DualRoleNotification::Update() { | 61 void DualRoleNotification::Update() { |
62 const PowerStatus& status = *PowerStatus::Get(); | 62 const PowerStatus& status = *PowerStatus::Get(); |
63 DCHECK(status.HasDualRoleDevices()); | 63 DCHECK(status.HasDualRoleDevices()); |
64 | 64 |
65 std::string current_power_source_id = status.GetCurrentPowerSourceID(); | 65 std::string current_power_source_id = status.GetCurrentPowerSourceID(); |
66 | 66 |
67 scoped_ptr<PowerStatus::PowerSource> new_source; | 67 std::unique_ptr<PowerStatus::PowerSource> new_source; |
68 scoped_ptr<PowerStatus::PowerSource> new_sink; | 68 std::unique_ptr<PowerStatus::PowerSource> new_sink; |
69 size_t num_sinks_found = 0; | 69 size_t num_sinks_found = 0; |
70 for (const auto& source : status.GetPowerSources()) { | 70 for (const auto& source : status.GetPowerSources()) { |
71 // The power source can't be changed if there's a dedicated charger. | 71 // The power source can't be changed if there's a dedicated charger. |
72 if (source.type == PowerStatus::DEDICATED_CHARGER) { | 72 if (source.type == PowerStatus::DEDICATED_CHARGER) { |
73 dual_role_source_.reset(); | 73 dual_role_source_.reset(); |
74 line_power_connected_ = true; | 74 line_power_connected_ = true; |
75 if (message_center_->FindVisibleNotificationById(kDualRoleNotificationId)) | 75 if (message_center_->FindVisibleNotificationById(kDualRoleNotificationId)) |
76 message_center_->RemoveNotification(kDualRoleNotificationId, false); | 76 message_center_->RemoveNotification(kDualRoleNotificationId, false); |
77 return; | 77 return; |
78 } | 78 } |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 return; | 118 return; |
119 | 119 |
120 if (!message_center_->FindVisibleNotificationById(kDualRoleNotificationId)) { | 120 if (!message_center_->FindVisibleNotificationById(kDualRoleNotificationId)) { |
121 message_center_->AddNotification(CreateNotification()); | 121 message_center_->AddNotification(CreateNotification()); |
122 } else { | 122 } else { |
123 message_center_->UpdateNotification(kDualRoleNotificationId, | 123 message_center_->UpdateNotification(kDualRoleNotificationId, |
124 CreateNotification()); | 124 CreateNotification()); |
125 } | 125 } |
126 } | 126 } |
127 | 127 |
128 scoped_ptr<Notification> DualRoleNotification::CreateNotification() { | 128 std::unique_ptr<Notification> DualRoleNotification::CreateNotification() { |
129 base::string16 title; | 129 base::string16 title; |
130 if (dual_role_source_) { | 130 if (dual_role_source_) { |
131 title = l10n_util::GetStringFUTF16( | 131 title = l10n_util::GetStringFUTF16( |
132 IDS_ASH_STATUS_TRAY_CHARGING_FROM_DUAL_ROLE_TITLE, | 132 IDS_ASH_STATUS_TRAY_CHARGING_FROM_DUAL_ROLE_TITLE, |
133 l10n_util::GetStringUTF16(dual_role_source_->description_id)); | 133 l10n_util::GetStringUTF16(dual_role_source_->description_id)); |
134 } else if (num_dual_role_sinks_ == 1) { | 134 } else if (num_dual_role_sinks_ == 1) { |
135 title = l10n_util::GetStringFUTF16( | 135 title = l10n_util::GetStringFUTF16( |
136 IDS_ASH_STATUS_TRAY_CHARGING_DUAL_ROLE_DEVICE_TITLE, | 136 IDS_ASH_STATUS_TRAY_CHARGING_DUAL_ROLE_DEVICE_TITLE, |
137 l10n_util::GetStringUTF16(dual_role_sink_->description_id)); | 137 l10n_util::GetStringUTF16(dual_role_sink_->description_id)); |
138 } else { | 138 } else { |
139 title = l10n_util::GetStringUTF16( | 139 title = l10n_util::GetStringUTF16( |
140 IDS_ASH_STATUS_TRAY_CHARGING_DUAL_ROLE_DEVICES_TITLE); | 140 IDS_ASH_STATUS_TRAY_CHARGING_DUAL_ROLE_DEVICES_TITLE); |
141 } | 141 } |
142 | 142 |
143 scoped_ptr<Notification> notification(new Notification( | 143 std::unique_ptr<Notification> notification(new Notification( |
144 message_center::NOTIFICATION_TYPE_SIMPLE, kDualRoleNotificationId, title, | 144 message_center::NOTIFICATION_TYPE_SIMPLE, kDualRoleNotificationId, title, |
145 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_DUAL_ROLE_MESSAGE), | 145 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_DUAL_ROLE_MESSAGE), |
146 ui::ResourceBundle::GetSharedInstance().GetImageNamed( | 146 ui::ResourceBundle::GetSharedInstance().GetImageNamed( |
147 IDR_AURA_NOTIFICATION_LOW_POWER_CHARGER), | 147 IDR_AURA_NOTIFICATION_LOW_POWER_CHARGER), |
148 base::string16(), GURL(), | 148 base::string16(), GURL(), |
149 message_center::NotifierId(message_center::NotifierId::SYSTEM_COMPONENT, | 149 message_center::NotifierId(message_center::NotifierId::SYSTEM_COMPONENT, |
150 system_notifier::kNotifierDualRole), | 150 system_notifier::kNotifierDualRole), |
151 message_center::RichNotificationData(), | 151 message_center::RichNotificationData(), |
152 new DualRoleNotificationDelegate)); | 152 new DualRoleNotificationDelegate)); |
153 notification->set_priority(message_center::MIN_PRIORITY); | 153 notification->set_priority(message_center::MIN_PRIORITY); |
154 return notification; | 154 return notification; |
155 } | 155 } |
156 | 156 |
157 } // namespace ash | 157 } // namespace ash |
OLD | NEW |