15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef IPC_IPC_CHANNEL_H_
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define IPC_IPC_CHANNEL_H_
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <string>
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(OS_POSIX)
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <sys/types.h>
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/compiler_specific.h"
15a3f7b4e666c476898878fa745f637129375cd889Ben Murdoch#include "base/process/process.h"
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ipc/ipc_channel_handle.h"
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ipc/ipc_message.h"
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ipc/ipc_sender.h"
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace IPC {
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class Listener;
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//------------------------------------------------------------------------------
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// See
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// http://www.chromium.org/developers/design-documents/inter-process-communication
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// for overview of IPC in Chromium.
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Channels are implemented using named pipes on Windows, and
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// socket pairs (or in some special cases unix domain sockets) on POSIX.
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// On Windows we access pipes in various processes by name.
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// On POSIX we pass file descriptors to child processes and assign names to them
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// in a lookup table.
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// In general on POSIX we do not use unix domain sockets due to security
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// concerns and the fact that they can leave garbage around the file system
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// (MacOS does not support abstract named unix domain sockets).
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// You can use unix domain sockets if you like on POSIX by constructing the
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// the channel with the mode set to one of the NAMED modes. NAMED modes are
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// currently used by automation and service processes.
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class IPC_EXPORT Channel : public Sender {
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Security tests need access to the pipe handle.
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  friend class ChannelTest;
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Flags to test modes
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  enum ModeFlags {
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    MODE_NO_FLAG = 0x0,
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    MODE_SERVER_FLAG = 0x1,
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    MODE_CLIENT_FLAG = 0x2,
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    MODE_NAMED_FLAG = 0x4,
525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(OS_POSIX)
535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    MODE_OPEN_ACCESS_FLAG = 0x8, // Don't restrict access based on client UID.
545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  };
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Some Standard Modes
585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  enum Mode {
595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    MODE_NONE = MODE_NO_FLAG,
605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    MODE_SERVER = MODE_SERVER_FLAG,
615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    MODE_CLIENT = MODE_CLIENT_FLAG,
625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Channels on Windows are named by default and accessible from other
635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // processes. On POSIX channels are anonymous by default and not accessible
645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // from other processes. Named channels work via named unix domain sockets.
655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // On Windows MODE_NAMED_SERVER is equivalent to MODE_SERVER and
665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // MODE_NAMED_CLIENT is equivalent to MODE_CLIENT.
675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    MODE_NAMED_SERVER = MODE_SERVER_FLAG | MODE_NAMED_FLAG,
685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    MODE_NAMED_CLIENT = MODE_CLIENT_FLAG | MODE_NAMED_FLAG,
695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(OS_POSIX)
705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // An "open" named server accepts connections from ANY client.
715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // The caller must then implement their own access-control based on the
725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // client process' user Id.
735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    MODE_OPEN_NAMED_SERVER = MODE_OPEN_ACCESS_FLAG | MODE_SERVER_FLAG |
745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                             MODE_NAMED_FLAG
755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  };
775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
784e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // Messages internal to the IPC implementation are defined here.
794e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // Uses Maximum value of message type (uint16), to avoid conflicting
804e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // with normal message types, which are enumeration constants starting from 0.
815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  enum {
824e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    // The Hello message is sent by the peer when the channel is connected.
834e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    // The message contains just the process id (pid).
844e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    // The message has a special routing_id (MSG_ROUTING_NONE)
854e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    // and type (HELLO_MESSAGE_TYPE).
864e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    HELLO_MESSAGE_TYPE = kuint16max,
874e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    // The CLOSE_FD_MESSAGE_TYPE is used in the IPC class to
884e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    // work around a bug in sendmsg() on Mac. When an FD is sent
894e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    // over the socket, a CLOSE_FD_MESSAGE is sent with hops = 2.
904e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    // The client will return the message with hops = 1, *after* it
914e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    // has received the message that contains the FD. When we
924e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    // receive it again on the sender side, we close the FD.
934e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    CLOSE_FD_MESSAGE_TYPE = HELLO_MESSAGE_TYPE - 1
945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  };
955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The maximum message size in bytes. Attempting to receive a message of this
975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // size or bigger results in a channel error.
985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static const size_t kMaximumMessageSize = 128 * 1024 * 1024;
995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Amount of data to read at once from the pipe.
1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static const size_t kReadBufferSize = 4 * 1024;
1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Initialize a Channel.
1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //
1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // |channel_handle| identifies the communication Channel. For POSIX, if
1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // the file descriptor in the channel handle is != -1, the channel takes
1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // ownership of the file descriptor and will close it appropriately, otherwise
1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // it will create a new descriptor internally.
1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // |mode| specifies whether this Channel is to operate in server mode or
1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // client mode.  In server mode, the Channel is responsible for setting up the
1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // IPC object, whereas in client mode, the Channel merely connects to the
1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // already established IPC object.
1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // |listener| receives a callback on the current thread for each newly
1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // received message.
1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //
1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Channel(const IPC::ChannelHandle &channel_handle, Mode mode,
1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)          Listener* listener);
1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual ~Channel();
1205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Connect the pipe.  On the server side, this will initiate
1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // waiting for connections.  On the client, it attempts to
1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // connect to a pre-existing pipe.  Note, calling Connect()
1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // will not block the calling thread and may complete
1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // asynchronously.
1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool Connect() WARN_UNUSED_RESULT;
1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Close this Channel explicitly.  May be called multiple times.
1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // On POSIX calling close on an IPC channel that listens for connections will
1305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // cause it to close any accepted connections, and it will stop listening for
1315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // new connections. If you just want to close the currently accepted
1325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // connection and listen for new ones, use ResetToAcceptingConnectionState.
1335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void Close();
1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Get the process ID for the connected peer.
1362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  //
1372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Returns base::kNullProcessId if the peer is not connected yet. Watch out
1382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // for race conditions. You can easily get a channel to another process, but
1392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // if your process has not yet processed the "hello" message from the remote
1402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // side, this will fail. You should either make sure calling this is either
1412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // in response to a message from the remote side (which guarantees that it's
1422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // been connected), or you wait for the "connected" notification on the
1432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // listener.
1445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  base::ProcessId peer_pid() const;
1455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Send a message over the Channel to the listener on the other end.
1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //
1485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // |message| must be allocated using operator new.  This object will be
1495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // deleted once the contents of the Message have been sent.
1505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual bool Send(Message* message) OVERRIDE;
1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(OS_POSIX)
1535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // On POSIX an IPC::Channel wraps a socketpair(), this method returns the
1545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // FD # for the client end of the socket.
1555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // This method may only be called on the server side of a channel.
1565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // This method can be called on any thread.
1575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int GetClientFileDescriptor() const;
1585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Same as GetClientFileDescriptor, but transfers the ownership of the
1605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // file descriptor to the caller.
1615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // This method can be called on any thread.
1625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int TakeClientFileDescriptor();
1635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // On POSIX an IPC::Channel can either wrap an established socket, or it
1655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // can wrap a socket that is listening for connections. Currently an
1665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // IPC::Channel that listens for connections can only accept one connection
1675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // at a time.
1685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns true if the channel supports listening for connections.
1705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool AcceptsConnections() const;
1715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns true if the channel supports listening for connections and is
1735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // currently connected.
1745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool HasAcceptedConnection() const;
1755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns true if the peer process' effective user id can be determined, in
1772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // which case the supplied peer_euid is updated with it.
1782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  bool GetPeerEuid(uid_t* peer_euid) const;
1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Closes any currently connected socket, and returns to a listening state
1815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // for more connections.
1825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void ResetToAcceptingConnectionState();
1835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif  // defined(OS_POSIX) && !defined(OS_NACL)
1845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns true if a named server channel is initialized on the given channel
1865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // ID. Even if true, the server may have already accepted a connection.
1875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static bool IsNamedServerInitialized(const std::string& channel_id);
1885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if !defined(OS_NACL)
1905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Generates a channel ID that's non-predictable and unique.
1915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static std::string GenerateUniqueRandomChannelID();
1925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Generates a channel ID that, if passed to the client as a shared secret,
1945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // will validate that the client's authenticity. On platforms that do not
1955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // require additional this is simply calls GenerateUniqueRandomChannelID().
1965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // For portability the prefix should not include the \ character.
1975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static std::string GenerateVerifiedChannelID(const std::string& prefix);
1985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
1995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(OS_LINUX)
2015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Sandboxed processes live in a PID namespace, so when sending the IPC hello
2025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // message from client to server we need to send the PID from the global
2035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // PID namespace.
2045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static void SetGlobalPid(int pid);
2055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
2065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) protected:
2085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Used in Chrome by the TestSink to provide a dummy channel implementation
2095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // for testing. TestSink overrides the "interesting" functions in Channel so
2105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // no actual implementation is needed. This will cause un-overridden calls to
2115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // segfault. Do not use outside of test code!
2125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Channel() : channel_impl_(0) { }
2135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private:
2155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // PIMPL to which all channel calls are delegated.
2165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  class ChannelImpl;
2175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ChannelImpl *channel_impl_;
2185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
2195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace IPC
2215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif  // IPC_IPC_CHANNEL_H_
223