OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "ui/arc/notification/arc_notification_item.h" | 5 #include "ui/arc/notification/arc_notification_item.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
(...skipping 21 matching lines...) Expand all Loading... |
32 DCHECK(base::WorkerPool::RunsTasksOnCurrentThread()); | 32 DCHECK(base::WorkerPool::RunsTasksOnCurrentThread()); |
33 DCHECK(!data.empty()); // empty string should be handled in caller. | 33 DCHECK(!data.empty()); // empty string should be handled in caller. |
34 | 34 |
35 // We may decode an image in the browser process since it has been generated | 35 // We may decode an image in the browser process since it has been generated |
36 // in NotificationListerService in Android and should be safe. | 36 // in NotificationListerService in Android and should be safe. |
37 SkBitmap bitmap; | 37 SkBitmap bitmap; |
38 gfx::PNGCodec::Decode(&data[0], data.size(), &bitmap); | 38 gfx::PNGCodec::Decode(&data[0], data.size(), &bitmap); |
39 return bitmap; | 39 return bitmap; |
40 } | 40 } |
41 | 41 |
| 42 // Converts from Android notification priority to Chrome notification priority. |
| 43 // On Android, PRIORITY_DEFAULT does not pop up, so this maps PRIORITY_DEFAULT |
| 44 // to Chrome's -1 to adapt that behavior. Also, this maps PRIORITY_LOW and _HIGH |
| 45 // to -2 and 0 respectively to adjust the value with keeping the order among |
| 46 // _LOW, _DEFAULT and _HIGH. |
| 47 int convertAndroidPriority(const int android_priority) { |
| 48 switch (android_priority) { |
| 49 case -2: // PRIORITY_MIN |
| 50 case -1: // PRIORITY_LOW |
| 51 return -2; |
| 52 case 0: // PRIORITY_DEFAULT |
| 53 return -1; |
| 54 case 1: // PRIORITY_HIGH |
| 55 return 0; |
| 56 case 2: // PRIORITY_MAX |
| 57 return 2; |
| 58 default: |
| 59 NOTREACHED() << "Invalid Priority: " << android_priority; |
| 60 return 0; |
| 61 } |
| 62 } |
| 63 |
42 class ArcNotificationDelegate : public message_center::NotificationDelegate { | 64 class ArcNotificationDelegate : public message_center::NotificationDelegate { |
43 public: | 65 public: |
44 explicit ArcNotificationDelegate(base::WeakPtr<ArcNotificationItem> item) | 66 explicit ArcNotificationDelegate(base::WeakPtr<ArcNotificationItem> item) |
45 : item_(item) {} | 67 : item_(item) {} |
46 | 68 |
47 void Close(bool by_user) override { | 69 void Close(bool by_user) override { |
48 if (item_) | 70 if (item_) |
49 item_->Close(by_user); | 71 item_->Close(by_user); |
50 } | 72 } |
51 | 73 |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 | 154 |
133 for (size_t i = 0; i < data.buttons.size(); i++) { | 155 for (size_t i = 0; i < data.buttons.size(); i++) { |
134 rich_data.buttons.push_back(message_center::ButtonInfo( | 156 rich_data.buttons.push_back(message_center::ButtonInfo( |
135 base::UTF8ToUTF16(data.buttons.at(i)->label.get()))); | 157 base::UTF8ToUTF16(data.buttons.at(i)->label.get()))); |
136 } | 158 } |
137 | 159 |
138 // If the client is old (version < 1), both |no_clear| and |ongoing_event| | 160 // If the client is old (version < 1), both |no_clear| and |ongoing_event| |
139 // are false. | 161 // are false. |
140 rich_data.pinned = (data.no_clear || data.ongoing_event); | 162 rich_data.pinned = (data.no_clear || data.ongoing_event); |
141 | 163 |
| 164 rich_data.priority = convertAndroidPriority(data.priority); |
| 165 |
142 // The identifier of the notifier, which is used to distinguish the notifiers | 166 // The identifier of the notifier, which is used to distinguish the notifiers |
143 // in the message center. | 167 // in the message center. |
144 message_center::NotifierId notifier_id( | 168 message_center::NotifierId notifier_id( |
145 message_center::NotifierId::SYSTEM_COMPONENT, kNotifierId); | 169 message_center::NotifierId::SYSTEM_COMPONENT, kNotifierId); |
146 notifier_id.profile_id = profile_id_.GetUserEmail(); | 170 notifier_id.profile_id = profile_id_.GetUserEmail(); |
147 | 171 |
148 DCHECK(!data.title.is_null()); | 172 DCHECK(!data.title.is_null()); |
149 DCHECK(!data.message.is_null()); | 173 DCHECK(!data.message.is_null()); |
150 notification_.reset(new message_center::Notification( | 174 notification_.reset(new message_center::Notification( |
151 type, notification_id_, base::UTF8ToUTF16(data.title.get()), | 175 type, notification_id_, base::UTF8ToUTF16(data.title.get()), |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 message_center_->AddNotification(std::move(notification_)); | 232 message_center_->AddNotification(std::move(notification_)); |
209 | 233 |
210 if (newer_data_) { | 234 if (newer_data_) { |
211 // There is the newer data, so updates again. | 235 // There is the newer data, so updates again. |
212 mojom::ArcNotificationDataPtr data(std::move(newer_data_)); | 236 mojom::ArcNotificationDataPtr data(std::move(newer_data_)); |
213 UpdateWithArcNotificationData(*data); | 237 UpdateWithArcNotificationData(*data); |
214 } | 238 } |
215 } | 239 } |
216 | 240 |
217 } // namespace arc | 241 } // namespace arc |
OLD | NEW |