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* bridge_service, |
13 const AccountId& main_profile_id) | 13 const AccountId& main_profile_id) |
14 : arc_bridge_(arc_bridge), | 14 : ArcService(bridge_service), |
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. | 17 arc_bridge_service()->AddObserver(this); |
18 DCHECK(arc_bridge_); | |
19 DCHECK_EQ(arc_bridge_, ArcBridgeService::Get()); | |
20 arc_bridge_->AddObserver(this); | |
21 } | 18 } |
22 | 19 |
23 ArcNotificationManager::~ArcNotificationManager() { | 20 ArcNotificationManager::~ArcNotificationManager() { |
24 // This should be free'd before ArcBridgeService. | 21 arc_bridge_service()->RemoveObserver(this); |
25 DCHECK(ArcBridgeService::Get()); | |
26 DCHECK_EQ(arc_bridge_, ArcBridgeService::Get()); | |
27 arc_bridge_->RemoveObserver(this); | |
28 } | 22 } |
29 | 23 |
30 void ArcNotificationManager::OnNotificationsInstanceReady() { | 24 void ArcNotificationManager::OnNotificationsInstanceReady() { |
31 NotificationsInstance* notifications_instance = | 25 NotificationsInstance* notifications_instance = |
32 arc_bridge_->notifications_instance(); | 26 arc_bridge_service()->notifications_instance(); |
33 if (!notifications_instance) { | 27 if (!notifications_instance) { |
34 VLOG(2) << "Request to refresh app list when bridge service is not ready."; | 28 VLOG(2) << "Request to refresh app list when bridge service is not ready."; |
35 return; | 29 return; |
36 } | 30 } |
37 | 31 |
38 NotificationsHostPtr host; | 32 NotificationsHostPtr host; |
39 binding_.Bind(mojo::GetProxy(&host)); | 33 binding_.Bind(mojo::GetProxy(&host)); |
40 notifications_instance->Init(std::move(host)); | 34 notifications_instance->Init(std::move(host)); |
41 } | 35 } |
42 | 36 |
(...skipping 25 matching lines...) Expand all Loading... |
68 const std::string& key) { | 62 const std::string& key) { |
69 ItemMap::iterator it = items_.find(key); | 63 ItemMap::iterator it = items_.find(key); |
70 if (it == items_.end()) { | 64 if (it == items_.end()) { |
71 VLOG(3) << "Chrome requests to remove a notification (key: " << key | 65 VLOG(3) << "Chrome requests to remove a notification (key: " << key |
72 << "), but it is already gone."; | 66 << "), but it is already gone."; |
73 return; | 67 return; |
74 } | 68 } |
75 | 69 |
76 scoped_ptr<ArcNotificationItem> item(items_.take_and_erase(it)); | 70 scoped_ptr<ArcNotificationItem> item(items_.take_and_erase(it)); |
77 | 71 |
78 arc_bridge_->notifications_instance()->SendNotificationEventToAndroid( | 72 arc_bridge_service() |
79 key, ArcNotificationEvent::CLOSED); | 73 ->notifications_instance() |
| 74 ->SendNotificationEventToAndroid(key, ArcNotificationEvent::CLOSED); |
80 } | 75 } |
81 | 76 |
82 void ArcNotificationManager::SendNotificationClickedOnChrome( | 77 void ArcNotificationManager::SendNotificationClickedOnChrome( |
83 const std::string& key) { | 78 const std::string& key) { |
84 if (!items_.contains(key)) { | 79 if (!items_.contains(key)) { |
85 VLOG(3) << "Chrome requests to fire a click event on notification (key: " | 80 VLOG(3) << "Chrome requests to fire a click event on notification (key: " |
86 << key << "), but it is gone."; | 81 << key << "), but it is gone."; |
87 return; | 82 return; |
88 } | 83 } |
89 | 84 |
90 arc_bridge_->notifications_instance()->SendNotificationEventToAndroid( | 85 arc_bridge_service() |
91 key, ArcNotificationEvent::BODY_CLICKED); | 86 ->notifications_instance() |
| 87 ->SendNotificationEventToAndroid(key, ArcNotificationEvent::BODY_CLICKED); |
92 } | 88 } |
93 | 89 |
94 } // namespace arc | 90 } // namespace arc |
OLD | NEW |