OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef IPC_MACH_PORT_ATTACHMENT_MAC_H_ | 5 #ifndef IPC_MACH_PORT_ATTACHMENT_MAC_H_ |
6 #define IPC_MACH_PORT_ATTACHMENT_MAC_H_ | 6 #define IPC_MACH_PORT_ATTACHMENT_MAC_H_ |
7 | 7 |
8 #include <mach/mach.h> | 8 #include <mach/mach.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
(...skipping 27 matching lines...) Expand all Loading... |
38 uint32_t mach_port; | 38 uint32_t mach_port; |
39 static_assert(sizeof(mach_port_t) <= sizeof(uint32_t), | 39 static_assert(sizeof(mach_port_t) <= sizeof(uint32_t), |
40 "mach_port_t must be smaller than uint32_t"); | 40 "mach_port_t must be smaller than uint32_t"); |
41 | 41 |
42 // The id of the destination process that the handle is duplicated into. | 42 // The id of the destination process that the handle is duplicated into. |
43 base::ProcessId destination_process; | 43 base::ProcessId destination_process; |
44 | 44 |
45 AttachmentId attachment_id; | 45 AttachmentId attachment_id; |
46 }; | 46 }; |
47 | 47 |
| 48 // This constructor increments the ref count of |mach_port_| and takes |
| 49 // ownership of the result. Should only be called by the sender of a Chrome |
| 50 // IPC message. |
48 explicit MachPortAttachmentMac(mach_port_t mach_port); | 51 explicit MachPortAttachmentMac(mach_port_t mach_port); |
| 52 |
| 53 // These constructors do not take ownership of |mach_port|, and should only be |
| 54 // called by the receiver of a Chrome IPC message. |
49 explicit MachPortAttachmentMac(const WireFormat& wire_format); | 55 explicit MachPortAttachmentMac(const WireFormat& wire_format); |
50 explicit MachPortAttachmentMac(const BrokerableAttachment::AttachmentId& id); | 56 explicit MachPortAttachmentMac(const BrokerableAttachment::AttachmentId& id); |
51 | 57 |
52 BrokerableType GetBrokerableType() const override; | 58 BrokerableType GetBrokerableType() const override; |
53 | 59 |
54 // Returns the wire format of this attachment. | 60 // Returns the wire format of this attachment. |
55 WireFormat GetWireFormat(const base::ProcessId& destination) const; | 61 WireFormat GetWireFormat(const base::ProcessId& destination) const; |
56 | 62 |
57 mach_port_t get_mach_port() const { return mach_port_; } | 63 mach_port_t get_mach_port() const { return mach_port_; } |
58 | 64 |
| 65 // The caller of this method has taken ownership of |mach_port_|. |
| 66 void reset_mach_port_ownership() { owns_mach_port_ = false; } |
| 67 |
59 private: | 68 private: |
60 ~MachPortAttachmentMac() override; | 69 ~MachPortAttachmentMac() override; |
61 mach_port_t mach_port_; | 70 mach_port_t mach_port_; |
| 71 |
| 72 // In the sender process, the attachment owns the Mach port of a newly created |
| 73 // message. The attachment broker will eventually take ownership, and set |
| 74 // this member to |false|. |
| 75 // In the destination process, the attachment never owns the Mach port. The |
| 76 // client code that receives the Chrome IPC message is always expected to take |
| 77 // ownership. |
| 78 bool owns_mach_port_; |
| 79 DISALLOW_COPY_AND_ASSIGN(MachPortAttachmentMac); |
62 }; | 80 }; |
63 | 81 |
64 } // namespace internal | 82 } // namespace internal |
65 } // namespace IPC | 83 } // namespace IPC |
66 | 84 |
67 #endif // IPC_MACH_PORT_ATTACHMENT_MAC_H_ | 85 #endif // IPC_MACH_PORT_ATTACHMENT_MAC_H_ |
OLD | NEW |