Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(35)

Unified Diff: components/exo/notification_surface_registry.cc

Issue 2065133002: exo: Implement notification surface support (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@notification-wayland-protocol
Patch Set: add NotificationServiceRegistry to track notification surface Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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

Powered by Google App Engine
This is Rietveld 408576698