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 | 959039d | 2015-08-11 21:17:47 | [diff] [blame] | 11 | #include "ipc/handle_win.h" |
erikchen | 151b2f9 | 2015-06-16 20:20:51 | [diff] [blame] | 12 | #include "ipc/ipc_export.h" |
sammc | 6ed3efb | 2016-11-23 03:17:35 | [diff] [blame] | 13 | #include "ipc/ipc_message_attachment.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. |
sammc | 6ed3efb | 2016-11-23 03:17:35 | [diff] [blame] | 19 | class IPC_EXPORT HandleAttachmentWin : public MessageAttachment { |
erikchen | eece6c3 | 2015-07-07 22:13:11 | [diff] [blame] | 20 | public: |
erikchen | 17b3483 | 2015-12-04 21:20:12 | [diff] [blame] | 21 | // This constructor makes a copy of |handle| and takes ownership of the |
| 22 | // result. Should only be called by the sender of a Chrome IPC message. |
erikchen | 959039d | 2015-08-11 21:17:47 | [diff] [blame] | 23 | HandleAttachmentWin(const HANDLE& handle, HandleWin::Permissions permissions); |
erikchen | 17b3483 | 2015-12-04 21:20:12 | [diff] [blame] | 24 | |
sammc | 57ed9f98 | 2016-03-10 06:28:35 | [diff] [blame] | 25 | enum FromWire { |
| 26 | FROM_WIRE, |
| 27 | }; |
| 28 | // This constructor takes ownership of |handle|. Should only be called by the |
| 29 | // receiver of a Chrome IPC message. |
| 30 | HandleAttachmentWin(const HANDLE& handle, FromWire from_wire); |
| 31 | |
sammc | 6ed3efb | 2016-11-23 03:17:35 | [diff] [blame] | 32 | Type GetType() const override; |
erikchen | eece6c3 | 2015-07-07 22:13:11 | [diff] [blame] | 33 | |
erikchen | 7252aa36 | 2015-07-15 01:35:39 | [diff] [blame] | 34 | HANDLE get_handle() const { return handle_; } |
| 35 | |
erikchen | 17b3483 | 2015-12-04 21:20:12 | [diff] [blame] | 36 | // The caller of this method has taken ownership of |handle_|. |
erikchen | 3d87ecf7 | 2016-01-08 02:17:04 | [diff] [blame] | 37 | void reset_handle_ownership() { |
| 38 | owns_handle_ = false; |
| 39 | handle_ = INVALID_HANDLE_VALUE; |
| 40 | } |
erikchen | 17b3483 | 2015-12-04 21:20:12 | [diff] [blame] | 41 | |
erikchen | 151b2f9 | 2015-06-16 20:20:51 | [diff] [blame] | 42 | private: |
erikchen | eece6c3 | 2015-07-07 22:13:11 | [diff] [blame] | 43 | ~HandleAttachmentWin() override; |
erikchen | 151b2f9 | 2015-06-16 20:20:51 | [diff] [blame] | 44 | HANDLE handle_; |
erikchen | 959039d | 2015-08-11 21:17:47 | [diff] [blame] | 45 | HandleWin::Permissions permissions_; |
erikchen | 17b3483 | 2015-12-04 21:20:12 | [diff] [blame] | 46 | |
| 47 | // In the sender process, the attachment owns the HANDLE of a newly created |
| 48 | // message. The attachment broker will eventually take ownership, and set |
| 49 | // this member to |false|. |
erikchen | 3d87ecf7 | 2016-01-08 02:17:04 | [diff] [blame] | 50 | // In the destination process, the attachment owns the Mach port until a call |
| 51 | // to ParamTraits<HandleWin>::Read() takes ownership. |
erikchen | 17b3483 | 2015-12-04 21:20:12 | [diff] [blame] | 52 | bool owns_handle_; |
erikchen | 151b2f9 | 2015-06-16 20:20:51 | [diff] [blame] | 53 | }; |
| 54 | |
| 55 | } // namespace internal |
| 56 | } // namespace IPC |
| 57 | |
| 58 | #endif // IPC_HANDLE_ATTACHMENT_WIN_H_ |