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..73dbe6f817ac35b1d97154f7bdd5caf420573769 |
| --- /dev/null |
| +++ b/components/arc/notification/arc_notification_manager.cc |
| @@ -0,0 +1,77 @@ |
| +// 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( |
| + arc::ArcBridgeService* arc_bridge, |
|
hidehiko
2015/12/17 07:47:51
Maybe, it's time to remove "arc::" from this CL :-
yoshiki
2015/12/17 19:15:14
Done.
|
| + 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_, arc::ArcBridgeService::Get()); |
| + arc_bridge_->AddNotificationObserver(this); |
| +} |
| + |
| +ArcNotificationManager::~ArcNotificationManager() { |
| + // This should be free'd before ArcBridgeService. |
| + DCHECK(arc::ArcBridgeService::Get()); |
| + DCHECK_EQ(arc_bridge_, arc::ArcBridgeService::Get()); |
| + arc_bridge_->RemoveNotificationObserver(this); |
| +} |
| + |
| +void ArcNotificationManager::OnNotificationPostedFromAndroid( |
| + const arc::ArcNotificationData& data) { |
| + if (items_.get(data.key) == nullptr) { |
|
hidehiko
2015/12/17 07:47:51
nit: contains()?
Or, if you do not want to search
yoshiki
2015/12/17 19:15:14
Done.
|
| + // 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()); |
| + } |
| + items_.get(data.key)->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 requested to remove a notification (key: " << key |
| + << "), but it is already gone."; |
| + } |
| +} |
| + |
| +void ArcNotificationManager::SendNotificationRemovedFromChrome( |
| + const std::string& key) { |
| + // Note: This method may be also called by ArcNotificationItem during |
| + // OnNotificationRemovedFromAndroid(), since that method should removes |
|
elijahtaylor1
2015/12/16 02:34:37
s/removes/remove
yoshiki
2015/12/17 19:15:14
Thanks, but I removed the comment.
|
| + // the notification on Chrome UI. |
|
elijahtaylor1
2015/12/16 02:34:37
s/on/in
|
| + |
| + Items::iterator it = items_.find(key); |
| + if (it != items_.end()) { |
| + scoped_ptr<ArcNotificationItem> item(items_.take_and_erase(it)); |
| + |
| + arc::ArcBridgeService::Get()->SendNotificationEventToAndroid( |
| + key, arc::ARC_NOTIFICATION_EVENT_CLOSED); |
| + } |
|
hidehiko
2015/12/17 07:47:51
nit: maybe logging on error?
yoshiki
2015/12/17 19:15:14
Done. And to make the logging code simpler, I adde
|
| +} |
| + |
| +void ArcNotificationManager::SendNotificationClickedOnChrome( |
| + const std::string& key) { |
| + if (items_.contains(key)) { |
| + arc::ArcBridgeService::Get()->SendNotificationEventToAndroid( |
| + key, arc::ARC_NOTIFICATION_EVENT_BODY_CLICKED); |
| + } |
|
hidehiko
2015/12/17 07:47:51
Ditto.
yoshiki
2015/12/17 19:15:14
Done.
|
| +} |
| + |
| +} // namespace components |