| 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_custom_notification_item.h" | 5 #include "ui/arc/notification/arc_custom_notification_item.h" |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "base/strings/string16.h" | 8 #include "base/strings/string16.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "components/arc/bitmap/bitmap_type_converters.h" | |
| 11 #include "ui/arc/notification/arc_custom_notification_view.h" | 10 #include "ui/arc/notification/arc_custom_notification_view.h" |
| 12 #include "ui/message_center/notification.h" | 11 #include "ui/message_center/notification.h" |
| 13 #include "ui/message_center/notification_types.h" | 12 #include "ui/message_center/notification_types.h" |
| 14 | 13 |
| 15 namespace arc { | 14 namespace arc { |
| 16 | 15 |
| 17 namespace { | 16 namespace { |
| 18 | 17 |
| 19 constexpr char kNotifierId[] = "ARC_NOTIFICATION"; | 18 constexpr char kNotifierId[] = "ARC_NOTIFICATION"; |
| 20 | 19 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 47 message_center, | 46 message_center, |
| 48 notification_key, | 47 notification_key, |
| 49 profile_id) { | 48 profile_id) { |
| 50 } | 49 } |
| 51 | 50 |
| 52 ArcCustomNotificationItem::~ArcCustomNotificationItem() { | 51 ArcCustomNotificationItem::~ArcCustomNotificationItem() { |
| 53 FOR_EACH_OBSERVER(Observer, observers_, OnItemDestroying()); | 52 FOR_EACH_OBSERVER(Observer, observers_, OnItemDestroying()); |
| 54 } | 53 } |
| 55 | 54 |
| 56 void ArcCustomNotificationItem::UpdateWithArcNotificationData( | 55 void ArcCustomNotificationItem::UpdateWithArcNotificationData( |
| 57 const mojom::ArcNotificationData& data) { | 56 mojom::ArcNotificationDataPtr data) { |
| 58 DCHECK(CalledOnValidThread()); | 57 DCHECK(CalledOnValidThread()); |
| 59 DCHECK_EQ(notification_key(), data.key); | 58 DCHECK_EQ(notification_key(), data->key); |
| 60 | 59 |
| 61 if (CacheArcNotificationData(data)) | 60 if (HasPendingNotification()) { |
| 61 CacheArcNotificationData(std::move(data)); |
| 62 return; | 62 return; |
| 63 } |
| 63 | 64 |
| 64 message_center::RichNotificationData rich_data; | 65 message_center::RichNotificationData rich_data; |
| 65 rich_data.pinned = (data.no_clear || data.ongoing_event); | 66 rich_data.pinned = (data->no_clear || data->ongoing_event); |
| 66 rich_data.priority = ConvertAndroidPriority(data.priority); | 67 rich_data.priority = ConvertAndroidPriority(data->priority); |
| 67 rich_data.small_image = ConvertAndroidSmallIcon(data.small_icon); | 68 if (data->small_icon) |
| 69 rich_data.small_image = gfx::Image::CreateFrom1xBitmap(*data->small_icon); |
| 68 | 70 |
| 69 message_center::NotifierId notifier_id( | 71 message_center::NotifierId notifier_id( |
| 70 message_center::NotifierId::SYSTEM_COMPONENT, kNotifierId); | 72 message_center::NotifierId::SYSTEM_COMPONENT, kNotifierId); |
| 71 notifier_id.profile_id = profile_id().GetUserEmail(); | 73 notifier_id.profile_id = profile_id().GetUserEmail(); |
| 72 | 74 |
| 73 DCHECK(!data.title.is_null()); | 75 DCHECK(!data->title.is_null()); |
| 74 DCHECK(!data.message.is_null()); | 76 DCHECK(!data->message.is_null()); |
| 75 SetNotification(base::MakeUnique<message_center::Notification>( | 77 SetNotification(base::MakeUnique<message_center::Notification>( |
| 76 message_center::NOTIFICATION_TYPE_CUSTOM, notification_id(), | 78 message_center::NOTIFICATION_TYPE_CUSTOM, notification_id(), |
| 77 base::UTF8ToUTF16(data.title.get()), | 79 base::UTF8ToUTF16(data->title.get()), |
| 78 base::UTF8ToUTF16(data.message.get()), gfx::Image(), | 80 base::UTF8ToUTF16(data->message.get()), gfx::Image(), |
| 79 base::UTF8ToUTF16("arc"), // display source | 81 base::UTF8ToUTF16("arc"), // display source |
| 80 GURL(), // empty origin url, for system component | 82 GURL(), // empty origin url, for system component |
| 81 notifier_id, rich_data, new ArcNotificationDelegate(this))); | 83 notifier_id, rich_data, new ArcNotificationDelegate(this))); |
| 82 | 84 |
| 83 pinned_ = rich_data.pinned; | 85 pinned_ = rich_data.pinned; |
| 84 | 86 |
| 85 if (data.snapshot_image.is_null()) { | 87 if (!data->snapshot_image || data->snapshot_image->isNull()) { |
| 86 snapshot_ = gfx::ImageSkia(); | 88 snapshot_ = gfx::ImageSkia(); |
| 87 } else { | 89 } else { |
| 88 snapshot_ = gfx::ImageSkia(gfx::ImageSkiaRep( | 90 snapshot_ = gfx::ImageSkia(gfx::ImageSkiaRep( |
| 89 data.snapshot_image.To<SkBitmap>(), data.snapshot_image_scale)); | 91 *data->snapshot_image, data->snapshot_image_scale)); |
| 90 } | 92 } |
| 91 | 93 |
| 92 FOR_EACH_OBSERVER(Observer, observers_, OnItemUpdated()); | 94 FOR_EACH_OBSERVER(Observer, observers_, OnItemUpdated()); |
| 93 | 95 |
| 94 AddToMessageCenter(); | 96 AddToMessageCenter(); |
| 95 } | 97 } |
| 96 | 98 |
| 97 void ArcCustomNotificationItem::CloseFromCloseButton() { | 99 void ArcCustomNotificationItem::CloseFromCloseButton() { |
| 98 // Needs to manually remove notification from MessageCenter because | 100 // Needs to manually remove notification from MessageCenter because |
| 99 // the floating close button is not part of MessageCenter. | 101 // the floating close button is not part of MessageCenter. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 116 } | 118 } |
| 117 | 119 |
| 118 void ArcCustomNotificationItem::DecrementWindowRefCount() { | 120 void ArcCustomNotificationItem::DecrementWindowRefCount() { |
| 119 DCHECK_GT(window_ref_count_, 0); | 121 DCHECK_GT(window_ref_count_, 0); |
| 120 --window_ref_count_; | 122 --window_ref_count_; |
| 121 if (window_ref_count_ == 0) | 123 if (window_ref_count_ == 0) |
| 122 manager()->CloseNotificationWindow(notification_key()); | 124 manager()->CloseNotificationWindow(notification_key()); |
| 123 } | 125 } |
| 124 | 126 |
| 125 } // namespace arc | 127 } // namespace arc |
| OLD | NEW |