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 <memory> | 7 #include <memory> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "ash/common/system/toast/toast_manager.h" | 10 #include "ash/common/system/toast/toast_manager.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 } | 42 } |
43 | 43 |
44 ArcNotificationManager::~ArcNotificationManager() { | 44 ArcNotificationManager::~ArcNotificationManager() { |
45 arc_bridge_service()->notifications()->RemoveObserver(this); | 45 arc_bridge_service()->notifications()->RemoveObserver(this); |
46 } | 46 } |
47 | 47 |
48 void ArcNotificationManager::OnInstanceReady() { | 48 void ArcNotificationManager::OnInstanceReady() { |
49 DCHECK(!ready_); | 49 DCHECK(!ready_); |
50 | 50 |
51 auto* notifications_instance = | 51 auto* notifications_instance = |
52 arc_bridge_service()->notifications()->instance(); | 52 arc_bridge_service()->notifications()->GetInstanceForMethod("Init"); |
53 if (!notifications_instance) { | 53 DCHECK(notifications_instance); |
54 VLOG(2) << "Request to refresh app list when bridge service is not ready."; | |
55 return; | |
56 } | |
57 | 54 |
58 notifications_instance->Init(binding_.CreateInterfacePtrAndBind()); | 55 notifications_instance->Init(binding_.CreateInterfacePtrAndBind()); |
59 ready_ = true; | 56 ready_ = true; |
60 } | 57 } |
61 | 58 |
62 void ArcNotificationManager::OnInstanceClosed() { | 59 void ArcNotificationManager::OnInstanceClosed() { |
63 DCHECK(ready_); | 60 DCHECK(ready_); |
64 while (!items_.empty()) { | 61 while (!items_.empty()) { |
65 auto it = items_.begin(); | 62 auto it = items_.begin(); |
66 std::unique_ptr<ArcNotificationItem> item = std::move(it->second); | 63 std::unique_ptr<ArcNotificationItem> item = std::move(it->second); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 << "), but it is already gone."; | 112 << "), but it is already gone."; |
116 return; | 113 return; |
117 } | 114 } |
118 | 115 |
119 // The removed ArcNotificationItem needs to live in this scope, since the | 116 // The removed ArcNotificationItem needs to live in this scope, since the |
120 // given argument |key| may be a part of the removed item. | 117 // given argument |key| may be a part of the removed item. |
121 std::unique_ptr<ArcNotificationItem> item = std::move(it->second); | 118 std::unique_ptr<ArcNotificationItem> item = std::move(it->second); |
122 items_.erase(it); | 119 items_.erase(it); |
123 | 120 |
124 auto* notifications_instance = | 121 auto* notifications_instance = |
125 arc_bridge_service()->notifications()->instance(); | 122 arc_bridge_service()->notifications()->GetInstanceForMethod( |
| 123 "SendNotificationEventToAndroid"); |
126 | 124 |
127 // On shutdown, the ARC channel may quit earlier then notifications. | 125 // On shutdown, the ARC channel may quit earlier then notifications. |
128 if (!notifications_instance) { | 126 if (!notifications_instance) { |
129 VLOG(2) << "ARC Notification (key: " << key | 127 VLOG(2) << "ARC Notification (key: " << key |
130 << ") is closed, but the ARC channel has already gone."; | 128 << ") is closed, but the ARC channel has already gone."; |
131 return; | 129 return; |
132 } | 130 } |
133 | 131 |
134 notifications_instance->SendNotificationEventToAndroid( | 132 notifications_instance->SendNotificationEventToAndroid( |
135 key, mojom::ArcNotificationEvent::CLOSED); | 133 key, mojom::ArcNotificationEvent::CLOSED); |
136 } | 134 } |
137 | 135 |
138 void ArcNotificationManager::SendNotificationClickedOnChrome( | 136 void ArcNotificationManager::SendNotificationClickedOnChrome( |
139 const std::string& key) { | 137 const std::string& key) { |
140 if (items_.find(key) == items_.end()) { | 138 if (items_.find(key) == items_.end()) { |
141 VLOG(3) << "Chrome requests to fire a click event on notification (key: " | 139 VLOG(3) << "Chrome requests to fire a click event on notification (key: " |
142 << key << "), but it is gone."; | 140 << key << "), but it is gone."; |
143 return; | 141 return; |
144 } | 142 } |
145 | 143 |
146 auto* notifications_instance = | 144 auto* notifications_instance = |
147 arc_bridge_service()->notifications()->instance(); | 145 arc_bridge_service()->notifications()->GetInstanceForMethod( |
| 146 "SendNotificationEventToAndroid"); |
148 | 147 |
149 // On shutdown, the ARC channel may quit earlier then notifications. | 148 // On shutdown, the ARC channel may quit earlier then notifications. |
150 if (!notifications_instance) { | 149 if (!notifications_instance) { |
151 VLOG(2) << "ARC Notification (key: " << key | 150 VLOG(2) << "ARC Notification (key: " << key |
152 << ") is clicked, but the ARC channel has already gone."; | 151 << ") is clicked, but the ARC channel has already gone."; |
153 return; | 152 return; |
154 } | 153 } |
155 | 154 |
156 notifications_instance->SendNotificationEventToAndroid( | 155 notifications_instance->SendNotificationEventToAndroid( |
157 key, mojom::ArcNotificationEvent::BODY_CLICKED); | 156 key, mojom::ArcNotificationEvent::BODY_CLICKED); |
158 } | 157 } |
159 | 158 |
160 void ArcNotificationManager::SendNotificationButtonClickedOnChrome( | 159 void ArcNotificationManager::SendNotificationButtonClickedOnChrome( |
161 const std::string& key, | 160 const std::string& key, |
162 int button_index) { | 161 int button_index) { |
163 if (items_.find(key) == items_.end()) { | 162 if (items_.find(key) == items_.end()) { |
164 VLOG(3) << "Chrome requests to fire a click event on notification (key: " | 163 VLOG(3) << "Chrome requests to fire a click event on notification (key: " |
165 << key << "), but it is gone."; | 164 << key << "), but it is gone."; |
166 return; | 165 return; |
167 } | 166 } |
168 | 167 |
169 auto* notifications_instance = | 168 auto* notifications_instance = |
170 arc_bridge_service()->notifications()->instance(); | 169 arc_bridge_service()->notifications()->GetInstanceForMethod( |
| 170 "SendNotificationEventToAndroid"); |
171 | 171 |
172 // On shutdown, the ARC channel may quit earlier then notifications. | 172 // On shutdown, the ARC channel may quit earlier then notifications. |
173 if (!notifications_instance) { | 173 if (!notifications_instance) { |
174 VLOG(2) << "ARC Notification (key: " << key | 174 VLOG(2) << "ARC Notification (key: " << key |
175 << ")'s button is clicked, but the ARC channel has already gone."; | 175 << ")'s button is clicked, but the ARC channel has already gone."; |
176 return; | 176 return; |
177 } | 177 } |
178 | 178 |
179 arc::mojom::ArcNotificationEvent command; | 179 arc::mojom::ArcNotificationEvent command; |
180 switch (button_index) { | 180 switch (button_index) { |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 ash::WmShell::Get()->toast_manager()->Show( | 238 ash::WmShell::Get()->toast_manager()->Show( |
239 ash::ToastData(data->id, data->text.To<base::string16>(), data->duration, | 239 ash::ToastData(data->id, data->text.To<base::string16>(), data->duration, |
240 data->dismiss_text.To<base::string16>())); | 240 data->dismiss_text.To<base::string16>())); |
241 } | 241 } |
242 | 242 |
243 void ArcNotificationManager::OnToastCancelled(mojom::ArcToastDataPtr data) { | 243 void ArcNotificationManager::OnToastCancelled(mojom::ArcToastDataPtr data) { |
244 ash::WmShell::Get()->toast_manager()->Cancel(data->id); | 244 ash::WmShell::Get()->toast_manager()->Cancel(data->id); |
245 } | 245 } |
246 | 246 |
247 } // namespace arc | 247 } // namespace arc |
OLD | NEW |