blob: ef3b89652caf8c2e0fa332b3af659d6a3571545a [file] [log] [blame]
erikchen151b2f92015-06-16 20:20:511// 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
erikcheneece6c32015-07-07 22:13:118#include <stdint.h>
9
10#include "base/process/process_handle.h"
erikchen959039d2015-08-11 21:17:4711#include "ipc/handle_win.h"
erikchen151b2f92015-06-16 20:20:5112#include "ipc/ipc_export.h"
sammc6ed3efb2016-11-23 03:17:3513#include "ipc/ipc_message_attachment.h"
erikchen151b2f92015-06-16 20:20:5114
15namespace IPC {
16namespace internal {
17
18// This class represents a Windows HANDLE attached to a Chrome IPC message.
sammc6ed3efb2016-11-23 03:17:3519class IPC_EXPORT HandleAttachmentWin : public MessageAttachment {
erikcheneece6c32015-07-07 22:13:1120 public:
erikchen17b34832015-12-04 21:20:1221 // 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.
erikchen959039d2015-08-11 21:17:4723 HandleAttachmentWin(const HANDLE& handle, HandleWin::Permissions permissions);
erikchen17b34832015-12-04 21:20:1224
sammc57ed9f982016-03-10 06:28:3525 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
sammc6ed3efb2016-11-23 03:17:3532 Type GetType() const override;
erikcheneece6c32015-07-07 22:13:1133
erikchen7252aa362015-07-15 01:35:3934 HANDLE get_handle() const { return handle_; }
35
erikchen17b34832015-12-04 21:20:1236 // The caller of this method has taken ownership of |handle_|.
erikchen3d87ecf72016-01-08 02:17:0437 void reset_handle_ownership() {
38 owns_handle_ = false;
39 handle_ = INVALID_HANDLE_VALUE;
40 }
erikchen17b34832015-12-04 21:20:1241
erikchen151b2f92015-06-16 20:20:5142 private:
erikcheneece6c32015-07-07 22:13:1143 ~HandleAttachmentWin() override;
erikchen151b2f92015-06-16 20:20:5144 HANDLE handle_;
erikchen959039d2015-08-11 21:17:4745 HandleWin::Permissions permissions_;
erikchen17b34832015-12-04 21:20:1246
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|.
erikchen3d87ecf72016-01-08 02:17:0450 // In the destination process, the attachment owns the Mach port until a call
51 // to ParamTraits<HandleWin>::Read() takes ownership.
erikchen17b34832015-12-04 21:20:1252 bool owns_handle_;
erikchen151b2f92015-06-16 20:20:5153};
54
55} // namespace internal
56} // namespace IPC
57
58#endif // IPC_HANDLE_ATTACHMENT_WIN_H_