#include "base/memory/scoped_ptr.h"
#include "base/single_thread_task_runner.h"
#include "base/thread_task_runner_handle.h"
+#include "ipc/ipc_channel_factory.h"
#include "ipc/ipc_listener.h"
#include "ipc/ipc_logging.h"
#include "ipc/ipc_message_macros.h"
ipc_task_runner_ = NULL;
}
-void ChannelProxy::Context::CreateChannel(const IPC::ChannelHandle& handle,
- const Channel::Mode& mode) {
+void ChannelProxy::Context::CreateChannel(scoped_ptr<ChannelFactory> factory) {
DCHECK(!channel_);
- channel_id_ = handle.name;
- channel_ = Channel::Create(handle, mode, this);
+ channel_id_ = factory->GetName();
+ channel_ = factory->BuildChannel(this);
}
bool ChannelProxy::Context::TryFilters(const Message& message) {
return channel.Pass();
}
+// static
+scoped_ptr<ChannelProxy> ChannelProxy::Create(
+ scoped_ptr<ChannelFactory> factory,
+ Listener* listener,
+ base::SingleThreadTaskRunner* ipc_task_runner) {
+ scoped_ptr<ChannelProxy> channel(new ChannelProxy(listener, ipc_task_runner));
+ channel->Init(factory.Pass(), true);
+ return channel.Pass();
+}
+
ChannelProxy::ChannelProxy(Context* context)
: context_(context),
did_init_(false) {
void ChannelProxy::Init(const IPC::ChannelHandle& channel_handle,
Channel::Mode mode,
bool create_pipe_now) {
- DCHECK(CalledOnValidThread());
- DCHECK(!did_init_);
#if defined(OS_POSIX)
// When we are creating a server on POSIX, we need its file descriptor
// to be created immediately so that it can be accessed and passed
create_pipe_now = true;
}
#endif // defined(OS_POSIX)
+ Init(ChannelFactory::Create(channel_handle, mode),
+ create_pipe_now);
+}
+
+void ChannelProxy::Init(scoped_ptr<ChannelFactory> factory,
+ bool create_pipe_now) {
+ DCHECK(CalledOnValidThread());
+ DCHECK(!did_init_);
if (create_pipe_now) {
// Create the channel immediately. This effectively sets up the
// low-level pipe so that the client can connect. Without creating
// the pipe immediately, it is possible for a listener to attempt
// to connect and get an error since the pipe doesn't exist yet.
- context_->CreateChannel(channel_handle, mode);
+ context_->CreateChannel(factory.Pass());
} else {
context_->ipc_task_runner()->PostTask(
- FROM_HERE, base::Bind(&Context::CreateChannel, context_.get(),
- channel_handle, mode));
+ FROM_HERE, base::Bind(&Context::CreateChannel,
+ context_.get(), Passed(factory.Pass())));
}
// complete initialization on the background thread