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 "base/stl_util.h" | 7 #include "base/stl_util.h" |
8 #include "ui/arc/notification/arc_notification_item.h" | 8 #include "ui/arc/notification/arc_notification_item.h" |
9 | 9 |
10 namespace arc { | 10 namespace arc { |
11 | 11 |
12 ArcNotificationManager::ArcNotificationManager(ArcBridgeService* arc_bridge, | 12 ArcNotificationManager::ArcNotificationManager(ArcBridgeService* arc_bridge, |
13 const AccountId& main_profile_id) | 13 const AccountId& main_profile_id) |
14 : arc_bridge_(arc_bridge), | 14 : arc_bridge_(arc_bridge), |
15 main_profile_id_(main_profile_id), | 15 main_profile_id_(main_profile_id), |
16 binding_(this) { | 16 binding_(this) { |
17 // This must be initialized after ArcBridgeService. | |
18 DCHECK(arc_bridge_); | 17 DCHECK(arc_bridge_); |
19 DCHECK_EQ(arc_bridge_, ArcBridgeService::Get()); | |
20 arc_bridge_->AddObserver(this); | 18 arc_bridge_->AddObserver(this); |
| 19 |
| 20 // If NotificationsInstance was ready before we AddObserver(), we won't get |
| 21 // OnNotificationsInstanceReady events. For such case, we have to call it |
| 22 // explicitly. |
| 23 if (arc_bridge_->notifications_instance()) |
| 24 OnNotificationsInstanceReady(); |
21 } | 25 } |
22 | 26 |
23 ArcNotificationManager::~ArcNotificationManager() { | 27 ArcNotificationManager::~ArcNotificationManager() { |
24 // This should be free'd before ArcBridgeService. | |
25 DCHECK(ArcBridgeService::Get()); | |
26 DCHECK_EQ(arc_bridge_, ArcBridgeService::Get()); | |
27 arc_bridge_->RemoveObserver(this); | 28 arc_bridge_->RemoveObserver(this); |
28 } | 29 } |
29 | 30 |
30 void ArcNotificationManager::OnNotificationsInstanceReady() { | 31 void ArcNotificationManager::OnNotificationsInstanceReady() { |
31 NotificationsInstance* notifications_instance = | 32 NotificationsInstance* notifications_instance = |
32 arc_bridge_->notifications_instance(); | 33 arc_bridge_->notifications_instance(); |
33 if (!notifications_instance) { | 34 if (!notifications_instance) { |
34 VLOG(2) << "Request to refresh app list when bridge service is not ready."; | 35 VLOG(2) << "Request to refresh app list when bridge service is not ready."; |
35 return; | 36 return; |
36 } | 37 } |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 VLOG(3) << "Chrome requests to fire a click event on notification (key: " | 86 VLOG(3) << "Chrome requests to fire a click event on notification (key: " |
86 << key << "), but it is gone."; | 87 << key << "), but it is gone."; |
87 return; | 88 return; |
88 } | 89 } |
89 | 90 |
90 arc_bridge_->notifications_instance()->SendNotificationEventToAndroid( | 91 arc_bridge_->notifications_instance()->SendNotificationEventToAndroid( |
91 key, ARC_NOTIFICATION_EVENT_BODY_CLICKED); | 92 key, ARC_NOTIFICATION_EVENT_BODY_CLICKED); |
92 } | 93 } |
93 | 94 |
94 } // namespace arc | 95 } // namespace arc |
OLD | NEW |