Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(178)

Side by Side Diff: ipc/mach_port_attachment_mac.h

Issue 2494943002: Remove IPC::BrokerableAttachment. (Closed)
Patch Set: extra test output Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ipc/ipc_send_fds_test.cc ('k') | ipc/mach_port_attachment_mac.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/process/process_handle.h" 12 #include "base/process/process_handle.h"
13 #include "ipc/brokerable_attachment.h"
14 #include "ipc/ipc_export.h" 13 #include "ipc/ipc_export.h"
14 #include "ipc/ipc_message_attachment.h"
15 #include "ipc/mach_port_mac.h" 15 #include "ipc/mach_port_mac.h"
16 16
17 namespace IPC { 17 namespace IPC {
18 namespace internal { 18 namespace internal {
19 19
20 // This class represents an OSX mach_port_t attached to a Chrome IPC message. 20 // This class represents an OSX mach_port_t attached to a Chrome IPC message.
21 class IPC_EXPORT MachPortAttachmentMac : public BrokerableAttachment { 21 class IPC_EXPORT MachPortAttachmentMac : public MessageAttachment {
22 public: 22 public:
23 struct IPC_EXPORT WireFormat {
24 // IPC translation requires that classes passed through IPC have a default
25 // constructor.
26 WireFormat() : mach_port(0), destination_process(0) {}
27
28 WireFormat(uint32_t mach_port, const base::ProcessId& destination_process)
29 : mach_port(mach_port), destination_process(destination_process) {}
30
31 // The mach port that is intended for duplication, or the mach port that has
32 // been duplicated, depending on context.
33 // The type is uint32_t instead of mach_port_t to ensure that the wire
34 // format stays consistent.
35 uint32_t mach_port;
36 static_assert(sizeof(mach_port_t) <= sizeof(uint32_t),
37 "mach_port_t must be smaller than uint32_t");
38
39 // The id of the destination process that the handle is duplicated into.
40 base::ProcessId destination_process;
41 };
42
43 // This constructor increments the ref count of |mach_port_| and takes 23 // This constructor increments the ref count of |mach_port_| and takes
44 // ownership of the result. Should only be called by the sender of a Chrome 24 // ownership of the result. Should only be called by the sender of a Chrome
45 // IPC message. 25 // IPC message.
46 explicit MachPortAttachmentMac(mach_port_t mach_port); 26 explicit MachPortAttachmentMac(mach_port_t mach_port);
47 27
48 enum FromWire { 28 enum FromWire {
49 FROM_WIRE, 29 FROM_WIRE,
50 }; 30 };
51 // This constructor takes ownership of |mach_port|, but does not modify its 31 // This constructor takes ownership of |mach_port|, but does not modify its
52 // ref count. Should only be called by the receiver of a Chrome IPC message. 32 // ref count. Should only be called by the receiver of a Chrome IPC message.
53 MachPortAttachmentMac(mach_port_t mach_port, FromWire from_wire); 33 MachPortAttachmentMac(mach_port_t mach_port, FromWire from_wire);
54 34
55 // This constructor takes ownership of |wire_format.mach_port|, but does not 35 Type GetType() const override;
56 // modify its ref count. Should only be called by the receiver of a Chrome IPC
57 // message.
58 explicit MachPortAttachmentMac(const WireFormat& wire_format);
59
60 BrokerableType GetBrokerableType() const override;
61
62 // Returns the wire format of this attachment.
63 WireFormat GetWireFormat(const base::ProcessId& destination) const;
64 36
65 mach_port_t get_mach_port() const { return mach_port_; } 37 mach_port_t get_mach_port() const { return mach_port_; }
66 38
67 // The caller of this method has taken ownership of |mach_port_|. 39 // The caller of this method has taken ownership of |mach_port_|.
68 void reset_mach_port_ownership() { owns_mach_port_ = false; } 40 void reset_mach_port_ownership() { owns_mach_port_ = false; }
69 41
70 private: 42 private:
71 ~MachPortAttachmentMac() override; 43 ~MachPortAttachmentMac() override;
72 const mach_port_t mach_port_; 44 const mach_port_t mach_port_;
73 45
74 // In the sender process, the attachment owns the Mach port of a newly created 46 // In the sender process, the attachment owns the Mach port of a newly created
75 // message. The attachment broker will eventually take ownership of 47 // message. The attachment broker will eventually take ownership of
76 // |mach_port_|. 48 // |mach_port_|.
77 // In the destination process, the attachment owns |mach_port_| until 49 // In the destination process, the attachment owns |mach_port_| until
78 // ParamTraits<MachPortMac>::Read() is called, which takes ownership. 50 // ParamTraits<MachPortMac>::Read() is called, which takes ownership.
79 bool owns_mach_port_; 51 bool owns_mach_port_;
80 DISALLOW_COPY_AND_ASSIGN(MachPortAttachmentMac); 52 DISALLOW_COPY_AND_ASSIGN(MachPortAttachmentMac);
81 }; 53 };
82 54
83 } // namespace internal 55 } // namespace internal
84 } // namespace IPC 56 } // namespace IPC
85 57
86 #endif // IPC_MACH_PORT_ATTACHMENT_MAC_H_ 58 #endif // IPC_MACH_PORT_ATTACHMENT_MAC_H_
OLDNEW
« no previous file with comments | « ipc/ipc_send_fds_test.cc ('k') | ipc/mach_port_attachment_mac.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698