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 namespace IPC { | |
8 | |
9 AttachmentBroker::AttachmentBroker() { | |
10 } | |
11 AttachmentBroker::~AttachmentBroker() { | |
12 } | |
13 | |
14 void AttachmentBroker::AddObserver(AttachmentBroker::Observer* observer) { | |
Tom Sepez
2015/07/13 18:28:47
do we care if |observer| has already been added?
erikchen
2015/07/17 18:44:00
I added logic to prevent the same observer from be
| |
15 observers_.push_back(observer); | |
16 } | |
17 | |
18 void AttachmentBroker::RemoveObserver(AttachmentBroker::Observer* observer) { | |
19 for (std::vector<Observer*>::iterator it = observers_.begin(); | |
Tom Sepez
2015/07/13 18:28:47
can we use ::find here? How about auto keyword to
erikchen
2015/07/17 18:44:00
Used auto and find.
| |
20 it != observers_.end(); ++it) { | |
21 if (*it == observer) { | |
22 observers_.erase(it); | |
23 break; | |
24 } | |
25 } | |
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 |