Add IPC::ChannelProxy::Create() and IPC::SyncChannel::Create()
This change replaces constructors with Create() methods of
ChannelProxy and SyncChannel. This open the possibility to introduce
polymorphism to these classes.
This is a revision of r274310 (https://codereview.chromium.org/301973003/)
in which I added bunch of Create*() method variants.
The chagne was reverted. This change no longer does it and just keeps
using Channel::Mode to specify the channel type.
TEST=none
BUG=377980
[email protected],[email protected]
Review URL: https://codereview.chromium.org/310853003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@275140 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/ipc/ipc_sync_channel.cc b/ipc/ipc_sync_channel.cc
index 0e0018c7..a7ed230 100644
--- a/ipc/ipc_sync_channel.cc
+++ b/ipc/ipc_sync_channel.cc
@@ -404,19 +404,27 @@
return base::Bind(&SyncChannel::SyncContext::OnWaitableEventSignaled, this);
}
-SyncChannel::SyncChannel(
+// static
+scoped_ptr<SyncChannel> SyncChannel::Create(
const IPC::ChannelHandle& channel_handle,
Channel::Mode mode,
Listener* listener,
base::SingleThreadTaskRunner* ipc_task_runner,
bool create_pipe_now,
- WaitableEvent* shutdown_event)
- : ChannelProxy(new SyncContext(listener, ipc_task_runner, shutdown_event)) {
- // The current (listener) thread must be distinct from the IPC thread, or else
- // sending synchronous messages will deadlock.
- DCHECK_NE(ipc_task_runner, base::ThreadTaskRunnerHandle::Get());
- ChannelProxy::Init(channel_handle, mode, create_pipe_now);
- StartWatching();
+ base::WaitableEvent* shutdown_event) {
+ scoped_ptr<SyncChannel> channel =
+ Create(listener, ipc_task_runner, shutdown_event);
+ channel->Init(channel_handle, mode, create_pipe_now);
+ return channel.Pass();
+}
+
+// static
+scoped_ptr<SyncChannel> SyncChannel::Create(
+ Listener* listener,
+ base::SingleThreadTaskRunner* ipc_task_runner,
+ WaitableEvent* shutdown_event) {
+ return make_scoped_ptr(
+ new SyncChannel(listener, ipc_task_runner, shutdown_event));
}
SyncChannel::SyncChannel(