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

Unified Diff: components/exo/notification_surface_registry.h

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.h
diff --git a/components/exo/notification_surface_registry.h b/components/exo/notification_surface_registry.h
new file mode 100644
index 0000000000000000000000000000000000000000..b4d204d714f25bdb680bc0ab6f68443c4c8c539f
--- /dev/null
+++ b/components/exo/notification_surface_registry.h
@@ -0,0 +1,61 @@
+// 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.
+
+#ifndef COMPONENTS_EXO_NOTIFICATION_SURFACE_REGISTRY_H_
+#define COMPONENTS_EXO_NOTIFICATION_SURFACE_REGISTRY_H_
+
+#include <map>
+#include <string>
+
+#include "base/lazy_instance.h"
+#include "base/macros.h"
+#include "base/observer_list.h"
+
+namespace exo {
+
+class NotificationSurface;
+
+// Keeps track of NotificationSurface.
+class NotificationSurfaceRegistry {
reveman 2016/06/16 03:35:20 I'd like to avoid this class if possible. So far c
xiyuan 2016/06/20 22:40:29 Unfortunately, we cannot avoid this class. We can
+ public:
+ class Observer {
+ public:
+ // Invoked when a notification surface is added to the registry.
+ virtual void OnNotificationSurfaceAdded(NotificationSurface* surface) = 0;
+
+ // Invoked when a notification surface is removed from the registry.
+ virtual void OnNotificationSurfaceRemoved(NotificationSurface* surface) = 0;
+
+ protected:
+ virtual ~Observer() = default;
+ };
+
+ static NotificationSurfaceRegistry* Get();
+
+ NotificationSurface* GetSurface(const std::string& notification_key) const;
+
+ void AddSurface(NotificationSurface* surface);
+ void RemoveSurface(NotificationSurface* surface);
+
+ void AddObserver(Observer* observer);
+ void RemoveObserver(Observer* observer);
+
+ private:
+ friend struct base::DefaultLazyInstanceTraits<NotificationSurfaceRegistry>;
+
+ NotificationSurfaceRegistry();
+ ~NotificationSurfaceRegistry();
+
+ using NotificationSurfaceMap =
+ std::map<std::string, exo::NotificationSurface*>;
+ NotificationSurfaceMap notification_surface_map_;
+
+ base::ObserverList<Observer> observers_;
+
+ DISALLOW_COPY_AND_ASSIGN(NotificationSurfaceRegistry);
+};
+
+} // namespace exo
+
+#endif // COMPONENTS_EXO_NOTIFICATION_SURFACE_REGISTRY_H_

Powered by Google App Engine
This is Rietveld 408576698