OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2017 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 #include "ui/arc/notification/arc_notification_surface_manager_impl.h" | |
6 | |
7 #include <string> | |
8 #include <utility> | |
9 | |
10 #include "base/memory/ptr_util.h" | |
11 #include "components/exo/notification_surface.h" | |
12 #include "ui/arc/notification/arc_notification_surface_impl.h" | |
13 | |
14 namespace arc { | |
15 | |
16 ArcNotificationSurfaceManagerImpl::ArcNotificationSurfaceManagerImpl() = | |
17 default; | |
18 | |
19 ArcNotificationSurfaceManagerImpl::~ArcNotificationSurfaceManagerImpl() = | |
20 default; | |
21 | |
22 ArcNotificationSurface* ArcNotificationSurfaceManagerImpl::GetArcSurface( | |
23 const std::string& notification_key) const { | |
24 auto it = notification_surface_map_.find(notification_key); | |
25 return it == notification_surface_map_.end() ? nullptr : it->second.get(); | |
26 } | |
27 | |
28 void ArcNotificationSurfaceManagerImpl::AddObserver(Observer* observer) { | |
29 observers_.AddObserver(observer); | |
30 } | |
31 | |
32 void ArcNotificationSurfaceManagerImpl::RemoveObserver(Observer* observer) { | |
33 observers_.RemoveObserver(observer); | |
34 } | |
35 | |
36 exo::NotificationSurface* ArcNotificationSurfaceManagerImpl::GetSurface( | |
37 const std::string& notification_key) const { | |
38 auto it = notification_surface_map_.find(notification_key); | |
39 return it == notification_surface_map_.end() ? nullptr | |
40 : it->second->surface(); | |
41 } | |
42 | |
43 void ArcNotificationSurfaceManagerImpl::AddSurface( | |
44 exo::NotificationSurface* surface) { | |
45 auto result = notification_surface_map_.insert( | |
46 std::pair<std::string, std::unique_ptr<ArcNotificationSurfaceImpl>>( | |
47 surface->notification_key(), | |
48 base::MakeUnique<ArcNotificationSurfaceImpl>(surface))); | |
49 if (!result.second) { | |
50 NOTREACHED(); | |
51 return; | |
52 } | |
53 | |
54 for (auto& observer : observers_) { | |
hidehiko
2017/06/18 17:44:05
Please elide braces for one line body statement.
yoshiki
2017/06/19 09:09:02
Done.
| |
55 observer.OnNotificationSurfaceAdded(result.first->second.get()); | |
56 } | |
57 } | |
58 | |
59 void ArcNotificationSurfaceManagerImpl::RemoveSurface( | |
60 exo::NotificationSurface* surface) { | |
61 auto it = notification_surface_map_.find(surface->notification_key()); | |
62 if (it == notification_surface_map_.end()) | |
63 return; | |
64 | |
65 auto arc_surface = std::move(it->second); | |
66 notification_surface_map_.erase(it); | |
67 for (auto& observer : observers_) | |
68 observer.OnNotificationSurfaceRemoved(arc_surface.get()); | |
69 } | |
70 | |
71 } // namespace arc | |
OLD | NEW |