Chromium Code Reviews| Index: components/arc/notification/arc_notification_manager.cc |
| diff --git a/components/arc/notification/arc_notification_manager.cc b/components/arc/notification/arc_notification_manager.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..4850f9873b2a18eb3ea5035a2568e7ae9f784174 |
| --- /dev/null |
| +++ b/components/arc/notification/arc_notification_manager.cc |
| @@ -0,0 +1,80 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "components/arc/notification/arc_notification_manager.h" |
| + |
| +#include "base/stl_util.h" |
| +#include "components/arc/notification/arc_notification_item.h" |
| + |
| +namespace arc { |
| + |
| +ArcNotificationManager::ArcNotificationManager( |
| + ArcBridgeService* arc_bridge, |
| + const AccountId& main_profile_id) |
| + : arc_bridge_(arc_bridge), main_profile_id_(main_profile_id) { |
| + // This must be initialized after ArcBridgeService. |
| + DCHECK(arc_bridge_); |
| + DCHECK_EQ(arc_bridge_, ArcBridgeService::Get()); |
| + arc_bridge_->AddNotificationObserver(this); |
| +} |
| + |
| +ArcNotificationManager::~ArcNotificationManager() { |
| + // This should be free'd before ArcBridgeService. |
| + DCHECK(ArcBridgeService::Get()); |
| + DCHECK_EQ(arc_bridge_, ArcBridgeService::Get()); |
| + arc_bridge_->RemoveNotificationObserver(this); |
| +} |
| + |
| +void ArcNotificationManager::OnNotificationPostedFromAndroid( |
| + const ArcNotificationData& data) { |
| + ArcNotificationItem* item = items_.get(data.key); |
| + if (!item) { |
| + // Show a notification on the primary loged-in user's desktop. |
| + // TODO(yoshiki): Reconsider when ARC supports multi-user. |
| + scoped_ptr<ArcNotificationItem> item(new ArcNotificationItem( |
| + this, message_center::MessageCenter::Get(), data, main_profile_id_)); |
| + items_.set(data.key, item.Pass()); |
| + } |
| + item->UpdateWithArcNotificationData(data); |
| +} |
| + |
| +void ArcNotificationManager::OnNotificationRemovedFromAndroid( |
| + const std::string& key) { |
| + Items::iterator it = items_.find(key); |
| + if (it != items_.end()) { |
| + scoped_ptr<ArcNotificationItem> item(items_.take_and_erase(it)); |
| + |
| + item->OnClosedFromAndroid(); |
| + } else { |
| + VLOG(3) << "Android requests to remove a notification (key: " << key |
| + << "), but it is already gone."; |
| + } |
| +} |
| + |
| +void ArcNotificationManager::SendNotificationRemovedFromChrome( |
| + const std::string& key) { |
| + Items::iterator it = items_.find(key); |
| + if (it != items_.end()) { |
| + scoped_ptr<ArcNotificationItem> item(items_.take_and_erase(it)); |
| + |
| + ArcBridgeService::Get()->SendNotificationEventToAndroid( |
|
Luis Héctor Chávez
2015/12/17 22:49:50
You already have |arc_bridge_|, any reason why you
yoshiki
2015/12/21 19:23:00
Done.
|
| + key, ARC_NOTIFICATION_EVENT_CLOSED); |
| + } else { |
| + VLOG(3) << "Chrome requests to remove a notification (key: " << key |
| + << "), but it is already gone."; |
| + } |
| +} |
| + |
| +void ArcNotificationManager::SendNotificationClickedOnChrome( |
| + const std::string& key) { |
| + if (items_.contains(key)) { |
| + ArcBridgeService::Get()->SendNotificationEventToAndroid( |
| + key, ARC_NOTIFICATION_EVENT_BODY_CLICKED); |
| + } else { |
| + VLOG(3) << "Chrome requests to fire a click event on notification (key: " |
| + << key << "), but it is gone."; |
| + } |
| +} |
| + |
| +} // namespace components |
|
Luis Héctor Chávez
2015/12/17 23:11:42
nit: namespace arc.
|