diff options
author | morrita@chromium.org <morrita@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-06 20:13:51 +0000 |
---|---|---|
committer | morrita@chromium.org <morrita@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-06 20:13:51 +0000 |
commit | 2f60c9b74db6c61424a5a9c731acef26a9260c9c (patch) | |
tree | ef3fb081703d0fb3f20f2d279f2d73310a14eac6 /ipc | |
parent | 42dbdaa6943939486e36e8ded5eb26f2419eeee3 (diff) | |
download | chromium_src-2f60c9b74db6c61424a5a9c731acef26a9260c9c.zip chromium_src-2f60c9b74db6c61424a5a9c731acef26a9260c9c.tar.gz chromium_src-2f60c9b74db6c61424a5a9c731acef26a9260c9c.tar.bz2 |
Make IPC::Channel polymorphic
This change makes each platform specific ChannelImpl into
a subclass of Channel: ChannelPosix, ChannelWin, ChannelNacl.
delegated functions are now virtual.
TEST=none
BUG=377980
R=darin@chromium.org, jam@chromium.org
Review URL: https://codereview.chromium.org/310293002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@275505 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ipc')
-rw-r--r-- | ipc/ipc_channel.h | 39 | ||||
-rw-r--r-- | ipc/ipc_channel_common.cc | 26 | ||||
-rw-r--r-- | ipc/ipc_channel_nacl.cc | 80 | ||||
-rw-r--r-- | ipc/ipc_channel_nacl.h | 21 | ||||
-rw-r--r-- | ipc/ipc_channel_posix.cc | 132 | ||||
-rw-r--r-- | ipc/ipc_channel_posix.h | 39 | ||||
-rw-r--r-- | ipc/ipc_channel_posix_unittest.cc | 8 | ||||
-rw-r--r-- | ipc/ipc_channel_proxy.cc | 4 | ||||
-rw-r--r-- | ipc/ipc_channel_proxy.h | 2 | ||||
-rw-r--r-- | ipc/ipc_channel_win.cc | 74 | ||||
-rw-r--r-- | ipc/ipc_channel_win.h | 29 | ||||
-rw-r--r-- | ipc/ipc_message.h | 3 | ||||
-rw-r--r-- | ipc/ipc_send_fds_test.cc | 3 | ||||
-rw-r--r-- | ipc/ipc_sync_channel_unittest.cc | 4 | ||||
-rw-r--r-- | ipc/ipc_test_base.cc | 5 | ||||
-rw-r--r-- | ipc/ipc_test_sink.cc | 48 | ||||
-rw-r--r-- | ipc/ipc_test_sink.h | 12 |
17 files changed, 257 insertions, 272 deletions
diff --git a/ipc/ipc_channel.h b/ipc/ipc_channel.h index be8f83c..a2b813b 100644 --- a/ipc/ipc_channel.h +++ b/ipc/ipc_channel.h @@ -117,8 +117,9 @@ class IPC_EXPORT Channel : public Sender { // // TODO(morrita): Replace CreateByModeForProxy() with one of above Create*(). // - static scoped_ptr<Channel> CreateByModeForProxy( + static scoped_ptr<Channel> Create( const IPC::ChannelHandle &channel_handle, Mode mode,Listener* listener); + static scoped_ptr<Channel> CreateClient( const IPC::ChannelHandle &channel_handle, Listener* listener); @@ -149,14 +150,14 @@ class IPC_EXPORT Channel : public Sender { // connect to a pre-existing pipe. Note, calling Connect() // will not block the calling thread and may complete // asynchronously. - bool Connect() WARN_UNUSED_RESULT; + virtual bool Connect() WARN_UNUSED_RESULT = 0; // Close this Channel explicitly. May be called multiple times. // On POSIX calling close on an IPC channel that listens for connections will // cause it to close any accepted connections, and it will stop listening for // new connections. If you just want to close the currently accepted // connection and listen for new ones, use ResetToAcceptingConnectionState. - void Close(); + virtual void Close() = 0; // Get the process ID for the connected peer. // @@ -167,25 +168,25 @@ class IPC_EXPORT Channel : public Sender { // in response to a message from the remote side (which guarantees that it's // been connected), or you wait for the "connected" notification on the // listener. - base::ProcessId peer_pid() const; + virtual base::ProcessId GetPeerPID() const = 0; // Send a message over the Channel to the listener on the other end. // // |message| must be allocated using operator new. This object will be // deleted once the contents of the Message have been sent. - virtual bool Send(Message* message) OVERRIDE; + virtual bool Send(Message* message) = 0; -#if defined(OS_POSIX) +#if defined(OS_POSIX) && !defined(OS_NACL) // On POSIX an IPC::Channel wraps a socketpair(), this method returns the // FD # for the client end of the socket. // This method may only be called on the server side of a channel. // This method can be called on any thread. - int GetClientFileDescriptor() const; + virtual int GetClientFileDescriptor() const = 0; // Same as GetClientFileDescriptor, but transfers the ownership of the // file descriptor to the caller. // This method can be called on any thread. - int TakeClientFileDescriptor(); + virtual int TakeClientFileDescriptor() = 0; // On POSIX an IPC::Channel can either wrap an established socket, or it // can wrap a socket that is listening for connections. Currently an @@ -193,19 +194,19 @@ class IPC_EXPORT Channel : public Sender { // at a time. // Returns true if the channel supports listening for connections. - bool AcceptsConnections() const; + virtual bool AcceptsConnections() const = 0; // Returns true if the channel supports listening for connections and is // currently connected. - bool HasAcceptedConnection() const; + virtual bool HasAcceptedConnection() const = 0; // Returns true if the peer process' effective user id can be determined, in // which case the supplied peer_euid is updated with it. - bool GetPeerEuid(uid_t* peer_euid) const; + virtual bool GetPeerEuid(uid_t* peer_euid) const = 0; // Closes any currently connected socket, and returns to a listening state // for more connections. - void ResetToAcceptingConnectionState(); + virtual void ResetToAcceptingConnectionState() = 0; #endif // defined(OS_POSIX) && !defined(OS_NACL) // Returns true if a named server channel is initialized on the given channel @@ -238,20 +239,6 @@ class IPC_EXPORT Channel : public Sender { static void NotifyProcessForkedForTesting(); #endif - protected: - // Used in Chrome by the TestSink to provide a dummy channel implementation - // for testing. TestSink overrides the "interesting" functions in Channel so - // no actual implementation is needed. This will cause un-overridden calls to - // segfault. Do not use outside of test code! - Channel() : channel_impl_(0) { } - - private: - Channel(const IPC::ChannelHandle &channel_handle, Mode mode, - Listener* listener); - - // PIMPL to which all channel calls are delegated. - class ChannelImpl; - ChannelImpl *channel_impl_; }; #if defined(OS_POSIX) diff --git a/ipc/ipc_channel_common.cc b/ipc/ipc_channel_common.cc index c5ceba3e..d7347cc 100644 --- a/ipc/ipc_channel_common.cc +++ b/ipc/ipc_channel_common.cc @@ -7,49 +7,41 @@ namespace IPC { // static -scoped_ptr<Channel> Channel::CreateByModeForProxy( - const IPC::ChannelHandle &channel_handle, Mode mode, Listener* listener) { - return make_scoped_ptr( - new Channel(channel_handle, mode, listener)); -} - -// static scoped_ptr<Channel> Channel::CreateClient( const IPC::ChannelHandle &channel_handle, Listener* listener) { - return make_scoped_ptr( - new Channel(channel_handle, Channel::MODE_CLIENT, listener)); + return Channel::Create(channel_handle, Channel::MODE_CLIENT, listener); } // static scoped_ptr<Channel> Channel::CreateNamedServer( const IPC::ChannelHandle &channel_handle, Listener* listener) { - return make_scoped_ptr( - new Channel(channel_handle, Channel::MODE_NAMED_SERVER, listener)); + return Channel::Create(channel_handle, Channel::MODE_NAMED_SERVER, listener); } // static scoped_ptr<Channel> Channel::CreateNamedClient( const IPC::ChannelHandle &channel_handle, Listener* listener) { - return make_scoped_ptr( - new Channel(channel_handle, Channel::MODE_NAMED_CLIENT, listener)); + return Channel::Create(channel_handle, Channel::MODE_NAMED_CLIENT, listener); } #if defined(OS_POSIX) // static scoped_ptr<Channel> Channel::CreateOpenNamedServer( const IPC::ChannelHandle &channel_handle, Listener* listener) { - return make_scoped_ptr( - new Channel(channel_handle, Channel::MODE_OPEN_NAMED_SERVER, listener)); + return Channel::Create(channel_handle, + Channel::MODE_OPEN_NAMED_SERVER, + listener); } #endif // static scoped_ptr<Channel> Channel::CreateServer( const IPC::ChannelHandle &channel_handle, Listener* listener) { - return make_scoped_ptr( - new Channel(channel_handle, Channel::MODE_SERVER, listener)); + return Channel::Create(channel_handle, Channel::MODE_SERVER, listener); } +Channel::~Channel() { +} } // namespace IPC diff --git a/ipc/ipc_channel_nacl.cc b/ipc/ipc_channel_nacl.cc index f796af9..0928ba6 100644 --- a/ipc/ipc_channel_nacl.cc +++ b/ipc/ipc_channel_nacl.cc @@ -62,7 +62,7 @@ bool ReadDataOnReaderThread(int pipe, MessageContents* contents) { } // namespace -class Channel::ChannelImpl::ReaderThreadRunner +class ChannelNacl::ReaderThreadRunner : public base::DelegateSimpleThread::Delegate { public: // |pipe|: A file descriptor from which we will read using imc_recvmsg. @@ -91,7 +91,7 @@ class Channel::ChannelImpl::ReaderThreadRunner DISALLOW_COPY_AND_ASSIGN(ReaderThreadRunner); }; -Channel::ChannelImpl::ReaderThreadRunner::ReaderThreadRunner( +ChannelNacl::ReaderThreadRunner::ReaderThreadRunner( int pipe, base::Callback<void (scoped_ptr<MessageContents>)> data_read_callback, base::Callback<void ()> failure_callback, @@ -102,7 +102,7 @@ Channel::ChannelImpl::ReaderThreadRunner::ReaderThreadRunner( main_message_loop_(main_message_loop) { } -void Channel::ChannelImpl::ReaderThreadRunner::Run() { +void ChannelNacl::ReaderThreadRunner::Run() { while (true) { scoped_ptr<MessageContents> msg_contents(new MessageContents); bool success = ReadDataOnReaderThread(pipe_, msg_contents.get()); @@ -118,9 +118,9 @@ void Channel::ChannelImpl::ReaderThreadRunner::Run() { } } -Channel::ChannelImpl::ChannelImpl(const IPC::ChannelHandle& channel_handle, - Mode mode, - Listener* listener) +ChannelNacl::ChannelNacl(const IPC::ChannelHandle& channel_handle, + Mode mode, + Listener* listener) : ChannelReader(listener), mode_(mode), waiting_connect_(true), @@ -135,17 +135,17 @@ Channel::ChannelImpl::ChannelImpl(const IPC::ChannelHandle& channel_handle, } } -Channel::ChannelImpl::~ChannelImpl() { +ChannelNacl::~ChannelNacl() { Close(); } -base::ProcessId Channel::ChannelImpl::peer_pid() const { +base::ProcessId ChannelNacl::GetPeerPID() const { // This shouldn't actually get used in the untrusted side of the proxy, and we // don't have the real pid anyway. return -1; } -bool Channel::ChannelImpl::Connect() { +bool ChannelNacl::Connect() { if (pipe_ == -1) { DLOG(WARNING) << "Channel creation failed: " << pipe_name_; return false; @@ -159,9 +159,9 @@ bool Channel::ChannelImpl::Connect() { reader_thread_runner_.reset( new ReaderThreadRunner( pipe_, - base::Bind(&Channel::ChannelImpl::DidRecvMsg, + base::Bind(&ChannelNacl::DidRecvMsg, weak_ptr_factory_.GetWeakPtr()), - base::Bind(&Channel::ChannelImpl::ReadDidFail, + base::Bind(&ChannelNacl::ReadDidFail, weak_ptr_factory_.GetWeakPtr()), base::MessageLoopProxy::current())); reader_thread_.reset( @@ -172,13 +172,13 @@ bool Channel::ChannelImpl::Connect() { // If there were any messages queued before connection, send them. ProcessOutgoingMessages(); base::MessageLoopProxy::current()->PostTask(FROM_HERE, - base::Bind(&Channel::ChannelImpl::CallOnChannelConnected, + base::Bind(&ChannelNacl::CallOnChannelConnected, weak_ptr_factory_.GetWeakPtr())); return true; } -void Channel::ChannelImpl::Close() { +void ChannelNacl::Close() { // For now, we assume that at shutdown, the reader thread will be woken with // a failure (see NaClIPCAdapter::BlockingRead and CloseChannel). Or... we // might simply be killed with no chance to clean up anyway :-). @@ -195,7 +195,7 @@ void Channel::ChannelImpl::Close() { output_queue_.clear(); } -bool Channel::ChannelImpl::Send(Message* message) { +bool ChannelNacl::Send(Message* message) { DVLOG(2) << "sending message @" << message << " on channel @" << this << " with type " << message->type(); scoped_ptr<Message> message_ptr(message); @@ -212,7 +212,7 @@ bool Channel::ChannelImpl::Send(Message* message) { return true; } -void Channel::ChannelImpl::DidRecvMsg(scoped_ptr<MessageContents> contents) { +void ChannelNacl::DidRecvMsg(scoped_ptr<MessageContents> contents) { // Close sets the pipe to -1. It's possible we'll get a buffer sent to us from // the reader thread after Close is called. If so, we ignore it. if (pipe_ == -1) @@ -233,11 +233,11 @@ void Channel::ChannelImpl::DidRecvMsg(scoped_ptr<MessageContents> contents) { ProcessIncomingMessages(); } -void Channel::ChannelImpl::ReadDidFail() { +void ChannelNacl::ReadDidFail() { Close(); } -bool Channel::ChannelImpl::CreatePipe( +bool ChannelNacl::CreatePipe( const IPC::ChannelHandle& channel_handle) { DCHECK(pipe_ == -1); @@ -256,7 +256,7 @@ bool Channel::ChannelImpl::CreatePipe( return true; } -bool Channel::ChannelImpl::ProcessOutgoingMessages() { +bool ChannelNacl::ProcessOutgoingMessages() { DCHECK(!waiting_connect_); // Why are we trying to send messages if there's // no connection? if (output_queue_.empty()) @@ -304,11 +304,11 @@ bool Channel::ChannelImpl::ProcessOutgoingMessages() { return true; } -void Channel::ChannelImpl::CallOnChannelConnected() { - listener()->OnChannelConnected(peer_pid()); +void ChannelNacl::CallOnChannelConnected() { + listener()->OnChannelConnected(GetPeerPID()); } -Channel::ChannelImpl::ReadState Channel::ChannelImpl::ReadData( +ChannelNacl::ReadState ChannelNacl::ReadData( char* buffer, int buffer_len, int* bytes_read) { @@ -339,7 +339,7 @@ Channel::ChannelImpl::ReadState Channel::ChannelImpl::ReadData( return READ_SUCCEEDED; } -bool Channel::ChannelImpl::WillDispatchInputMessage(Message* msg) { +bool ChannelNacl::WillDispatchInputMessage(Message* msg) { uint16 header_fds = msg->header()->num_fds; CHECK(header_fds == input_fds_.size()); if (header_fds == 0) @@ -354,44 +354,24 @@ bool Channel::ChannelImpl::WillDispatchInputMessage(Message* msg) { return true; } -bool Channel::ChannelImpl::DidEmptyInputBuffers() { +bool ChannelNacl::DidEmptyInputBuffers() { // When the input data buffer is empty, the fds should be too. return input_fds_.empty(); } -void Channel::ChannelImpl::HandleInternalMessage(const Message& msg) { +void ChannelNacl::HandleInternalMessage(const Message& msg) { // The trusted side IPC::Channel should handle the "hello" handshake; we // should not receive the "Hello" message. NOTREACHED(); } -//------------------------------------------------------------------------------ -// Channel's methods simply call through to ChannelImpl. +// Channel's methods -Channel::Channel(const IPC::ChannelHandle& channel_handle, - Mode mode, - Listener* listener) - : channel_impl_(new ChannelImpl(channel_handle, mode, listener)) { -} - -Channel::~Channel() { - delete channel_impl_; -} - -bool Channel::Connect() { - return channel_impl_->Connect(); -} - -void Channel::Close() { - channel_impl_->Close(); -} - -base::ProcessId Channel::peer_pid() const { - return channel_impl_->peer_pid(); -} - -bool Channel::Send(Message* message) { - return channel_impl_->Send(message); +// static +scoped_ptr<Channel> Channel::Create( + const IPC::ChannelHandle &channel_handle, Mode mode, Listener* listener) { + return scoped_ptr<Channel>( + new ChannelNacl(channel_handle, mode, listener)); } } // namespace IPC diff --git a/ipc/ipc_channel_nacl.h b/ipc/ipc_channel_nacl.h index 29a9d57..c47892d 100644 --- a/ipc/ipc_channel_nacl.h +++ b/ipc/ipc_channel_nacl.h @@ -22,7 +22,7 @@ namespace IPC { // descriptors). struct MessageContents; -// Similar to the Posix version of ChannelImpl but for Native Client code. +// Similar to the ChannelPosix but for Native Client code. // This is somewhat different because sendmsg/recvmsg here do not follow POSIX // semantics. Instead, they are implemented by a custom embedding of // NaClDescCustom. See NaClIPCAdapter for the trusted-side implementation. @@ -31,19 +31,20 @@ struct MessageContents; // sharing handles. We also currently do not support passing file descriptors or // named pipes, and we use background threads to emulate signaling when we can // read or write without blocking. -class Channel::ChannelImpl : public internal::ChannelReader { +class ChannelNacl : public Channel, + public internal::ChannelReader { public: // Mirror methods of Channel, see ipc_channel.h for description. - ChannelImpl(const IPC::ChannelHandle& channel_handle, + ChannelNacl(const IPC::ChannelHandle& channel_handle, Mode mode, Listener* listener); - virtual ~ChannelImpl(); + virtual ~ChannelNacl(); // Channel implementation. - base::ProcessId peer_pid() const; - bool Connect(); - void Close(); - bool Send(Message* message); + virtual base::ProcessId GetPeerPID() const OVERRIDE; + virtual bool Connect() OVERRIDE; + virtual void Close() OVERRIDE; + virtual bool Send(Message* message) OVERRIDE; // Posted to the main thread by ReaderThreadRunner. void DidRecvMsg(scoped_ptr<MessageContents> contents); @@ -110,9 +111,9 @@ class Channel::ChannelImpl : public internal::ChannelReader { // called. Normally after we're connected, the queue is empty. std::deque<linked_ptr<Message> > output_queue_; - base::WeakPtrFactory<ChannelImpl> weak_ptr_factory_; + base::WeakPtrFactory<ChannelNacl> weak_ptr_factory_; - DISALLOW_IMPLICIT_CONSTRUCTORS(ChannelImpl); + DISALLOW_IMPLICIT_CONSTRUCTORS(ChannelNacl); }; } // namespace IPC diff --git a/ipc/ipc_channel_posix.cc b/ipc/ipc_channel_posix.cc index 11b20ff..3972788 100644 --- a/ipc/ipc_channel_posix.cc +++ b/ipc/ipc_channel_posix.cc @@ -174,11 +174,11 @@ void Channel::NotifyProcessForkedForTesting() { //------------------------------------------------------------------------------ #if defined(OS_LINUX) -int Channel::ChannelImpl::global_pid_ = 0; +int ChannelPosix::global_pid_ = 0; #endif // OS_LINUX -Channel::ChannelImpl::ChannelImpl(const IPC::ChannelHandle& channel_handle, - Mode mode, Listener* listener) +ChannelPosix::ChannelPosix(const IPC::ChannelHandle& channel_handle, + Mode mode, Listener* listener) : ChannelReader(listener), mode_(mode), peer_pid_(base::kNullProcessId), @@ -203,7 +203,7 @@ Channel::ChannelImpl::ChannelImpl(const IPC::ChannelHandle& channel_handle, } } -Channel::ChannelImpl::~ChannelImpl() { +ChannelPosix::~ChannelPosix() { Close(); } @@ -231,7 +231,7 @@ bool SocketPair(int* fd1, int* fd2) { return true; } -bool Channel::ChannelImpl::CreatePipe( +bool ChannelPosix::CreatePipe( const IPC::ChannelHandle& channel_handle) { DCHECK(server_listen_pipe_ == -1 && pipe_ == -1); @@ -337,7 +337,7 @@ bool Channel::ChannelImpl::CreatePipe( return true; } -bool Channel::ChannelImpl::Connect() { +bool ChannelPosix::Connect() { if (server_listen_pipe_ == -1 && pipe_ == -1) { DLOG(WARNING) << "Channel creation failed: " << pipe_name_; return false; @@ -359,7 +359,7 @@ bool Channel::ChannelImpl::Connect() { return did_connect; } -void Channel::ChannelImpl::CloseFileDescriptors(Message* msg) { +void ChannelPosix::CloseFileDescriptors(Message* msg) { #if defined(OS_MACOSX) // There is a bug on OSX which makes it dangerous to close // a file descriptor while it is in transit. So instead we @@ -380,7 +380,7 @@ void Channel::ChannelImpl::CloseFileDescriptors(Message* msg) { #endif } -bool Channel::ChannelImpl::ProcessOutgoingMessages() { +bool ChannelPosix::ProcessOutgoingMessages() { DCHECK(!waiting_connect_); // Why are we trying to send messages if there's // no connection? if (output_queue_.empty()) @@ -526,7 +526,7 @@ bool Channel::ChannelImpl::ProcessOutgoingMessages() { return true; } -bool Channel::ChannelImpl::Send(Message* message) { +bool ChannelPosix::Send(Message* message) { DVLOG(2) << "sending message @" << message << " on channel @" << this << " with type " << message->type() << " (" << output_queue_.size() << " in queue)"; @@ -544,12 +544,12 @@ bool Channel::ChannelImpl::Send(Message* message) { return true; } -int Channel::ChannelImpl::GetClientFileDescriptor() { +int ChannelPosix::GetClientFileDescriptor() const { base::AutoLock lock(client_pipe_lock_); return client_pipe_; } -int Channel::ChannelImpl::TakeClientFileDescriptor() { +int ChannelPosix::TakeClientFileDescriptor() { base::AutoLock lock(client_pipe_lock_); int fd = client_pipe_; if (client_pipe_ != -1) { @@ -559,7 +559,7 @@ int Channel::ChannelImpl::TakeClientFileDescriptor() { return fd; } -void Channel::ChannelImpl::CloseClientFileDescriptor() { +void ChannelPosix::CloseClientFileDescriptor() { base::AutoLock lock(client_pipe_lock_); if (client_pipe_ != -1) { PipeMap::GetInstance()->Remove(pipe_name_); @@ -569,20 +569,20 @@ void Channel::ChannelImpl::CloseClientFileDescriptor() { } } -bool Channel::ChannelImpl::AcceptsConnections() const { +bool ChannelPosix::AcceptsConnections() const { return server_listen_pipe_ != -1; } -bool Channel::ChannelImpl::HasAcceptedConnection() const { +bool ChannelPosix::HasAcceptedConnection() const { return AcceptsConnections() && pipe_ != -1; } -bool Channel::ChannelImpl::GetPeerEuid(uid_t* peer_euid) const { +bool ChannelPosix::GetPeerEuid(uid_t* peer_euid) const { DCHECK(!(mode_ & MODE_SERVER) || HasAcceptedConnection()); return IPC::GetPeerEuid(pipe_, peer_euid); } -void Channel::ChannelImpl::ResetToAcceptingConnectionState() { +void ChannelPosix::ResetToAcceptingConnectionState() { // Unregister libevent for the unix domain socket and close it. read_watcher_.StopWatchingFileDescriptor(); write_watcher_.StopWatchingFileDescriptor(); @@ -626,20 +626,20 @@ void Channel::ChannelImpl::ResetToAcceptingConnectionState() { } // static -bool Channel::ChannelImpl::IsNamedServerInitialized( +bool ChannelPosix::IsNamedServerInitialized( const std::string& channel_id) { return base::PathExists(base::FilePath(channel_id)); } #if defined(OS_LINUX) // static -void Channel::ChannelImpl::SetGlobalPid(int pid) { +void ChannelPosix::SetGlobalPid(int pid) { global_pid_ = pid; } #endif // OS_LINUX // Called by libevent when we can read from the pipe without blocking. -void Channel::ChannelImpl::OnFileCanReadWithoutBlocking(int fd) { +void ChannelPosix::OnFileCanReadWithoutBlocking(int fd) { if (fd == server_listen_pipe_) { int new_pipe = 0; if (!ServerAcceptConnection(server_listen_pipe_, &new_pipe) || @@ -705,7 +705,7 @@ void Channel::ChannelImpl::OnFileCanReadWithoutBlocking(int fd) { } // Called by libevent when we can write to the pipe without blocking. -void Channel::ChannelImpl::OnFileCanWriteWithoutBlocking(int fd) { +void ChannelPosix::OnFileCanWriteWithoutBlocking(int fd) { DCHECK_EQ(pipe_, fd); is_blocked_on_write_ = false; if (!ProcessOutgoingMessages()) { @@ -713,7 +713,7 @@ void Channel::ChannelImpl::OnFileCanWriteWithoutBlocking(int fd) { } } -bool Channel::ChannelImpl::AcceptConnection() { +bool ChannelPosix::AcceptConnection() { base::MessageLoopForIO::current()->WatchFileDescriptor( pipe_, true, base::MessageLoopForIO::WATCH_READ, &read_watcher_, this); QueueHelloMessage(); @@ -733,7 +733,7 @@ bool Channel::ChannelImpl::AcceptConnection() { } } -void Channel::ChannelImpl::ClosePipeOnError() { +void ChannelPosix::ClosePipeOnError() { if (HasAcceptedConnection()) { ResetToAcceptingConnectionState(); listener()->OnChannelError(); @@ -747,7 +747,7 @@ void Channel::ChannelImpl::ClosePipeOnError() { } } -int Channel::ChannelImpl::GetHelloMessageProcId() { +int ChannelPosix::GetHelloMessageProcId() { int pid = base::GetCurrentProcId(); #if defined(OS_LINUX) // Our process may be in a sandbox with a separate PID namespace. @@ -758,7 +758,7 @@ int Channel::ChannelImpl::GetHelloMessageProcId() { return pid; } -void Channel::ChannelImpl::QueueHelloMessage() { +void ChannelPosix::QueueHelloMessage() { // Create the Hello message scoped_ptr<Message> msg(new Message(MSG_ROUTING_NONE, HELLO_MESSAGE_TYPE, @@ -779,7 +779,7 @@ void Channel::ChannelImpl::QueueHelloMessage() { output_queue_.push(msg.release()); } -Channel::ChannelImpl::ReadState Channel::ChannelImpl::ReadData( +ChannelPosix::ReadState ChannelPosix::ReadData( char* buffer, int buffer_len, int* bytes_read) { @@ -837,7 +837,7 @@ Channel::ChannelImpl::ReadState Channel::ChannelImpl::ReadData( } #if defined(IPC_USES_READWRITE) -bool Channel::ChannelImpl::ReadFileDescriptorsFromFDPipe() { +bool ChannelPosix::ReadFileDescriptorsFromFDPipe() { char dummy; struct iovec fd_pipe_iov = { &dummy, 1 }; @@ -862,7 +862,7 @@ bool Channel::ChannelImpl::ReadFileDescriptorsFromFDPipe() { // // This will read from the input_fds_ (READWRITE mode only) and read more // handles from the FD pipe if necessary. -bool Channel::ChannelImpl::WillDispatchInputMessage(Message* msg) { +bool ChannelPosix::WillDispatchInputMessage(Message* msg) { uint16 header_fds = msg->header()->num_fds; if (!header_fds) return true; // Nothing to do. @@ -902,14 +902,14 @@ bool Channel::ChannelImpl::WillDispatchInputMessage(Message* msg) { return true; } -bool Channel::ChannelImpl::DidEmptyInputBuffers() { +bool ChannelPosix::DidEmptyInputBuffers() { // When the input data buffer is empty, the fds should be too. If this is // not the case, we probably have a rogue renderer which is trying to fill // our descriptor table. return input_fds_.empty(); } -bool Channel::ChannelImpl::ExtractFileDescriptorsFromMsghdr(msghdr* msg) { +bool ChannelPosix::ExtractFileDescriptorsFromMsghdr(msghdr* msg) { // Check that there are any control messages. On OSX, CMSG_FIRSTHDR will // return an invalid non-NULL pointer in the case that controllen == 0. if (msg->msg_controllen == 0) @@ -941,7 +941,7 @@ bool Channel::ChannelImpl::ExtractFileDescriptorsFromMsghdr(msghdr* msg) { return true; } -void Channel::ChannelImpl::ClearInputFDs() { +void ChannelPosix::ClearInputFDs() { for (size_t i = 0; i < input_fds_.size(); ++i) { if (IGNORE_EINTR(close(input_fds_[i])) < 0) PLOG(ERROR) << "close "; @@ -949,7 +949,7 @@ void Channel::ChannelImpl::ClearInputFDs() { input_fds_.clear(); } -void Channel::ChannelImpl::QueueCloseFDMessage(int fd, int hops) { +void ChannelPosix::QueueCloseFDMessage(int fd, int hops) { switch (hops) { case 1: case 2: { @@ -971,7 +971,7 @@ void Channel::ChannelImpl::QueueCloseFDMessage(int fd, int hops) { } } -void Channel::ChannelImpl::HandleInternalMessage(const Message& msg) { +void ChannelPosix::HandleInternalMessage(const Message& msg) { // The Hello message contains only the process id. PickleIterator iter(msg); @@ -1025,7 +1025,7 @@ void Channel::ChannelImpl::HandleInternalMessage(const Message& msg) { } } -void Channel::ChannelImpl::Close() { +void ChannelPosix::Close() { // Close can be called multiple time, so we need to make sure we're // idempotent. @@ -1046,61 +1046,18 @@ void Channel::ChannelImpl::Close() { CloseClientFileDescriptor(); } -//------------------------------------------------------------------------------ -// Channel's methods simply call through to ChannelImpl. -Channel::Channel(const IPC::ChannelHandle& channel_handle, Mode mode, - Listener* listener) - : channel_impl_(new ChannelImpl(channel_handle, mode, listener)) { -} - -Channel::~Channel() { - delete channel_impl_; -} - -bool Channel::Connect() { - return channel_impl_->Connect(); -} - -void Channel::Close() { - if (channel_impl_) - channel_impl_->Close(); -} - -base::ProcessId Channel::peer_pid() const { - return channel_impl_->peer_pid(); -} - -bool Channel::Send(Message* message) { - return channel_impl_->Send(message); -} - -int Channel::GetClientFileDescriptor() const { - return channel_impl_->GetClientFileDescriptor(); +base::ProcessId ChannelPosix::GetPeerPID() const { + return peer_pid_; } -int Channel::TakeClientFileDescriptor() { - return channel_impl_->TakeClientFileDescriptor(); -} - -bool Channel::AcceptsConnections() const { - return channel_impl_->AcceptsConnections(); -} - -bool Channel::HasAcceptedConnection() const { - return channel_impl_->HasAcceptedConnection(); -} - -bool Channel::GetPeerEuid(uid_t* peer_euid) const { - return channel_impl_->GetPeerEuid(peer_euid); -} - -void Channel::ResetToAcceptingConnectionState() { - channel_impl_->ResetToAcceptingConnectionState(); -} +//------------------------------------------------------------------------------ +// Channel's methods // static -bool Channel::IsNamedServerInitialized(const std::string& channel_id) { - return ChannelImpl::IsNamedServerInitialized(channel_id); +scoped_ptr<Channel> Channel::Create( + const IPC::ChannelHandle &channel_handle, Mode mode, Listener* listener) { + return scoped_ptr<Channel>( + new ChannelPosix(channel_handle, mode, listener)); } // static @@ -1116,10 +1073,15 @@ std::string Channel::GenerateVerifiedChannelID(const std::string& prefix) { } +bool Channel::IsNamedServerInitialized( + const std::string& channel_id) { + return ChannelPosix::IsNamedServerInitialized(channel_id); +} + #if defined(OS_LINUX) // static void Channel::SetGlobalPid(int pid) { - ChannelImpl::SetGlobalPid(pid); + ChannelPosix::SetGlobalPid(pid); } #endif // OS_LINUX diff --git a/ipc/ipc_channel_posix.h b/ipc/ipc_channel_posix.h index 1e587c1..ae2de72 100644 --- a/ipc/ipc_channel_posix.h +++ b/ipc/ipc_channel_posix.h @@ -49,24 +49,29 @@ namespace IPC { -class Channel::ChannelImpl : public internal::ChannelReader, - public base::MessageLoopForIO::Watcher { +class ChannelPosix : public Channel, + public internal::ChannelReader, + public base::MessageLoopForIO::Watcher { public: // Mirror methods of Channel, see ipc_channel.h for description. - ChannelImpl(const IPC::ChannelHandle& channel_handle, Mode mode, - Listener* listener); - virtual ~ChannelImpl(); - bool Connect(); - void Close(); - bool Send(Message* message); - int GetClientFileDescriptor(); - int TakeClientFileDescriptor(); + ChannelPosix(const IPC::ChannelHandle& channel_handle, Mode mode, + Listener* listener); + virtual ~ChannelPosix(); + + // Channel implementation + virtual bool Connect() OVERRIDE; + virtual void Close() OVERRIDE; + virtual bool Send(Message* message) OVERRIDE; + virtual base::ProcessId GetPeerPID() const OVERRIDE; + virtual int GetClientFileDescriptor() const OVERRIDE; + virtual int TakeClientFileDescriptor() OVERRIDE; + virtual bool AcceptsConnections() const OVERRIDE; + virtual bool HasAcceptedConnection() const OVERRIDE; + virtual bool GetPeerEuid(uid_t* peer_euid) const OVERRIDE; + virtual void ResetToAcceptingConnectionState() OVERRIDE; + void CloseClientFileDescriptor(); - bool AcceptsConnections() const; - bool HasAcceptedConnection() const; - bool GetPeerEuid(uid_t* peer_euid) const; - void ResetToAcceptingConnectionState(); - base::ProcessId peer_pid() const { return peer_pid_; } + static bool IsNamedServerInitialized(const std::string& channel_id); #if defined(OS_LINUX) static void SetGlobalPid(int pid); @@ -144,7 +149,7 @@ class Channel::ChannelImpl : public internal::ChannelReader, // For a server, the client end of our socketpair() -- the other end of our // pipe_ that is passed to the client. int client_pipe_; - base::Lock client_pipe_lock_; // Lock that protects |client_pipe_|. + mutable base::Lock client_pipe_lock_; // Lock that protects |client_pipe_|. #if defined(IPC_USES_READWRITE) // Linux/BSD use a dedicated socketpair() for passing file descriptors. @@ -202,7 +207,7 @@ class Channel::ChannelImpl : public internal::ChannelReader, static int global_pid_; #endif // OS_LINUX - DISALLOW_IMPLICIT_CONSTRUCTORS(ChannelImpl); + DISALLOW_IMPLICIT_CONSTRUCTORS(ChannelPosix); }; } // namespace IPC diff --git a/ipc/ipc_channel_posix_unittest.cc b/ipc/ipc_channel_posix_unittest.cc index d001920..be43b2a 100644 --- a/ipc/ipc_channel_posix_unittest.cc +++ b/ipc/ipc_channel_posix_unittest.cc @@ -245,7 +245,8 @@ TEST_F(IPCChannelPosixTest, SendHangTest) { IPC::ChannelHandle in_handle("IN"); scoped_ptr<IPC::Channel> in_chan( IPC::Channel::CreateServer(in_handle, &in_listener)); - base::FileDescriptor out_fd(in_chan->TakeClientFileDescriptor(), false); + base::FileDescriptor out_fd( + in_chan->TakeClientFileDescriptor(), false); IPC::ChannelHandle out_handle("OUT", out_fd); scoped_ptr<IPC::Channel> out_chan( IPC::Channel::CreateClient(out_handle, &out_listener)); @@ -270,7 +271,8 @@ TEST_F(IPCChannelPosixTest, AcceptHangTest) { IPC::ChannelHandle in_handle("IN"); scoped_ptr<IPC::Channel> in_chan( IPC::Channel::CreateServer(in_handle, &in_listener)); - base::FileDescriptor out_fd(in_chan->TakeClientFileDescriptor(), false); + base::FileDescriptor out_fd( + in_chan->TakeClientFileDescriptor(), false); IPC::ChannelHandle out_handle("OUT", out_fd); scoped_ptr<IPC::Channel> out_chan( IPC::Channel::CreateClient(out_handle, &out_listener)); @@ -423,7 +425,7 @@ TEST_F(IPCChannelPosixTest, BadMode) { // Test setting up two servers with a bad mode. IPCChannelPosixTestListener listener(false); IPC::ChannelHandle chan_handle(GetConnectionSocketName()); - scoped_ptr<IPC::Channel> channel(IPC::Channel::CreateByModeForProxy( + scoped_ptr<IPC::Channel> channel(IPC::Channel::Create( chan_handle, IPC::Channel::MODE_NONE, &listener)); ASSERT_FALSE(channel->Connect()); } diff --git a/ipc/ipc_channel_proxy.cc b/ipc/ipc_channel_proxy.cc index ceffb94..2f2a893 100644 --- a/ipc/ipc_channel_proxy.cc +++ b/ipc/ipc_channel_proxy.cc @@ -52,7 +52,7 @@ void ChannelProxy::Context::CreateChannel(const IPC::ChannelHandle& handle, const Channel::Mode& mode) { DCHECK(!channel_); channel_id_ = handle.name; - channel_ = Channel::CreateByModeForProxy(handle, mode, this); + channel_ = Channel::Create(handle, mode, this); } bool ChannelProxy::Context::TryFilters(const Message& message) { @@ -95,7 +95,7 @@ bool ChannelProxy::Context::OnMessageReceivedNoFilter(const Message& message) { // Called on the IPC::Channel thread void ChannelProxy::Context::OnChannelConnected(int32 peer_pid) { // We cache off the peer_pid so it can be safely accessed from both threads. - peer_pid_ = channel_->peer_pid(); + peer_pid_ = channel_->GetPeerPID(); // Add any pending filters. This avoids a race condition where someone // creates a ChannelProxy, calls AddFilter, and then right after starts the diff --git a/ipc/ipc_channel_proxy.h b/ipc/ipc_channel_proxy.h index 31ca211..7b71d5b 100644 --- a/ipc/ipc_channel_proxy.h +++ b/ipc/ipc_channel_proxy.h @@ -110,7 +110,7 @@ class IPC_EXPORT ChannelProxy : public Sender, public base::NonThreadSafe { // Get the process ID for the connected peer. // Returns base::kNullProcessId if the peer is not connected yet. - base::ProcessId peer_pid() const { return context_->peer_pid_; } + base::ProcessId GetPeerPID() const { return context_->peer_pid_; } #if defined(OS_POSIX) && !defined(OS_NACL) // Calls through to the underlying channel's methods. diff --git a/ipc/ipc_channel_win.cc b/ipc/ipc_channel_win.cc index d044ef1..4023097 100644 --- a/ipc/ipc_channel_win.cc +++ b/ipc/ipc_channel_win.cc @@ -23,17 +23,17 @@ namespace IPC { -Channel::ChannelImpl::State::State(ChannelImpl* channel) : is_pending(false) { +ChannelWin::State::State(ChannelWin* channel) : is_pending(false) { memset(&context.overlapped, 0, sizeof(context.overlapped)); context.handler = channel; } -Channel::ChannelImpl::State::~State() { - COMPILE_ASSERT(!offsetof(Channel::ChannelImpl::State, context), +ChannelWin::State::~State() { + COMPILE_ASSERT(!offsetof(ChannelWin::State, context), starts_with_io_context); } -Channel::ChannelImpl::ChannelImpl(const IPC::ChannelHandle &channel_handle, +ChannelWin::ChannelWin(const IPC::ChannelHandle &channel_handle, Mode mode, Listener* listener) : ChannelReader(listener), input_state_(this), @@ -48,11 +48,11 @@ Channel::ChannelImpl::ChannelImpl(const IPC::ChannelHandle &channel_handle, CreatePipe(channel_handle, mode); } -Channel::ChannelImpl::~ChannelImpl() { +ChannelWin::~ChannelWin() { Close(); } -void Channel::ChannelImpl::Close() { +void ChannelWin::Close() { if (thread_check_.get()) { DCHECK(thread_check_->CalledOnValidThread()); } @@ -80,7 +80,7 @@ void Channel::ChannelImpl::Close() { } } -bool Channel::ChannelImpl::Send(Message* message) { +bool ChannelWin::Send(Message* message) { DCHECK(thread_check_->CalledOnValidThread()); DVLOG(2) << "sending message @" << message << " on channel @" << this << " with type " << message->type() @@ -103,8 +103,12 @@ bool Channel::ChannelImpl::Send(Message* message) { return true; } +base::ProcessId ChannelWin::GetPeerPID() const { + return peer_pid_; +} + // static -bool Channel::ChannelImpl::IsNamedServerInitialized( +bool ChannelWin::IsNamedServerInitialized( const std::string& channel_id) { if (WaitNamedPipe(PipeName(channel_id, NULL).c_str(), 1)) return true; @@ -113,7 +117,7 @@ bool Channel::ChannelImpl::IsNamedServerInitialized( return GetLastError() == ERROR_SEM_TIMEOUT; } -Channel::ChannelImpl::ReadState Channel::ChannelImpl::ReadData( +ChannelWin::ReadState ChannelWin::ReadData( char* buffer, int buffer_len, int* /* bytes_read */) { @@ -145,14 +149,14 @@ Channel::ChannelImpl::ReadState Channel::ChannelImpl::ReadData( return READ_PENDING; } -bool Channel::ChannelImpl::WillDispatchInputMessage(Message* msg) { +bool ChannelWin::WillDispatchInputMessage(Message* msg) { // Make sure we get a hello when client validation is required. if (validate_client_) return IsHelloMessage(*msg); return true; } -void Channel::ChannelImpl::HandleInternalMessage(const Message& msg) { +void ChannelWin::HandleInternalMessage(const Message& msg) { DCHECK_EQ(msg.type(), static_cast<unsigned>(Channel::HELLO_MESSAGE_TYPE)); // The hello message contains one parameter containing the PID. PickleIterator it(msg); @@ -177,13 +181,13 @@ void Channel::ChannelImpl::HandleInternalMessage(const Message& msg) { listener()->OnChannelConnected(claimed_pid); } -bool Channel::ChannelImpl::DidEmptyInputBuffers() { +bool ChannelWin::DidEmptyInputBuffers() { // We don't need to do anything here. return true; } // static -const base::string16 Channel::ChannelImpl::PipeName( +const base::string16 ChannelWin::PipeName( const std::string& channel_id, int32* secret) { std::string name("\\\\.\\pipe\\chrome."); @@ -201,7 +205,7 @@ const base::string16 Channel::ChannelImpl::PipeName( return base::ASCIIToWide(name.append(channel_id)); } -bool Channel::ChannelImpl::CreatePipe(const IPC::ChannelHandle &channel_handle, +bool ChannelWin::CreatePipe(const IPC::ChannelHandle &channel_handle, Mode mode) { DCHECK_EQ(INVALID_HANDLE_VALUE, pipe_); base::string16 pipe_name; @@ -286,7 +290,7 @@ bool Channel::ChannelImpl::CreatePipe(const IPC::ChannelHandle &channel_handle, return true; } -bool Channel::ChannelImpl::Connect() { +bool ChannelWin::Connect() { DLOG_IF(WARNING, thread_check_.get()) << "Connect called more than once"; if (!thread_check_.get()) @@ -307,7 +311,7 @@ bool Channel::ChannelImpl::Connect() { // initialization signal. base::MessageLoopForIO::current()->PostTask( FROM_HERE, - base::Bind(&Channel::ChannelImpl::OnIOCompleted, + base::Bind(&ChannelWin::OnIOCompleted, weak_factory_.GetWeakPtr(), &input_state_.context, 0, @@ -319,7 +323,7 @@ bool Channel::ChannelImpl::Connect() { return true; } -bool Channel::ChannelImpl::ProcessConnection() { +bool ChannelWin::ProcessConnection() { DCHECK(thread_check_->CalledOnValidThread()); if (input_state_.is_pending) input_state_.is_pending = false; @@ -356,7 +360,7 @@ bool Channel::ChannelImpl::ProcessConnection() { return true; } -bool Channel::ChannelImpl::ProcessOutgoingMessages( +bool ChannelWin::ProcessOutgoingMessages( base::MessageLoopForIO::IOContext* context, DWORD bytes_written) { DCHECK(!waiting_connect_); // Why are we trying to send messages if there's @@ -413,7 +417,7 @@ bool Channel::ChannelImpl::ProcessOutgoingMessages( return true; } -void Channel::ChannelImpl::OnIOCompleted( +void ChannelWin::OnIOCompleted( base::MessageLoopForIO::IOContext* context, DWORD bytes_transfered, DWORD error) { @@ -463,36 +467,18 @@ void Channel::ChannelImpl::OnIOCompleted( } //------------------------------------------------------------------------------ -// Channel's methods simply call through to ChannelImpl. -Channel::Channel(const IPC::ChannelHandle &channel_handle, Mode mode, - Listener* listener) - : channel_impl_(new ChannelImpl(channel_handle, mode, listener)) { -} - -Channel::~Channel() { - delete channel_impl_; -} - -bool Channel::Connect() { - return channel_impl_->Connect(); -} - -void Channel::Close() { - if (channel_impl_) - channel_impl_->Close(); -} +// Channel's methods -base::ProcessId Channel::peer_pid() const { - return channel_impl_->peer_pid(); -} - -bool Channel::Send(Message* message) { - return channel_impl_->Send(message); +// static +scoped_ptr<Channel> Channel::Create( + const IPC::ChannelHandle &channel_handle, Mode mode, Listener* listener) { + return scoped_ptr<Channel>( + new ChannelWin(channel_handle, mode, listener)); } // static bool Channel::IsNamedServerInitialized(const std::string& channel_id) { - return ChannelImpl::IsNamedServerInitialized(channel_id); + return ChannelWin::IsNamedServerInitialized(channel_id); } // static diff --git a/ipc/ipc_channel_win.h b/ipc/ipc_channel_win.h index 5bdba93..29042bf 100644 --- a/ipc/ipc_channel_win.h +++ b/ipc/ipc_channel_win.h @@ -21,18 +21,23 @@ class ThreadChecker; namespace IPC { -class Channel::ChannelImpl : public internal::ChannelReader, - public base::MessageLoopForIO::IOHandler { +class ChannelWin : public Channel, + public internal::ChannelReader, + public base::MessageLoopForIO::IOHandler { public: // Mirror methods of Channel, see ipc_channel.h for description. - ChannelImpl(const IPC::ChannelHandle &channel_handle, Mode mode, - Listener* listener); - ~ChannelImpl(); - bool Connect(); - void Close(); - bool Send(Message* message); + ChannelWin(const IPC::ChannelHandle &channel_handle, Mode mode, + Listener* listener); + ~ChannelWin(); + + // Channel implementation + virtual bool Connect() OVERRIDE; + virtual void Close() OVERRIDE; + virtual bool Send(Message* message) OVERRIDE; + virtual base::ProcessId GetPeerPID() const OVERRIDE; + static bool IsNamedServerInitialized(const std::string& channel_id); - base::ProcessId peer_pid() const { return peer_pid_; } + private: // ChannelReader implementation. @@ -58,7 +63,7 @@ class Channel::ChannelImpl : public internal::ChannelReader, private: struct State { - explicit State(ChannelImpl* channel); + explicit State(ChannelWin* channel); ~State(); base::MessageLoopForIO::IOContext context; bool is_pending; @@ -94,11 +99,11 @@ class Channel::ChannelImpl : public internal::ChannelReader, int32 client_secret_; - base::WeakPtrFactory<ChannelImpl> weak_factory_; + base::WeakPtrFactory<ChannelWin> weak_factory_; scoped_ptr<base::ThreadChecker> thread_check_; - DISALLOW_COPY_AND_ASSIGN(ChannelImpl); + DISALLOW_COPY_AND_ASSIGN(ChannelWin); }; } // namespace IPC diff --git a/ipc/ipc_message.h b/ipc/ipc_message.h index e4b6208..fc37d72 100644 --- a/ipc/ipc_message.h +++ b/ipc/ipc_message.h @@ -222,6 +222,9 @@ class IPC_EXPORT Message : public Pickle { protected: friend class Channel; + friend class ChannelNacl; + friend class ChannelPosix; + friend class ChannelWin; friend class MessageReplyDeserializer; friend class SyncMessage; diff --git a/ipc/ipc_send_fds_test.cc b/ipc/ipc_send_fds_test.cc index 7e6a4e4..1df6be9 100644 --- a/ipc/ipc_send_fds_test.cc +++ b/ipc/ipc_send_fds_test.cc @@ -234,7 +234,8 @@ class PipeChannelHelper { void Init() { IPC::ChannelHandle in_handle("IN"); in = IPC::Channel::CreateServer(in_handle, &null_listener_); - base::FileDescriptor out_fd(in->TakeClientFileDescriptor(), false); + base::FileDescriptor out_fd( + in->TakeClientFileDescriptor(), false); IPC::ChannelHandle out_handle("OUT", out_fd); out = IPC::Channel::CreateClient(out_handle, &cb_listener_); // PostTask the connect calls to make sure the callbacks happens diff --git a/ipc/ipc_sync_channel_unittest.cc b/ipc/ipc_sync_channel_unittest.cc index 817f17e..a145f6b 100644 --- a/ipc/ipc_sync_channel_unittest.cc +++ b/ipc/ipc_sync_channel_unittest.cc @@ -1722,7 +1722,7 @@ class VerifiedServer : public Worker { VLOG(1) << __FUNCTION__ << " Sending reply: " << reply_text_; SyncChannelNestedTestMsg_String::WriteReplyParams(reply_msg, reply_text_); Send(reply_msg); - ASSERT_EQ(channel()->peer_pid(), base::GetCurrentProcId()); + ASSERT_EQ(channel()->GetPeerPID(), base::GetCurrentProcId()); Done(); } @@ -1751,7 +1751,7 @@ class VerifiedClient : public Worker { (void)expected_text_; VLOG(1) << __FUNCTION__ << " Received reply: " << response; - ASSERT_EQ(channel()->peer_pid(), base::GetCurrentProcId()); + ASSERT_EQ(channel()->GetPeerPID(), base::GetCurrentProcId()); Done(); } diff --git a/ipc/ipc_test_base.cc b/ipc/ipc_test_base.cc index 4e7133b..589ee98 100644 --- a/ipc/ipc_test_base.cc +++ b/ipc/ipc_test_base.cc @@ -97,8 +97,9 @@ bool IPCTestBase::StartClient() { client_process_ = SpawnChild(test_main); #elif defined(OS_POSIX) base::FileHandleMappingVector fds_to_map; - const int ipcfd = channel_.get() ? channel_->GetClientFileDescriptor() : - channel_proxy_->GetClientFileDescriptor(); + const int ipcfd = channel_.get() + ? channel_->GetClientFileDescriptor() + : channel_proxy_->GetClientFileDescriptor(); if (ipcfd > -1) fds_to_map.push_back(std::pair<int, int>(ipcfd, kPrimaryIPCChannel + base::GlobalDescriptors::kBaseDescriptor)); diff --git a/ipc/ipc_test_sink.cc b/ipc/ipc_test_sink.cc index 070fe12..65951fb 100644 --- a/ipc/ipc_test_sink.cc +++ b/ipc/ipc_test_sink.cc @@ -21,6 +21,21 @@ bool TestSink::Send(Message* message) { return true; } +bool TestSink::Connect() { + NOTIMPLEMENTED(); + return false; +} + +void TestSink::Close() { + NOTIMPLEMENTED(); +} + +base::ProcessId TestSink::GetPeerPID() const { + NOTIMPLEMENTED(); + return base::ProcessId(); +} + + bool TestSink::OnMessageReceived(const Message& msg) { ObserverListBase<Listener>::Iterator it(filter_list_); Listener* observer; @@ -74,4 +89,37 @@ void TestSink::RemoveFilter(Listener* filter) { filter_list_.RemoveObserver(filter); } +#if defined(OS_POSIX) && !defined(OS_NACL) + +int TestSink::GetClientFileDescriptor() const { + NOTREACHED(); + return -1; +} + +int TestSink::TakeClientFileDescriptor() { + NOTREACHED(); + return -1; +} + +bool TestSink::AcceptsConnections() const { + NOTREACHED(); + return false; +} + +bool TestSink::HasAcceptedConnection() const { + NOTREACHED(); + return false; +} + +bool TestSink::GetPeerEuid(uid_t* peer_euid) const { + NOTREACHED(); + return false; +} + +void TestSink::ResetToAcceptingConnectionState() { + NOTREACHED(); +} + +#endif // defined(OS_POSIX) && !defined(OS_NACL) + } // namespace IPC diff --git a/ipc/ipc_test_sink.h b/ipc/ipc_test_sink.h index 78be9e7..10ace55 100644 --- a/ipc/ipc_test_sink.h +++ b/ipc/ipc_test_sink.h @@ -78,6 +78,18 @@ class TestSink : public Channel { // Interface in IPC::Channel. This copies the message to the sink and then // deletes it. virtual bool Send(IPC::Message* message) OVERRIDE; + virtual bool Connect() WARN_UNUSED_RESULT OVERRIDE; + virtual void Close() OVERRIDE; + virtual base::ProcessId GetPeerPID() const OVERRIDE; + +#if defined(OS_POSIX) && !defined(OS_NACL) + virtual int GetClientFileDescriptor() const OVERRIDE; + virtual int TakeClientFileDescriptor() OVERRIDE; + virtual bool AcceptsConnections() const OVERRIDE; + virtual bool HasAcceptedConnection() const OVERRIDE; + virtual bool GetPeerEuid(uid_t* peer_euid) const OVERRIDE; + virtual void ResetToAcceptingConnectionState() OVERRIDE; +#endif // defined(OS_POSIX) && !defined(OS_NACL) // Used by the source of the messages to send the message to the sink. This // will make a copy of the message and store it in the list. |