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

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

Issue 2319893002: 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/common/system/toast/toast_manager.h" 7 #include "ash/common/system/toast/toast_manager.h"
8 #include "ash/common/wm_shell.h" 8 #include "ash/common/wm_shell.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 "mojo/common/common_type_converters.h" 11 #include "mojo/common/common_type_converters.h"
12 #include "ui/arc/notification/arc_custom_notification_item.h" 12 #include "ui/arc/notification/arc_custom_notification_item.h"
13 #include "ui/arc/notification/arc_notification_item.h" 13 #include "ui/arc/notification/arc_notification_item.h"
14 14
15 namespace arc { 15 namespace arc {
16 16
17 namespace {
18
19 // Min version to support Create/CloseNotificationWindow.
20 constexpr int kMinVersionNotificationWindow = 7;
21
22 } // namespace
23
17 ArcNotificationManager::ArcNotificationManager(ArcBridgeService* bridge_service, 24 ArcNotificationManager::ArcNotificationManager(ArcBridgeService* bridge_service,
18 const AccountId& main_profile_id) 25 const AccountId& main_profile_id)
19 : ArcNotificationManager(bridge_service, 26 : ArcNotificationManager(bridge_service,
20 main_profile_id, 27 main_profile_id,
21 message_center::MessageCenter::Get()) {} 28 message_center::MessageCenter::Get()) {}
22 29
23 ArcNotificationManager::ArcNotificationManager( 30 ArcNotificationManager::ArcNotificationManager(
24 ArcBridgeService* bridge_service, 31 ArcBridgeService* bridge_service,
25 const AccountId& main_profile_id, 32 const AccountId& main_profile_id,
26 message_center::MessageCenter* message_center) 33 message_center::MessageCenter* message_center)
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 break; 192 break;
186 default: 193 default:
187 VLOG(3) << "Invalid button index (key: " << key 194 VLOG(3) << "Invalid button index (key: " << key
188 << ", index: " << button_index << ")."; 195 << ", index: " << button_index << ").";
189 return; 196 return;
190 } 197 }
191 198
192 notifications_instance->SendNotificationEventToAndroid(key, command); 199 notifications_instance->SendNotificationEventToAndroid(key, command);
193 } 200 }
194 201
202 void ArcNotificationManager::CreateNotificationWindow(const std::string& key) {
203 if (items_.find(key) == items_.end()) {
204 VLOG(3) << "Chrome requests to create window on notification (key: " << key
205 << "), but it is gone.";
206 return;
207 }
208
209 auto* notifications_instance =
210 arc_bridge_service()->notifications()->instance();
211 // On shutdown, the ARC channel may quit earlier then notifications.
212 if (!notifications_instance) {
213 VLOG(2) << "Request to create window for ARC Notification (key: " << key
214 << "), but the ARC channel has already gone.";
215 return;
216 }
217
218 if (arc_bridge_service()->notifications()->version() <
219 kMinVersionNotificationWindow) {
220 VLOG(2)
221 << "NotificationInstance does not support CreateNotificationWindow.";
222 return;
223 }
224
225 notifications_instance->CreateNotificationWindow(key);
226 }
227
228 void ArcNotificationManager::CloseNotificationWindow(const std::string& key) {
229 if (items_.find(key) == items_.end()) {
230 VLOG(3) << "Chrome requests to close window on notification (key: " << key
231 << "), but it is gone.";
232 return;
233 }
234
235 auto* notifications_instance =
236 arc_bridge_service()->notifications()->instance();
237 // On shutdown, the ARC channel may quit earlier then notifications.
238 if (!notifications_instance) {
239 VLOG(2) << "Request to close window for ARC Notification (key: " << key
240 << "), but the ARC channel has already gone.";
241 return;
242 }
243
244 if (arc_bridge_service()->notifications()->version() <
245 kMinVersionNotificationWindow) {
246 VLOG(2) << "NotificationInstance does not support CloseNotificationWindow.";
247 return;
248 }
249
250 notifications_instance->CloseNotificationWindow(key);
251 }
252
195 void ArcNotificationManager::OnToastPosted(mojom::ArcToastDataPtr data) { 253 void ArcNotificationManager::OnToastPosted(mojom::ArcToastDataPtr data) {
196 ash::WmShell::Get()->toast_manager()->Show( 254 ash::WmShell::Get()->toast_manager()->Show(
197 ash::ToastData(data->id, data->text.To<base::string16>(), data->duration, 255 ash::ToastData(data->id, data->text.To<base::string16>(), data->duration,
198 data->dismiss_text.To<base::string16>())); 256 data->dismiss_text.To<base::string16>()));
199 } 257 }
200 258
201 void ArcNotificationManager::OnToastCancelled(mojom::ArcToastDataPtr data) { 259 void ArcNotificationManager::OnToastCancelled(mojom::ArcToastDataPtr data) {
202 ash::WmShell::Get()->toast_manager()->Cancel(data->id); 260 ash::WmShell::Get()->toast_manager()->Cancel(data->id);
203 } 261 }
204 262
205 } // namespace arc 263 } // 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