OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/arc/notification/arc_notification_surface_manager.h" | 5 #include "ui/arc/notification/arc_notification_surface_manager.h" |
6 | 6 |
7 #include <algorithm> | |
8 | |
9 #include "components/exo/notification_surface.h" | |
10 | |
11 namespace arc { | 7 namespace arc { |
12 | 8 |
13 namespace { | 9 // static |
14 | 10 ArcNotificationSurfaceManager* ArcNotificationSurfaceManager::instance_ = |
15 ArcNotificationSurfaceManager* instance = nullptr; | 11 nullptr; |
16 | |
17 } // namespace | |
18 | 12 |
19 ArcNotificationSurfaceManager::ArcNotificationSurfaceManager() { | 13 ArcNotificationSurfaceManager::ArcNotificationSurfaceManager() { |
20 DCHECK(!instance); | 14 DCHECK(!instance_); |
21 instance = this; | 15 instance_ = this; |
22 } | 16 } |
23 | 17 |
24 ArcNotificationSurfaceManager::~ArcNotificationSurfaceManager() { | 18 ArcNotificationSurfaceManager::~ArcNotificationSurfaceManager() { |
25 DCHECK_EQ(this, instance); | 19 DCHECK_EQ(this, instance_); |
26 instance = nullptr; | 20 instance_ = nullptr; |
27 } | 21 } |
28 | 22 |
29 // static | 23 // static |
30 ArcNotificationSurfaceManager* ArcNotificationSurfaceManager::Get() { | 24 ArcNotificationSurfaceManager* ArcNotificationSurfaceManager::Get() { |
31 return instance; | 25 return instance_; |
32 } | |
33 | |
34 exo::NotificationSurface* ArcNotificationSurfaceManager::GetSurface( | |
35 const std::string& notification_key) const { | |
36 auto it = notification_surface_map_.find(notification_key); | |
37 return it == notification_surface_map_.end() ? nullptr : it->second; | |
38 } | |
39 | |
40 void ArcNotificationSurfaceManager::AddSurface( | |
41 exo::NotificationSurface* surface) { | |
42 if (notification_surface_map_.find(surface->notification_id()) != | |
43 notification_surface_map_.end()) { | |
44 NOTREACHED(); | |
45 return; | |
46 } | |
47 | |
48 notification_surface_map_[surface->notification_id()] = surface; | |
49 | |
50 for (auto& observer : observers_) | |
51 observer.OnNotificationSurfaceAdded(surface); | |
52 } | |
53 | |
54 void ArcNotificationSurfaceManager::RemoveSurface( | |
55 exo::NotificationSurface* surface) { | |
56 auto it = notification_surface_map_.find(surface->notification_id()); | |
57 if (it == notification_surface_map_.end()) | |
58 return; | |
59 | |
60 notification_surface_map_.erase(it); | |
61 for (auto& observer : observers_) | |
62 observer.OnNotificationSurfaceRemoved(surface); | |
63 } | |
64 | |
65 void ArcNotificationSurfaceManager::AddObserver(Observer* observer) { | |
66 observers_.AddObserver(observer); | |
67 } | |
68 | |
69 void ArcNotificationSurfaceManager::RemoveObserver(Observer* observer) { | |
70 observers_.RemoveObserver(observer); | |
71 } | 26 } |
72 | 27 |
73 } // namespace arc | 28 } // namespace arc |
OLD | NEW |