Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / ipc / handle_attachment_win.h
blob127cd57292e45303ecb35fc4ff675be992ac7b95
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.
5 #ifndef IPC_HANDLE_ATTACHMENT_WIN_H_
6 #define IPC_HANDLE_ATTACHMENT_WIN_H_
8 #include <stdint.h>
10 #include "base/process/process_handle.h"
11 #include "ipc/brokerable_attachment.h"
12 #include "ipc/handle_win.h"
13 #include "ipc/ipc_export.h"
15 namespace IPC {
16 namespace internal {
18 // This class represents a Windows HANDLE attached to a Chrome IPC message.
19 class IPC_EXPORT HandleAttachmentWin : public BrokerableAttachment {
20 public:
21 // The wire format for this handle.
22 struct IPC_EXPORT WireFormat {
23 // The HANDLE that is intended for duplication, or the HANDLE that has been
24 // duplicated, depending on context.
25 // The type is int32_t instead of HANDLE because HANDLE gets typedefed to
26 // void*, whose size varies between 32 and 64-bit processes. Using a
27 // int32_t means that 64-bit processes will need to perform both up-casting
28 // and down-casting. This is performed using the appropriate Windows apis.
29 // A value of 0 is equivalent to an invalid handle.
30 int32_t handle;
31 // The id of the destination process that the handle is duplicated into.
32 base::ProcessId destination_process;
33 // The permissions to use when duplicating the handle.
34 HandleWin::Permissions permissions;
35 AttachmentId attachment_id;
38 HandleAttachmentWin(const HANDLE& handle, HandleWin::Permissions permissions);
39 explicit HandleAttachmentWin(const WireFormat& wire_format);
40 explicit HandleAttachmentWin(const BrokerableAttachment::AttachmentId& id);
42 BrokerableType GetBrokerableType() const override;
43 void PopulateWithAttachment(const BrokerableAttachment* attachment) override;
45 // Returns the wire format of this attachment.
46 WireFormat GetWireFormat(const base::ProcessId& destination) const;
48 HANDLE get_handle() const { return handle_; }
50 private:
51 ~HandleAttachmentWin() override;
52 HANDLE handle_;
53 HandleWin::Permissions permissions_;
56 } // namespace internal
57 } // namespace IPC
59 #endif // IPC_HANDLE_ATTACHMENT_WIN_H_