 Chromium Code Reviews
 Chromium Code Reviews Issue 1924213002:
  ARC: Support Android Notification Priority  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master
    
  
    Issue 1924213002:
  ARC: Support Android Notification Priority  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master| 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 // Convert from Android notification priority to Chrome notification priority. | |
| 
hidehiko
2016/05/01 17:13:36
nit: s/Convert/Converts/
 
yoshiki
2016/05/02 06:52:47
Done.
 | |
| 43 int convertAndroidPriority(const int androidPriority) { | |
| 
hidehiko
2016/05/01 17:13:35
nit: s/androidPriority/android_priority/ for chrom
 
yoshiki
2016/05/02 06:52:47
Thanks, I confused. Fixed.
 | |
| 44 switch (androidPriority) { | |
| 45 case -2: // PRIORITY_MIN | |
| 46 case -1: // PRIORITY_LOW | |
| 47 return -2; | |
| 48 case 0: // PRIORITY_DEFAULT | |
| 49 // Mapped to Chrome's -1, not to pop up the notification. | |
| 
hidehiko
2016/05/01 17:13:36
How about;
On Android, PRIORITY_DEFAULT does not
 
yoshiki
2016/05/02 06:52:47
Thank you for suggestion. Done.
 | |
| 50 return -1; | |
| 51 case 1: // PRIORITY_HIGH | |
| 52 return 0; | |
| 53 case 2: // PRIORITY_MAX | |
| 54 return 2; | |
| 55 default: | |
| 56 NOTREACHED() << "Invalid Priority"; | |
| 
hidehiko
2016/05/01 17:13:35
nit:
NOTREACHED() << "Invalid Priority: " << andr
 
yoshiki
2016/05/02 06:52:47
It should be useful. Done.
 | |
| 57 return 0; | |
| 58 } | |
| 59 } | |
| 60 | |
| 42 class ArcNotificationDelegate : public message_center::NotificationDelegate { | 61 class ArcNotificationDelegate : public message_center::NotificationDelegate { | 
| 43 public: | 62 public: | 
| 44 explicit ArcNotificationDelegate(base::WeakPtr<ArcNotificationItem> item) | 63 explicit ArcNotificationDelegate(base::WeakPtr<ArcNotificationItem> item) | 
| 45 : item_(item) {} | 64 : item_(item) {} | 
| 46 | 65 | 
| 47 void Close(bool by_user) override { | 66 void Close(bool by_user) override { | 
| 48 if (item_) | 67 if (item_) | 
| 49 item_->Close(by_user); | 68 item_->Close(by_user); | 
| 50 } | 69 } | 
| 51 | 70 | 
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 132 | 151 | 
| 133 for (size_t i = 0; i < data.buttons.size(); i++) { | 152 for (size_t i = 0; i < data.buttons.size(); i++) { | 
| 134 rich_data.buttons.push_back(message_center::ButtonInfo( | 153 rich_data.buttons.push_back(message_center::ButtonInfo( | 
| 135 base::UTF8ToUTF16(data.buttons.at(i)->label.get()))); | 154 base::UTF8ToUTF16(data.buttons.at(i)->label.get()))); | 
| 136 } | 155 } | 
| 137 | 156 | 
| 138 // If the client is old (version < 1), both |no_clear| and |ongoing_event| | 157 // If the client is old (version < 1), both |no_clear| and |ongoing_event| | 
| 139 // are false. | 158 // are false. | 
| 140 rich_data.pinned = (data.no_clear || data.ongoing_event); | 159 rich_data.pinned = (data.no_clear || data.ongoing_event); | 
| 141 | 160 | 
| 161 rich_data.priority = convertAndroidPriority(data.priority); | |
| 162 | |
| 142 // The identifier of the notifier, which is used to distinguish the notifiers | 163 // The identifier of the notifier, which is used to distinguish the notifiers | 
| 143 // in the message center. | 164 // in the message center. | 
| 144 message_center::NotifierId notifier_id( | 165 message_center::NotifierId notifier_id( | 
| 145 message_center::NotifierId::SYSTEM_COMPONENT, kNotifierId); | 166 message_center::NotifierId::SYSTEM_COMPONENT, kNotifierId); | 
| 146 notifier_id.profile_id = profile_id_.GetUserEmail(); | 167 notifier_id.profile_id = profile_id_.GetUserEmail(); | 
| 147 | 168 | 
| 148 DCHECK(!data.title.is_null()); | 169 DCHECK(!data.title.is_null()); | 
| 149 DCHECK(!data.message.is_null()); | 170 DCHECK(!data.message.is_null()); | 
| 150 notification_.reset(new message_center::Notification( | 171 notification_.reset(new message_center::Notification( | 
| 151 type, notification_id_, base::UTF8ToUTF16(data.title.get()), | 172 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_)); | 229 message_center_->AddNotification(std::move(notification_)); | 
| 209 | 230 | 
| 210 if (newer_data_) { | 231 if (newer_data_) { | 
| 211 // There is the newer data, so updates again. | 232 // There is the newer data, so updates again. | 
| 212 mojom::ArcNotificationDataPtr data(std::move(newer_data_)); | 233 mojom::ArcNotificationDataPtr data(std::move(newer_data_)); | 
| 213 UpdateWithArcNotificationData(*data); | 234 UpdateWithArcNotificationData(*data); | 
| 214 } | 235 } | 
| 215 } | 236 } | 
| 216 | 237 | 
| 217 } // namespace arc | 238 } // namespace arc | 
| OLD | NEW |