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 "ui/arc/notification/arc_notification_surface_collection.h" | |
| 6 | |
| 7 #include <algorithm> | |
| 8 | |
| 9 #include "components/exo/display.h" | |
| 10 #include "components/exo/notification_surface.h" | |
| 11 #include "ui/arc/notification/arc_notification_manager.h" | |
| 12 | |
| 13 namespace arc { | |
| 14 | |
| 15 ArcNotificationSurfaceCollection::ArcNotificationSurfaceCollection() { | |
|
yoshiki
2016/06/15 11:47:20
Can we ensure that no notification surface is adde
xiyuan
2016/06/15 19:32:44
This is created with ArcNotificationManager when w
| |
| 16 exo::Display::GetInstance()->AddObserver(this); | |
| 17 } | |
| 18 | |
| 19 ArcNotificationSurfaceCollection::~ArcNotificationSurfaceCollection() { | |
| 20 exo::Display::GetInstance()->RemoveObserver(this); | |
| 21 for (auto& entry : notification_surface_map_) | |
| 22 entry.second->RemoveObserver(this); | |
| 23 } | |
| 24 | |
| 25 exo::NotificationSurface* ArcNotificationSurfaceCollection::GetSurface( | |
| 26 const std::string& arc_notification_key) const { | |
| 27 auto it = notification_surface_map_.find(arc_notification_key); | |
| 28 return it == notification_surface_map_.end() ? nullptr : it->second; | |
| 29 } | |
| 30 | |
| 31 void ArcNotificationSurfaceCollection::AddObserver(Observer* observer) { | |
| 32 observers_.AddObserver(observer); | |
| 33 } | |
| 34 | |
| 35 void ArcNotificationSurfaceCollection::RemoveObserver(Observer* observer) { | |
| 36 observers_.RemoveObserver(observer); | |
| 37 } | |
| 38 | |
| 39 void ArcNotificationSurfaceCollection::AddSurface( | |
| 40 exo::NotificationSurface* surface) { | |
| 41 DCHECK(notification_surface_map_.find(surface->notification_id()) == | |
| 42 notification_surface_map_.end()); | |
| 43 | |
| 44 notification_surface_map_[surface->notification_id()] = surface; | |
| 45 surface->AddObserver(this); | |
| 46 | |
| 47 FOR_EACH_OBSERVER(Observer, observers_, OnNotificationSurfaceAdded(surface)); | |
| 48 } | |
| 49 | |
| 50 void ArcNotificationSurfaceCollection::OnNotificationSurfaceCreated( | |
| 51 exo::NotificationSurface* surface) { | |
| 52 AddSurface(surface); | |
| 53 } | |
| 54 | |
| 55 void ArcNotificationSurfaceCollection::OnNotificationSurfaceDestroying( | |
| 56 exo::NotificationSurface* surface) { | |
| 57 auto it = notification_surface_map_.find(surface->notification_id()); | |
| 58 if (it == notification_surface_map_.end()) { | |
| 59 NOTREACHED(); | |
| 60 return; | |
| 61 } | |
| 62 | |
| 63 surface->RemoveObserver(this); | |
| 64 notification_surface_map_.erase(it); | |
| 65 } | |
| 66 | |
| 67 } // namespace arc | |
| OLD | NEW |