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() {} | |
hidehiko
2017/06/15 15:26:21
nit: s/{}/= default;/ please for consistency. (Ple
yoshiki
2017/06/16 11:29:08
Done.
| |
17 | |
18 ArcNotificationSurfaceManagerImpl::~ArcNotificationSurfaceManagerImpl() {} | |
19 | |
20 ArcNotificationSurface* ArcNotificationSurfaceManagerImpl::GetArcSurface( | |
21 const std::string& notification_key) const { | |
22 auto it = notification_surface_map_.find(notification_key); | |
23 return it == notification_surface_map_.end() ? nullptr : it->second.get(); | |
24 } | |
25 | |
26 void ArcNotificationSurfaceManagerImpl::AddObserver(Observer* observer) { | |
27 observers_.AddObserver(observer); | |
28 } | |
29 | |
30 void ArcNotificationSurfaceManagerImpl::RemoveObserver(Observer* observer) { | |
31 observers_.RemoveObserver(observer); | |
32 } | |
33 | |
34 exo::NotificationSurface* ArcNotificationSurfaceManagerImpl::GetSurface( | |
35 const std::string& notification_key) const { | |
36 auto it = notification_surface_map_.find(notification_key); | |
hidehiko
2017/06/15 15:26:21
nit/optional: you can avoid dup code?
ArcNotificat
yoshiki
2017/06/16 11:29:08
ArcNotificationSurface class doesn't have surface(
| |
37 return it == notification_surface_map_.end() ? nullptr | |
38 : it->second->surface(); | |
39 } | |
40 | |
41 void ArcNotificationSurfaceManagerImpl::AddSurface( | |
42 exo::NotificationSurface* surface) { | |
43 if (notification_surface_map_.find(surface->notification_key()) != | |
hidehiko
2017/06/15 15:26:21
Can you use
auto result = map::insert(...);
if (!
yoshiki
2017/06/16 11:29:08
Done.
| |
44 notification_surface_map_.end()) { | |
45 NOTREACHED(); | |
46 return; | |
47 } | |
48 | |
49 notification_surface_map_[surface->notification_key()] = | |
50 base::MakeUnique<ArcNotificationSurfaceImpl>(surface); | |
51 | |
52 for (auto& observer : observers_) { | |
53 observer.OnNotificationSurfaceAdded( | |
54 notification_surface_map_[surface->notification_key()].get()); | |
hidehiko
2017/06/15 15:26:21
Let's avoid searching map repeatedly.
yoshiki
2017/06/16 11:29:09
Done.
| |
55 } | |
56 } | |
57 | |
58 void ArcNotificationSurfaceManagerImpl::RemoveSurface( | |
59 exo::NotificationSurface* surface) { | |
60 auto it = notification_surface_map_.find(surface->notification_key()); | |
61 if (it == notification_surface_map_.end()) | |
62 return; | |
63 | |
64 auto arc_surface = std::move(it->second); | |
65 notification_surface_map_.erase(it); | |
66 for (auto& observer : observers_) | |
67 observer.OnNotificationSurfaceRemoved(arc_surface.get()); | |
68 } | |
69 | |
70 } // namespace arc | |
OLD | NEW |