Chromium Code Reviews| 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 <memory> | 7 #include <memory> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 43 | 43 |
| 44 private: | 44 private: |
| 45 // The destructor is private since this class is ref-counted. | 45 // The destructor is private since this class is ref-counted. |
| 46 ~ArcNotificationDelegate() override {} | 46 ~ArcNotificationDelegate() override {} |
| 47 | 47 |
| 48 ArcCustomNotificationItem* const item_; | 48 ArcCustomNotificationItem* const item_; |
| 49 | 49 |
| 50 DISALLOW_COPY_AND_ASSIGN(ArcNotificationDelegate); | 50 DISALLOW_COPY_AND_ASSIGN(ArcNotificationDelegate); |
| 51 }; | 51 }; |
| 52 | 52 |
| 53 message_center::NotificationExpandState ToNotificationExpandState( | |
|
yoshiki
2017/03/24 10:47:27
I think it's enough to use the mojo enum values (m
| |
| 54 mojom::ArcNotificationExpandState state) { | |
| 55 switch (state) { | |
| 56 case mojom::ArcNotificationExpandState::FIXED_SIZE: | |
| 57 return message_center::NotificationExpandState::FIXED_SIZE; | |
| 58 case mojom::ArcNotificationExpandState::COLLAPSED: | |
| 59 return message_center::NotificationExpandState::COLLAPSED; | |
| 60 case mojom::ArcNotificationExpandState::EXPANDED: | |
| 61 return message_center::NotificationExpandState::EXPANDED; | |
| 62 default: | |
| 63 NOTREACHED(); | |
| 64 break; | |
| 65 } | |
| 66 NOTREACHED(); | |
| 67 return message_center::NotificationExpandState::FIXED_SIZE; | |
| 68 } | |
| 69 | |
| 53 } // namespace | 70 } // namespace |
| 54 | 71 |
| 55 ArcCustomNotificationItem::ArcCustomNotificationItem( | 72 ArcCustomNotificationItem::ArcCustomNotificationItem( |
| 56 ArcNotificationManager* manager, | 73 ArcNotificationManager* manager, |
| 57 message_center::MessageCenter* message_center, | 74 message_center::MessageCenter* message_center, |
| 58 const std::string& notification_key, | 75 const std::string& notification_key, |
| 59 const AccountId& profile_id) | 76 const AccountId& profile_id) |
| 60 : ArcNotificationItem(manager, | 77 : ArcNotificationItem(manager, |
| 61 message_center, | 78 message_center, |
| 62 notification_key, | 79 notification_key, |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 73 DCHECK(CalledOnValidThread()); | 90 DCHECK(CalledOnValidThread()); |
| 74 DCHECK_EQ(notification_key(), data->key); | 91 DCHECK_EQ(notification_key(), data->key); |
| 75 | 92 |
| 76 if (HasPendingNotification()) { | 93 if (HasPendingNotification()) { |
| 77 CacheArcNotificationData(std::move(data)); | 94 CacheArcNotificationData(std::move(data)); |
| 78 return; | 95 return; |
| 79 } | 96 } |
| 80 | 97 |
| 81 message_center::RichNotificationData rich_data; | 98 message_center::RichNotificationData rich_data; |
| 82 rich_data.pinned = (data->no_clear || data->ongoing_event); | 99 rich_data.pinned = (data->no_clear || data->ongoing_event); |
| 100 rich_data.expand_state = ToNotificationExpandState(data->expand_state); | |
| 83 rich_data.priority = ConvertAndroidPriority(data->priority); | 101 rich_data.priority = ConvertAndroidPriority(data->priority); |
| 84 if (data->small_icon) | 102 if (data->small_icon) |
| 85 rich_data.small_image = gfx::Image::CreateFrom1xBitmap(*data->small_icon); | 103 rich_data.small_image = gfx::Image::CreateFrom1xBitmap(*data->small_icon); |
| 86 if (data->accessible_name.has_value()) | 104 if (data->accessible_name.has_value()) |
| 87 rich_data.accessible_name = base::UTF8ToUTF16(*data->accessible_name); | 105 rich_data.accessible_name = base::UTF8ToUTF16(*data->accessible_name); |
| 88 | 106 |
| 89 message_center::NotifierId notifier_id( | 107 message_center::NotifierId notifier_id( |
| 90 message_center::NotifierId::SYSTEM_COMPONENT, kNotifierId); | 108 message_center::NotifierId::SYSTEM_COMPONENT, kNotifierId); |
| 91 notifier_id.profile_id = profile_id().GetUserEmail(); | 109 notifier_id.profile_id = profile_id().GetUserEmail(); |
| 92 | 110 |
| 93 auto notification = base::MakeUnique<message_center::Notification>( | 111 auto notification = base::MakeUnique<message_center::Notification>( |
| 94 message_center::NOTIFICATION_TYPE_CUSTOM, notification_id(), | 112 message_center::NOTIFICATION_TYPE_CUSTOM, notification_id(), |
| 95 base::UTF8ToUTF16(data->title), base::UTF8ToUTF16(data->message), | 113 base::UTF8ToUTF16(data->title), base::UTF8ToUTF16(data->message), |
| 96 gfx::Image(), | 114 gfx::Image(), |
| 97 base::UTF8ToUTF16("arc"), // display source | 115 base::UTF8ToUTF16("arc"), // display source |
| 98 GURL(), // empty origin url, for system component | 116 GURL(), // empty origin url, for system component |
| 99 notifier_id, rich_data, new ArcNotificationDelegate(this)); | 117 notifier_id, rich_data, new ArcNotificationDelegate(this)); |
| 100 notification->set_timestamp(base::Time::FromJavaTime(data->time)); | 118 notification->set_timestamp(base::Time::FromJavaTime(data->time)); |
| 101 SetNotification(std::move(notification)); | 119 SetNotification(std::move(notification)); |
| 102 | 120 |
| 103 pinned_ = rich_data.pinned; | 121 pinned_ = rich_data.pinned; |
| 122 expand_state_ = rich_data.expand_state; | |
| 104 | 123 |
| 105 if (!data->snapshot_image || data->snapshot_image->isNull()) { | 124 if (!data->snapshot_image || data->snapshot_image->isNull()) { |
| 106 snapshot_ = gfx::ImageSkia(); | 125 snapshot_ = gfx::ImageSkia(); |
| 107 } else { | 126 } else { |
| 108 snapshot_ = gfx::ImageSkia(gfx::ImageSkiaRep( | 127 snapshot_ = gfx::ImageSkia(gfx::ImageSkiaRep( |
| 109 *data->snapshot_image, data->snapshot_image_scale)); | 128 *data->snapshot_image, data->snapshot_image_scale)); |
| 110 } | 129 } |
| 111 | 130 |
| 112 for (auto& observer : observers_) | 131 for (auto& observer : observers_) |
| 113 observer.OnItemUpdated(); | 132 observer.OnItemUpdated(); |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 130 } | 149 } |
| 131 | 150 |
| 132 void ArcCustomNotificationItem::DecrementWindowRefCount() { | 151 void ArcCustomNotificationItem::DecrementWindowRefCount() { |
| 133 DCHECK_GT(window_ref_count_, 0); | 152 DCHECK_GT(window_ref_count_, 0); |
| 134 --window_ref_count_; | 153 --window_ref_count_; |
| 135 if (window_ref_count_ == 0) | 154 if (window_ref_count_ == 0) |
| 136 manager()->CloseNotificationWindow(notification_key()); | 155 manager()->CloseNotificationWindow(notification_key()); |
| 137 } | 156 } |
| 138 | 157 |
| 139 } // namespace arc | 158 } // namespace arc |
| OLD | NEW |