OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 MOJO_EDK_SYSTEM_CHANNEL_H_ | 5 #ifndef MOJO_EDK_SYSTEM_CHANNEL_H_ |
6 #define MOJO_EDK_SYSTEM_CHANNEL_H_ | 6 #define MOJO_EDK_SYSTEM_CHANNEL_H_ |
7 | 7 |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 uint16_t num_handles; | 62 uint16_t num_handles; |
63 | 63 |
64 MessageType message_type; | 64 MessageType message_type; |
65 | 65 |
66 char padding[6]; | 66 char padding[6]; |
67 #endif // defined(OS_CHROMEOS) || defined(OS_ANDROID) | 67 #endif // defined(OS_CHROMEOS) || defined(OS_ANDROID) |
68 }; | 68 }; |
69 | 69 |
70 #if defined(OS_MACOSX) && !defined(OS_IOS) | 70 #if defined(OS_MACOSX) && !defined(OS_IOS) |
71 struct MachPortsEntry { | 71 struct MachPortsEntry { |
| 72 // Index of Mach port in the original vector of PlatformHandles. |
72 uint16_t index; | 73 uint16_t index; |
| 74 |
| 75 // Mach port name. |
73 uint32_t mach_port; | 76 uint32_t mach_port; |
74 static_assert(sizeof(mach_port_t) <= sizeof(uint32_t), | 77 static_assert(sizeof(mach_port_t) <= sizeof(uint32_t), |
75 "mach_port_t must be no larger than uint32_t"); | 78 "mach_port_t must be no larger than uint32_t"); |
76 }; | 79 }; |
77 static_assert(sizeof(MachPortsEntry) == 6, | 80 static_assert(sizeof(MachPortsEntry) == 6, |
78 "sizeof(MachPortsEntry) must be 6 bytes"); | 81 "sizeof(MachPortsEntry) must be 6 bytes"); |
| 82 |
| 83 // Structure of the extra header field when present on OSX. |
| 84 struct MachPortsExtraHeader { |
| 85 // Actual number of Mach ports encoded in the extra header. |
| 86 uint16_t num_ports; |
| 87 |
| 88 // Array of encoded Mach ports. If |num_ports| > 0, |entires[0]| through |
| 89 // to |entries[num_ports-1]| inclusive are valid. |
| 90 MachPortsEntry entries[0]; |
| 91 }; |
| 92 static_assert(sizeof(MachPortsExtraHeader) == 2, |
| 93 "sizeof(MachPortsExtraHeader) must be 2 bytes"); |
79 #endif | 94 #endif |
80 #pragma pack(pop) | 95 #pragma pack(pop) |
81 | 96 |
82 // Allocates and owns a buffer for message data with enough capacity for | 97 // Allocates and owns a buffer for message data with enough capacity for |
83 // |payload_size| bytes plus a header, plus |max_handles| platform handles. | 98 // |payload_size| bytes plus a header, plus |max_handles| platform handles. |
84 Message(size_t payload_size, | 99 Message(size_t payload_size, |
85 size_t max_handles, | 100 size_t max_handles, |
86 Header::MessageType message_type = Header::MessageType::NORMAL); | 101 Header::MessageType message_type = Header::MessageType::NORMAL); |
87 | 102 |
88 ~Message(); | 103 ~Message(); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 | 163 |
149 #if defined(OS_WIN) | 164 #if defined(OS_WIN) |
150 // On Windows, handles are serialised into the extra header section. | 165 // On Windows, handles are serialised into the extra header section. |
151 PlatformHandle* handles_ = nullptr; | 166 PlatformHandle* handles_ = nullptr; |
152 #else | 167 #else |
153 ScopedPlatformHandleVectorPtr handle_vector_; | 168 ScopedPlatformHandleVectorPtr handle_vector_; |
154 #endif | 169 #endif |
155 | 170 |
156 #if defined(OS_MACOSX) && !defined(OS_IOS) | 171 #if defined(OS_MACOSX) && !defined(OS_IOS) |
157 // On OSX, handles are serialised into the extra header section. | 172 // On OSX, handles are serialised into the extra header section. |
158 MachPortsEntry* mach_ports_ = nullptr; | 173 MachPortsExtraHeader* mach_ports_header_ = nullptr; |
159 #endif | 174 #endif |
160 | 175 |
161 DISALLOW_COPY_AND_ASSIGN(Message); | 176 DISALLOW_COPY_AND_ASSIGN(Message); |
162 }; | 177 }; |
163 | 178 |
164 // Delegate methods are called from the I/O task runner with which the Channel | 179 // Delegate methods are called from the I/O task runner with which the Channel |
165 // was created (see Channel::Create). | 180 // was created (see Channel::Create). |
166 class Delegate { | 181 class Delegate { |
167 public: | 182 public: |
168 virtual ~Delegate() {} | 183 virtual ~Delegate() {} |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 Delegate* delegate_; | 267 Delegate* delegate_; |
253 const scoped_ptr<ReadBuffer> read_buffer_; | 268 const scoped_ptr<ReadBuffer> read_buffer_; |
254 | 269 |
255 DISALLOW_COPY_AND_ASSIGN(Channel); | 270 DISALLOW_COPY_AND_ASSIGN(Channel); |
256 }; | 271 }; |
257 | 272 |
258 } // namespace edk | 273 } // namespace edk |
259 } // namespace mojo | 274 } // namespace mojo |
260 | 275 |
261 #endif // MOJO_EDK_SYSTEM_CHANNEL_H_ | 276 #endif // MOJO_EDK_SYSTEM_CHANNEL_H_ |
OLD | NEW |