Index: components/exo/notification_surface_registry.cc |
diff --git a/components/exo/notification_surface_registry.cc b/components/exo/notification_surface_registry.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..0fffd5eede28429a17bd224d8f3be64bc67e4d12 |
--- /dev/null |
+++ b/components/exo/notification_surface_registry.cc |
@@ -0,0 +1,63 @@ |
+// 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 "components/exo/notification_surface_registry.h" |
+ |
+#include <algorithm> |
+ |
+#include "components/exo/notification_surface.h" |
+#include "ui/arc/notification/arc_notification_manager.h" |
+ |
+namespace exo { |
+ |
+namespace { |
+ |
+base::LazyInstance<NotificationSurfaceRegistry> instance = |
+ LAZY_INSTANCE_INITIALIZER; |
+ |
+} // namespace |
+ |
+NotificationSurfaceRegistry::NotificationSurfaceRegistry() {} |
+ |
+NotificationSurfaceRegistry::~NotificationSurfaceRegistry() {} |
+ |
+// static |
+NotificationSurfaceRegistry* NotificationSurfaceRegistry::Get() { |
+ return instance.Pointer(); |
+} |
+ |
+NotificationSurface* NotificationSurfaceRegistry::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 NotificationSurfaceRegistry::AddSurface(NotificationSurface* surface) { |
+ DCHECK(notification_surface_map_.find(surface->notification_id()) == |
reveman
2016/06/16 03:35:20
Can a client cause this to fail? That would be a s
xiyuan
2016/06/20 22:40:29
Do the check when processing the request. Client s
|
+ notification_surface_map_.end()); |
+ |
+ notification_surface_map_[surface->notification_id()] = surface; |
+ |
+ FOR_EACH_OBSERVER(Observer, observers_, OnNotificationSurfaceAdded(surface)); |
+} |
+ |
+void NotificationSurfaceRegistry::RemoveSurface(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 NotificationSurfaceRegistry::AddObserver(Observer* observer) { |
+ observers_.AddObserver(observer); |
+} |
+ |
+void NotificationSurfaceRegistry::RemoveObserver(Observer* observer) { |
+ observers_.RemoveObserver(observer); |
+} |
+ |
+} // namespace exo |