OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef COMPONENTS_EXO_NOTIFICATION_SURFACE_REGISTRY_H_ | |
6 #define COMPONENTS_EXO_NOTIFICATION_SURFACE_REGISTRY_H_ | |
7 | |
8 #include <map> | |
9 #include <string> | |
10 | |
11 #include "base/lazy_instance.h" | |
12 #include "base/macros.h" | |
13 #include "base/observer_list.h" | |
14 | |
15 namespace exo { | |
16 | |
17 class NotificationSurface; | |
18 | |
19 // Keeps track of NotificationSurface. | |
20 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
| |
21 public: | |
22 class Observer { | |
23 public: | |
24 // Invoked when a notification surface is added to the registry. | |
25 virtual void OnNotificationSurfaceAdded(NotificationSurface* surface) = 0; | |
26 | |
27 // Invoked when a notification surface is removed from the registry. | |
28 virtual void OnNotificationSurfaceRemoved(NotificationSurface* surface) = 0; | |
29 | |
30 protected: | |
31 virtual ~Observer() = default; | |
32 }; | |
33 | |
34 static NotificationSurfaceRegistry* Get(); | |
35 | |
36 NotificationSurface* GetSurface(const std::string& notification_key) const; | |
37 | |
38 void AddSurface(NotificationSurface* surface); | |
39 void RemoveSurface(NotificationSurface* surface); | |
40 | |
41 void AddObserver(Observer* observer); | |
42 void RemoveObserver(Observer* observer); | |
43 | |
44 private: | |
45 friend struct base::DefaultLazyInstanceTraits<NotificationSurfaceRegistry>; | |
46 | |
47 NotificationSurfaceRegistry(); | |
48 ~NotificationSurfaceRegistry(); | |
49 | |
50 using NotificationSurfaceMap = | |
51 std::map<std::string, exo::NotificationSurface*>; | |
52 NotificationSurfaceMap notification_surface_map_; | |
53 | |
54 base::ObserverList<Observer> observers_; | |
55 | |
56 DISALLOW_COPY_AND_ASSIGN(NotificationSurfaceRegistry); | |
57 }; | |
58 | |
59 } // namespace exo | |
60 | |
61 #endif // COMPONENTS_EXO_NOTIFICATION_SURFACE_REGISTRY_H_ | |
OLD | NEW |