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" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 DCHECK(ready_); | 50 DCHECK(ready_); |
51 while (!items_.empty()) { | 51 while (!items_.empty()) { |
52 auto it = items_.begin(); | 52 auto it = items_.begin(); |
53 std::unique_ptr<ArcNotificationItem> item = std::move(it->second); | 53 std::unique_ptr<ArcNotificationItem> item = std::move(it->second); |
54 items_.erase(it); | 54 items_.erase(it); |
55 item->OnClosedFromAndroid(false /* by_user */); | 55 item->OnClosedFromAndroid(false /* by_user */); |
56 } | 56 } |
57 ready_ = false; | 57 ready_ = false; |
58 } | 58 } |
59 | 59 |
60 void ArcNotificationManager::OnNotificationPosted(ArcNotificationDataPtr data) { | 60 void ArcNotificationManager::OnNotificationPosted( |
| 61 mojom::ArcNotificationDataPtr data) { |
61 const std::string& key = data->key; | 62 const std::string& key = data->key; |
62 auto it = items_.find(key); | 63 auto it = items_.find(key); |
63 if (it == items_.end()) { | 64 if (it == items_.end()) { |
64 // Show a notification on the primary loged-in user's desktop. | 65 // Show a notification on the primary loged-in user's desktop. |
65 // TODO(yoshiki): Reconsider when ARC supports multi-user. | 66 // TODO(yoshiki): Reconsider when ARC supports multi-user. |
66 ArcNotificationItem* item = | 67 ArcNotificationItem* item = |
67 new ArcNotificationItem(this, message_center_, key, main_profile_id_); | 68 new ArcNotificationItem(this, message_center_, key, main_profile_id_); |
68 // TODO(yoshiki): Use emplacement for performance when it's available. | 69 // TODO(yoshiki): Use emplacement for performance when it's available. |
69 auto result = items_.insert(std::make_pair(key, base::WrapUnique(item))); | 70 auto result = items_.insert(std::make_pair(key, base::WrapUnique(item))); |
70 DCHECK(result.second); | 71 DCHECK(result.second); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 auto notifications_instance = arc_bridge_service()->notifications_instance(); | 104 auto notifications_instance = arc_bridge_service()->notifications_instance(); |
104 | 105 |
105 // On shutdown, the ARC channel may quit earlier then notifications. | 106 // On shutdown, the ARC channel may quit earlier then notifications. |
106 if (!notifications_instance) { | 107 if (!notifications_instance) { |
107 VLOG(2) << "ARC Notification (key: " << key | 108 VLOG(2) << "ARC Notification (key: " << key |
108 << ") is closed, but the ARC channel has already gone."; | 109 << ") is closed, but the ARC channel has already gone."; |
109 return; | 110 return; |
110 } | 111 } |
111 | 112 |
112 notifications_instance->SendNotificationEventToAndroid( | 113 notifications_instance->SendNotificationEventToAndroid( |
113 key, ArcNotificationEvent::CLOSED); | 114 key, mojom::ArcNotificationEvent::CLOSED); |
114 } | 115 } |
115 | 116 |
116 void ArcNotificationManager::SendNotificationClickedOnChrome( | 117 void ArcNotificationManager::SendNotificationClickedOnChrome( |
117 const std::string& key) { | 118 const std::string& key) { |
118 if (items_.find(key) == items_.end()) { | 119 if (items_.find(key) == items_.end()) { |
119 VLOG(3) << "Chrome requests to fire a click event on notification (key: " | 120 VLOG(3) << "Chrome requests to fire a click event on notification (key: " |
120 << key << "), but it is gone."; | 121 << key << "), but it is gone."; |
121 return; | 122 return; |
122 } | 123 } |
123 | 124 |
124 auto notifications_instance = arc_bridge_service()->notifications_instance(); | 125 auto notifications_instance = arc_bridge_service()->notifications_instance(); |
125 | 126 |
126 // On shutdown, the ARC channel may quit earlier then notifications. | 127 // On shutdown, the ARC channel may quit earlier then notifications. |
127 if (!notifications_instance) { | 128 if (!notifications_instance) { |
128 VLOG(2) << "ARC Notification (key: " << key | 129 VLOG(2) << "ARC Notification (key: " << key |
129 << ") is clicked, but the ARC channel has already gone."; | 130 << ") is clicked, but the ARC channel has already gone."; |
130 return; | 131 return; |
131 } | 132 } |
132 | 133 |
133 notifications_instance->SendNotificationEventToAndroid( | 134 notifications_instance->SendNotificationEventToAndroid( |
134 key, ArcNotificationEvent::BODY_CLICKED); | 135 key, mojom::ArcNotificationEvent::BODY_CLICKED); |
135 } | 136 } |
136 | 137 |
137 void ArcNotificationManager::SendNotificationButtonClickedOnChrome( | 138 void ArcNotificationManager::SendNotificationButtonClickedOnChrome( |
138 const std::string& key, int button_index) { | 139 const std::string& key, int button_index) { |
139 if (items_.find(key) == items_.end()) { | 140 if (items_.find(key) == items_.end()) { |
140 VLOG(3) << "Chrome requests to fire a click event on notification (key: " | 141 VLOG(3) << "Chrome requests to fire a click event on notification (key: " |
141 << key << "), but it is gone."; | 142 << key << "), but it is gone."; |
142 return; | 143 return; |
143 } | 144 } |
144 | 145 |
145 auto notifications_instance = arc_bridge_service()->notifications_instance(); | 146 auto notifications_instance = arc_bridge_service()->notifications_instance(); |
146 | 147 |
147 // On shutdown, the ARC channel may quit earlier then notifications. | 148 // On shutdown, the ARC channel may quit earlier then notifications. |
148 if (!notifications_instance) { | 149 if (!notifications_instance) { |
149 VLOG(2) << "ARC Notification (key: " << key | 150 VLOG(2) << "ARC Notification (key: " << key |
150 << ")'s button is clicked, but the ARC channel has already gone."; | 151 << ")'s button is clicked, but the ARC channel has already gone."; |
151 return; | 152 return; |
152 } | 153 } |
153 | 154 |
154 arc::ArcNotificationEvent command; | 155 arc::mojom::ArcNotificationEvent command; |
155 switch (button_index) { | 156 switch (button_index) { |
156 case 0: | 157 case 0: |
157 command = ArcNotificationEvent::BUTTON_1_CLICKED; | 158 command = mojom::ArcNotificationEvent::BUTTON_1_CLICKED; |
158 break; | 159 break; |
159 case 1: | 160 case 1: |
160 command = ArcNotificationEvent::BUTTON_2_CLICKED; | 161 command = mojom::ArcNotificationEvent::BUTTON_2_CLICKED; |
161 break; | 162 break; |
162 case 2: | 163 case 2: |
163 command = ArcNotificationEvent::BUTTON_3_CLICKED; | 164 command = mojom::ArcNotificationEvent::BUTTON_3_CLICKED; |
164 break; | 165 break; |
165 case 3: | 166 case 3: |
166 command = ArcNotificationEvent::BUTTON_4_CLICKED; | 167 command = mojom::ArcNotificationEvent::BUTTON_4_CLICKED; |
167 break; | 168 break; |
168 case 4: | 169 case 4: |
169 command = ArcNotificationEvent::BUTTON_5_CLICKED; | 170 command = mojom::ArcNotificationEvent::BUTTON_5_CLICKED; |
170 break; | 171 break; |
171 default: | 172 default: |
172 VLOG(3) << "Invalid button index (key: " << key << ", index: " << | 173 VLOG(3) << "Invalid button index (key: " << key << ", index: " << |
173 button_index << ")."; | 174 button_index << ")."; |
174 return; | 175 return; |
175 } | 176 } |
176 | 177 |
177 notifications_instance->SendNotificationEventToAndroid(key, command); | 178 notifications_instance->SendNotificationEventToAndroid(key, command); |
178 } | 179 } |
179 | 180 |
180 void ArcNotificationManager::OnToastPosted(ArcToastDataPtr data) { | 181 void ArcNotificationManager::OnToastPosted(mojom::ArcToastDataPtr data) { |
181 ash::Shell::GetInstance()->toast_manager()->Show(data->text, data->duration); | 182 ash::Shell::GetInstance()->toast_manager()->Show(data->text, data->duration); |
182 } | 183 } |
183 | 184 |
184 void ArcNotificationManager::OnToastCancelled(ArcToastDataPtr data) { | 185 void ArcNotificationManager::OnToastCancelled(mojom::ArcToastDataPtr data) { |
185 // TODO(yoshiki): Implement cancel. | 186 // TODO(yoshiki): Implement cancel. |
186 } | 187 } |
187 | 188 |
188 } // namespace arc | 189 } // namespace arc |
OLD | NEW |