Chromium Code Reviews| 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 "components/exo/notification_surface_registry.h" | |
| 6 | |
| 7 #include <algorithm> | |
| 8 | |
| 9 #include "components/exo/notification_surface.h" | |
| 10 #include "ui/arc/notification/arc_notification_manager.h" | |
| 11 | |
| 12 namespace exo { | |
| 13 | |
| 14 namespace { | |
| 15 | |
| 16 base::LazyInstance<NotificationSurfaceRegistry> instance = | |
| 17 LAZY_INSTANCE_INITIALIZER; | |
| 18 | |
| 19 } // namespace | |
| 20 | |
| 21 NotificationSurfaceRegistry::NotificationSurfaceRegistry() {} | |
| 22 | |
| 23 NotificationSurfaceRegistry::~NotificationSurfaceRegistry() {} | |
| 24 | |
| 25 // static | |
| 26 NotificationSurfaceRegistry* NotificationSurfaceRegistry::Get() { | |
| 27 return instance.Pointer(); | |
| 28 } | |
| 29 | |
| 30 NotificationSurface* NotificationSurfaceRegistry::GetSurface( | |
| 31 const std::string& notification_key) const { | |
| 32 auto it = notification_surface_map_.find(notification_key); | |
| 33 return it == notification_surface_map_.end() ? nullptr : it->second; | |
| 34 } | |
| 35 | |
| 36 void NotificationSurfaceRegistry::AddSurface(NotificationSurface* surface) { | |
| 37 DCHECK(notification_surface_map_.find(surface->notification_id()) == | |
|
reveman
2016/06/16 03:35:20
Can a client cause this to fail? That would be a s
xiyuan
2016/06/20 22:40:29
Do the check when processing the request. Client s
| |
| 38 notification_surface_map_.end()); | |
| 39 | |
| 40 notification_surface_map_[surface->notification_id()] = surface; | |
| 41 | |
| 42 FOR_EACH_OBSERVER(Observer, observers_, OnNotificationSurfaceAdded(surface)); | |
| 43 } | |
| 44 | |
| 45 void NotificationSurfaceRegistry::RemoveSurface(NotificationSurface* surface) { | |
| 46 auto it = notification_surface_map_.find(surface->notification_id()); | |
| 47 if (it == notification_surface_map_.end()) | |
| 48 return; | |
| 49 | |
| 50 notification_surface_map_.erase(it); | |
| 51 FOR_EACH_OBSERVER(Observer, observers_, | |
| 52 OnNotificationSurfaceRemoved(surface)); | |
| 53 } | |
| 54 | |
| 55 void NotificationSurfaceRegistry::AddObserver(Observer* observer) { | |
| 56 observers_.AddObserver(observer); | |
| 57 } | |
| 58 | |
| 59 void NotificationSurfaceRegistry::RemoveObserver(Observer* observer) { | |
| 60 observers_.RemoveObserver(observer); | |
| 61 } | |
| 62 | |
| 63 } // namespace exo | |
| OLD | NEW |