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

Unified Diff: ipc/attachment_broker.h

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.h
diff --git a/ipc/attachment_broker.h b/ipc/attachment_broker.h
index 6bee1b29643aef464132ad9d6decb15ee8c5afb6..efde3c132ead007b978ec14bd0b64cd9ff8f9ce5 100644
--- a/ipc/attachment_broker.h
+++ b/ipc/attachment_broker.h
@@ -27,10 +27,20 @@ class IPC_EXPORT SupportsAttachmentBrokering {
// Responsible for brokering attachments to Chrome IPC messages. On platforms
// that support attachment brokering, every IPC channel should have a reference
// to a AttachmentBroker.
+// This class is not thread safe. The implementation of this class assumes that
+// it is only ever used on the same thread as its consumers.
class IPC_EXPORT AttachmentBroker : public Listener {
public:
- AttachmentBroker() {}
- ~AttachmentBroker() override {}
+ // A standard observer interface that allows consumers of the AttachmentBroker
+ // to be notified when a new attachment has been received.
+ class Observer {
+ public:
+ virtual void ReceivedBrokerableAttachmentWithId(
+ const BrokerableAttachment::AttachmentId& id) = 0;
+ };
+
+ AttachmentBroker();
+ ~AttachmentBroker() override;
// Sends |attachment| to |destination_process|. The implementation uses an
// IPC::Channel to communicate with the broker process. This may be the same
@@ -40,13 +50,22 @@ class IPC_EXPORT AttachmentBroker : public Listener {
base::ProcessId destination_process) = 0;
// Returns whether the attachment was available. If the attachment was
- // available, populates the output parameter |attachment|. The caller then
- // becomes the owner of |attachment|.
- virtual bool GetAttachmentWithId(BrokerableAttachment::AttachmentId id,
- BrokerableAttachment* attachment) = 0;
+ // available, populates the output parameter |attachment|.
+ virtual bool GetAttachmentWithId(
+ BrokerableAttachment::AttachmentId id,
+ scoped_refptr<BrokerableAttachment>* attachment) = 0;
+
+ // Any given observer should only ever add itself once to the observer list.
+ void AddObserver(Observer* observer);
+ void RemoveObserver(Observer* observer);
+
+ protected:
+ void NotifyObservers(const BrokerableAttachment::AttachmentId& id);
private:
DISALLOW_COPY_AND_ASSIGN(AttachmentBroker);
+
+ std::vector<Observer*> observers_;
};
} // namespace IPC
« no previous file with comments | « ipc/BUILD.gn ('k') | ipc/attachment_broker.cc » ('j') | ipc/attachment_broker.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698