Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "ui/arc/notification/arc_notification_manager.h" | |
| 6 | |
| 7 #include "base/stl_util.h" | |
| 8 #include "ui/arc/notification/arc_notification_item.h" | |
| 9 | |
| 10 namespace arc { | |
| 11 | |
| 12 ArcNotificationManager::ArcNotificationManager(ArcBridgeService* arc_bridge, | |
| 13 const AccountId& main_profile_id) | |
| 14 : arc_bridge_(arc_bridge), | |
| 15 main_profile_id_(main_profile_id), | |
| 16 binding_(this) { | |
| 17 // This must be initialized after ArcBridgeService. | |
| 18 DCHECK(arc_bridge_); | |
| 19 DCHECK_EQ(arc_bridge_, ArcBridgeService::Get()); | |
| 20 arc_bridge_->AddObserver(this); | |
| 21 } | |
| 22 | |
| 23 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 } | |
| 29 | |
| 30 void ArcNotificationManager::OnNotificationsInstanceReady() { | |
| 31 NotificationsInstance* notifications_instance = | |
| 32 arc_bridge_->notifications_instance(); | |
| 33 if (!notifications_instance) { | |
| 34 VLOG(2) << "Request to refresh app list when bridge service is not ready."; | |
| 35 return; | |
| 36 } | |
| 37 | |
| 38 NotificationsHostPtr host; | |
| 39 binding_.Bind(mojo::GetProxy(&host)); | |
| 40 notifications_instance->Init(std::move(host)); | |
| 41 } | |
| 42 | |
| 43 void ArcNotificationManager::OnNotificationPosted(ArcNotificationDataPtr data) { | |
| 44 ArcNotificationItem* item = items_.get(data->key); | |
| 45 if (!item) { | |
| 46 // Show a notification on the primary loged-in user's desktop. | |
| 47 // TODO(yoshiki): Reconsider when ARC supports multi-user. | |
| 48 item = new ArcNotificationItem(this, message_center::MessageCenter::Get(), | |
| 49 *data, main_profile_id_); | |
| 50 items_.set(data->key, make_scoped_ptr(item)); | |
| 51 } | |
| 52 item->UpdateWithArcNotificationData(*data); | |
| 53 } | |
| 54 | |
| 55 void ArcNotificationManager::OnNotificationRemoved(const mojo::String& key) { | |
| 56 Items::iterator it = items_.find(key.get()); | |
| 57 if (it != items_.end()) { | |
| 58 scoped_ptr<ArcNotificationItem> item(items_.take_and_erase(it)); | |
| 59 item->OnClosedFromAndroid(); | |
| 60 } else { | |
| 61 VLOG(3) << "Android requests to remove a notification (key: " << key | |
| 62 << "), but it is already gone."; | |
| 63 } | |
|
stevenjb
2016/01/05 16:59:06
nit: invert logic and early exit if not found.
yoshiki
2016/01/06 08:50:17
Done.
| |
| 64 } | |
| 65 | |
| 66 void ArcNotificationManager::SendNotificationRemovedFromChrome( | |
| 67 const std::string& key) { | |
| 68 Items::iterator it = items_.find(key); | |
| 69 if (it != items_.end()) { | |
| 70 scoped_ptr<ArcNotificationItem> item(items_.take_and_erase(it)); | |
| 71 | |
| 72 arc_bridge_->notifications_instance()->SendNotificationEventToAndroid( | |
| 73 key, ARC_NOTIFICATION_EVENT_CLOSED); | |
| 74 } else { | |
| 75 VLOG(3) << "Chrome requests to remove a notification (key: " << key | |
| 76 << "), but it is already gone."; | |
| 77 } | |
|
stevenjb
2016/01/05 16:59:06
same here and below.
yoshiki
2016/01/06 08:50:17
Done.
| |
| 78 } | |
| 79 | |
| 80 void ArcNotificationManager::SendNotificationClickedOnChrome( | |
| 81 const std::string& key) { | |
| 82 if (items_.contains(key)) { | |
| 83 arc_bridge_->notifications_instance()->SendNotificationEventToAndroid( | |
| 84 key, ARC_NOTIFICATION_EVENT_BODY_CLICKED); | |
| 85 } else { | |
| 86 VLOG(3) << "Chrome requests to fire a click event on notification (key: " | |
| 87 << key << "), but it is gone."; | |
| 88 } | |
| 89 } | |
| 90 | |
| 91 } // namespace arc | |
| OLD | NEW |