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_manager.h" | 5 #include "ui/arc/notification/arc_notification_manager.h" |
6 | 6 |
7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
8 #include "ash/system/toast/toast_manager.h" | 8 #include "ash/system/toast/toast_manager.h" |
9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
11 #include "ui/arc/notification/arc_custom_notification_item.h" | 11 #include "ui/arc/notification/arc_custom_notification_item.h" |
12 #include "ui/arc/notification/arc_notification_item.h" | 12 #include "ui/arc/notification/arc_notification_item.h" |
13 | 13 |
14 namespace arc { | 14 namespace arc { |
15 | 15 |
16 ArcNotificationManager::ArcNotificationManager(ArcBridgeService* bridge_service, | 16 ArcNotificationManager::ArcNotificationManager(ArcBridgeService* bridge_service, |
17 const AccountId& main_profile_id) | 17 const AccountId& main_profile_id) |
18 : ArcNotificationManager(bridge_service, | 18 : ArcNotificationManager(bridge_service, |
19 main_profile_id, | 19 main_profile_id, |
20 message_center::MessageCenter::Get()) {} | 20 message_center::MessageCenter::Get()) {} |
21 | 21 |
22 ArcNotificationManager::ArcNotificationManager( | 22 ArcNotificationManager::ArcNotificationManager( |
23 ArcBridgeService* bridge_service, | 23 ArcBridgeService* bridge_service, |
24 const AccountId& main_profile_id, | 24 const AccountId& main_profile_id, |
25 message_center::MessageCenter* message_center) | 25 message_center::MessageCenter* message_center) |
26 : ArcService(bridge_service), | 26 : ArcService(bridge_service), |
27 main_profile_id_(main_profile_id), | 27 main_profile_id_(main_profile_id), |
28 message_center_(message_center), | 28 message_center_(message_center), |
29 binding_(this) { | 29 binding_(this) { |
30 arc_bridge_service()->AddObserver(this); | 30 arc_bridge_service()->notifications()->AddObserver(this); |
31 } | 31 } |
32 | 32 |
33 ArcNotificationManager::~ArcNotificationManager() { | 33 ArcNotificationManager::~ArcNotificationManager() { |
34 arc_bridge_service()->RemoveObserver(this); | 34 arc_bridge_service()->notifications()->RemoveObserver(this); |
35 } | 35 } |
36 | 36 |
37 void ArcNotificationManager::OnNotificationsInstanceReady() { | 37 void ArcNotificationManager::OnInstanceReady( |
| 38 mojom::NotificationsInstance* notifications_instance, |
| 39 uint32_t version) { |
38 DCHECK(!ready_); | 40 DCHECK(!ready_); |
39 | 41 |
40 auto notifications_instance = arc_bridge_service()->notifications_instance(); | |
41 if (!notifications_instance) { | |
42 VLOG(2) << "Request to refresh app list when bridge service is not ready."; | |
43 return; | |
44 } | |
45 | |
46 notifications_instance->Init(binding_.CreateInterfacePtrAndBind()); | 42 notifications_instance->Init(binding_.CreateInterfacePtrAndBind()); |
47 ready_ = true; | 43 ready_ = true; |
48 } | 44 } |
49 | 45 |
50 void ArcNotificationManager::OnNotificationsInstanceClosed() { | 46 void ArcNotificationManager::OnInstanceClosed(mojom::NotificationsInstance*) { |
51 DCHECK(ready_); | 47 DCHECK(ready_); |
52 while (!items_.empty()) { | 48 while (!items_.empty()) { |
53 auto it = items_.begin(); | 49 auto it = items_.begin(); |
54 std::unique_ptr<ArcNotificationItem> item = std::move(it->second); | 50 std::unique_ptr<ArcNotificationItem> item = std::move(it->second); |
55 items_.erase(it); | 51 items_.erase(it); |
56 item->OnClosedFromAndroid(false /* by_user */); | 52 item->OnClosedFromAndroid(false /* by_user */); |
57 } | 53 } |
58 ready_ = false; | 54 ready_ = false; |
59 } | 55 } |
60 | 56 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 VLOG(3) << "Chrome requests to remove a notification (key: " << key | 98 VLOG(3) << "Chrome requests to remove a notification (key: " << key |
103 << "), but it is already gone."; | 99 << "), but it is already gone."; |
104 return; | 100 return; |
105 } | 101 } |
106 | 102 |
107 // The removed ArcNotificationItem needs to live in this scope, since the | 103 // The removed ArcNotificationItem needs to live in this scope, since the |
108 // given argument |key| may be a part of the removed item. | 104 // given argument |key| may be a part of the removed item. |
109 std::unique_ptr<ArcNotificationItem> item = std::move(it->second); | 105 std::unique_ptr<ArcNotificationItem> item = std::move(it->second); |
110 items_.erase(it); | 106 items_.erase(it); |
111 | 107 |
112 auto notifications_instance = arc_bridge_service()->notifications_instance(); | 108 auto notifications_instance = |
| 109 arc_bridge_service()->notifications()->instance(); |
113 | 110 |
114 // On shutdown, the ARC channel may quit earlier then notifications. | 111 // On shutdown, the ARC channel may quit earlier then notifications. |
115 if (!notifications_instance) { | 112 if (!notifications_instance) { |
116 VLOG(2) << "ARC Notification (key: " << key | 113 VLOG(2) << "ARC Notification (key: " << key |
117 << ") is closed, but the ARC channel has already gone."; | 114 << ") is closed, but the ARC channel has already gone."; |
118 return; | 115 return; |
119 } | 116 } |
120 | 117 |
121 notifications_instance->SendNotificationEventToAndroid( | 118 notifications_instance->SendNotificationEventToAndroid( |
122 key, mojom::ArcNotificationEvent::CLOSED); | 119 key, mojom::ArcNotificationEvent::CLOSED); |
123 } | 120 } |
124 | 121 |
125 void ArcNotificationManager::SendNotificationClickedOnChrome( | 122 void ArcNotificationManager::SendNotificationClickedOnChrome( |
126 const std::string& key) { | 123 const std::string& key) { |
127 if (items_.find(key) == items_.end()) { | 124 if (items_.find(key) == items_.end()) { |
128 VLOG(3) << "Chrome requests to fire a click event on notification (key: " | 125 VLOG(3) << "Chrome requests to fire a click event on notification (key: " |
129 << key << "), but it is gone."; | 126 << key << "), but it is gone."; |
130 return; | 127 return; |
131 } | 128 } |
132 | 129 |
133 auto notifications_instance = arc_bridge_service()->notifications_instance(); | 130 auto notifications_instance = |
| 131 arc_bridge_service()->notifications()->instance(); |
134 | 132 |
135 // On shutdown, the ARC channel may quit earlier then notifications. | 133 // On shutdown, the ARC channel may quit earlier then notifications. |
136 if (!notifications_instance) { | 134 if (!notifications_instance) { |
137 VLOG(2) << "ARC Notification (key: " << key | 135 VLOG(2) << "ARC Notification (key: " << key |
138 << ") is clicked, but the ARC channel has already gone."; | 136 << ") is clicked, but the ARC channel has already gone."; |
139 return; | 137 return; |
140 } | 138 } |
141 | 139 |
142 notifications_instance->SendNotificationEventToAndroid( | 140 notifications_instance->SendNotificationEventToAndroid( |
143 key, mojom::ArcNotificationEvent::BODY_CLICKED); | 141 key, mojom::ArcNotificationEvent::BODY_CLICKED); |
144 } | 142 } |
145 | 143 |
146 void ArcNotificationManager::SendNotificationButtonClickedOnChrome( | 144 void ArcNotificationManager::SendNotificationButtonClickedOnChrome( |
147 const std::string& key, int button_index) { | 145 const std::string& key, |
| 146 int button_index) { |
148 if (items_.find(key) == items_.end()) { | 147 if (items_.find(key) == items_.end()) { |
149 VLOG(3) << "Chrome requests to fire a click event on notification (key: " | 148 VLOG(3) << "Chrome requests to fire a click event on notification (key: " |
150 << key << "), but it is gone."; | 149 << key << "), but it is gone."; |
151 return; | 150 return; |
152 } | 151 } |
153 | 152 |
154 auto notifications_instance = arc_bridge_service()->notifications_instance(); | 153 auto notifications_instance = |
| 154 arc_bridge_service()->notifications()->instance(); |
155 | 155 |
156 // On shutdown, the ARC channel may quit earlier then notifications. | 156 // On shutdown, the ARC channel may quit earlier then notifications. |
157 if (!notifications_instance) { | 157 if (!notifications_instance) { |
158 VLOG(2) << "ARC Notification (key: " << key | 158 VLOG(2) << "ARC Notification (key: " << key |
159 << ")'s button is clicked, but the ARC channel has already gone."; | 159 << ")'s button is clicked, but the ARC channel has already gone."; |
160 return; | 160 return; |
161 } | 161 } |
162 | 162 |
163 arc::mojom::ArcNotificationEvent command; | 163 arc::mojom::ArcNotificationEvent command; |
164 switch (button_index) { | 164 switch (button_index) { |
165 case 0: | 165 case 0: |
166 command = mojom::ArcNotificationEvent::BUTTON_1_CLICKED; | 166 command = mojom::ArcNotificationEvent::BUTTON_1_CLICKED; |
167 break; | 167 break; |
168 case 1: | 168 case 1: |
169 command = mojom::ArcNotificationEvent::BUTTON_2_CLICKED; | 169 command = mojom::ArcNotificationEvent::BUTTON_2_CLICKED; |
170 break; | 170 break; |
171 case 2: | 171 case 2: |
172 command = mojom::ArcNotificationEvent::BUTTON_3_CLICKED; | 172 command = mojom::ArcNotificationEvent::BUTTON_3_CLICKED; |
173 break; | 173 break; |
174 case 3: | 174 case 3: |
175 command = mojom::ArcNotificationEvent::BUTTON_4_CLICKED; | 175 command = mojom::ArcNotificationEvent::BUTTON_4_CLICKED; |
176 break; | 176 break; |
177 case 4: | 177 case 4: |
178 command = mojom::ArcNotificationEvent::BUTTON_5_CLICKED; | 178 command = mojom::ArcNotificationEvent::BUTTON_5_CLICKED; |
179 break; | 179 break; |
180 default: | 180 default: |
181 VLOG(3) << "Invalid button index (key: " << key << ", index: " << | 181 VLOG(3) << "Invalid button index (key: " << key |
182 button_index << ")."; | 182 << ", index: " << button_index << ")."; |
183 return; | 183 return; |
184 } | 184 } |
185 | 185 |
186 notifications_instance->SendNotificationEventToAndroid(key, command); | 186 notifications_instance->SendNotificationEventToAndroid(key, command); |
187 } | 187 } |
188 | 188 |
189 void ArcNotificationManager::OnToastPosted(mojom::ArcToastDataPtr data) { | 189 void ArcNotificationManager::OnToastPosted(mojom::ArcToastDataPtr data) { |
190 ash::Shell::GetInstance()->toast_manager()->Show( | 190 ash::Shell::GetInstance()->toast_manager()->Show( |
191 ash::ToastData(data->id, data->text, data->duration, data->dismiss_text)); | 191 ash::ToastData(data->id, data->text, data->duration, data->dismiss_text)); |
192 } | 192 } |
193 | 193 |
194 void ArcNotificationManager::OnToastCancelled(mojom::ArcToastDataPtr data) { | 194 void ArcNotificationManager::OnToastCancelled(mojom::ArcToastDataPtr data) { |
195 ash::Shell::GetInstance()->toast_manager()->Cancel(data->id); | 195 ash::Shell::GetInstance()->toast_manager()->Cancel(data->id); |
196 } | 196 } |
197 | 197 |
198 } // namespace arc | 198 } // namespace arc |
OLD | NEW |