Index: ui/arc/notification/arc_notification_surface_manager.cc |
diff --git a/ui/arc/notification/arc_notification_surface_manager.cc b/ui/arc/notification/arc_notification_surface_manager.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..d816da8a234891c50acc7f88446cccabfb03685f |
--- /dev/null |
+++ b/ui/arc/notification/arc_notification_surface_manager.cc |
@@ -0,0 +1,72 @@ |
+// Copyright 2016 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 "ui/arc/notification/arc_notification_surface_manager.h" |
+ |
+#include <algorithm> |
+ |
+#include "components/exo/notification_surface.h" |
+ |
+namespace arc { |
+ |
+namespace { |
+ |
+ArcNotificationSurfaceManager* instance = nullptr; |
+ |
+} // namespace |
+ |
+ArcNotificationSurfaceManager::ArcNotificationSurfaceManager() { |
+ DCHECK(!instance); |
+ instance = this; |
+} |
+ |
+ArcNotificationSurfaceManager::~ArcNotificationSurfaceManager() { |
+ DCHECK_EQ(this, instance); |
+ instance = nullptr; |
+} |
+ |
+// static |
+ArcNotificationSurfaceManager* ArcNotificationSurfaceManager::Get() { |
+ return instance; |
+} |
+ |
+exo::NotificationSurface* ArcNotificationSurfaceManager::GetSurface( |
+ const std::string& notification_key) const { |
+ auto it = notification_surface_map_.find(notification_key); |
+ return it == notification_surface_map_.end() ? nullptr : it->second; |
+} |
+ |
+void ArcNotificationSurfaceManager::AddSurface( |
+ exo::NotificationSurface* surface) { |
+ if (notification_surface_map_.find(surface->notification_id()) != |
+ notification_surface_map_.end()) { |
+ NOTREACHED(); |
+ return; |
+ } |
+ |
+ notification_surface_map_[surface->notification_id()] = surface; |
+ |
+ FOR_EACH_OBSERVER(Observer, observers_, OnNotificationSurfaceAdded(surface)); |
+} |
+ |
+void ArcNotificationSurfaceManager::RemoveSurface( |
+ exo::NotificationSurface* surface) { |
+ auto it = notification_surface_map_.find(surface->notification_id()); |
+ if (it == notification_surface_map_.end()) |
+ return; |
+ |
+ notification_surface_map_.erase(it); |
+ FOR_EACH_OBSERVER(Observer, observers_, |
+ OnNotificationSurfaceRemoved(surface)); |
+} |
+ |
+void ArcNotificationSurfaceManager::AddObserver(Observer* observer) { |
+ observers_.AddObserver(observer); |
+} |
+ |
+void ArcNotificationSurfaceManager::RemoveObserver(Observer* observer) { |
+ observers_.RemoveObserver(observer); |
+} |
+ |
+} // namespace arc |