Chromium Code Reviews| Index: chrome/browser/chromeos/arc/notification/arc_notification_manager.cc |
| diff --git a/chrome/browser/chromeos/arc/notification/arc_notification_manager.cc b/chrome/browser/chromeos/arc/notification/arc_notification_manager.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..135d0eabc8535036c45eb9d771920e2232cfbd0a |
| --- /dev/null |
| +++ b/chrome/browser/chromeos/arc/notification/arc_notification_manager.cc |
| @@ -0,0 +1,81 @@ |
| +// 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 "chrome/browser/chromeos/arc/notification/arc_notification_manager.h" |
| + |
| +#include "base/stl_util.h" |
| +#include "chrome/browser/browser_process.h" |
| +#include "chrome/browser/chromeos/arc/notification/arc_notification_item.h" |
| + |
| +namespace chromeos { |
| + |
| +ArcNotificationManager::ArcNotificationManager( |
| + arc::ArcBridgeService* arc_bridge, |
| + Profile* main_profile) |
| + : arc_bridge_(arc_bridge), main_profile_(main_profile) { |
| + // This must be initialized after ArcBridgeService. |
| + DCHECK(arc::ArcBridgeService::Get()); |
|
elijahtaylor1
2015/12/09 06:41:25
comments on https://codereview.chromium.org/149572
yoshiki
2015/12/09 17:11:09
I want to ensure that this is initialized after th
|
| + DCHECK_EQ(arc_bridge_, arc::ArcBridgeService::Get()); |
| + arc_bridge_->AddNotificationObserver(this); |
| +} |
| + |
| +ArcNotificationManager::~ArcNotificationManager() { |
| + STLDeleteValues(&items_); |
| + // This should be free'd before ArcBridgeService. |
|
elijahtaylor1
2015/12/09 06:41:26
is this actually guaranteed?
yoshiki
2015/12/09 17:11:09
It's guaranteed in the definition order in chrome_
|
| + DCHECK(arc::ArcBridgeService::Get()); |
| + DCHECK_EQ(arc_bridge_, arc::ArcBridgeService::Get()); |
| + arc_bridge_->RemoveNotificationObserver(this); |
| +} |
| + |
| +void ArcNotificationManager::OnNotificationPostedFromAndroid( |
| + const arc::ArcNotificationData& data) { |
| + // Show a notification on the main user's desktop as for now. |
| + // TODO(yoshiki): Consider multi-user. |
|
elijahtaylor1
2015/12/09 06:41:26
I don't know how multi-user works but I would assu
yoshiki
2015/12/09 17:11:09
I meant that "multi-user" is simultaneous multi-us
|
| + ArcNotificationItem* item = new ArcNotificationItem( |
| + this, g_browser_process->message_center(), data, main_profile_); |
| + items_.insert(make_pair(data.key, item)); |
| +} |
| + |
| +void ArcNotificationManager::OnNotificationRemovedFromAndroid( |
| + const std::string& key) { |
| + Items::iterator it = items_.find(key); |
| + if (it != items_.end()) { |
| + ArcNotificationItem* item = it->second; |
| + items_.erase(it); |
| + |
| + item->OnClosedFromAndroid(); |
| + delete item; |
| + } else { |
| + VLOG(3) << "Android requested to remove the notification (key: " << key |
|
elijahtaylor1
2015/12/09 06:41:25
s/the/a/
yoshiki
2015/12/09 17:11:09
Done.
|
| + << "), but it has already gone."; |
|
elijahtaylor1
2015/12/09 06:41:26
s/has/is/
yoshiki
2015/12/09 17:11:09
Done.
|
| + } |
| +} |
| + |
| +void ArcNotificationManager::NotifyNotificationRemovedFromChrome( |
| + const std::string& key) { |
| + // Note: This method may be also called by ArcNotificationItem during |
| + // OnNotificationRemovedFromAndroid(), since that method should removes |
| + // the notification on Chrome UI. |
| + |
| + Items::iterator it = items_.find(key); |
| + if (it != items_.end()) { |
| + ArcNotificationItem* item = it->second; |
| + items_.erase(it); |
| + |
| + arc::ArcBridgeService::Get()->SendNotificationEventToAndroid( |
| + key, arc::ArcNotificationEvent::CLOSED); |
| + delete item; |
| + } |
| +} |
| + |
| +void ArcNotificationManager::NotifyNotificationClickedFromChrome( |
| + const std::string& key) { |
| + Items::iterator it = items_.find(key); |
| + if (it != items_.end()) { |
| + arc::ArcBridgeService::Get()->SendNotificationEventToAndroid( |
| + key, arc::ArcNotificationEvent::BODY_CLICKED); |
| + } |
| +} |
| + |
| +} // namespace chromeos |