| 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> | 7 #include "base/logging.h" |
| 8 | |
| 9 #include "components/exo/notification_surface.h" | |
| 10 | 8 |
| 11 namespace arc { | 9 namespace arc { |
| 12 | 10 |
| 13 namespace { | 11 // static |
| 14 | 12 ArcNotificationSurfaceManager* ArcNotificationSurfaceManager::instance_ = |
| 15 ArcNotificationSurfaceManager* instance = nullptr; | 13 nullptr; |
| 16 | |
| 17 } // namespace | |
| 18 | 14 |
| 19 ArcNotificationSurfaceManager::ArcNotificationSurfaceManager() { | 15 ArcNotificationSurfaceManager::ArcNotificationSurfaceManager() { |
| 20 DCHECK(!instance); | 16 DCHECK(!instance_); |
| 21 instance = this; | 17 instance_ = this; |
| 22 } | 18 } |
| 23 | 19 |
| 24 ArcNotificationSurfaceManager::~ArcNotificationSurfaceManager() { | 20 ArcNotificationSurfaceManager::~ArcNotificationSurfaceManager() { |
| 25 DCHECK_EQ(this, instance); | 21 DCHECK_EQ(this, instance_); |
| 26 instance = nullptr; | 22 instance_ = nullptr; |
| 27 } | 23 } |
| 28 | 24 |
| 29 // static | 25 // static |
| 30 ArcNotificationSurfaceManager* ArcNotificationSurfaceManager::Get() { | 26 ArcNotificationSurfaceManager* ArcNotificationSurfaceManager::Get() { |
| 31 return instance; | 27 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_key()) != | |
| 43 notification_surface_map_.end()) { | |
| 44 NOTREACHED(); | |
| 45 return; | |
| 46 } | |
| 47 | |
| 48 notification_surface_map_[surface->notification_key()] = 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_key()); | |
| 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 } | 28 } |
| 72 | 29 |
| 73 } // namespace arc | 30 } // namespace arc |
| OLD | NEW |