diff options
author | morrita@chromium.org <morrita@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-05 16:15:38 +0000 |
---|---|---|
committer | morrita@chromium.org <morrita@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-05 16:15:38 +0000 |
commit | fca876a107b04f46eabeff93dbd09e3612d96c61 (patch) | |
tree | 5f851173c0418a9653f43d72618a34aba9cd01f4 | |
parent | 3408115e2fd1fcfb264d8a47498c9cc376e977c1 (diff) | |
download | chromium_src-fca876a107b04f46eabeff93dbd09e3612d96c61.zip chromium_src-fca876a107b04f46eabeff93dbd09e3612d96c61.tar.gz chromium_src-fca876a107b04f46eabeff93dbd09e3612d96c61.tar.bz2 |
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
R=darin@chromium.org,jam@chromium.org
Review URL: https://codereview.chromium.org/310853003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@275140 0039d316-1c4b-4281-b951-d872f2087c98
38 files changed, 230 insertions, 198 deletions
diff --git a/apps/app_shim/app_shim_host_mac.cc b/apps/app_shim/app_shim_host_mac.cc index 437fb6b..9d9e66d 100644 --- a/apps/app_shim/app_shim_host_mac.cc +++ b/apps/app_shim/app_shim_host_mac.cc @@ -24,12 +24,12 @@ AppShimHost::~AppShimHost() { void AppShimHost::ServeChannel(const IPC::ChannelHandle& handle) { DCHECK(CalledOnValidThread()); DCHECK(!channel_.get()); - channel_.reset(new IPC::ChannelProxy( + channel_ = IPC::ChannelProxy::Create( 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 c97f544..efd2278 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,10 @@ TestShimClient::TestShimClient() : io_thread_("TestShimClientIO") { 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::Create(handle, + IPC::Channel::MODE_NAMED_CLIENT, + 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 c04b9a4..b033916 100644 --- a/apps/app_shim/chrome_main_app_mode_mac.mm +++ b/apps/app_shim/chrome_main_app_mode_mac.mm @@ -214,11 +214,10 @@ void AppShimController::Init() { 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::Create(handle, + IPC::Channel::MODE_NAMED_CLIENT, + 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 cce36d6..5f1c55e 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,11 @@ int CloudPrintMockService_Main(SetExpectationsCallback set_expectations) { CommandLine::ForCurrentProcess()->GetSwitchValueASCII( switches::kProcessChannelID); scoped_ptr<IPC::ChannelProxy> startup_channel; - startup_channel.reset( - new IPC::ChannelProxy(startup_channel_name, - IPC::Channel::MODE_CLIENT, - &listener, - service_process.IOMessageLoopProxy())); + startup_channel = + IPC::ChannelProxy::Create(startup_channel_name, + IPC::Channel::MODE_CLIENT, + &listener, + service_process.IOMessageLoopProxy()); main_message_loop.Run(); if (!Mock::VerifyAndClearExpectations(&server)) @@ -442,9 +442,10 @@ base::ProcessHandle CloudPrintProxyPolicyStartupTest::Launch( base::StringPrintf("%d.%p.%d", base::GetCurrentProcId(), this, base::RandInt(0, std::numeric_limits<int>::max())); - startup_channel_.reset(new IPC::ChannelProxy( - startup_channel_id_, IPC::Channel::MODE_SERVER, - this, IOMessageLoopProxy())); + startup_channel_ = IPC::ChannelProxy::Create(startup_channel_id_, + IPC::Channel::MODE_SERVER, + this, + IOMessageLoopProxy()); #if defined(OS_POSIX) base::FileHandleMappingVector ipc_file_list; @@ -466,10 +467,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::Create(GetServiceProcessChannel(), + IPC::Channel::MODE_NAMED_CLIENT, + 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 b9cfa57..3650429 100644 --- a/chrome/browser/service_process/service_process_control.cc +++ b/chrome/browser/service_process/service_process_control.cc @@ -51,15 +51,15 @@ void ServiceProcessControl::ConnectInternal() { // TODO(hclam): Handle error connecting to channel. const IPC::ChannelHandle channel_id = GetServiceProcessChannel(); - SetChannel(new IPC::ChannelProxy( + SetChannel(IPC::ChannelProxy::Create( 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<IPC::ChannelProxy> 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 9db9324..4f58e59 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<IPC::ChannelProxy> channel); static void RunAllTasksHelper(TaskList* task_list); diff --git a/chrome/service/service_ipc_server.cc b/chrome/service/service_ipc_server.cc index 987f806..3265b9e 100644 --- a/chrome/service/service_ipc_server.cc +++ b/chrome/service/service_ipc_server.cc @@ -26,13 +26,13 @@ bool ServiceIPCServer::Init() { void ServiceIPCServer::CreateChannel() { channel_.reset(NULL); // Tear down the existing channel, if any. - channel_.reset(new IPC::SyncChannel( + channel_ = IPC::SyncChannel::Create( 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 7451fe6..cbb716c 100644 --- a/components/nacl/browser/nacl_process_host.cc +++ b/components/nacl/browser/nacl_process_host.cc @@ -905,11 +905,11 @@ 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::Create(browser_channel_handle, + IPC::Channel::MODE_CLIENT, + 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 5056f0f..9aa210f 100644 --- a/components/nacl/loader/nacl_listener.cc +++ b/components/nacl/loader/nacl_listener.cc @@ -244,8 +244,8 @@ 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); diff --git a/components/nacl/loader/nacl_trusted_listener.cc b/components/nacl/loader/nacl_trusted_listener.cc index 19a6038..425381f 100644 --- a/components/nacl/loader/nacl_trusted_listener.cc +++ b/components/nacl/loader/nacl_trusted_listener.cc @@ -8,9 +8,12 @@ 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::Create(handle, + IPC::Channel::MODE_SERVER, + 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 606be61..407b92b 100644 --- a/components/nacl/renderer/manifest_service_channel.cc +++ b/components/nacl/renderer/manifest_service_channel.cc @@ -22,10 +22,13 @@ 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::Create( + handle, + IPC::Channel::MODE_CLIENT, + this, content::RenderThread::Get()->GetIOMessageLoopProxy(), - true, waitable_event)), + 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 7ce3d84..88c2dcd 100644 --- a/components/nacl/renderer/trusted_plugin_channel.cc +++ b/components/nacl/renderer/trusted_plugin_channel.cc @@ -17,9 +17,12 @@ TrustedPluginChannel::TrustedPluginChannel( const base::Callback<void(int32_t)>& connected_callback, base::WaitableEvent* waitable_event) : connected_callback_(connected_callback), - channel_(new IPC::SyncChannel( - handle, IPC::Channel::MODE_CLIENT, this, - content::RenderThread::Get()->GetIOMessageLoopProxy(), true, + channel_(IPC::SyncChannel::Create( + handle, + IPC::Channel::MODE_CLIENT, + 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 a9e8ab5..aed78ae 100644 --- a/content/browser/renderer_host/render_process_host_impl.cc +++ b/content/browser/renderer_host/render_process_host_impl.cc @@ -569,12 +569,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::Create( + channel_id, + IPC::Channel::MODE_SERVER, + 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 cbadb21..044a5ca 100644 --- a/content/child/child_thread.cc +++ b/content/child/child_thread.cc @@ -225,13 +225,13 @@ 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::Create(channel_name_, + IPC::Channel::MODE_CLIENT, + 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 76845bd..e7f2ca2 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_ = IPC::SyncChannel::Create( channel_handle_, mode_, this, ipc_message_loop, create_pipe_now, - shutdown_event)); + shutdown_event); #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 f503051..247971f 100644 --- a/content/common/gpu/client/gpu_channel_host.cc +++ b/content/common/gpu/client/gpu_channel_host.cc @@ -73,12 +73,12 @@ 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<base::MessageLoopProxy> io_loop = factory_->GetIOLoopProxy(); - channel_.reset(new IPC::SyncChannel(channel_handle, + channel_ = IPC::SyncChannel::Create(channel_handle, IPC::Channel::MODE_CLIENT, NULL, io_loop.get(), true, - shutdown_event)); + 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 1c8e4f9..6262ed5 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_id_, - IPC::Channel::MODE_SERVER, - this, - io_message_loop, - false, - shutdown_event)); + channel_ = IPC::SyncChannel::Create(channel_id_, + IPC::Channel::MODE_SERVER, + this, + io_message_loop, + false, + shutdown_event); filter_ = new GpuChannelMessageFilter(weak_factory_.GetWeakPtr(), diff --git a/ipc/ipc_channel_proxy.cc b/ipc/ipc_channel_proxy.cc index e88bb5d..ceffb94 100644 --- a/ipc/ipc_channel_proxy.cc +++ b/ipc/ipc_channel_proxy.cc @@ -304,13 +304,15 @@ 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> ChannelProxy::Create( + const IPC::ChannelHandle& channel_handle, + Channel::Mode mode, + Listener* listener, + base::SingleThreadTaskRunner* ipc_task_runner) { + scoped_ptr<ChannelProxy> channel(new ChannelProxy(listener, ipc_task_runner)); + channel->Init(channel_handle, mode, true); + return channel.Pass(); } ChannelProxy::ChannelProxy(Context* context) @@ -318,6 +320,11 @@ 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()); diff --git a/ipc/ipc_channel_proxy.h b/ipc/ipc_channel_proxy.h index 0a3a5d2..31ca211 100644 --- a/ipc/ipc_channel_proxy.h +++ b/ipc/ipc_channel_proxy.h @@ -64,10 +64,11 @@ 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); + static scoped_ptr<ChannelProxy> Create( + const IPC::ChannelHandle& channel_handle, + Channel::Mode mode, + Listener* listener, + base::SingleThreadTaskRunner* ipc_task_runner); virtual ~ChannelProxy(); @@ -124,6 +125,9 @@ 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<Context>, public Listener { diff --git a/ipc/ipc_sync_channel.cc b/ipc/ipc_sync_channel.cc index 0e0018c..a7ed230 100644 --- a/ipc/ipc_sync_channel.cc +++ b/ipc/ipc_sync_channel.cc @@ -404,19 +404,27 @@ base::WaitableEventWatcher::EventCallback 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( diff --git a/ipc/ipc_sync_channel.h b/ipc/ipc_sync_channel.h index f18fcff9..8984184 100644 --- a/ipc/ipc_sync_channel.h +++ b/ipc/ipc_sync_channel.h @@ -66,19 +66,22 @@ 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<SyncChannel> Create( + const IPC::ChannelHandle& channel_handle, + IPC::Channel::Mode mode, + 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<SyncChannel> Create( + Listener* listener, + base::SingleThreadTaskRunner* ipc_task_runner, + base::WaitableEvent* shutdown_event); virtual ~SyncChannel(); @@ -188,6 +191,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 ca8d5d7..817f17e 100644 --- a/ipc/ipc_sync_channel_unittest.cc +++ b/ipc/ipc_sync_channel_unittest.cc @@ -151,12 +151,10 @@ 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<SyncChannel> channel = SyncChannel::Create( + channel_name_, mode_, this, ipc_thread_.message_loop_proxy().get(), + true, &shutdown_event_); + return channel.release(); } base::Thread* ListenerThread() { @@ -324,9 +322,11 @@ 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(channel_name(), mode(), this, + ipc_thread().message_loop_proxy().get(), + create_pipe_now_, + shutdown_event()).release(); return channel; } @@ -345,9 +345,11 @@ 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(channel_name(), mode(), this, + ipc_thread().message_loop_proxy().get(), + create_pipe_now_, + shutdown_event()).release(); return channel; } @@ -1135,13 +1137,13 @@ 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::Create("non_restricted_channel", + IPC::Channel::MODE_CLIENT, + 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 +1528,13 @@ 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::Create(other_channel_name_, + IPC::Channel::MODE_CLIENT, + this, + ipc_thread().message_loop_proxy().get(), + true, + shutdown_event()); other_channel_->SetRestrictDispatchChannelGroup(group_); if (!is_first()) { event1_->Signal(); @@ -1606,13 +1608,13 @@ 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::Create("reentrant_reply2", + IPC::Channel::MODE_CLIENT, + 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 ca45d16..4e7133b 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_), + channel_proxy_ = IPC::ChannelProxy::Create(GetChannelName(test_client_name_), IPC::Channel::MODE_SERVER, listener, - ipc_task_runner)); + ipc_task_runner); } void IPCTestBase::DestroyChannelProxy() { diff --git a/ppapi/nacl_irt/manifest_service.cc b/ppapi/nacl_irt/manifest_service.cc index 0afa217..85b7fae 100644 --- a/ppapi/nacl_irt/manifest_service.cc +++ b/ppapi/nacl_irt/manifest_service.cc @@ -22,10 +22,10 @@ ManifestService::ManifestService( scoped_refptr<base::MessageLoopProxy> io_message_loop, base::WaitableEvent* shutdown_event) { filter_ = new IPC::SyncMessageFilter(shutdown_event); - channel_.reset(new IPC::ChannelProxy(handle, + channel_ = IPC::ChannelProxy::Create(handle, IPC::Channel::MODE_SERVER, NULL, // Listener - io_message_loop)); + io_message_loop); channel_->AddFilter(filter_.get()); } diff --git a/ppapi/nacl_irt/ppapi_dispatcher.cc b/ppapi/nacl_irt/ppapi_dispatcher.cc index 9ca76b2..0600fc1 100644 --- a/ppapi/nacl_irt/ppapi_dispatcher.cc +++ b/ppapi/nacl_irt/ppapi_dispatcher.cc @@ -63,8 +63,8 @@ PpapiDispatcher::PpapiDispatcher(scoped_refptr<base::MessageLoopProxy> 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( diff --git a/ppapi/proxy/proxy_channel.cc b/ppapi/proxy/proxy_channel.cc index c1f48de..7a7dfaa 100644 --- a/ppapi/proxy/proxy_channel.cc +++ b/ppapi/proxy/proxy_channel.cc @@ -31,11 +31,12 @@ 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, + IPC::Channel::Mode mode = is_client + ? IPC::Channel::MODE_CLIENT + : IPC::Channel::MODE_SERVER; + channel_ = IPC::SyncChannel::Create(channel_handle, mode, this, delegate->GetIPCMessageLoop(), true, - delegate->GetShutdownEvent())); + delegate->GetShutdownEvent()); return true; } diff --git a/remoting/host/desktop_process.cc b/remoting/host/desktop_process.cc index 4592bfd..5f0303e 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_, + daemon_channel_ = IPC::ChannelProxy::Create(daemon_channel_name_, IPC::Channel::MODE_CLIENT, this, - io_task_runner.get())); + 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 3f5f109..19e5b56 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, + network_channel_ = IPC::ChannelProxy::Create(channel_handle, IPC::Channel::MODE_CLIENT, &network_listener_, - io_task_runner_.get())); + 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), + daemon_channel_ = IPC::ChannelProxy::Create(IPC::ChannelHandle(channel_name), IPC::Channel::MODE_SERVER, &daemon_listener_, - io_task_runner_.get())); + io_task_runner_.get()); scoped_ptr<MockDesktopEnvironmentFactory> desktop_environment_factory( new MockDesktopEnvironmentFactory()); diff --git a/remoting/host/desktop_session_proxy.cc b/remoting/host/desktop_session_proxy.cc index 28f8296..7904a2d 100644 --- a/remoting/host/desktop_session_proxy.cc +++ b/remoting/host/desktop_session_proxy.cc @@ -253,10 +253,10 @@ bool DesktopSessionProxy::AttachToDesktop( #endif // Connect to the desktop process. - desktop_channel_.reset(new IPC::ChannelProxy(desktop_channel_handle, + desktop_channel_ = IPC::ChannelProxy::Create(desktop_channel_handle, IPC::Channel::MODE_CLIENT, this, - io_task_runner_.get())); + 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 7e31688..c51f063 100644 --- a/remoting/host/ipc_desktop_environment_unittest.cc +++ b/remoting/host/ipc_desktop_environment_unittest.cc @@ -367,11 +367,11 @@ 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::Create(IPC::ChannelHandle(desktop_channel_name_), + IPC::Channel::MODE_SERVER, + &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 4901c99..b0cee30 100644 --- a/remoting/host/ipc_util_posix.cc +++ b/remoting/host/ipc_util_posix.cc @@ -46,10 +46,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), + *server_out = IPC::ChannelProxy::Create(IPC::ChannelHandle(socket_name, fd), IPC::Channel::MODE_SERVER, listener, - io_task_runner.get())); + io_task_runner.get()); *client_out = base::File(pipe_fds[1]); return true; diff --git a/remoting/host/ipc_util_win.cc b/remoting/host/ipc_util_win.cc index dabdbe1..a1cdbb2 100644 --- a/remoting/host/ipc_util_win.cc +++ b/remoting/host/ipc_util_win.cc @@ -52,11 +52,11 @@ bool CreateConnectedIpcChannel( } // Wrap the pipe into an IPC channel. - scoped_ptr<IPC::ChannelProxy> server(new IPC::ChannelProxy( - IPC::ChannelHandle(pipe), - IPC::Channel::MODE_SERVER, - listener, - io_task_runner)); + scoped_ptr<IPC::ChannelProxy> server = + IPC::ChannelProxy::Create(IPC::ChannelHandle(pipe), + IPC::Channel::MODE_SERVER, + listener, + 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 22f5da0..681dca7 100644 --- a/remoting/host/remoting_me2me_host.cc +++ b/remoting/host/remoting_me2me_host.cc @@ -384,21 +384,20 @@ bool HostProcess::InitWithCommandLine(const base::CommandLine* cmd_line) { #endif // defined(OS_POSIX) // Connect to the daemon process. - daemon_channel_.reset(new IPC::ChannelProxy( - channel_handle, - IPC::Channel::MODE_CLIENT, - this, - context_->network_task_runner())); + daemon_channel_ = IPC::ChannelProxy::Create(channel_handle, + IPC::Channel::MODE_CLIENT, + this, + 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::Create(channel_name, + IPC::Channel::MODE_CLIENT, + 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 5503ab9..917aeb6 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( - IPC::ChannelHandle(channel_name_), - IPC::Channel::MODE_CLIENT, - &client_listener_, - task_runner_)); + channel_client_ = IPC::ChannelProxy::Create(IPC::ChannelHandle(channel_name_), + IPC::Channel::MODE_CLIENT, + &client_listener_, + task_runner_); // Pretend that |kLaunchSuccessTimeoutSeconds| passed since launching // the worker process. This will make the backoff algorithm think that this @@ -361,11 +360,8 @@ void WorkerProcessLauncherTest::DoLaunchProcess() { ASSERT_TRUE(CreateIpcChannel(channel_name_, kIpcSecurityDescriptor, &pipe)); // Wrap the pipe into an IPC channel. - channel_server_.reset(new IPC::ChannelProxy( - IPC::ChannelHandle(pipe), - IPC::Channel::MODE_SERVER, - this, - task_runner_)); + channel_server_ = IPC::ChannelProxy::Create( + IPC::ChannelHandle(pipe), IPC::Channel::MODE_SERVER, this, task_runner_); HANDLE temp_handle; ASSERT_TRUE(DuplicateHandle(GetCurrentProcess(), diff --git a/remoting/host/win/wts_session_process_delegate.cc b/remoting/host/win/wts_session_process_delegate.cc index f939abf..eb310df 100644 --- a/remoting/host/win/wts_session_process_delegate.cc +++ b/remoting/host/win/wts_session_process_delegate.cc @@ -379,11 +379,11 @@ void WtsSessionProcessDelegate::Core::DoLaunchProcess() { } // Wrap the pipe into an IPC channel. - scoped_ptr<IPC::ChannelProxy> channel(new IPC::ChannelProxy( - IPC::ChannelHandle(pipe), - IPC::Channel::MODE_SERVER, - this, - io_task_runner_)); + scoped_ptr<IPC::ChannelProxy> channel( + IPC::ChannelProxy::Create(IPC::ChannelHandle(pipe), + IPC::Channel::MODE_SERVER, + this, + io_task_runner_)); // Pass the name of the IPC channel to use. command_line.AppendSwitchNative(kDaemonPipeSwitchName, diff --git a/tools/ipc_fuzzer/replay/replay_process.cc b/tools/ipc_fuzzer/replay/replay_process.cc index b141cd0..1e6f4c2 100644 --- a/tools/ipc_fuzzer/replay/replay_process.cc +++ b/tools/ipc_fuzzer/replay/replay_process.cc @@ -55,11 +55,10 @@ 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::Create(channel_name, + IPC::Channel::MODE_CLIENT, + 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 c104a15..fd19385 100644 --- a/win8/metro_driver/chrome_app_view_ash.cc +++ b/win8/metro_driver/chrome_app_view_ash.cc @@ -694,11 +694,12 @@ 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<IPC::ChannelProxy> channel = + IPC::ChannelProxy::Create(win8::kMetroViewerIPCChannelName, + IPC::Channel::MODE_NAMED_CLIENT, + &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 70b6b35..dde741b 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( - kMetroViewerIPCChannelName, - IPC::Channel::MODE_NAMED_SERVER, - this, - ipc_task_runner)); + channel_ = IPC::ChannelProxy::Create(kMetroViewerIPCChannelName, + IPC::Channel::MODE_NAMED_SERVER, + this, + ipc_task_runner); } MetroViewerProcessHost::~MetroViewerProcessHost() { |