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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 return header_->num_header_bytes - sizeof(Header); | 121 return header_->num_header_bytes - sizeof(Header); |
122 } | 122 } |
123 | 123 |
124 void* mutable_payload() { return data_ + header_->num_header_bytes; } | 124 void* mutable_payload() { return data_ + header_->num_header_bytes; } |
125 const void* payload() const { return data_ + header_->num_header_bytes; } | 125 const void* payload() const { return data_ + header_->num_header_bytes; } |
126 size_t payload_size() const; | 126 size_t payload_size() const; |
127 #endif // defined(OS_CHROMEOS) || defined(OS_ANDROID) | 127 #endif // defined(OS_CHROMEOS) || defined(OS_ANDROID) |
128 | 128 |
129 size_t num_handles() const { return header_->num_handles; } | 129 size_t num_handles() const { return header_->num_handles; } |
130 bool has_handles() const { return header_->num_handles > 0; } | 130 bool has_handles() const { return header_->num_handles > 0; } |
131 PlatformHandle* handles(); | |
132 #if defined(OS_MACOSX) && !defined(OS_IOS) | 131 #if defined(OS_MACOSX) && !defined(OS_IOS) |
133 bool has_mach_ports() const; | 132 bool has_mach_ports() const; |
134 #endif | 133 #endif |
135 | 134 |
136 // Note: SetHandles() and TakeHandles() invalidate any previous value of | 135 // Note: SetHandles() and TakeHandles() invalidate any previous value of |
137 // handles(). | 136 // handles(). |
138 void SetHandles(ScopedPlatformHandleVectorPtr new_handles); | 137 void SetHandles(ScopedPlatformHandleVectorPtr new_handles); |
139 ScopedPlatformHandleVectorPtr TakeHandles(); | 138 ScopedPlatformHandleVectorPtr TakeHandles(); |
140 // Version of TakeHandles that returns a vector of platform handles suitable | 139 // Version of TakeHandles that returns a vector of platform handles suitable |
141 // for transfer over an underlying OS mechanism. i.e. file descriptors over | 140 // for transfer over an underlying OS mechanism. i.e. file descriptors over |
142 // a unix domain socket. Any handle that cannot be transferred this way, | 141 // a unix domain socket. Any handle that cannot be transferred this way, |
143 // such as Mach ports, will be removed. | 142 // such as Mach ports, will be removed. |
144 ScopedPlatformHandleVectorPtr TakeHandlesForTransport(); | 143 ScopedPlatformHandleVectorPtr TakeHandlesForTransport(); |
145 | 144 |
146 #if defined(OS_WIN) | 145 #if defined(OS_WIN) |
147 // Prepares the handles in this message for use in a different process. | 146 // Prepares the handles in this message for use in a different process. |
148 // Upon calling this the handles should belong to |from_process|; after the | 147 // Upon calling this the handles should belong to |from_process|; after the |
149 // call they'll belong to |to_process|. The source handles are always | 148 // call they'll belong to |to_process|. The source handles are always |
150 // closed by this call. Returns false iff one or more handles failed | 149 // closed by this call. Returns false iff one or more handles failed |
151 // duplication. | 150 // duplication. |
152 static bool RewriteHandles(base::ProcessHandle from_process, | 151 static bool RewriteHandles(base::ProcessHandle from_process, |
153 base::ProcessHandle to_process, | 152 base::ProcessHandle to_process, |
154 PlatformHandle* handles, | 153 PlatformHandleVector* handles); |
155 size_t num_handles); | |
156 #endif | 154 #endif |
157 | 155 |
158 private: | 156 private: |
159 size_t size_; | 157 size_t size_; |
160 size_t max_handles_; | 158 size_t max_handles_; |
161 char* data_; | 159 char* data_; |
162 Header* header_; | 160 Header* header_; |
163 | 161 |
| 162 ScopedPlatformHandleVectorPtr handle_vector_; |
| 163 |
164 #if defined(OS_WIN) | 164 #if defined(OS_WIN) |
165 // On Windows, handles are serialised into the extra header section. | 165 // On Windows, handles are serialised into the extra header section. |
166 PlatformHandle* handles_ = nullptr; | 166 HANDLE* handles_ = nullptr; |
167 #else | 167 #elif defined(OS_MACOSX) && !defined(OS_IOS) |
168 ScopedPlatformHandleVectorPtr handle_vector_; | |
169 #endif | |
170 | |
171 #if defined(OS_MACOSX) && !defined(OS_IOS) | |
172 // On OSX, handles are serialised into the extra header section. | 168 // On OSX, handles are serialised into the extra header section. |
173 MachPortsExtraHeader* mach_ports_header_ = nullptr; | 169 MachPortsExtraHeader* mach_ports_header_ = nullptr; |
174 #endif | 170 #endif |
175 | 171 |
176 DISALLOW_COPY_AND_ASSIGN(Message); | 172 DISALLOW_COPY_AND_ASSIGN(Message); |
177 }; | 173 }; |
178 | 174 |
179 // Delegate methods are called from the I/O task runner with which the Channel | 175 // Delegate methods are called from the I/O task runner with which the Channel |
180 // was created (see Channel::Create). | 176 // was created (see Channel::Create). |
181 class Delegate { | 177 class Delegate { |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 Delegate* delegate_; | 271 Delegate* delegate_; |
276 const std::unique_ptr<ReadBuffer> read_buffer_; | 272 const std::unique_ptr<ReadBuffer> read_buffer_; |
277 | 273 |
278 DISALLOW_COPY_AND_ASSIGN(Channel); | 274 DISALLOW_COPY_AND_ASSIGN(Channel); |
279 }; | 275 }; |
280 | 276 |
281 } // namespace edk | 277 } // namespace edk |
282 } // namespace mojo | 278 } // namespace mojo |
283 | 279 |
284 #endif // MOJO_EDK_SYSTEM_CHANNEL_H_ | 280 #endif // MOJO_EDK_SYSTEM_CHANNEL_H_ |
OLD | NEW |