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 | |
Wez | 51eaaad | 2017-08-09 05:51:38 | [diff] [blame] | 10 | #include "base/win/scoped_handle.h" |
erikchen | 959039d | 2015-08-11 21:17:47 | [diff] [blame] | 11 | #include "ipc/handle_win.h" |
sammc | 6ed3efb | 2016-11-23 03:17:35 | [diff] [blame] | 12 | #include "ipc/ipc_message_attachment.h" |
Ken Rockot | fd90763 | 2017-09-14 04:23:41 | [diff] [blame] | 13 | #include "ipc/ipc_message_support_export.h" |
erikchen | 151b2f9 | 2015-06-16 20:20:51 | [diff] [blame] | 14 | |
| 15 | namespace IPC { |
| 16 | namespace internal { |
| 17 | |
| 18 | // This class represents a Windows HANDLE attached to a Chrome IPC message. |
Ken Rockot | fd90763 | 2017-09-14 04:23:41 | [diff] [blame] | 19 | class IPC_MESSAGE_SUPPORT_EXPORT HandleAttachmentWin |
| 20 | : public MessageAttachment { |
erikchen | eece6c3 | 2015-07-07 22:13:11 | [diff] [blame] | 21 | public: |
erikchen | 17b3483 | 2015-12-04 21:20:12 | [diff] [blame] | 22 | // This constructor makes a copy of |handle| and takes ownership of the |
| 23 | // result. Should only be called by the sender of a Chrome IPC message. |
Wez | 51eaaad | 2017-08-09 05:51:38 | [diff] [blame] | 24 | explicit HandleAttachmentWin(const HANDLE& handle); |
erikchen | 17b3483 | 2015-12-04 21:20:12 | [diff] [blame] | 25 | |
sammc | 57ed9f98 | 2016-03-10 06:28:35 | [diff] [blame] | 26 | enum FromWire { |
| 27 | FROM_WIRE, |
| 28 | }; |
| 29 | // This constructor takes ownership of |handle|. Should only be called by the |
| 30 | // receiver of a Chrome IPC message. |
| 31 | HandleAttachmentWin(const HANDLE& handle, FromWire from_wire); |
| 32 | |
Wez | 51eaaad | 2017-08-09 05:51:38 | [diff] [blame] | 33 | // MessageAttachment interface. |
sammc | 6ed3efb | 2016-11-23 03:17:35 | [diff] [blame] | 34 | Type GetType() const override; |
erikchen | eece6c3 | 2015-07-07 22:13:11 | [diff] [blame] | 35 | |
Wez | 51eaaad | 2017-08-09 05:51:38 | [diff] [blame] | 36 | HANDLE Take() { return handle_.Take(); } |
erikchen | 17b3483 | 2015-12-04 21:20:12 | [diff] [blame] | 37 | |
erikchen | 151b2f9 | 2015-06-16 20:20:51 | [diff] [blame] | 38 | private: |
erikchen | eece6c3 | 2015-07-07 22:13:11 | [diff] [blame] | 39 | ~HandleAttachmentWin() override; |
erikchen | 17b3483 | 2015-12-04 21:20:12 | [diff] [blame] | 40 | |
Wez | 51eaaad | 2017-08-09 05:51:38 | [diff] [blame] | 41 | base::win::ScopedHandle handle_; |
erikchen | 151b2f9 | 2015-06-16 20:20:51 | [diff] [blame] | 42 | }; |
| 43 | |
| 44 | } // namespace internal |
| 45 | } // namespace IPC |
| 46 | |
| 47 | #endif // IPC_HANDLE_ATTACHMENT_WIN_H_ |