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..a0758a85e90d6f7af139e9c05ccd4d113dfb882b |
| --- /dev/null |
| +++ b/components/arc/notification/arc_notification_manager.cc |
| @@ -0,0 +1,79 @@ |
| +// 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. |
| + item = new ArcNotificationItem(this, message_center::MessageCenter::Get(), |
| + data, main_profile_id_); |
| + items_.set(data.key, make_scoped_ptr(item)); |
| + } |
| + 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)); |
| + |
|
hidehiko
2015/12/22 08:51:28
nit: unnecessary an empty line?
yoshiki
2015/12/22 10:13:54
Done.
|
| + 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)); |
| + |
| + arc_bridge_->SendNotificationEventToAndroid(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)) { |
| + arc_bridge_->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 arc |