Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 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 "components/arc/notification/arc_notification_manager.h" | |
| 6 | |
| 7 #include "base/stl_util.h" | |
| 8 #include "components/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), main_profile_id_(main_profile_id) { | |
| 15 // This must be initialized after ArcBridgeService. | |
| 16 DCHECK(arc_bridge_); | |
| 17 DCHECK_EQ(arc_bridge_, ArcBridgeService::Get()); | |
| 18 arc_bridge_->AddNotificationObserver(this); | |
| 19 } | |
| 20 | |
| 21 ArcNotificationManager::~ArcNotificationManager() { | |
| 22 // This should be free'd before ArcBridgeService. | |
| 23 DCHECK(ArcBridgeService::Get()); | |
| 24 DCHECK_EQ(arc_bridge_, ArcBridgeService::Get()); | |
| 25 arc_bridge_->RemoveNotificationObserver(this); | |
| 26 } | |
| 27 | |
| 28 void ArcNotificationManager::OnNotificationPostedFromAndroid( | |
| 29 const ArcNotificationData& data) { | |
| 30 ArcNotificationItem* item = items_.get(data.key); | |
| 31 if (!item) { | |
| 32 // Show a notification on the primary loged-in user's desktop. | |
| 33 // TODO(yoshiki): Reconsider when ARC supports multi-user. | |
| 34 item = new ArcNotificationItem(this, message_center::MessageCenter::Get(), | |
| 35 data, main_profile_id_); | |
| 36 items_.set(data.key, make_scoped_ptr(item)); | |
| 37 } | |
| 38 item->UpdateWithArcNotificationData(data); | |
| 39 } | |
| 40 | |
| 41 void ArcNotificationManager::OnNotificationRemovedFromAndroid( | |
| 42 const std::string& key) { | |
| 43 Items::iterator it = items_.find(key); | |
| 44 if (it != items_.end()) { | |
| 45 scoped_ptr<ArcNotificationItem> item(items_.take_and_erase(it)); | |
| 46 | |
|
hidehiko
2015/12/22 08:51:28
nit: unnecessary an empty line?
yoshiki
2015/12/22 10:13:54
Done.
| |
| 47 item->OnClosedFromAndroid(); | |
| 48 } else { | |
| 49 VLOG(3) << "Android requests to remove a notification (key: " << key | |
| 50 << "), but it is already gone."; | |
| 51 } | |
| 52 } | |
| 53 | |
| 54 void ArcNotificationManager::SendNotificationRemovedFromChrome( | |
| 55 const std::string& key) { | |
| 56 Items::iterator it = items_.find(key); | |
| 57 if (it != items_.end()) { | |
| 58 scoped_ptr<ArcNotificationItem> item(items_.take_and_erase(it)); | |
| 59 | |
| 60 arc_bridge_->SendNotificationEventToAndroid(key, | |
| 61 ARC_NOTIFICATION_EVENT_CLOSED); | |
| 62 } else { | |
| 63 VLOG(3) << "Chrome requests to remove a notification (key: " << key | |
| 64 << "), but it is already gone."; | |
| 65 } | |
| 66 } | |
| 67 | |
| 68 void ArcNotificationManager::SendNotificationClickedOnChrome( | |
| 69 const std::string& key) { | |
| 70 if (items_.contains(key)) { | |
| 71 arc_bridge_->SendNotificationEventToAndroid( | |
| 72 key, ARC_NOTIFICATION_EVENT_BODY_CLICKED); | |
| 73 } else { | |
| 74 VLOG(3) << "Chrome requests to fire a click event on notification (key: " | |
| 75 << key << "), but it is gone."; | |
| 76 } | |
| 77 } | |
| 78 | |
| 79 } // namespace arc | |
| OLD | NEW |