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 #include "ui/arc/notification/arc_notification_surface_manager_impl.h" |
| 6 |
| 7 #include <algorithm> |
| 8 |
| 9 #include "base/memory/ptr_util.h" |
| 10 #include "components/exo/notification_surface.h" |
| 11 #include "ui/arc/notification/arc_notification_surface_impl.h" |
| 12 |
| 13 namespace arc { |
| 14 |
| 15 ArcNotificationSurfaceManagerImpl::ArcNotificationSurfaceManagerImpl() {} |
| 16 |
| 17 ArcNotificationSurfaceManagerImpl::~ArcNotificationSurfaceManagerImpl() {} |
| 18 |
| 19 ArcNotificationSurface* ArcNotificationSurfaceManagerImpl::GetArcSurface( |
| 20 const std::string& notification_key) const { |
| 21 auto it = notification_surface_map_.find(notification_key); |
| 22 return it == notification_surface_map_.end() ? nullptr : it->second.get(); |
| 23 } |
| 24 |
| 25 void ArcNotificationSurfaceManagerImpl::AddObserver(Observer* observer) { |
| 26 observers_.AddObserver(observer); |
| 27 } |
| 28 |
| 29 void ArcNotificationSurfaceManagerImpl::RemoveObserver(Observer* observer) { |
| 30 observers_.RemoveObserver(observer); |
| 31 } |
| 32 |
| 33 exo::NotificationSurface* ArcNotificationSurfaceManagerImpl::GetSurface( |
| 34 const std::string& notification_key) const { |
| 35 auto it = notification_surface_map_.find(notification_key); |
| 36 return it == notification_surface_map_.end() ? nullptr |
| 37 : it->second->surface(); |
| 38 } |
| 39 |
| 40 void ArcNotificationSurfaceManagerImpl::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()] = |
| 49 base::MakeUnique<ArcNotificationSurfaceImpl>(surface); |
| 50 |
| 51 for (auto& observer : observers_) { |
| 52 observer.OnNotificationSurfaceAdded( |
| 53 notification_surface_map_[surface->notification_id()].get()); |
| 54 } |
| 55 } |
| 56 |
| 57 void ArcNotificationSurfaceManagerImpl::RemoveSurface( |
| 58 exo::NotificationSurface* surface) { |
| 59 auto it = notification_surface_map_.find(surface->notification_id()); |
| 60 if (it == notification_surface_map_.end()) |
| 61 return; |
| 62 |
| 63 auto arc_surface = std::move(it->second); |
| 64 notification_surface_map_.erase(it); |
| 65 for (auto& observer : observers_) |
| 66 observer.OnNotificationSurfaceRemoved(arc_surface.get()); |
| 67 } |
| 68 |
| 69 } // namespace arc |
OLD | NEW |