OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_IPC_CHANNEL_H_ | 5 #ifndef IPC_IPC_CHANNEL_H_ |
6 #define IPC_IPC_CHANNEL_H_ | 6 #define IPC_IPC_CHANNEL_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #if defined(OS_POSIX) | 10 #if defined(OS_POSIX) |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
173 | 173 |
174 // Get its own process id. This value is told to the peer. | 174 // Get its own process id. This value is told to the peer. |
175 virtual base::ProcessId GetSelfPID() const = 0; | 175 virtual base::ProcessId GetSelfPID() const = 0; |
176 | 176 |
177 // Send a message over the Channel to the listener on the other end. | 177 // Send a message over the Channel to the listener on the other end. |
178 // | 178 // |
179 // |message| must be allocated using operator new. This object will be | 179 // |message| must be allocated using operator new. This object will be |
180 // deleted once the contents of the Message have been sent. | 180 // deleted once the contents of the Message have been sent. |
181 virtual bool Send(Message* message) = 0; | 181 virtual bool Send(Message* message) = 0; |
182 | 182 |
183 #if defined(OS_POSIX) && !defined(OS_NACL) | 183 // NaCl in Non-SFI mode runs on Linux directly, and the following functions |
184 // compiled on Linux are also needed. Please see also comments in | |
185 // components/nacl_nonsfi.gyp for more details. | |
186 #if defined(OS_POSIX) && \ | |
187 (!defined(OS_NACL) || defined(__native_client_nonsfi__)) | |
184 // On POSIX an IPC::Channel wraps a socketpair(), this method returns the | 188 // On POSIX an IPC::Channel wraps a socketpair(), this method returns the |
185 // FD # for the client end of the socket. | 189 // FD # for the client end of the socket. |
186 // This method may only be called on the server side of a channel. | 190 // This method may only be called on the server side of a channel. |
187 // This method can be called on any thread. | 191 // This method can be called on any thread. |
188 virtual int GetClientFileDescriptor() const = 0; | 192 virtual int GetClientFileDescriptor() const = 0; |
189 | 193 |
190 // Same as GetClientFileDescriptor, but transfers the ownership of the | 194 // Same as GetClientFileDescriptor, but transfers the ownership of the |
191 // file descriptor to the caller. | 195 // file descriptor to the caller. |
192 // This method can be called on any thread. | 196 // This method can be called on any thread. |
193 virtual base::ScopedFD TakeClientFileDescriptor() = 0; | 197 virtual base::ScopedFD TakeClientFileDescriptor() = 0; |
194 #endif // defined(OS_POSIX) && !defined(OS_NACL) | 198 #endif |
195 | 199 |
196 // Returns true if a named server channel is initialized on the given channel | 200 // Returns true if a named server channel is initialized on the given channel |
197 // ID. Even if true, the server may have already accepted a connection. | 201 // ID. Even if true, the server may have already accepted a connection. |
198 static bool IsNamedServerInitialized(const std::string& channel_id); | 202 static bool IsNamedServerInitialized(const std::string& channel_id); |
199 | 203 |
200 #if !defined(OS_NACL) | 204 #if !defined(OS_NACL) || defined(__native_client_nonsfi__) |
Junichi Uekawa
2014/10/23 05:34:24
optional: I wish we had OS_NACL_NONSFI, OS_NACL_SF
hidehiko
2014/10/23 14:19:10
Ok, but please let me work on it separately, becau
| |
201 // Generates a channel ID that's non-predictable and unique. | 205 // Generates a channel ID that's non-predictable and unique. |
202 static std::string GenerateUniqueRandomChannelID(); | 206 static std::string GenerateUniqueRandomChannelID(); |
203 | 207 |
204 // Generates a channel ID that, if passed to the client as a shared secret, | 208 // Generates a channel ID that, if passed to the client as a shared secret, |
205 // will validate that the client's authenticity. On platforms that do not | 209 // will validate that the client's authenticity. On platforms that do not |
206 // require additional this is simply calls GenerateUniqueRandomChannelID(). | 210 // require additional this is simply calls GenerateUniqueRandomChannelID(). |
207 // For portability the prefix should not include the \ character. | 211 // For portability the prefix should not include the \ character. |
208 static std::string GenerateVerifiedChannelID(const std::string& prefix); | 212 static std::string GenerateVerifiedChannelID(const std::string& prefix); |
209 #endif | 213 #endif |
210 | 214 |
211 #if defined(OS_LINUX) | 215 #if defined(OS_LINUX) || defined(__native_client_nonsfi__) |
212 // Sandboxed processes live in a PID namespace, so when sending the IPC hello | 216 // Sandboxed processes live in a PID namespace, so when sending the IPC hello |
213 // message from client to server we need to send the PID from the global | 217 // message from client to server we need to send the PID from the global |
214 // PID namespace. | 218 // PID namespace. |
215 static void SetGlobalPid(int pid); | 219 static void SetGlobalPid(int pid); |
216 #endif | 220 #endif |
217 | 221 |
218 #if defined(OS_ANDROID) | 222 #if defined(OS_ANDROID) |
219 // Most tests are single process and work the same on all platforms. However | 223 // Most tests are single process and work the same on all platforms. However |
220 // in some cases we want to test multi-process, and Android differs in that it | 224 // in some cases we want to test multi-process, and Android differs in that it |
221 // can't 'exec' after forking. This callback resets any data in the forked | 225 // can't 'exec' after forking. This callback resets any data in the forked |
222 // process such that it acts similar to if it was exec'd, for tests. | 226 // process such that it acts similar to if it was exec'd, for tests. |
223 static void NotifyProcessForkedForTesting(); | 227 static void NotifyProcessForkedForTesting(); |
224 #endif | 228 #endif |
225 | 229 |
226 }; | 230 }; |
227 | 231 |
228 #if defined(OS_POSIX) | 232 #if defined(OS_POSIX) |
229 // SocketPair() creates a pair of socket FDs suitable for using with | 233 // SocketPair() creates a pair of socket FDs suitable for using with |
230 // IPC::Channel. | 234 // IPC::Channel. |
231 IPC_EXPORT bool SocketPair(int* fd1, int* fd2); | 235 IPC_EXPORT bool SocketPair(int* fd1, int* fd2); |
232 #endif | 236 #endif |
233 | 237 |
234 } // namespace IPC | 238 } // namespace IPC |
235 | 239 |
236 #endif // IPC_IPC_CHANNEL_H_ | 240 #endif // IPC_IPC_CHANNEL_H_ |
OLD | NEW |