OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 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 "ipc/attachment_broker.h" |
| 6 |
| 7 #include <algorithm> |
| 8 |
| 9 namespace IPC { |
| 10 |
| 11 AttachmentBroker::AttachmentBroker() { |
| 12 } |
| 13 AttachmentBroker::~AttachmentBroker() { |
| 14 } |
| 15 |
| 16 void AttachmentBroker::AddObserver(AttachmentBroker::Observer* observer) { |
| 17 auto it = std::find(observers_.begin(), observers_.end(), observer); |
| 18 if (it == observers_.end()) |
| 19 observers_.push_back(observer); |
| 20 } |
| 21 |
| 22 void AttachmentBroker::RemoveObserver(AttachmentBroker::Observer* observer) { |
| 23 auto it = std::find(observers_.begin(), observers_.end(), observer); |
| 24 if (it != observers_.end()) |
| 25 observers_.erase(it); |
| 26 } |
| 27 |
| 28 void AttachmentBroker::NotifyObservers( |
| 29 const BrokerableAttachment::AttachmentId& id) { |
| 30 // Make a copy of observers_ to avoid mutations during iteration. |
| 31 std::vector<Observer*> observers = observers_; |
| 32 for (Observer* observer : observers) { |
| 33 observer->ReceivedBrokerableAttachmentWithId(id); |
| 34 } |
| 35 } |
| 36 |
| 37 } // namespace IPC |
OLD | NEW |