| OLD | NEW |
| 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_WIN_H_ | 5 #ifndef IPC_ATTACHMENT_BROKER_WIN_H_ |
| 6 #define IPC_ATTACHMENT_BROKER_WIN_H_ | 6 #define IPC_ATTACHMENT_BROKER_WIN_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/gtest_prod_util.h" | 10 #include "base/gtest_prod_util.h" |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "ipc/attachment_broker.h" | 12 #include "ipc/attachment_broker.h" |
| 13 #include "ipc/brokerable_attachment.h" |
| 13 #include "ipc/handle_attachment_win.h" | 14 #include "ipc/handle_attachment_win.h" |
| 14 #include "ipc/ipc_export.h" | 15 #include "ipc/ipc_export.h" |
| 15 | 16 |
| 16 namespace IPC { | 17 namespace IPC { |
| 17 | 18 |
| 18 class Sender; | 19 class Sender; |
| 19 | 20 |
| 20 // This class is an implementation of AttachmentBroker for the Windows platform. | 21 // This class is an implementation of AttachmentBroker for the Windows platform. |
| 21 class IPC_EXPORT AttachmentBrokerWin : public IPC::AttachmentBroker { | 22 class IPC_EXPORT AttachmentBrokerWin : public IPC::AttachmentBroker { |
| 22 public: | 23 public: |
| 23 AttachmentBrokerWin(); | 24 AttachmentBrokerWin(); |
| 24 ~AttachmentBrokerWin() override; | 25 ~AttachmentBrokerWin() override; |
| 25 | 26 |
| 26 // In a non-broker process, the single instance of this class listens for | 27 // In a non-broker process, the single instance of this class listens for |
| 27 // an IPC from the broker process indicating that a new attachment has been | 28 // an IPC from the broker process indicating that a new attachment has been |
| 28 // duplicated. | 29 // duplicated. |
| 29 void OnReceiveDuplicatedHandle(HANDLE, BrokerableAttachment::AttachmentId id); | 30 void OnReceiveDuplicatedHandle(HANDLE, BrokerableAttachment::AttachmentId id); |
| 30 | 31 |
| 31 // IPC::AttachmentBroker overrides. | 32 // IPC::AttachmentBroker overrides. |
| 32 bool SendAttachmentToProcess(const BrokerableAttachment* attachment, | 33 bool SendAttachmentToProcess(const BrokerableAttachment* attachment, |
| 33 base::ProcessId destination_process) override; | 34 base::ProcessId destination_process) override; |
| 34 bool GetAttachmentWithId(BrokerableAttachment::AttachmentId id, | 35 bool GetAttachmentWithId( |
| 35 BrokerableAttachment* attachment) override; | 36 BrokerableAttachment::AttachmentId id, |
| 37 scoped_refptr<BrokerableAttachment>* attachment) override; |
| 36 | 38 |
| 37 // IPC::Listener overrides. | 39 // IPC::Listener overrides. |
| 38 bool OnMessageReceived(const Message& message) override; | 40 bool OnMessageReceived(const Message& message) override; |
| 39 | 41 |
| 40 // |sender_| is used to send Messages to the broker. |sender_| must live at | 42 // |sender_| is used to send Messages to the broker. |sender_| must live at |
| 41 // least as long as this instance. | 43 // least as long as this instance. |
| 42 void set_sender(IPC::Sender* sender) { sender_ = sender; } | 44 void set_sender(IPC::Sender* sender) { sender_ = sender; } |
| 43 | 45 |
| 44 private: | 46 private: |
| 45 FRIEND_TEST_ALL_PREFIXES(AttachmentBrokerWinTest, ReceiveValidMessage); | 47 FRIEND_TEST_ALL_PREFIXES(AttachmentBrokerWinTest, ReceiveValidMessage); |
| 46 FRIEND_TEST_ALL_PREFIXES(AttachmentBrokerWinTest, ReceiveInvalidMessage); | 48 FRIEND_TEST_ALL_PREFIXES(AttachmentBrokerWinTest, ReceiveInvalidMessage); |
| 49 using AttachmentVector = std::vector<scoped_refptr<BrokerableAttachment>>; |
| 47 | 50 |
| 48 // IPC message handlers. | 51 // IPC message handlers. |
| 49 void OnWinHandleHasBeenDuplicated( | 52 void OnWinHandleHasBeenDuplicated( |
| 50 const IPC::internal::HandleAttachmentWin::WireFormat& wire_format); | 53 const IPC::internal::HandleAttachmentWin::WireFormat& wire_format); |
| 51 | 54 |
| 52 // A vector of BrokerableAttachments that have been received, but not yet | 55 // A vector of BrokerableAttachments that have been received, but not yet |
| 53 // consumed. | 56 // consumed. |
| 54 // A std::vector is used instead of a std::map because this container is | 57 // A std::vector is used instead of a std::map because this container is |
| 55 // expected to have few elements, for which a std::vector is expected to have | 58 // expected to have few elements, for which a std::vector is expected to have |
| 56 // better performance. | 59 // better performance. |
| 57 std::vector<scoped_refptr<BrokerableAttachment>> attachments_; | 60 AttachmentVector attachments_; |
| 58 | 61 |
| 59 // |sender_| is used to send Messages to the broker. |sender_| must live at | 62 // |sender_| is used to send Messages to the broker. |sender_| must live at |
| 60 // least as long as this instance. | 63 // least as long as this instance. |
| 61 IPC::Sender* sender_; | 64 IPC::Sender* sender_; |
| 62 DISALLOW_COPY_AND_ASSIGN(AttachmentBrokerWin); | 65 DISALLOW_COPY_AND_ASSIGN(AttachmentBrokerWin); |
| 63 }; | 66 }; |
| 64 | 67 |
| 65 } // namespace IPC | 68 } // namespace IPC |
| 66 | 69 |
| 67 #endif // IPC_ATTACHMENT_BROKER_WIN_H_ | 70 #endif // IPC_ATTACHMENT_BROKER_WIN_H_ |
| OLD | NEW |