Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1060)

Unified Diff: ipc/attachment_broker.cc

Issue 1206093002: Update ChannelReader to use AttachmentBroker. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@attachment_broker3_listener
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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

Powered by Google App Engine
This is Rietveld 408576698