| 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 #include "ipc/attachment_broker_privileged_win.h" | 5 #include "ipc/attachment_broker_privileged_win.h" |
| 6 | 6 |
| 7 #include <windows.h> | 7 #include <windows.h> |
| 8 | 8 |
| 9 #include "base/process/process.h" | 9 #include "base/process/process.h" |
| 10 #include "ipc/attachment_broker_messages.h" | 10 #include "ipc/attachment_broker_messages.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 if (new_wire_format.handle == 0) | 32 if (new_wire_format.handle == 0) |
| 33 return false; | 33 return false; |
| 34 RouteDuplicatedHandle(new_wire_format); | 34 RouteDuplicatedHandle(new_wire_format); |
| 35 return true; | 35 return true; |
| 36 } | 36 } |
| 37 return false; | 37 return false; |
| 38 } | 38 } |
| 39 | 39 |
| 40 bool AttachmentBrokerPrivilegedWin::OnMessageReceived(const Message& msg) { | 40 bool AttachmentBrokerPrivilegedWin::OnMessageReceived(const Message& msg) { |
| 41 bool handled = true; | 41 bool handled = true; |
| 42 IPC_BEGIN_MESSAGE_MAP(AttachmentBrokerPrivilegedWin, msg) | 42 switch (msg.type()) { |
| 43 IPC_MESSAGE_HANDLER(AttachmentBrokerMsg_DuplicateWinHandle, | 43 IPC_MESSAGE_HANDLER_GENERIC(AttachmentBrokerMsg_DuplicateWinHandle, |
| 44 OnDuplicateWinHandle) | 44 OnDuplicateWinHandle(msg)) |
| 45 IPC_MESSAGE_UNHANDLED(handled = false) | 45 IPC_MESSAGE_UNHANDLED(handled = false) |
| 46 IPC_END_MESSAGE_MAP() | 46 } |
| 47 return handled; | 47 return handled; |
| 48 } | 48 } |
| 49 | 49 |
| 50 void AttachmentBrokerPrivilegedWin::RegisterCommunicationChannel( | 50 void AttachmentBrokerPrivilegedWin::RegisterCommunicationChannel( |
| 51 Channel* channel) { | 51 Channel* channel) { |
| 52 auto it = std::find(channels_.begin(), channels_.end(), channel); | 52 auto it = std::find(channels_.begin(), channels_.end(), channel); |
| 53 DCHECK(channels_.end() == it); | 53 DCHECK(channels_.end() == it); |
| 54 channels_.push_back(channel); | 54 channels_.push_back(channel); |
| 55 } | 55 } |
| 56 | 56 |
| 57 void AttachmentBrokerPrivilegedWin::DeregisterCommunicationChannel( | 57 void AttachmentBrokerPrivilegedWin::DeregisterCommunicationChannel( |
| 58 Channel* channel) { | 58 Channel* channel) { |
| 59 auto it = std::find(channels_.begin(), channels_.end(), channel); | 59 auto it = std::find(channels_.begin(), channels_.end(), channel); |
| 60 DCHECK(it != channels_.end()); | 60 DCHECK(it != channels_.end()); |
| 61 channels_.erase(it); | 61 channels_.erase(it); |
| 62 } | 62 } |
| 63 | 63 |
| 64 void AttachmentBrokerPrivilegedWin::OnDuplicateWinHandle( | 64 void AttachmentBrokerPrivilegedWin::OnDuplicateWinHandle( |
| 65 const HandleWireFormat& wire_format, | 65 const IPC::Message& message) { |
| 66 base::ProcessId source_pid) { | 66 AttachmentBrokerMsg_DuplicateWinHandle::Param param; |
| 67 if (!AttachmentBrokerMsg_DuplicateWinHandle::Read(&message, ¶m)) |
| 68 return; |
| 69 IPC::internal::HandleAttachmentWin::WireFormat wire_format = |
| 70 base::get<0>(param); |
| 71 |
| 67 if (wire_format.destination_process == base::kNullProcessId) | 72 if (wire_format.destination_process == base::kNullProcessId) |
| 68 return; | 73 return; |
| 69 | 74 |
| 70 HandleWireFormat new_wire_format = | 75 HandleWireFormat new_wire_format = |
| 71 DuplicateWinHandle(wire_format, source_pid); | 76 DuplicateWinHandle(wire_format, message.get_sender_pid()); |
| 72 RouteDuplicatedHandle(new_wire_format); | 77 RouteDuplicatedHandle(new_wire_format); |
| 73 } | 78 } |
| 74 | 79 |
| 75 void AttachmentBrokerPrivilegedWin::RouteDuplicatedHandle( | 80 void AttachmentBrokerPrivilegedWin::RouteDuplicatedHandle( |
| 76 const HandleWireFormat& wire_format) { | 81 const HandleWireFormat& wire_format) { |
| 77 // This process is the destination. | 82 // This process is the destination. |
| 78 if (wire_format.destination_process == base::Process::Current().Pid()) { | 83 if (wire_format.destination_process == base::Process::Current().Pid()) { |
| 79 scoped_refptr<BrokerableAttachment> attachment( | 84 scoped_refptr<BrokerableAttachment> attachment( |
| 80 new internal::HandleAttachmentWin(wire_format)); | 85 new internal::HandleAttachmentWin(wire_format)); |
| 81 HandleReceivedAttachment(attachment); | 86 HandleReceivedAttachment(attachment); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 FALSE, DUPLICATE_SAME_ACCESS); | 125 FALSE, DUPLICATE_SAME_ACCESS); |
| 121 | 126 |
| 122 new_wire_format.handle = (result != 0) ? HandleToLong(new_handle) : 0; | 127 new_wire_format.handle = (result != 0) ? HandleToLong(new_handle) : 0; |
| 123 } else { | 128 } else { |
| 124 new_wire_format.handle = 0; | 129 new_wire_format.handle = 0; |
| 125 } | 130 } |
| 126 return new_wire_format; | 131 return new_wire_format; |
| 127 } | 132 } |
| 128 | 133 |
| 129 } // namespace IPC | 134 } // namespace IPC |
| OLD | NEW |