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

Side by Side 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, 5 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef IPC_ATTACHMENT_BROKER_H_ 5 #ifndef IPC_ATTACHMENT_BROKER_H_
6 #define IPC_ATTACHMENT_BROKER_H_ 6 #define IPC_ATTACHMENT_BROKER_H_
7 7
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/process/process_handle.h" 9 #include "base/process/process_handle.h"
10 #include "ipc/brokerable_attachment.h" 10 #include "ipc/brokerable_attachment.h"
11 #include "ipc/ipc_export.h" 11 #include "ipc/ipc_export.h"
12 #include "ipc/ipc_listener.h" 12 #include "ipc/ipc_listener.h"
13 13
14 namespace IPC { 14 namespace IPC {
15 15
16 class AttachmentBroker; 16 class AttachmentBroker;
17 // Classes that inherit from this abstract base class are capable of 17 // Classes that inherit from this abstract base class are capable of
18 // communicating with a broker to send and receive attachments to Chrome IPC 18 // communicating with a broker to send and receive attachments to Chrome IPC
19 // messages. 19 // messages.
20 class IPC_EXPORT SupportsAttachmentBrokering { 20 class IPC_EXPORT SupportsAttachmentBrokering {
21 public: 21 public:
22 // Returns an AttachmentBroker used to broker attachments of IPC messages to 22 // Returns an AttachmentBroker used to broker attachments of IPC messages to
23 // other processes. There must be exactly one AttachmentBroker per process. 23 // other processes. There must be exactly one AttachmentBroker per process.
24 virtual AttachmentBroker* GetAttachmentBroker() = 0; 24 virtual AttachmentBroker* GetAttachmentBroker() = 0;
25 }; 25 };
26 26
27 // Responsible for brokering attachments to Chrome IPC messages. On platforms 27 // Responsible for brokering attachments to Chrome IPC messages. On platforms
28 // that support attachment brokering, every IPC channel should have a reference 28 // that support attachment brokering, every IPC channel should have a reference
29 // to a AttachmentBroker. 29 // to a AttachmentBroker.
30 // This class is not thread safe. The implementation of this class assumes that
31 // it is only ever used on the same thread as its consumers.
30 class IPC_EXPORT AttachmentBroker : public Listener { 32 class IPC_EXPORT AttachmentBroker : public Listener {
31 public: 33 public:
32 AttachmentBroker() {} 34 // A standard observer interface that allows consumers of the AttachmentBroker
33 ~AttachmentBroker() override {} 35 // to be notified when a new attachment has been received.
36 class Observer {
37 public:
38 virtual void ReceivedBrokerableAttachmentWithId(
39 const BrokerableAttachment::AttachmentId& id) = 0;
40 };
41
42 AttachmentBroker();
43 ~AttachmentBroker() override;
34 44
35 // Sends |attachment| to |destination_process|. The implementation uses an 45 // Sends |attachment| to |destination_process|. The implementation uses an
36 // IPC::Channel to communicate with the broker process. This may be the same 46 // IPC::Channel to communicate with the broker process. This may be the same
37 // IPC::Channel that is requesting the brokering of an attachment. 47 // IPC::Channel that is requesting the brokering of an attachment.
38 // Returns true on success and false otherwise. 48 // Returns true on success and false otherwise.
39 virtual bool SendAttachmentToProcess(const BrokerableAttachment* attachment, 49 virtual bool SendAttachmentToProcess(const BrokerableAttachment* attachment,
40 base::ProcessId destination_process) = 0; 50 base::ProcessId destination_process) = 0;
41 51
42 // Returns whether the attachment was available. If the attachment was 52 // Returns whether the attachment was available. If the attachment was
43 // available, populates the output parameter |attachment|. The caller then 53 // available, populates the output parameter |attachment|.
44 // becomes the owner of |attachment|. 54 virtual bool GetAttachmentWithId(
45 virtual bool GetAttachmentWithId(BrokerableAttachment::AttachmentId id, 55 BrokerableAttachment::AttachmentId id,
46 BrokerableAttachment* attachment) = 0; 56 scoped_refptr<BrokerableAttachment>* attachment) = 0;
57
58 // Any given observer should only ever add itself once to the observer list.
59 void AddObserver(Observer* observer);
60 void RemoveObserver(Observer* observer);
61
62 protected:
63 void NotifyObservers(const BrokerableAttachment::AttachmentId& id);
47 64
48 private: 65 private:
49 DISALLOW_COPY_AND_ASSIGN(AttachmentBroker); 66 DISALLOW_COPY_AND_ASSIGN(AttachmentBroker);
67
68 std::vector<Observer*> observers_;
50 }; 69 };
51 70
52 } // namespace IPC 71 } // namespace IPC
53 72
54 #endif // IPC_ATTACHMENT_BROKER_H_ 73 #endif // IPC_ATTACHMENT_BROKER_H_
OLDNEW
« 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