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/exo/notification_surface.h" | 10 #include "components/exo/notification_surface.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 } // namespace | 47 } // namespace |
48 | 48 |
49 ArcCustomNotificationItem::ArcCustomNotificationItem( | 49 ArcCustomNotificationItem::ArcCustomNotificationItem( |
50 ArcNotificationManager* manager, | 50 ArcNotificationManager* manager, |
51 message_center::MessageCenter* message_center, | 51 message_center::MessageCenter* message_center, |
52 const std::string& notification_key, | 52 const std::string& notification_key, |
53 const AccountId& profile_id) | 53 const AccountId& profile_id) |
54 : ArcNotificationItem(manager, | 54 : ArcNotificationItem(manager, |
55 message_center, | 55 message_center, |
56 notification_key, | 56 notification_key, |
57 profile_id) {} | 57 profile_id) { |
| 58 ArcNotificationSurfaceManager::Get()->AddObserver(this); |
| 59 } |
58 | 60 |
59 ArcCustomNotificationItem::~ArcCustomNotificationItem() { | 61 ArcCustomNotificationItem::~ArcCustomNotificationItem() { |
60 if (ArcNotificationSurfaceManager::Get()) | 62 if (ArcNotificationSurfaceManager::Get()) |
61 ArcNotificationSurfaceManager::Get()->RemoveObserver(this); | 63 ArcNotificationSurfaceManager::Get()->RemoveObserver(this); |
62 | 64 |
63 FOR_EACH_OBSERVER(Observer, observers_, OnItemDestroying()); | 65 FOR_EACH_OBSERVER(Observer, observers_, OnItemDestroying()); |
64 } | 66 } |
65 | 67 |
66 void ArcCustomNotificationItem::UpdateWithArcNotificationData( | 68 void ArcCustomNotificationItem::UpdateWithArcNotificationData( |
67 const mojom::ArcNotificationData& data) { | 69 const mojom::ArcNotificationData& data) { |
(...skipping 18 matching lines...) Expand all Loading... |
86 base::UTF8ToUTF16(data.title.get()), | 88 base::UTF8ToUTF16(data.title.get()), |
87 base::UTF8ToUTF16(data.message.get()), gfx::Image(), | 89 base::UTF8ToUTF16(data.message.get()), gfx::Image(), |
88 base::UTF8ToUTF16("arc"), // display source | 90 base::UTF8ToUTF16("arc"), // display source |
89 GURL(), // empty origin url, for system component | 91 GURL(), // empty origin url, for system component |
90 notifier_id, rich_data, new ArcNotificationDelegate(this))); | 92 notifier_id, rich_data, new ArcNotificationDelegate(this))); |
91 | 93 |
92 exo::NotificationSurface* surface = | 94 exo::NotificationSurface* surface = |
93 ArcNotificationSurfaceManager::Get()->GetSurface(notification_key()); | 95 ArcNotificationSurfaceManager::Get()->GetSurface(notification_key()); |
94 if (surface) | 96 if (surface) |
95 OnNotificationSurfaceAdded(surface); | 97 OnNotificationSurfaceAdded(surface); |
96 else | |
97 ArcNotificationSurfaceManager::Get()->AddObserver(this); | |
98 | 98 |
99 pinned_ = rich_data.pinned; | 99 pinned_ = rich_data.pinned; |
100 FOR_EACH_OBSERVER(Observer, observers_, OnItemPinnedChanged()); | 100 FOR_EACH_OBSERVER(Observer, observers_, OnItemPinnedChanged()); |
101 } | 101 } |
102 | 102 |
103 void ArcCustomNotificationItem::CloseFromCloseButton() { | 103 void ArcCustomNotificationItem::CloseFromCloseButton() { |
104 // Needs to manually remove notification from MessageCenter because | 104 // Needs to manually remove notification from MessageCenter because |
105 // the floating close button is not part of MessageCenter. | 105 // the floating close button is not part of MessageCenter. |
106 message_center()->RemoveNotification(notification_id(), true); | 106 message_center()->RemoveNotification(notification_id(), true); |
107 Close(true); | 107 Close(true); |
(...skipping 17 matching lines...) Expand all Loading... |
125 static_cast<ArcNotificationDelegate*>(pending_notification()->delegate()) | 125 static_cast<ArcNotificationDelegate*>(pending_notification()->delegate()) |
126 ->set_notification_surface(surface); | 126 ->set_notification_surface(surface); |
127 AddToMessageCenter(); | 127 AddToMessageCenter(); |
128 } | 128 } |
129 | 129 |
130 void ArcCustomNotificationItem::OnNotificationSurfaceRemoved( | 130 void ArcCustomNotificationItem::OnNotificationSurfaceRemoved( |
131 exo::NotificationSurface* surface) { | 131 exo::NotificationSurface* surface) { |
132 if (surface->notification_id() != notification_key()) | 132 if (surface->notification_id() != notification_key()) |
133 return; | 133 return; |
134 | 134 |
135 OnClosedFromAndroid(false); | 135 FOR_EACH_OBSERVER(Observer, observers_, OnItemNotificationSurfaceRemoved()); |
136 } | 136 } |
137 | 137 |
138 } // namespace arc | 138 } // namespace arc |
OLD | NEW |