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 int convertAndroidPriority(const int androidPriority) { | |
hidehiko
2016/04/28 17:07:48
Could you comment your intention of this mapping?
yoshiki
2016/04/28 18:09:07
Done.
| |
43 switch (androidPriority) { | |
44 case -2: // PRIORITY_MIN | |
45 case -1: // PRIORITY_LOW | |
46 return -2; | |
47 case 0: // PRIORITY_DEFAULT | |
48 return -1; | |
49 case 1: // PRIORITY_HIGH | |
50 return 0; | |
51 case 2: // PRIORITY_MAX | |
52 return 2; | |
53 default: | |
54 NOTREACHED() << "Invalid Priority"; | |
55 return 0; | |
hidehiko
2016/04/28 17:07:48
Maybe -1 not to show the popup?
yoshiki
2016/04/28 18:09:07
I think the default priority (= 0) should be used
| |
56 } | |
57 } | |
58 | |
42 class ArcNotificationDelegate : public message_center::NotificationDelegate { | 59 class ArcNotificationDelegate : public message_center::NotificationDelegate { |
43 public: | 60 public: |
44 explicit ArcNotificationDelegate(base::WeakPtr<ArcNotificationItem> item) | 61 explicit ArcNotificationDelegate(base::WeakPtr<ArcNotificationItem> item) |
45 : item_(item) {} | 62 : item_(item) {} |
46 | 63 |
47 void Close(bool by_user) override { | 64 void Close(bool by_user) override { |
48 if (item_) | 65 if (item_) |
49 item_->Close(by_user); | 66 item_->Close(by_user); |
50 } | 67 } |
51 | 68 |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
132 | 149 |
133 for (size_t i = 0; i < data.buttons.size(); i++) { | 150 for (size_t i = 0; i < data.buttons.size(); i++) { |
134 rich_data.buttons.push_back(message_center::ButtonInfo( | 151 rich_data.buttons.push_back(message_center::ButtonInfo( |
135 base::UTF8ToUTF16(data.buttons.at(i)->label.get()))); | 152 base::UTF8ToUTF16(data.buttons.at(i)->label.get()))); |
136 } | 153 } |
137 | 154 |
138 // If the client is old (version < 1), both |no_clear| and |ongoing_event| | 155 // If the client is old (version < 1), both |no_clear| and |ongoing_event| |
139 // are false. | 156 // are false. |
140 rich_data.pinned = (data.no_clear || data.ongoing_event); | 157 rich_data.pinned = (data.no_clear || data.ongoing_event); |
141 | 158 |
159 rich_data.priority = convertAndroidPriority(data.priority); | |
160 | |
142 // The identifier of the notifier, which is used to distinguish the notifiers | 161 // The identifier of the notifier, which is used to distinguish the notifiers |
143 // in the message center. | 162 // in the message center. |
144 message_center::NotifierId notifier_id( | 163 message_center::NotifierId notifier_id( |
145 message_center::NotifierId::SYSTEM_COMPONENT, kNotifierId); | 164 message_center::NotifierId::SYSTEM_COMPONENT, kNotifierId); |
146 notifier_id.profile_id = profile_id_.GetUserEmail(); | 165 notifier_id.profile_id = profile_id_.GetUserEmail(); |
147 | 166 |
148 DCHECK(!data.title.is_null()); | 167 DCHECK(!data.title.is_null()); |
149 DCHECK(!data.message.is_null()); | 168 DCHECK(!data.message.is_null()); |
150 notification_.reset(new message_center::Notification( | 169 notification_.reset(new message_center::Notification( |
151 type, notification_id_, base::UTF8ToUTF16(data.title.get()), | 170 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_)); | 227 message_center_->AddNotification(std::move(notification_)); |
209 | 228 |
210 if (newer_data_) { | 229 if (newer_data_) { |
211 // There is the newer data, so updates again. | 230 // There is the newer data, so updates again. |
212 mojom::ArcNotificationDataPtr data(std::move(newer_data_)); | 231 mojom::ArcNotificationDataPtr data(std::move(newer_data_)); |
213 UpdateWithArcNotificationData(*data); | 232 UpdateWithArcNotificationData(*data); |
214 } | 233 } |
215 } | 234 } |
216 | 235 |
217 } // namespace arc | 236 } // namespace arc |
OLD | NEW |