summaryrefslogtreecommitdiffstats
path: root/chromium/ipc/ipc_channel_nacl.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/ipc/ipc_channel_nacl.cc')
-rw-r--r--chromium/ipc/ipc_channel_nacl.cc91
1 files changed, 42 insertions, 49 deletions
diff --git a/chromium/ipc/ipc_channel_nacl.cc b/chromium/ipc/ipc_channel_nacl.cc
index 1ecd5718245..0928ba63305 100644
--- a/chromium/ipc/ipc_channel_nacl.cc
+++ b/chromium/ipc/ipc_channel_nacl.cc
@@ -17,6 +17,7 @@
#include "base/task_runner_util.h"
#include "base/threading/simple_thread.h"
#include "ipc/file_descriptor_set_posix.h"
+#include "ipc/ipc_listener.h"
#include "ipc/ipc_logging.h"
#include "native_client/src/public/imc_syscalls.h"
#include "native_client/src/public/imc_types.h"
@@ -61,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.
@@ -90,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,
@@ -101,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());
@@ -117,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),
@@ -134,13 +135,19 @@ Channel::ChannelImpl::ChannelImpl(const IPC::ChannelHandle& channel_handle,
}
}
-Channel::ChannelImpl::~ChannelImpl() {
+ChannelNacl::~ChannelNacl() {
Close();
}
-bool Channel::ChannelImpl::Connect() {
+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 ChannelNacl::Connect() {
if (pipe_ == -1) {
- DLOG(INFO) << "Channel creation failed: " << pipe_name_;
+ DLOG(WARNING) << "Channel creation failed: " << pipe_name_;
return false;
}
@@ -152,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(
@@ -164,10 +171,14 @@ bool Channel::ChannelImpl::Connect() {
waiting_connect_ = false;
// If there were any messages queued before connection, send them.
ProcessOutgoingMessages();
+ base::MessageLoopProxy::current()->PostTask(FROM_HERE,
+ 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 :-).
@@ -184,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);
@@ -201,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)
@@ -222,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);
@@ -245,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())
@@ -293,7 +304,11 @@ bool Channel::ChannelImpl::ProcessOutgoingMessages() {
return true;
}
-Channel::ChannelImpl::ReadState Channel::ChannelImpl::ReadData(
+void ChannelNacl::CallOnChannelConnected() {
+ listener()->OnChannelConnected(GetPeerPID());
+}
+
+ChannelNacl::ReadState ChannelNacl::ReadData(
char* buffer,
int buffer_len,
int* bytes_read) {
@@ -324,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)
@@ -339,46 +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::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 {
- // This shouldn't actually get used in the untrusted side of the proxy, and we
- // don't have the real pid anyway.
- return -1;
-}
+// Channel's methods
-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