From cf178fb755d0fda06fd770c1a94eb8696063c001 Mon Sep 17 00:00:00 2001 From: "morrita@chromium.org" Date: Mon, 2 Jun 2014 19:41:12 +0000 Subject: [PATCH] Introduce IPC::ChannelProxy::Create*() and IPC::SynChannel::Create*() This change hides constructors of these classes so that we can turn them polymorphic classes. Note that having almost identical ChannelProxy::Init*() isn't great and they will be replaced by a factory-like abstraction in coming changes. TEST=none R=darin,cpu BUG=377980 Review URL: https://codereview.chromium.org/301973003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@274310 0039d316-1c4b-4281-b951-d872f2087c98 --- apps/app_shim/app_shim_host_mac.cc | 5 +- .../app_shim_host_manager_browsertest_mac.mm | 4 +- apps/app_shim/chrome_main_app_mode_mac.mm | 7 +- .../cloud_print_proxy_process_browsertest.cc | 22 +++-- .../service_process_control.cc | 7 +- .../service_process/service_process_control.h | 2 +- chrome/service/service_ipc_server.cc | 5 +- components/nacl/browser/nacl_process_host.cc | 9 +- components/nacl/loader/nacl_listener.cc | 6 +- .../nacl/loader/nacl_trusted_listener.cc | 5 +- .../nacl/renderer/manifest_service_channel.cc | 4 +- .../nacl/renderer/trusted_plugin_channel.cc | 4 +- .../renderer_host/render_process_host_impl.cc | 11 ++- content/child/child_thread.cc | 13 ++- content/child/npapi/np_channel_base.cc | 6 +- content/common/gpu/client/gpu_channel_host.cc | 8 +- content/common/gpu/gpu_channel.cc | 5 +- ipc/ipc_channel_proxy.cc | 90 ++++++++++++++++--- ipc/ipc_channel_proxy.h | 46 ++++++++-- ipc/ipc_sync_channel.cc | 64 +++++++++++-- ipc/ipc_sync_channel.h | 45 ++++++++-- ipc/ipc_sync_channel_unittest.cc | 65 +++++++------- ipc/ipc_test_base.cc | 8 +- ppapi/nacl_irt/manifest_service.cc | 7 +- ppapi/nacl_irt/ppapi_dispatcher.cc | 6 +- ppapi/proxy/proxy_channel.cc | 13 +-- remoting/host/desktop_process.cc | 8 +- remoting/host/desktop_process_unittest.cc | 16 ++-- remoting/host/desktop_session_proxy.cc | 8 +- .../host/ipc_desktop_environment_unittest.cc | 9 +- remoting/host/ipc_util_posix.cc | 8 +- remoting/host/ipc_util_win.cc | 5 +- remoting/host/remoting_me2me_host.cc | 14 ++- .../win/worker_process_launcher_unittest.cc | 10 +-- tools/ipc_fuzzer/replay/replay_process.cc | 7 +- win8/metro_driver/chrome_app_view_ash.cc | 10 +-- win8/viewer/metro_viewer_process_host.cc | 5 +- 37 files changed, 359 insertions(+), 208 deletions(-) diff --git a/apps/app_shim/app_shim_host_mac.cc b/apps/app_shim/app_shim_host_mac.cc index 437fb6bff8adfb..57316e5776bb1c 100644 --- a/apps/app_shim/app_shim_host_mac.cc +++ b/apps/app_shim/app_shim_host_mac.cc @@ -24,12 +24,11 @@ AppShimHost::~AppShimHost() { void AppShimHost::ServeChannel(const IPC::ChannelHandle& handle) { DCHECK(CalledOnValidThread()); DCHECK(!channel_.get()); - channel_.reset(new IPC::ChannelProxy( + channel_ = IPC::ChannelProxy::CreateServer( handle, - IPC::Channel::MODE_SERVER, this, content::BrowserThread::GetMessageLoopProxyForThread( - content::BrowserThread::IO).get())); + content::BrowserThread::IO).get()); } base::FilePath AppShimHost::GetProfilePath() const { diff --git a/apps/app_shim/app_shim_host_manager_browsertest_mac.mm b/apps/app_shim/app_shim_host_manager_browsertest_mac.mm index c97f544d974163..4327e9797ca8a9 100644 --- a/apps/app_shim/app_shim_host_manager_browsertest_mac.mm +++ b/apps/app_shim/app_shim_host_manager_browsertest_mac.mm @@ -63,8 +63,8 @@ void Send(const T& message) { app_mode::VerifySocketPermissions(socket_path); IPC::ChannelHandle handle(socket_path.value()); - channel_.reset(new IPC::ChannelProxy(handle, IPC::Channel::MODE_NAMED_CLIENT, - this, io_thread_.message_loop_proxy().get())); + channel_ = IPC::ChannelProxy::CreateNamedClient( + handle, this, io_thread_.message_loop_proxy().get()); } TestShimClient::~TestShimClient() {} diff --git a/apps/app_shim/chrome_main_app_mode_mac.mm b/apps/app_shim/chrome_main_app_mode_mac.mm index c04b9a40756d47..ecc18bf8373784 100644 --- a/apps/app_shim/chrome_main_app_mode_mac.mm +++ b/apps/app_shim/chrome_main_app_mode_mac.mm @@ -214,11 +214,8 @@ bool SendFocusApp(apps::AppShimFocusType focus_type, void AppShimController::CreateChannelAndSendLaunchApp( const base::FilePath& socket_path) { IPC::ChannelHandle handle(socket_path.value()); - channel_.reset( - new IPC::ChannelProxy(handle, - IPC::Channel::MODE_NAMED_CLIENT, - this, - g_io_thread->message_loop_proxy().get())); + channel_ = IPC::ChannelProxy::CreateNamedClient( + handle, this, g_io_thread->message_loop_proxy().get()); bool launched_by_chrome = CommandLine::ForCurrentProcess()->HasSwitch( diff --git a/chrome/browser/printing/cloud_print/test/cloud_print_proxy_process_browsertest.cc b/chrome/browser/printing/cloud_print/test/cloud_print_proxy_process_browsertest.cc index cce36d643d0930..e2ecd5fb326c73 100644 --- a/chrome/browser/printing/cloud_print/test/cloud_print_proxy_process_browsertest.cc +++ b/chrome/browser/printing/cloud_print/test/cloud_print_proxy_process_browsertest.cc @@ -266,11 +266,10 @@ int CloudPrintMockService_Main(SetExpectationsCallback set_expectations) { CommandLine::ForCurrentProcess()->GetSwitchValueASCII( switches::kProcessChannelID); scoped_ptr startup_channel; - startup_channel.reset( - new IPC::ChannelProxy(startup_channel_name, - IPC::Channel::MODE_CLIENT, - &listener, - service_process.IOMessageLoopProxy())); + startup_channel = IPC::ChannelProxy::CreateClient( + startup_channel_name, + &listener, + service_process.IOMessageLoopProxy()); main_message_loop.Run(); if (!Mock::VerifyAndClearExpectations(&server)) @@ -442,9 +441,8 @@ base::ProcessHandle CloudPrintProxyPolicyStartupTest::Launch( base::StringPrintf("%d.%p.%d", base::GetCurrentProcId(), this, base::RandInt(0, std::numeric_limits::max())); - startup_channel_.reset(new IPC::ChannelProxy( - startup_channel_id_, IPC::Channel::MODE_SERVER, - this, IOMessageLoopProxy())); + startup_channel_ = IPC::ChannelProxy::CreateServer( + startup_channel_id_, this, IOMessageLoopProxy()); #if defined(OS_POSIX) base::FileHandleMappingVector ipc_file_list; @@ -466,10 +464,10 @@ void CloudPrintProxyPolicyStartupTest::WaitForConnect() { EXPECT_TRUE(CheckServiceProcessReady()); EXPECT_TRUE(base::MessageLoopProxy::current().get()); ServiceProcessControl::GetInstance()->SetChannel( - new IPC::ChannelProxy(GetServiceProcessChannel(), - IPC::Channel::MODE_NAMED_CLIENT, - ServiceProcessControl::GetInstance(), - IOMessageLoopProxy())); + IPC::ChannelProxy::CreateNamedClient( + GetServiceProcessChannel(), + ServiceProcessControl::GetInstance(), + IOMessageLoopProxy())); } bool CloudPrintProxyPolicyStartupTest::Send(IPC::Message* message) { diff --git a/chrome/browser/service_process/service_process_control.cc b/chrome/browser/service_process/service_process_control.cc index b9cfa571464632..1a58f113352b1e 100644 --- a/chrome/browser/service_process/service_process_control.cc +++ b/chrome/browser/service_process/service_process_control.cc @@ -51,15 +51,14 @@ void ServiceProcessControl::ConnectInternal() { // TODO(hclam): Handle error connecting to channel. const IPC::ChannelHandle channel_id = GetServiceProcessChannel(); - SetChannel(new IPC::ChannelProxy( + SetChannel(IPC::ChannelProxy::CreateNamedClient( channel_id, - IPC::Channel::MODE_NAMED_CLIENT, this, BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO).get())); } -void ServiceProcessControl::SetChannel(IPC::ChannelProxy* channel) { - channel_.reset(channel); +void ServiceProcessControl::SetChannel(scoped_ptr channel) { + channel_ = channel.Pass(); } void ServiceProcessControl::RunConnectDoneTasks() { diff --git a/chrome/browser/service_process/service_process_control.h b/chrome/browser/service_process/service_process_control.h index 9db9324f843761..4f58e595ef5d77 100644 --- a/chrome/browser/service_process/service_process_control.h +++ b/chrome/browser/service_process/service_process_control.h @@ -201,7 +201,7 @@ class ServiceProcessControl : public IPC::Sender, void ConnectInternal(); // Takes ownership of the pointer. Split out for testing. - void SetChannel(IPC::ChannelProxy* channel); + void SetChannel(scoped_ptr channel); static void RunAllTasksHelper(TaskList* task_list); diff --git a/chrome/service/service_ipc_server.cc b/chrome/service/service_ipc_server.cc index 987f8060fd6cde..7d47db3b7823eb 100644 --- a/chrome/service/service_ipc_server.cc +++ b/chrome/service/service_ipc_server.cc @@ -26,13 +26,12 @@ bool ServiceIPCServer::Init() { void ServiceIPCServer::CreateChannel() { channel_.reset(NULL); // Tear down the existing channel, if any. - channel_.reset(new IPC::SyncChannel( + channel_= IPC::SyncChannel::CreateNamedServer( channel_handle_, - IPC::Channel::MODE_NAMED_SERVER, this, g_service_process->io_thread()->message_loop_proxy().get(), true, - g_service_process->shutdown_event())); + g_service_process->shutdown_event()); DCHECK(sync_message_filter_.get()); channel_->AddFilter(sync_message_filter_.get()); } diff --git a/components/nacl/browser/nacl_process_host.cc b/components/nacl/browser/nacl_process_host.cc index 7451fe610e2695..ce2700de6dfb77 100644 --- a/components/nacl/browser/nacl_process_host.cc +++ b/components/nacl/browser/nacl_process_host.cc @@ -905,11 +905,10 @@ void NaClProcessHost::OnPpapiChannelsCreated( if (!ipc_proxy_channel_.get()) { DCHECK_EQ(PROCESS_TYPE_NACL_LOADER, process_->GetData().process_type); - ipc_proxy_channel_.reset( - new IPC::ChannelProxy(browser_channel_handle, - IPC::Channel::MODE_CLIENT, - NULL, - base::MessageLoopProxy::current().get())); + ipc_proxy_channel_ = IPC::ChannelProxy::CreateClient( + browser_channel_handle, + NULL, + base::MessageLoopProxy::current().get()); // Create the browser ppapi host and enable PPAPI message dispatching to the // browser process. ppapi_host_.reset(content::BrowserPpapiHost::CreateExternalPluginProcess( diff --git a/components/nacl/loader/nacl_listener.cc b/components/nacl/loader/nacl_listener.cc index 5056f0f70e986d..5f1966d861b505 100644 --- a/components/nacl/loader/nacl_listener.cc +++ b/components/nacl/loader/nacl_listener.cc @@ -244,11 +244,11 @@ void NaClListener::Listen() { std::string channel_name = CommandLine::ForCurrentProcess()->GetSwitchValueASCII( switches::kProcessChannelID); - channel_.reset(new IPC::SyncChannel( - this, io_thread_.message_loop_proxy().get(), &shutdown_event_)); + channel_ = IPC::SyncChannel::Create( + this, io_thread_.message_loop_proxy().get(), &shutdown_event_); filter_ = new IPC::SyncMessageFilter(&shutdown_event_); channel_->AddFilter(filter_.get()); - channel_->Init(channel_name, IPC::Channel::MODE_CLIENT, true); + channel_->InitClient(channel_name, true); main_loop_ = base::MessageLoop::current(); main_loop_->Run(); } diff --git a/components/nacl/loader/nacl_trusted_listener.cc b/components/nacl/loader/nacl_trusted_listener.cc index 19a60387e713d7..2392e9a75a60c6 100644 --- a/components/nacl/loader/nacl_trusted_listener.cc +++ b/components/nacl/loader/nacl_trusted_listener.cc @@ -8,9 +8,8 @@ NaClTrustedListener::NaClTrustedListener( const IPC::ChannelHandle& handle, base::MessageLoopProxy* message_loop_proxy, base::WaitableEvent* shutdown_event) { - channel_.reset(new IPC::SyncChannel(handle, IPC::Channel::MODE_SERVER, this, - message_loop_proxy, true, - shutdown_event)); + channel_ = IPC::SyncChannel::CreateServer( + handle, this, message_loop_proxy, true, shutdown_event); } NaClTrustedListener::~NaClTrustedListener() { diff --git a/components/nacl/renderer/manifest_service_channel.cc b/components/nacl/renderer/manifest_service_channel.cc index 606be616a1ab23..3544d6e2d6053c 100644 --- a/components/nacl/renderer/manifest_service_channel.cc +++ b/components/nacl/renderer/manifest_service_channel.cc @@ -22,8 +22,8 @@ ManifestServiceChannel::ManifestServiceChannel( base::WaitableEvent* waitable_event) : connected_callback_(connected_callback), delegate_(delegate.Pass()), - channel_(new IPC::SyncChannel( - handle, IPC::Channel::MODE_CLIENT, this, + channel_(IPC::SyncChannel::CreateClient( + handle, this, content::RenderThread::Get()->GetIOMessageLoopProxy(), true, waitable_event)), weak_ptr_factory_(this) { diff --git a/components/nacl/renderer/trusted_plugin_channel.cc b/components/nacl/renderer/trusted_plugin_channel.cc index 7ce3d843994745..cfb9523b695e31 100644 --- a/components/nacl/renderer/trusted_plugin_channel.cc +++ b/components/nacl/renderer/trusted_plugin_channel.cc @@ -17,8 +17,8 @@ TrustedPluginChannel::TrustedPluginChannel( const base::Callback& connected_callback, base::WaitableEvent* waitable_event) : connected_callback_(connected_callback), - channel_(new IPC::SyncChannel( - handle, IPC::Channel::MODE_CLIENT, this, + channel_(IPC::SyncChannel::CreateClient( + handle, this, content::RenderThread::Get()->GetIOMessageLoopProxy(), true, waitable_event)) { } diff --git a/content/browser/renderer_host/render_process_host_impl.cc b/content/browser/renderer_host/render_process_host_impl.cc index 98e45d6a13a360..d2f231cab91e7f 100644 --- a/content/browser/renderer_host/render_process_host_impl.cc +++ b/content/browser/renderer_host/render_process_host_impl.cc @@ -568,12 +568,11 @@ bool RenderProcessHostImpl::Init() { // Setup the IPC channel. const std::string channel_id = IPC::Channel::GenerateVerifiedChannelID(std::string()); - channel_.reset( - new IPC::ChannelProxy(channel_id, - IPC::Channel::MODE_SERVER, - this, - BrowserThread::GetMessageLoopProxyForThread( - BrowserThread::IO).get())); + channel_ = IPC::ChannelProxy::CreateServer( + channel_id, + this, + BrowserThread::GetMessageLoopProxyForThread( + BrowserThread::IO).get()); // Setup the Mojo channel. mojo_application_host_.reset(new MojoApplicationHost()); diff --git a/content/child/child_thread.cc b/content/child/child_thread.cc index ab276a67fc7f41..8e4af638d0c3ca 100644 --- a/content/child/child_thread.cc +++ b/content/child/child_thread.cc @@ -225,13 +225,12 @@ void ChildThread::Init() { // the logger, and the logger does not like being created on the IO thread. IPC::Logging::GetInstance(); #endif - channel_.reset( - new IPC::SyncChannel(channel_name_, - IPC::Channel::MODE_CLIENT, - this, - ChildProcess::current()->io_message_loop_proxy(), - true, - ChildProcess::current()->GetShutDownEvent())); + channel_ = IPC::SyncChannel::CreateClient( + channel_name_, + this, + ChildProcess::current()->io_message_loop_proxy(), + true, + ChildProcess::current()->GetShutDownEvent()); #ifdef IPC_MESSAGE_LOG_ENABLED if (!in_browser_process_) IPC::Logging::GetInstance()->SetIPCSender(this); diff --git a/content/child/npapi/np_channel_base.cc b/content/child/npapi/np_channel_base.cc index 76845bd8f21a97..d7e7508840cbff 100644 --- a/content/child/npapi/np_channel_base.cc +++ b/content/child/npapi/np_channel_base.cc @@ -178,9 +178,9 @@ bool NPChannelBase::Init(base::MessageLoopProxy* ipc_message_loop, return false; #endif - channel_.reset(new IPC::SyncChannel( - channel_handle_, mode_, this, ipc_message_loop, create_pipe_now, - shutdown_event)); + channel_ = IPC::SyncChannel::Create( + this, ipc_message_loop, shutdown_event); + channel_->InitByMode(channel_handle_, mode_, create_pipe_now); #if defined(OS_POSIX) // Check the validity of fd for bug investigation. Remove after fixed. diff --git a/content/common/gpu/client/gpu_channel_host.cc b/content/common/gpu/client/gpu_channel_host.cc index f503051fb162ee..3a12f860303f91 100644 --- a/content/common/gpu/client/gpu_channel_host.cc +++ b/content/common/gpu/client/gpu_channel_host.cc @@ -73,12 +73,8 @@ void GpuChannelHost::Connect(const IPC::ChannelHandle& channel_handle, // Open a channel to the GPU process. We pass NULL as the main listener here // since we need to filter everything to route it to the right thread. scoped_refptr io_loop = factory_->GetIOLoopProxy(); - channel_.reset(new IPC::SyncChannel(channel_handle, - IPC::Channel::MODE_CLIENT, - NULL, - io_loop.get(), - true, - shutdown_event)); + channel_ = IPC::SyncChannel::CreateClient( + channel_handle, NULL, io_loop.get(), true, shutdown_event); sync_filter_ = new IPC::SyncMessageFilter(shutdown_event); diff --git a/content/common/gpu/gpu_channel.cc b/content/common/gpu/gpu_channel.cc index 1c8e4f95f3cb85..429e8a55665e97 100644 --- a/content/common/gpu/gpu_channel.cc +++ b/content/common/gpu/gpu_channel.cc @@ -411,13 +411,12 @@ void GpuChannel::Init(base::MessageLoopProxy* io_message_loop, DCHECK(!channel_.get()); // Map renderer ID to a (single) channel to that process. - channel_.reset(new IPC::SyncChannel( + channel_ = IPC::SyncChannel::CreateServer( channel_id_, - IPC::Channel::MODE_SERVER, this, io_message_loop, false, - shutdown_event)); + shutdown_event); filter_ = new GpuChannelMessageFilter(weak_factory_.GetWeakPtr(), diff --git a/ipc/ipc_channel_proxy.cc b/ipc/ipc_channel_proxy.cc index e88bb5d0e72abd..cf28ed6a2e8b62 100644 --- a/ipc/ipc_channel_proxy.cc +++ b/ipc/ipc_channel_proxy.cc @@ -304,13 +304,56 @@ void ChannelProxy::Context::OnDispatchBadMessage(const Message& message) { //----------------------------------------------------------------------------- -ChannelProxy::ChannelProxy(const IPC::ChannelHandle& channel_handle, - Channel::Mode mode, - Listener* listener, - base::SingleThreadTaskRunner* ipc_task_runner) - : context_(new Context(listener, ipc_task_runner)), - did_init_(false) { - Init(channel_handle, mode, true); +// static +scoped_ptr ChannelProxy::Create( + Listener* listener, + base::SingleThreadTaskRunner* ipc_task_runner) { + return make_scoped_ptr(new ChannelProxy( + listener, ipc_task_runner)); +} + +// static +scoped_ptr ChannelProxy::CreateClient( + const IPC::ChannelHandle& channel_handle, + Listener* listener, + base::SingleThreadTaskRunner* ipc_task_runner) { + scoped_ptr channel = Create( + listener, ipc_task_runner); + channel->InitClient(channel_handle, true); + return channel.Pass(); +} + +// static +scoped_ptr ChannelProxy::CreateServer( + const IPC::ChannelHandle& channel_handle, + Listener* listener, + base::SingleThreadTaskRunner* ipc_task_runner) { + scoped_ptr channel = Create( + listener, ipc_task_runner); + channel->InitServer(channel_handle, true); + return channel.Pass(); +} + +// static +scoped_ptr ChannelProxy::CreateNamedClient( + const IPC::ChannelHandle& channel_handle, + Listener* listener, + base::SingleThreadTaskRunner* ipc_task_runner) { + scoped_ptr channel = Create( + listener, ipc_task_runner); + channel->InitNamedClient(channel_handle, true); + return channel.Pass(); +} + +// static +scoped_ptr ChannelProxy::CreateNamedServer( + const IPC::ChannelHandle& channel_handle, + Listener* listener, + base::SingleThreadTaskRunner* ipc_task_runner) { + scoped_ptr channel = Create( + listener, ipc_task_runner); + channel->InitNamedServer(channel_handle, true); + return channel.Pass(); } ChannelProxy::ChannelProxy(Context* context) @@ -318,15 +361,22 @@ ChannelProxy::ChannelProxy(Context* context) did_init_(false) { } +ChannelProxy::ChannelProxy(Listener* listener, + base::SingleThreadTaskRunner* ipc_task_runner) + : context_(new Context(listener, ipc_task_runner)), + did_init_(false) { +} + ChannelProxy::~ChannelProxy() { DCHECK(CalledOnValidThread()); Close(); } -void ChannelProxy::Init(const IPC::ChannelHandle& channel_handle, - Channel::Mode mode, - bool create_pipe_now) { +void ChannelProxy::InitByMode( + const IPC::ChannelHandle& channel_handle, + Channel::Mode mode, + bool create_pipe_now) { DCHECK(CalledOnValidThread()); DCHECK(!did_init_); #if defined(OS_POSIX) @@ -358,6 +408,26 @@ void ChannelProxy::Init(const IPC::ChannelHandle& channel_handle, did_init_ = true; } +void ChannelProxy::InitClient(const IPC::ChannelHandle& channel_handle, + bool create_pipe_now) { + InitByMode(channel_handle, Channel::MODE_CLIENT, create_pipe_now); +} + +void ChannelProxy::InitServer(const IPC::ChannelHandle& channel_handle, + bool create_pipe_now) { + InitByMode(channel_handle, Channel::MODE_SERVER, create_pipe_now); +} + +void ChannelProxy::InitNamedClient(const IPC::ChannelHandle& channel_handle, + bool create_pipe_now) { + InitByMode(channel_handle, Channel::MODE_NAMED_CLIENT, create_pipe_now); +} + +void ChannelProxy::InitNamedServer(const IPC::ChannelHandle& channel_handle, + bool create_pipe_now) { + InitByMode(channel_handle, Channel::MODE_NAMED_SERVER, create_pipe_now); +} + void ChannelProxy::Close() { DCHECK(CalledOnValidThread()); diff --git a/ipc/ipc_channel_proxy.h b/ipc/ipc_channel_proxy.h index 0a3a5d2fb05b48..d1f270dd5b18c9 100644 --- a/ipc/ipc_channel_proxy.h +++ b/ipc/ipc_channel_proxy.h @@ -64,10 +64,31 @@ class IPC_EXPORT ChannelProxy : public Sender, public base::NonThreadSafe { // on the background thread. Any message not handled by the filter will be // dispatched to the listener. The given task runner correspond to a thread // on which IPC::Channel is created and used (e.g. IO thread). - ChannelProxy(const IPC::ChannelHandle& channel_handle, - Channel::Mode mode, - Listener* listener, - base::SingleThreadTaskRunner* ipc_task_runner); + // The naming pattern follows IPC::Channel. The Create() does not create + // underlying channel and let Init*() do it. + static scoped_ptr Create( + Listener* listener, + base::SingleThreadTaskRunner* ipc_task_runner); + + static scoped_ptr CreateClient( + const IPC::ChannelHandle& channel_handle, + Listener* listener, + base::SingleThreadTaskRunner* ipc_task_runner); + + static scoped_ptr CreateServer( + const IPC::ChannelHandle& channel_handle, + Listener* listener, + base::SingleThreadTaskRunner* ipc_task_runner); + + static scoped_ptr CreateNamedClient( + const IPC::ChannelHandle& channel_handle, + Listener* listener, + base::SingleThreadTaskRunner* ipc_task_runner); + + static scoped_ptr CreateNamedServer( + const IPC::ChannelHandle& channel_handle, + Listener* listener, + base::SingleThreadTaskRunner* ipc_task_runner); virtual ~ChannelProxy(); @@ -75,8 +96,17 @@ class IPC_EXPORT ChannelProxy : public Sender, public base::NonThreadSafe { // proxy that was not initialized in its constructor. If create_pipe_now is // true, the pipe is created synchronously. Otherwise it's created on the IO // thread. - void Init(const IPC::ChannelHandle& channel_handle, Channel::Mode mode, - bool create_pipe_now); + // The naming pattern follows IPC::Channel::Create*(). + void InitByMode(const IPC::ChannelHandle& channel_handle, Channel::Mode mode, + bool create_pipe_now); + void InitClient(const IPC::ChannelHandle& channel_handle, + bool create_pipe_now); + void InitServer(const IPC::ChannelHandle& channel_handle, + bool create_pipe_now); + void InitNamedClient(const IPC::ChannelHandle& channel_handle, + bool create_pipe_now); + void InitNamedServer(const IPC::ChannelHandle& channel_handle, + bool create_pipe_now); // Close the IPC::Channel. This operation completes asynchronously, once the // background thread processes the command to close the channel. It is ok to @@ -124,6 +154,10 @@ class IPC_EXPORT ChannelProxy : public Sender, public base::NonThreadSafe { // to the internal state. ChannelProxy(Context* context); + ChannelProxy(Listener* listener, + base::SingleThreadTaskRunner* ipc_task_runner); + + // Used internally to hold state that is referenced on the IPC thread. class Context : public base::RefCountedThreadSafe, public Listener { diff --git a/ipc/ipc_sync_channel.cc b/ipc/ipc_sync_channel.cc index 0e0018c7eae747..32f8619bd977e1 100644 --- a/ipc/ipc_sync_channel.cc +++ b/ipc/ipc_sync_channel.cc @@ -404,19 +404,65 @@ base::WaitableEventWatcher::EventCallback return base::Bind(&SyncChannel::SyncContext::OnWaitableEventSignaled, this); } -SyncChannel::SyncChannel( +// static +scoped_ptr SyncChannel::CreateClient( + const IPC::ChannelHandle& channel_handle, + Listener* listener, + base::SingleThreadTaskRunner* ipc_task_runner, + bool create_pipe_now, + base::WaitableEvent* shutdown_event) { + scoped_ptr channel = Create( + listener, ipc_task_runner, shutdown_event); + channel->InitClient(channel_handle, create_pipe_now); + return channel.Pass(); +} + +// static +scoped_ptr SyncChannel::CreateServer( 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 channel = Create( + listener, ipc_task_runner, shutdown_event); + channel->InitServer(channel_handle, create_pipe_now); + return channel.Pass(); +} + +// static +scoped_ptr SyncChannel::CreateNamedClient( + const IPC::ChannelHandle& channel_handle, + Listener* listener, + base::SingleThreadTaskRunner* ipc_task_runner, + bool create_pipe_now, + base::WaitableEvent* shutdown_event) { + scoped_ptr channel = Create( + listener, ipc_task_runner, shutdown_event); + channel->InitNamedClient(channel_handle, create_pipe_now); + return channel.Pass(); +} + +// static +scoped_ptr SyncChannel::CreateNamedServer( + const IPC::ChannelHandle& channel_handle, + Listener* listener, + base::SingleThreadTaskRunner* ipc_task_runner, + bool create_pipe_now, + base::WaitableEvent* shutdown_event) { + scoped_ptr channel = Create( + listener, ipc_task_runner, shutdown_event); + channel->InitNamedServer(channel_handle, create_pipe_now); + return channel.Pass(); +} + +// static +scoped_ptr 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( diff --git a/ipc/ipc_sync_channel.h b/ipc/ipc_sync_channel.h index f18fcff95ddd36..9ae3fd95d440dd 100644 --- a/ipc/ipc_sync_channel.h +++ b/ipc/ipc_sync_channel.h @@ -66,19 +66,42 @@ class IPC_EXPORT SyncChannel : public ChannelProxy { // Creates and initializes a sync channel. If create_pipe_now is specified, // the channel will be initialized synchronously. - SyncChannel(const IPC::ChannelHandle& channel_handle, - Channel::Mode mode, - Listener* listener, - base::SingleThreadTaskRunner* ipc_task_runner, - bool create_pipe_now, - base::WaitableEvent* shutdown_event); + // The naming pattern follows IPC::Channel. + static scoped_ptr CreateClient( + const IPC::ChannelHandle& channel_handle, + Listener* listener, + base::SingleThreadTaskRunner* ipc_task_runner, + bool create_pipe_now, + base::WaitableEvent* shutdown_event); + + static scoped_ptr CreateServer( + const IPC::ChannelHandle& channel_handle, + Listener* listener, + base::SingleThreadTaskRunner* ipc_task_runner, + bool create_pipe_now, + base::WaitableEvent* shutdown_event); + + static scoped_ptr CreateNamedClient( + const IPC::ChannelHandle& channel_handle, + Listener* listener, + base::SingleThreadTaskRunner* ipc_task_runner, + bool create_pipe_now, + base::WaitableEvent* shutdown_event); + + static scoped_ptr CreateNamedServer( + const IPC::ChannelHandle& channel_handle, + Listener* listener, + base::SingleThreadTaskRunner* ipc_task_runner, + bool create_pipe_now, + base::WaitableEvent* shutdown_event); // Creates an uninitialized sync channel. Call ChannelProxy::Init to // initialize the channel. This two-step setup allows message filters to be // added before any messages are sent or received. - SyncChannel(Listener* listener, - base::SingleThreadTaskRunner* ipc_task_runner, - base::WaitableEvent* shutdown_event); + static scoped_ptr Create( + Listener* listener, + base::SingleThreadTaskRunner* ipc_task_runner, + base::WaitableEvent* shutdown_event); virtual ~SyncChannel(); @@ -188,6 +211,10 @@ class IPC_EXPORT SyncChannel : public ChannelProxy { }; private: + SyncChannel(Listener* listener, + base::SingleThreadTaskRunner* ipc_task_runner, + base::WaitableEvent* shutdown_event); + void OnWaitableEventSignaled(base::WaitableEvent* arg); SyncContext* sync_context() { diff --git a/ipc/ipc_sync_channel_unittest.cc b/ipc/ipc_sync_channel_unittest.cc index ca8d5d789a2a7c..33653c736b226c 100644 --- a/ipc/ipc_sync_channel_unittest.cc +++ b/ipc/ipc_sync_channel_unittest.cc @@ -151,12 +151,12 @@ class Worker : public Listener, public Sender { } virtual SyncChannel* CreateChannel() { - return new SyncChannel(channel_name_, - mode_, - this, - ipc_thread_.message_loop_proxy().get(), - true, - &shutdown_event_); + scoped_ptr channel = SyncChannel::Create( + this, + ipc_thread_.message_loop_proxy().get(), + &shutdown_event_); + channel->InitByMode(channel_name_, mode_, true); + return channel.release(); } base::Thread* ListenerThread() { @@ -324,9 +324,10 @@ class TwoStepServer : public Worker { } virtual SyncChannel* CreateChannel() OVERRIDE { - SyncChannel* channel = new SyncChannel( - this, ipc_thread().message_loop_proxy().get(), shutdown_event()); - channel->Init(channel_name(), mode(), create_pipe_now_); + SyncChannel* channel = SyncChannel::Create( + this, ipc_thread().message_loop_proxy().get(), + shutdown_event()).release(); + channel->InitByMode(channel_name(), mode(), create_pipe_now_); return channel; } @@ -345,9 +346,10 @@ class TwoStepClient : public Worker { } virtual SyncChannel* CreateChannel() OVERRIDE { - SyncChannel* channel = new SyncChannel( - this, ipc_thread().message_loop_proxy().get(), shutdown_event()); - channel->Init(channel_name(), mode(), create_pipe_now_); + SyncChannel* channel = SyncChannel::Create( + this, ipc_thread().message_loop_proxy().get(), + shutdown_event()).release(); + channel->InitByMode(channel_name(), mode(), create_pipe_now_); return channel; } @@ -1135,13 +1137,12 @@ class RestrictedDispatchClient : public Worker { else LOG(ERROR) << "Send failed to dispatch incoming message on same channel"; - non_restricted_channel_.reset( - new SyncChannel("non_restricted_channel", - Channel::MODE_CLIENT, - this, - ipc_thread().message_loop_proxy().get(), - true, - shutdown_event())); + non_restricted_channel_ = + SyncChannel::CreateClient("non_restricted_channel", + this, + ipc_thread().message_loop_proxy().get(), + true, + shutdown_event()); server_->ListenerThread()->message_loop()->PostTask( FROM_HERE, base::Bind(&RestrictedDispatchServer::OnDoPing, server_, 2)); @@ -1526,13 +1527,12 @@ class RestrictedDispatchPipeWorker : public Worker { if (is_first()) event1_->Signal(); event2_->Wait(); - other_channel_.reset( - new SyncChannel(other_channel_name_, - Channel::MODE_CLIENT, - this, - ipc_thread().message_loop_proxy().get(), - true, - shutdown_event())); + other_channel_ = SyncChannel::CreateClient( + other_channel_name_, + this, + ipc_thread().message_loop_proxy().get(), + true, + shutdown_event()); other_channel_->SetRestrictDispatchChannelGroup(group_); if (!is_first()) { event1_->Signal(); @@ -1606,13 +1606,12 @@ class ReentrantReplyServer1 : public Worker { server_ready_(server_ready) { } virtual void Run() OVERRIDE { - server2_channel_.reset( - new SyncChannel("reentrant_reply2", - Channel::MODE_CLIENT, - this, - ipc_thread().message_loop_proxy().get(), - true, - shutdown_event())); + server2_channel_ = SyncChannel::CreateClient( + "reentrant_reply2", + this, + ipc_thread().message_loop_proxy().get(), + true, + shutdown_event()); server_ready_->Signal(); Message* msg = new SyncChannelTestMsg_Reentrant1(); server2_channel_->Send(msg); diff --git a/ipc/ipc_test_base.cc b/ipc/ipc_test_base.cc index ca45d16de30df7..3d4ca88ffd36a1 100644 --- a/ipc/ipc_test_base.cc +++ b/ipc/ipc_test_base.cc @@ -77,10 +77,10 @@ void IPCTestBase::CreateChannelProxy( base::SingleThreadTaskRunner* ipc_task_runner) { CHECK(!channel_.get()); CHECK(!channel_proxy_.get()); - channel_proxy_.reset(new IPC::ChannelProxy(GetChannelName(test_client_name_), - IPC::Channel::MODE_SERVER, - listener, - ipc_task_runner)); + channel_proxy_ = IPC::ChannelProxy::CreateServer( + GetChannelName(test_client_name_), + listener, + ipc_task_runner); } void IPCTestBase::DestroyChannelProxy() { diff --git a/ppapi/nacl_irt/manifest_service.cc b/ppapi/nacl_irt/manifest_service.cc index 0afa217e2897a1..79da286c2a29a4 100644 --- a/ppapi/nacl_irt/manifest_service.cc +++ b/ppapi/nacl_irt/manifest_service.cc @@ -22,10 +22,9 @@ ManifestService::ManifestService( scoped_refptr io_message_loop, base::WaitableEvent* shutdown_event) { filter_ = new IPC::SyncMessageFilter(shutdown_event); - channel_.reset(new IPC::ChannelProxy(handle, - IPC::Channel::MODE_SERVER, - NULL, // Listener - io_message_loop)); + channel_ = IPC::ChannelProxy::CreateServer(handle, + NULL, // Listener + io_message_loop); channel_->AddFilter(filter_.get()); } diff --git a/ppapi/nacl_irt/ppapi_dispatcher.cc b/ppapi/nacl_irt/ppapi_dispatcher.cc index 9ca76b28b8240d..e01114e831d0b5 100644 --- a/ppapi/nacl_irt/ppapi_dispatcher.cc +++ b/ppapi/nacl_irt/ppapi_dispatcher.cc @@ -63,13 +63,13 @@ PpapiDispatcher::PpapiDispatcher(scoped_refptr io_loop, // Delay initializing the SyncChannel until after we add filters. This // ensures that the filters won't miss any messages received by // the channel. - channel_.reset(new IPC::SyncChannel( - this, GetIPCMessageLoop(), GetShutdownEvent())); + channel_ =IPC::SyncChannel::Create( + this, GetIPCMessageLoop(), GetShutdownEvent()); channel_->AddFilter(new proxy::PluginMessageFilter( NULL, proxy::PluginGlobals::Get()->resource_reply_thread_registrar())); channel_->AddFilter( new tracing::ChildTraceMessageFilter(message_loop_.get())); - channel_->Init(channel_handle, IPC::Channel::MODE_SERVER, true); + channel_->InitServer(channel_handle, true); } base::MessageLoopProxy* PpapiDispatcher::GetIPCMessageLoop() { diff --git a/ppapi/proxy/proxy_channel.cc b/ppapi/proxy/proxy_channel.cc index b7f8a826ce3245..db2a30f8094b69 100644 --- a/ppapi/proxy/proxy_channel.cc +++ b/ppapi/proxy/proxy_channel.cc @@ -31,11 +31,14 @@ bool ProxyChannel::InitWithChannel(Delegate* delegate, bool is_client) { delegate_ = delegate; peer_pid_ = peer_pid; - IPC::Channel::Mode mode = is_client ? IPC::Channel::MODE_CLIENT - : IPC::Channel::MODE_SERVER; - channel_.reset(new IPC::SyncChannel(channel_handle, mode, this, - delegate->GetIPCMessageLoop(), true, - delegate->GetShutdownEvent())); + channel_ = IPC::SyncChannel::Create( + this, + delegate->GetIPCMessageLoop(), + delegate->GetShutdownEvent()); + if (is_client) + channel_->InitClient(channel_handle, true); + else + channel_->InitServer(channel_handle, true); return true; } diff --git a/remoting/host/desktop_process.cc b/remoting/host/desktop_process.cc index 4592bfdc613315..53bb336b96a26c 100644 --- a/remoting/host/desktop_process.cc +++ b/remoting/host/desktop_process.cc @@ -139,10 +139,10 @@ bool DesktopProcess::Start( } // Connect to the daemon. - daemon_channel_.reset(new IPC::ChannelProxy(daemon_channel_name_, - IPC::Channel::MODE_CLIENT, - this, - io_task_runner.get())); + daemon_channel_ = IPC::ChannelProxy::CreateClient( + daemon_channel_name_, + this, + io_task_runner.get()); // Pass |desktop_pipe| to the daemon. daemon_channel_->Send( diff --git a/remoting/host/desktop_process_unittest.cc b/remoting/host/desktop_process_unittest.cc index d83d8032657780..6b08c9f8f0d0c0 100644 --- a/remoting/host/desktop_process_unittest.cc +++ b/remoting/host/desktop_process_unittest.cc @@ -175,10 +175,10 @@ void DesktopProcessTest::ConnectNetworkChannel( IPC::ChannelHandle channel_handle(desktop_process); #endif // defined(OS_WIN) - network_channel_.reset(new IPC::ChannelProxy(channel_handle, - IPC::Channel::MODE_CLIENT, - &network_listener_, - io_task_runner_.get())); + network_channel_ = IPC::ChannelProxy::CreateClient( + channel_handle, + &network_listener_, + io_task_runner_.get()); } void DesktopProcessTest::OnDesktopAttached( @@ -246,10 +246,10 @@ void DesktopProcessTest::RunDesktopProcess() { "IPC thread", ui_task_runner, base::MessageLoop::TYPE_IO); std::string channel_name = IPC::Channel::GenerateUniqueRandomChannelID(); - daemon_channel_.reset(new IPC::ChannelProxy(IPC::ChannelHandle(channel_name), - IPC::Channel::MODE_SERVER, - &daemon_listener_, - io_task_runner_.get())); + daemon_channel_ = IPC::ChannelProxy::CreateServer( + IPC::ChannelHandle(channel_name), + &daemon_listener_, + io_task_runner_.get()); scoped_ptr desktop_environment_factory( new MockDesktopEnvironmentFactory()); diff --git a/remoting/host/desktop_session_proxy.cc b/remoting/host/desktop_session_proxy.cc index 73497f9ded9cbe..f34dd04ec6f584 100644 --- a/remoting/host/desktop_session_proxy.cc +++ b/remoting/host/desktop_session_proxy.cc @@ -254,10 +254,10 @@ bool DesktopSessionProxy::AttachToDesktop( #endif // Connect to the desktop process. - desktop_channel_.reset(new IPC::ChannelProxy(desktop_channel_handle, - IPC::Channel::MODE_CLIENT, - this, - io_task_runner_.get())); + desktop_channel_ = IPC::ChannelProxy::CreateClient( + desktop_channel_handle, + this, + io_task_runner_.get()); // Pass ID of the client (which is authenticated at this point) to the desktop // session agent and start the agent. diff --git a/remoting/host/ipc_desktop_environment_unittest.cc b/remoting/host/ipc_desktop_environment_unittest.cc index 7e3168868ab21c..32ce885cd96a0f 100644 --- a/remoting/host/ipc_desktop_environment_unittest.cc +++ b/remoting/host/ipc_desktop_environment_unittest.cc @@ -367,11 +367,10 @@ void IpcDesktopEnvironmentTest::CreateDesktopProcess() { // Create the daemon end of the daemon-to-desktop channel. desktop_channel_name_ = IPC::Channel::GenerateUniqueRandomChannelID(); - desktop_channel_.reset( - new IPC::ChannelProxy(IPC::ChannelHandle(desktop_channel_name_), - IPC::Channel::MODE_SERVER, - &desktop_listener_, - io_task_runner_.get())); + desktop_channel_ = IPC::ChannelProxy::CreateServer( + IPC::ChannelHandle(desktop_channel_name_), + &desktop_listener_, + io_task_runner_.get()); // Create and start the desktop process. desktop_process_.reset(new DesktopProcess(task_runner_, diff --git a/remoting/host/ipc_util_posix.cc b/remoting/host/ipc_util_posix.cc index d7c6a5d894988d..0b423cde81cc57 100644 --- a/remoting/host/ipc_util_posix.cc +++ b/remoting/host/ipc_util_posix.cc @@ -45,10 +45,10 @@ bool CreateConnectedIpcChannel( // Wrap the pipe into an IPC channel. base::FileDescriptor fd(pipe_fds[0], false); IPC::ChannelHandle handle(socket_name, fd); - server_out->reset(new IPC::ChannelProxy(IPC::ChannelHandle(socket_name, fd), - IPC::Channel::MODE_SERVER, - listener, - io_task_runner.get())); + *server_out = IPC::ChannelProxy::CreateServer( + IPC::ChannelHandle(socket_name, fd), + listener, + io_task_runner.get()); *client_out = base::FileDescriptor(pipe_fds[1], false); return true; diff --git a/remoting/host/ipc_util_win.cc b/remoting/host/ipc_util_win.cc index 37c3383087e157..452c7bdcd04172 100644 --- a/remoting/host/ipc_util_win.cc +++ b/remoting/host/ipc_util_win.cc @@ -51,11 +51,10 @@ bool CreateConnectedIpcChannel( } // Wrap the pipe into an IPC channel. - scoped_ptr server(new IPC::ChannelProxy( + scoped_ptr server = IPC::ChannelProxy::CreateServer( IPC::ChannelHandle(pipe), - IPC::Channel::MODE_SERVER, listener, - io_task_runner)); + io_task_runner); // Convert the channel name to the pipe name. std::string pipe_name(kChromePipeNamePrefix); diff --git a/remoting/host/remoting_me2me_host.cc b/remoting/host/remoting_me2me_host.cc index 22f5da068cc2b5..5eefaad17d7e9d 100644 --- a/remoting/host/remoting_me2me_host.cc +++ b/remoting/host/remoting_me2me_host.cc @@ -384,21 +384,19 @@ bool HostProcess::InitWithCommandLine(const base::CommandLine* cmd_line) { #endif // defined(OS_POSIX) // Connect to the daemon process. - daemon_channel_.reset(new IPC::ChannelProxy( + daemon_channel_ = IPC::ChannelProxy::CreateClient( channel_handle, - IPC::Channel::MODE_CLIENT, this, - context_->network_task_runner())); + context_->network_task_runner()); #else // !defined(REMOTING_MULTI_PROCESS) // Connect to the daemon process. std::string channel_name = cmd_line->GetSwitchValueASCII(kDaemonPipeSwitchName); if (!channel_name.empty()) { - daemon_channel_.reset( - new IPC::ChannelProxy(channel_name, - IPC::Channel::MODE_CLIENT, - this, - context_->network_task_runner().get())); + daemon_channel_= IPC::ChannelProxy::CreateClient( + channel_name, + this, + context_->network_task_runner().get()); } if (cmd_line->HasSwitch(kHostConfigSwitchName)) { diff --git a/remoting/host/win/worker_process_launcher_unittest.cc b/remoting/host/win/worker_process_launcher_unittest.cc index 5503ab9ab763c8..fc3ef601d8e345 100644 --- a/remoting/host/win/worker_process_launcher_unittest.cc +++ b/remoting/host/win/worker_process_launcher_unittest.cc @@ -273,11 +273,10 @@ void WorkerProcessLauncherTest::TerminateWorker(DWORD exit_code) { } void WorkerProcessLauncherTest::ConnectClient() { - channel_client_.reset(new IPC::ChannelProxy( + channel_client_ = IPC::ChannelProxy::CreateClient( IPC::ChannelHandle(channel_name_), - IPC::Channel::MODE_CLIENT, &client_listener_, - task_runner_)); + task_runner_); // Pretend that |kLaunchSuccessTimeoutSeconds| passed since launching // the worker process. This will make the backoff algorithm think that this @@ -361,11 +360,10 @@ void WorkerProcessLauncherTest::DoLaunchProcess() { ASSERT_TRUE(CreateIpcChannel(channel_name_, kIpcSecurityDescriptor, &pipe)); // Wrap the pipe into an IPC channel. - channel_server_.reset(new IPC::ChannelProxy( + channel_server_ = IPC::ChannelProxy::CreateServer( IPC::ChannelHandle(pipe), - IPC::Channel::MODE_SERVER, this, - task_runner_)); + task_runner_); HANDLE temp_handle; ASSERT_TRUE(DuplicateHandle(GetCurrentProcess(), diff --git a/tools/ipc_fuzzer/replay/replay_process.cc b/tools/ipc_fuzzer/replay/replay_process.cc index b141cd0029e253..1db6f188ed20d4 100644 --- a/tools/ipc_fuzzer/replay/replay_process.cc +++ b/tools/ipc_fuzzer/replay/replay_process.cc @@ -55,11 +55,8 @@ void ReplayProcess::OpenChannel() { CommandLine::ForCurrentProcess()->GetSwitchValueASCII( switches::kProcessChannelID); - channel_.reset( - new IPC::ChannelProxy(channel_name, - IPC::Channel::MODE_CLIENT, - this, - io_thread_.message_loop_proxy())); + channel_ = IPC::ChannelProxy::CreateClient( + channel_name, this, io_thread_.message_loop_proxy()); } bool ReplayProcess::OpenTestcase() { diff --git a/win8/metro_driver/chrome_app_view_ash.cc b/win8/metro_driver/chrome_app_view_ash.cc index c104a15cc80ceb..2ade77ae388865 100644 --- a/win8/metro_driver/chrome_app_view_ash.cc +++ b/win8/metro_driver/chrome_app_view_ash.cc @@ -694,11 +694,11 @@ ChromeAppViewAsh::Run() { // In Aura mode we create an IPC channel to the browser, then ask it to // connect to us. ChromeChannelListener ui_channel_listener(&ui_loop_, this); - IPC::ChannelProxy ui_channel(win8::kMetroViewerIPCChannelName, - IPC::Channel::MODE_NAMED_CLIENT, - &ui_channel_listener, - io_thread.message_loop_proxy()); - ui_channel_ = &ui_channel; + scoped_ptr channel = IPC::ChannelProxy::CreateNamedClient( + win8::kMetroViewerIPCChannelName, + &ui_channel_listener, + io_thread.message_loop_proxy()); + ui_channel_ = channel.get(); // Upon receipt of the MetroViewerHostMsg_SetTargetSurface message the // browser will use D3D from the browser process to present to our Window. diff --git a/win8/viewer/metro_viewer_process_host.cc b/win8/viewer/metro_viewer_process_host.cc index 70b6b35a70015c..eaeaedfc8cca53 100644 --- a/win8/viewer/metro_viewer_process_host.cc +++ b/win8/viewer/metro_viewer_process_host.cc @@ -51,11 +51,10 @@ MetroViewerProcessHost::MetroViewerProcessHost( DCHECK(!instance_); instance_ = this; - channel_.reset(new IPC::ChannelProxy( + channel_ = IPC::ChannelProxy::CreateNamedServer( kMetroViewerIPCChannelName, - IPC::Channel::MODE_NAMED_SERVER, this, - ipc_task_runner)); + ipc_task_runner); } MetroViewerProcessHost::~MetroViewerProcessHost() {