erikchen | 151b2f9 | 2015-06-16 20:20:51 | [diff] [blame] | 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. |
| 4 | |
| 5 | #ifndef IPC_HANDLE_ATTACHMENT_WIN_H_ |
| 6 | #define IPC_HANDLE_ATTACHMENT_WIN_H_ |
| 7 | |
erikchen | eece6c3 | 2015-07-07 22:13:11 | [diff] [blame] | 8 | #include <stdint.h> |
| 9 | |
| 10 | #include "base/process/process_handle.h" |
erikchen | 151b2f9 | 2015-06-16 20:20:51 | [diff] [blame] | 11 | #include "ipc/brokerable_attachment.h" |
| 12 | #include "ipc/ipc_export.h" |
| 13 | |
| 14 | namespace IPC { |
| 15 | namespace internal { |
| 16 | |
| 17 | // This class represents a Windows HANDLE attached to a Chrome IPC message. |
| 18 | class IPC_EXPORT HandleAttachmentWin : public BrokerableAttachment { |
erikchen | eece6c3 | 2015-07-07 22:13:11 | [diff] [blame] | 19 | public: |
| 20 | // The wire format for this handle. |
| 21 | struct IPC_EXPORT WireFormat { |
| 22 | // The HANDLE that is intended for duplication, or the HANDLE that has been |
| 23 | // duplicated, depending on context. |
| 24 | // The type is int32_t instead of HANDLE because HANDLE gets typedefed to |
| 25 | // void*, whose size varies between 32 and 64-bit processes. Using a |
| 26 | // int32_t means that 64-bit processes will need to perform both up-casting |
| 27 | // and down-casting. This is performed using the appropriate Windows apis. |
| 28 | int32_t handle; |
| 29 | // The id of the destination process that the handle is duplicated into. |
| 30 | base::ProcessId destination_process; |
| 31 | AttachmentId attachment_id; |
| 32 | }; |
| 33 | |
erikchen | 7252aa36 | 2015-07-15 01:35:39 | [diff] [blame^] | 34 | explicit HandleAttachmentWin(const HANDLE& handle); |
| 35 | explicit HandleAttachmentWin(const WireFormat& wire_format); |
erikchen | eece6c3 | 2015-07-07 22:13:11 | [diff] [blame] | 36 | |
| 37 | BrokerableType GetBrokerableType() const override; |
| 38 | |
| 39 | // Returns the wire format of this attachment. |
| 40 | WireFormat GetWireFormat(const base::ProcessId& destination) const; |
| 41 | |
erikchen | 7252aa36 | 2015-07-15 01:35:39 | [diff] [blame^] | 42 | HANDLE get_handle() const { return handle_; } |
| 43 | |
erikchen | 151b2f9 | 2015-06-16 20:20:51 | [diff] [blame] | 44 | private: |
erikchen | eece6c3 | 2015-07-07 22:13:11 | [diff] [blame] | 45 | ~HandleAttachmentWin() override; |
erikchen | 151b2f9 | 2015-06-16 20:20:51 | [diff] [blame] | 46 | HANDLE handle_; |
| 47 | }; |
| 48 | |
| 49 | } // namespace internal |
| 50 | } // namespace IPC |
| 51 | |
| 52 | #endif // IPC_HANDLE_ATTACHMENT_WIN_H_ |