Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(273)

Side by Side Diff: ui/arc/notification/arc_notification_manager.cc

Issue 2323533002: Merge "arc: Defer notification surface creation" (Closed)
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/arc/notification/arc_notification_manager.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 namespace {
17
18 // Min version to support Create/CloseNotificationWindow.
19 constexpr int kMinVersionNotificationWindow = 7;
20
21 } // namespace
22
16 ArcNotificationManager::ArcNotificationManager(ArcBridgeService* bridge_service, 23 ArcNotificationManager::ArcNotificationManager(ArcBridgeService* bridge_service,
17 const AccountId& main_profile_id) 24 const AccountId& main_profile_id)
18 : ArcNotificationManager(bridge_service, 25 : ArcNotificationManager(bridge_service,
19 main_profile_id, 26 main_profile_id,
20 message_center::MessageCenter::Get()) {} 27 message_center::MessageCenter::Get()) {}
21 28
22 ArcNotificationManager::ArcNotificationManager( 29 ArcNotificationManager::ArcNotificationManager(
23 ArcBridgeService* bridge_service, 30 ArcBridgeService* bridge_service,
24 const AccountId& main_profile_id, 31 const AccountId& main_profile_id,
25 message_center::MessageCenter* message_center) 32 message_center::MessageCenter* message_center)
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 break; 191 break;
185 default: 192 default:
186 VLOG(3) << "Invalid button index (key: " << key 193 VLOG(3) << "Invalid button index (key: " << key
187 << ", index: " << button_index << ")."; 194 << ", index: " << button_index << ").";
188 return; 195 return;
189 } 196 }
190 197
191 notifications_instance->SendNotificationEventToAndroid(key, command); 198 notifications_instance->SendNotificationEventToAndroid(key, command);
192 } 199 }
193 200
201 void ArcNotificationManager::CreateNotificationWindow(const std::string& key) {
202 if (items_.find(key) == items_.end()) {
203 VLOG(3) << "Chrome requests to create window on notification (key: " << key
204 << "), but it is gone.";
205 return;
206 }
207
208 auto* notifications_instance =
209 arc_bridge_service()->notifications()->instance();
210 // On shutdown, the ARC channel may quit earlier then notifications.
211 if (!notifications_instance) {
212 VLOG(2) << "Request to create window for ARC Notification (key: " << key
213 << "), but the ARC channel has already gone.";
214 return;
215 }
216
217 if (arc_bridge_service()->notifications()->version() <
218 kMinVersionNotificationWindow) {
219 VLOG(2)
220 << "NotificationInstance does not support CreateNotificationWindow.";
221 return;
222 }
223
224 notifications_instance->CreateNotificationWindow(key);
225 }
226
227 void ArcNotificationManager::CloseNotificationWindow(const std::string& key) {
228 if (items_.find(key) == items_.end()) {
229 VLOG(3) << "Chrome requests to close window on notification (key: " << key
230 << "), but it is gone.";
231 return;
232 }
233
234 auto* notifications_instance =
235 arc_bridge_service()->notifications()->instance();
236 // On shutdown, the ARC channel may quit earlier then notifications.
237 if (!notifications_instance) {
238 VLOG(2) << "Request to close window for ARC Notification (key: " << key
239 << "), but the ARC channel has already gone.";
240 return;
241 }
242
243 if (arc_bridge_service()->notifications()->version() <
244 kMinVersionNotificationWindow) {
245 VLOG(2) << "NotificationInstance does not support CloseNotificationWindow.";
246 return;
247 }
248
249 notifications_instance->CloseNotificationWindow(key);
250 }
251
194 void ArcNotificationManager::OnToastPosted(mojom::ArcToastDataPtr data) { 252 void ArcNotificationManager::OnToastPosted(mojom::ArcToastDataPtr data) {
195 ash::Shell::GetInstance()->toast_manager()->Show( 253 ash::Shell::GetInstance()->toast_manager()->Show(
196 ash::ToastData(data->id, data->text, data->duration, data->dismiss_text)); 254 ash::ToastData(data->id, data->text, data->duration, data->dismiss_text));
197 } 255 }
198 256
199 void ArcNotificationManager::OnToastCancelled(mojom::ArcToastDataPtr data) { 257 void ArcNotificationManager::OnToastCancelled(mojom::ArcToastDataPtr data) {
200 ash::Shell::GetInstance()->toast_manager()->Cancel(data->id); 258 ash::Shell::GetInstance()->toast_manager()->Cancel(data->id);
201 } 259 }
202 260
203 } // namespace arc 261 } // namespace arc
OLDNEW
« no previous file with comments | « ui/arc/notification/arc_notification_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698