Chromium Code Reviews| Index: ui/arc/notification/arc_notification_surface_collection.cc |
| diff --git a/ui/arc/notification/arc_notification_surface_collection.cc b/ui/arc/notification/arc_notification_surface_collection.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..7acb559da140077c16bd46dd8a431195d21e5b20 |
| --- /dev/null |
| +++ b/ui/arc/notification/arc_notification_surface_collection.cc |
| @@ -0,0 +1,67 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "ui/arc/notification/arc_notification_surface_collection.h" |
| + |
| +#include <algorithm> |
| + |
| +#include "components/exo/display.h" |
| +#include "components/exo/notification_surface.h" |
| +#include "ui/arc/notification/arc_notification_manager.h" |
| + |
| +namespace arc { |
| + |
| +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
|
| + exo::Display::GetInstance()->AddObserver(this); |
| +} |
| + |
| +ArcNotificationSurfaceCollection::~ArcNotificationSurfaceCollection() { |
| + exo::Display::GetInstance()->RemoveObserver(this); |
| + for (auto& entry : notification_surface_map_) |
| + entry.second->RemoveObserver(this); |
| +} |
| + |
| +exo::NotificationSurface* ArcNotificationSurfaceCollection::GetSurface( |
| + const std::string& arc_notification_key) const { |
| + auto it = notification_surface_map_.find(arc_notification_key); |
| + return it == notification_surface_map_.end() ? nullptr : it->second; |
| +} |
| + |
| +void ArcNotificationSurfaceCollection::AddObserver(Observer* observer) { |
| + observers_.AddObserver(observer); |
| +} |
| + |
| +void ArcNotificationSurfaceCollection::RemoveObserver(Observer* observer) { |
| + observers_.RemoveObserver(observer); |
| +} |
| + |
| +void ArcNotificationSurfaceCollection::AddSurface( |
| + exo::NotificationSurface* surface) { |
| + DCHECK(notification_surface_map_.find(surface->notification_id()) == |
| + notification_surface_map_.end()); |
| + |
| + notification_surface_map_[surface->notification_id()] = surface; |
| + surface->AddObserver(this); |
| + |
| + FOR_EACH_OBSERVER(Observer, observers_, OnNotificationSurfaceAdded(surface)); |
| +} |
| + |
| +void ArcNotificationSurfaceCollection::OnNotificationSurfaceCreated( |
| + exo::NotificationSurface* surface) { |
| + AddSurface(surface); |
| +} |
| + |
| +void ArcNotificationSurfaceCollection::OnNotificationSurfaceDestroying( |
| + exo::NotificationSurface* surface) { |
| + auto it = notification_surface_map_.find(surface->notification_id()); |
| + if (it == notification_surface_map_.end()) { |
| + NOTREACHED(); |
| + return; |
| + } |
| + |
| + surface->RemoveObserver(this); |
| + notification_surface_map_.erase(it); |
| +} |
| + |
| +} // namespace arc |