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..ba2fa90f2b199a2eb55d675f8a6e1acdcd372875 |
--- /dev/null |
+++ b/chrome/browser/chromeos/arc/notification/arc_notification_manager.cc |
@@ -0,0 +1,85 @@ |
+// 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_bridge_); |
+ DCHECK_EQ(arc_bridge_, arc::ArcBridgeService::Get()); |
+ arc_bridge_->AddNotificationObserver(this); |
+} |
+ |
+ArcNotificationManager::~ArcNotificationManager() { |
+ STLDeleteValues(&items_); |
+ // 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_.find(data.key) == items_.end()) { |
+ // Show a notification on the primary loged-in user's desktop. |
+ // TODO(yoshiki): Reconsider when ARC supports multi-user. |
+ ArcNotificationItem* item = new ArcNotificationItem( |
+ this, g_browser_process->message_center(), data, main_profile_); |
+ items_.insert(std::make_pair(data.key, item)); |
hidehiko
2015/12/11 05:18:00
emplace?
yoshiki
2015/12/14 15:19:30
I changed std::map to ScopedPtrHashMap and use set
|
+ } else { |
+ items_[data.key]->UpdateWithArcNotificationData(data); |
+ } |
+} |
+ |
+void ArcNotificationManager::OnNotificationRemovedFromAndroid( |
+ const std::string& key) { |
+ Items::iterator it = items_.find(key); |
+ if (it != items_.end()) { |
+ ArcNotificationItem* item = it->second; |
hidehiko
2015/12/11 05:18:00
Let's use scoped_ptr.
yoshiki
2015/12/14 15:19:30
Done.
|
+ items_.erase(it); |
+ |
+ item->OnClosedFromAndroid(); |
+ delete item; |
+ } 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 |
+ // the notification on Chrome UI. |
+ |
+ Items::iterator it = items_.find(key); |
+ if (it != items_.end()) { |
+ ArcNotificationItem* item = it->second; |
hidehiko
2015/12/11 05:18:00
Ditto.
yoshiki
2015/12/14 15:19:30
Done.
|
+ items_.erase(it); |
+ |
+ arc::ArcBridgeService::Get()->SendNotificationEventToAndroid( |
+ key, arc::ARC_NOTIFICATION_EVENT_CLOSED); |
+ delete item; |
+ } |
+} |
+ |
+void ArcNotificationManager::SendNotificationClickedOnChrome( |
+ const std::string& key) { |
+ Items::iterator it = items_.find(key); |
+ if (it != items_.end()) { |
+ arc::ArcBridgeService::Get()->SendNotificationEventToAndroid( |
+ key, arc::ARC_NOTIFICATION_EVENT_BODY_CLICKED); |
+ } |
+} |
+ |
+} // namespace chromeos |