Index: ipc/attachment_broker.cc |
diff --git a/ipc/attachment_broker.cc b/ipc/attachment_broker.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..195b5c72660ca9ef415f4febce3158fff148b2a5 |
--- /dev/null |
+++ b/ipc/attachment_broker.cc |
@@ -0,0 +1,37 @@ |
+// Copyright 2015 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 "ipc/attachment_broker.h" |
+ |
+namespace IPC { |
+ |
+AttachmentBroker::AttachmentBroker() { |
+} |
+AttachmentBroker::~AttachmentBroker() { |
+} |
+ |
+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
|
+ observers_.push_back(observer); |
+} |
+ |
+void AttachmentBroker::RemoveObserver(AttachmentBroker::Observer* observer) { |
+ 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.
|
+ it != observers_.end(); ++it) { |
+ if (*it == observer) { |
+ observers_.erase(it); |
+ break; |
+ } |
+ } |
+} |
+ |
+void AttachmentBroker::NotifyObservers( |
+ const BrokerableAttachment::AttachmentId& id) { |
+ // Make a copy of observers_ to avoid mutations during iteration. |
+ std::vector<Observer*> observers = observers_; |
+ for (Observer* observer : observers) { |
+ observer->ReceivedBrokerableAttachmentWithId(id); |
+ } |
+} |
+ |
+} // namespace IPC |