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
3 // found in the LICENSE file.
5 #include "ipc/attachment_broker_win.h"
7 #include "base/process/process.h"
8 #include "ipc/attachment_broker_messages.h"
9 #include "ipc/brokerable_attachment.h"
10 #include "ipc/handle_attachment_win.h"
11 #include "ipc/ipc_sender.h"
15 AttachmentBrokerWin::AttachmentBrokerWin() {
18 AttachmentBrokerWin::~AttachmentBrokerWin() {
21 void AttachmentBrokerWin::OnReceiveDuplicatedHandle(
23 BrokerableAttachment::AttachmentId id
) {
24 // TODO(erikchen): Implement me. http://crbug.com/493414
27 bool AttachmentBrokerWin::SendAttachmentToProcess(
28 const BrokerableAttachment
* attachment
,
29 base::ProcessId destination_process
) {
30 switch (attachment
->GetBrokerableType()) {
31 case BrokerableAttachment::WIN_HANDLE
:
32 const internal::HandleAttachmentWin
* handle_attachment
=
33 static_cast<const internal::HandleAttachmentWin
*>(attachment
);
34 internal::HandleAttachmentWin::WireFormat format
=
35 handle_attachment
->GetWireFormat(destination_process
);
37 new AttachmentBrokerMsg_DuplicateWinHandle(format
));
42 bool AttachmentBrokerWin::GetAttachmentWithId(
43 BrokerableAttachment::AttachmentId id
,
44 BrokerableAttachment
* attachment
) {
45 // TODO(erikchen): Implement me. http://crbug.com/493414
49 bool AttachmentBrokerWin::OnMessageReceived(const Message
& msg
) {
51 IPC_BEGIN_MESSAGE_MAP(AttachmentBrokerWin
, msg
)
52 IPC_MESSAGE_HANDLER(AttachmentBrokerMsg_WinHandleHasBeenDuplicated
,
53 OnWinHandleHasBeenDuplicated
)
54 IPC_MESSAGE_UNHANDLED(handled
= false)
59 void AttachmentBrokerWin::OnWinHandleHasBeenDuplicated(
60 const IPC::internal::HandleAttachmentWin::WireFormat
& wire_format
) {
61 // The IPC message was intended for a different process. Ignore it.
62 if (wire_format
.destination_process
!= base::Process::Current().Pid())
65 scoped_refptr
<BrokerableAttachment
> attachment(
66 new IPC::internal::HandleAttachmentWin(wire_format
));
67 attachments_
.push_back(attachment
);