diff options
37 files changed, 208 insertions, 359 deletions
diff --git a/apps/app_shim/app_shim_host_mac.cc b/apps/app_shim/app_shim_host_mac.cc index 57316e5..437fb6b 100644 --- a/apps/app_shim/app_shim_host_mac.cc +++ b/apps/app_shim/app_shim_host_mac.cc @@ -24,11 +24,12 @@ AppShimHost::~AppShimHost() { void AppShimHost::ServeChannel(const IPC::ChannelHandle& handle) { DCHECK(CalledOnValidThread()); DCHECK(!channel_.get()); - channel_ = IPC::ChannelProxy::CreateServer( + channel_.reset(new IPC::ChannelProxy( 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 4327e97..c97f544 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 @@ TestShimClient::TestShimClient() : io_thread_("TestShimClientIO") { app_mode::VerifySocketPermissions(socket_path); IPC::ChannelHandle handle(socket_path.value()); - channel_ = IPC::ChannelProxy::CreateNamedClient( - handle, this, io_thread_.message_loop_proxy().get()); + channel_.reset(new IPC::ChannelProxy(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 ecc18bf..c04b9a4 100644 --- a/apps/app_shim/chrome_main_app_mode_mac.mm +++ b/apps/app_shim/chrome_main_app_mode_mac.mm @@ -214,8 +214,11 @@ void AppShimController::Init() { void AppShimController::CreateChannelAndSendLaunchApp( const base::FilePath& socket_path) { IPC::ChannelHandle handle(socket_path.value()); - channel_ = IPC::ChannelProxy::CreateNamedClient( - handle, this, g_io_thread->message_loop_proxy().get()); + channel_.reset( + new IPC::ChannelProxy(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 e2ecd5f..cce36d6 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,10 +266,11 @@ int CloudPrintMockService_Main(SetExpectationsCallback set_expectations) { CommandLine::ForCurrentProcess()->GetSwitchValueASCII( switches::kProcessChannelID); scoped_ptr<IPC::ChannelProxy> startup_channel; - startup_channel = IPC::ChannelProxy::CreateClient( - startup_channel_name, - &listener, - service_process.IOMessageLoopProxy()); + startup_channel.reset( + new IPC::ChannelProxy(startup_channel_name, + IPC::Channel::MODE_CLIENT, + &listener, + service_process.IOMessageLoopProxy())); main_message_loop.Run(); if (!Mock::VerifyAndClearExpectations(&server)) @@ -441,8 +442,9 @@ base::ProcessHandle CloudPrintProxyPolicyStartupTest::Launch( base::StringPrintf("%d.%p.%d", base::GetCurrentProcId(), this, base::RandInt(0, std::numeric_limits<int>::max())); - startup_channel_ = IPC::ChannelProxy::CreateServer( - startup_channel_id_, this, IOMessageLoopProxy()); + startup_channel_.reset(new IPC::ChannelProxy( + startup_channel_id_, IPC::Channel::MODE_SERVER, + this, IOMessageLoopProxy())); #if defined(OS_POSIX) base::FileHandleMappingVector ipc_file_list; @@ -464,10 +466,10 @@ void CloudPrintProxyPolicyStartupTest::WaitForConnect() { EXPECT_TRUE(CheckServiceProcessReady()); EXPECT_TRUE(base::MessageLoopProxy::current().get()); ServiceProcessControl::GetInstance()->SetChannel( - IPC::ChannelProxy::CreateNamedClient( - GetServiceProcessChannel(), - ServiceProcessControl::GetInstance(), - IOMessageLoopProxy())); + new IPC::ChannelProxy(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 1a58f11..b9cfa57 100644 --- a/chrome/browser/service_process/service_process_control.cc +++ b/chrome/browser/service_process/service_process_control.cc @@ -51,14 +51,15 @@ void ServiceProcessControl::ConnectInternal() { // TODO(hclam): Handle error connecting to channel. const IPC::ChannelHandle channel_id = GetServiceProcessChannel(); - SetChannel(IPC::ChannelProxy::CreateNamedClient( + SetChannel(new IPC::ChannelProxy( channel_id, + IPC::Channel::MODE_NAMED_CLIENT, this, BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO).get())); } -void ServiceProcessControl::SetChannel(scoped_ptr<IPC::ChannelProxy> channel) { - channel_ = channel.Pass(); +void ServiceProcessControl::SetChannel(IPC::ChannelProxy* channel) { + channel_.reset(channel); } void ServiceProcessControl::RunConnectDoneTasks() { diff --git a/chrome/browser/service_process/service_process_control.h b/chrome/browser/service_process/service_process_control.h index 4f58e59..9db9324 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(scoped_ptr<IPC::ChannelProxy> channel); + void SetChannel(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 7d47db3..987f806 100644 --- a/chrome/service/service_ipc_server.cc +++ b/chrome/service/service_ipc_server.cc @@ -26,12 +26,13 @@ bool ServiceIPCServer::Init() { void ServiceIPCServer::CreateChannel() { channel_.reset(NULL); // Tear down the existing channel, if any. - channel_= IPC::SyncChannel::CreateNamedServer( + channel_.reset(new IPC::SyncChannel( 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 ce2700d..7451fe6 100644 --- a/components/nacl/browser/nacl_process_host.cc +++ b/components/nacl/browser/nacl_process_host.cc @@ -905,10 +905,11 @@ void NaClProcessHost::OnPpapiChannelsCreated( if (!ipc_proxy_channel_.get()) { DCHECK_EQ(PROCESS_TYPE_NACL_LOADER, process_->GetData().process_type); - ipc_proxy_channel_ = IPC::ChannelProxy::CreateClient( - browser_channel_handle, - NULL, - base::MessageLoopProxy::current().get()); + ipc_proxy_channel_.reset( + new IPC::ChannelProxy(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 5f1966d..5056f0f 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_ = IPC::SyncChannel::Create( - this, io_thread_.message_loop_proxy().get(), &shutdown_event_); + channel_.reset(new IPC::SyncChannel( + this, io_thread_.message_loop_proxy().get(), &shutdown_event_)); filter_ = new IPC::SyncMessageFilter(&shutdown_event_); channel_->AddFilter(filter_.get()); - channel_->InitClient(channel_name, true); + channel_->Init(channel_name, IPC::Channel::MODE_CLIENT, 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 2392e9a..19a6038 100644 --- a/components/nacl/loader/nacl_trusted_listener.cc +++ b/components/nacl/loader/nacl_trusted_listener.cc @@ -8,8 +8,9 @@ NaClTrustedListener::NaClTrustedListener( const IPC::ChannelHandle& handle, base::MessageLoopProxy* message_loop_proxy, base::WaitableEvent* shutdown_event) { - channel_ = IPC::SyncChannel::CreateServer( - handle, this, message_loop_proxy, true, shutdown_event); + channel_.reset(new IPC::SyncChannel(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 3544d6e..606be61 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_(IPC::SyncChannel::CreateClient( - handle, this, + channel_(new IPC::SyncChannel( + handle, IPC::Channel::MODE_CLIENT, 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 cfb9523..7ce3d84 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<void(int32_t)>& connected_callback, base::WaitableEvent* waitable_event) : connected_callback_(connected_callback), - channel_(IPC::SyncChannel::CreateClient( - handle, this, + channel_(new IPC::SyncChannel( + 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 d2f231c..98e45d6 100644 --- a/content/browser/renderer_host/render_process_host_impl.cc +++ b/content/browser/renderer_host/render_process_host_impl.cc @@ -568,11 +568,12 @@ bool RenderProcessHostImpl::Init() { // Setup the IPC channel. const std::string channel_id = IPC::Channel::GenerateVerifiedChannelID(std::string()); - channel_ = IPC::ChannelProxy::CreateServer( - channel_id, - this, - BrowserThread::GetMessageLoopProxyForThread( - BrowserThread::IO).get()); + channel_.reset( + new IPC::ChannelProxy(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 8e4af63..ab276a6 100644 --- a/content/child/child_thread.cc +++ b/content/child/child_thread.cc @@ -225,12 +225,13 @@ void ChildThread::Init() { // the logger, and the logger does not like being created on the IO thread. IPC::Logging::GetInstance(); #endif - channel_ = IPC::SyncChannel::CreateClient( - channel_name_, - this, - ChildProcess::current()->io_message_loop_proxy(), - true, - ChildProcess::current()->GetShutDownEvent()); + channel_.reset( + new IPC::SyncChannel(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 d7e7508..76845bd 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_ = IPC::SyncChannel::Create( - this, ipc_message_loop, shutdown_event); - channel_->InitByMode(channel_handle_, mode_, create_pipe_now); + channel_.reset(new IPC::SyncChannel( + channel_handle_, mode_, this, ipc_message_loop, create_pipe_now, + 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 3a12f86..f503051 100644 --- a/content/common/gpu/client/gpu_channel_host.cc +++ b/content/common/gpu/client/gpu_channel_host.cc @@ -73,8 +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_ = IPC::SyncChannel::CreateClient( - channel_handle, NULL, io_loop.get(), true, shutdown_event); + channel_.reset(new IPC::SyncChannel(channel_handle, + IPC::Channel::MODE_CLIENT, + 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 429e8a5..1c8e4f9 100644 --- a/content/common/gpu/gpu_channel.cc +++ b/content/common/gpu/gpu_channel.cc @@ -411,12 +411,13 @@ void GpuChannel::Init(base::MessageLoopProxy* io_message_loop, DCHECK(!channel_.get()); // Map renderer ID to a (single) channel to that process. - channel_ = IPC::SyncChannel::CreateServer( + channel_.reset(new IPC::SyncChannel( 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 cf28ed6..e88bb5d 100644 --- a/ipc/ipc_channel_proxy.cc +++ b/ipc/ipc_channel_proxy.cc @@ -304,56 +304,13 @@ void ChannelProxy::Context::OnDispatchBadMessage(const Message& message) { //----------------------------------------------------------------------------- -// static -scoped_ptr<ChannelProxy> ChannelProxy::Create( - Listener* listener, - base::SingleThreadTaskRunner* ipc_task_runner) { - return make_scoped_ptr(new ChannelProxy( - listener, ipc_task_runner)); -} - -// static -scoped_ptr<ChannelProxy> ChannelProxy::CreateClient( - const IPC::ChannelHandle& channel_handle, - Listener* listener, - base::SingleThreadTaskRunner* ipc_task_runner) { - scoped_ptr<ChannelProxy> channel = Create( - listener, ipc_task_runner); - channel->InitClient(channel_handle, true); - return channel.Pass(); -} - -// static -scoped_ptr<ChannelProxy> ChannelProxy::CreateServer( - const IPC::ChannelHandle& channel_handle, - Listener* listener, - base::SingleThreadTaskRunner* ipc_task_runner) { - scoped_ptr<ChannelProxy> channel = Create( - listener, ipc_task_runner); - channel->InitServer(channel_handle, true); - return channel.Pass(); -} - -// static -scoped_ptr<ChannelProxy> ChannelProxy::CreateNamedClient( - const IPC::ChannelHandle& channel_handle, - Listener* listener, - base::SingleThreadTaskRunner* ipc_task_runner) { - scoped_ptr<ChannelProxy> channel = Create( - listener, ipc_task_runner); - channel->InitNamedClient(channel_handle, true); - return channel.Pass(); -} - -// static -scoped_ptr<ChannelProxy> ChannelProxy::CreateNamedServer( - const IPC::ChannelHandle& channel_handle, - Listener* listener, - base::SingleThreadTaskRunner* ipc_task_runner) { - scoped_ptr<ChannelProxy> channel = Create( - listener, ipc_task_runner); - channel->InitNamedServer(channel_handle, true); - return channel.Pass(); +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); } ChannelProxy::ChannelProxy(Context* context) @@ -361,22 +318,15 @@ 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::InitByMode( - const IPC::ChannelHandle& channel_handle, - Channel::Mode mode, - bool create_pipe_now) { +void ChannelProxy::Init(const IPC::ChannelHandle& channel_handle, + Channel::Mode mode, + bool create_pipe_now) { DCHECK(CalledOnValidThread()); DCHECK(!did_init_); #if defined(OS_POSIX) @@ -408,26 +358,6 @@ void ChannelProxy::InitByMode( 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 d1f270d..0a3a5d2 100644 --- a/ipc/ipc_channel_proxy.h +++ b/ipc/ipc_channel_proxy.h @@ -64,31 +64,10 @@ 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). - // The naming pattern follows IPC::Channel. The Create() does not create - // underlying channel and let Init*() do it. - static scoped_ptr<ChannelProxy> Create( - Listener* listener, - base::SingleThreadTaskRunner* ipc_task_runner); - - static scoped_ptr<ChannelProxy> CreateClient( - const IPC::ChannelHandle& channel_handle, - Listener* listener, - base::SingleThreadTaskRunner* ipc_task_runner); - - static scoped_ptr<ChannelProxy> CreateServer( - const IPC::ChannelHandle& channel_handle, - Listener* listener, - base::SingleThreadTaskRunner* ipc_task_runner); - - static scoped_ptr<ChannelProxy> CreateNamedClient( - const IPC::ChannelHandle& channel_handle, - Listener* listener, - base::SingleThreadTaskRunner* ipc_task_runner); - - static scoped_ptr<ChannelProxy> CreateNamedServer( - const IPC::ChannelHandle& channel_handle, - Listener* listener, - base::SingleThreadTaskRunner* ipc_task_runner); + ChannelProxy(const IPC::ChannelHandle& channel_handle, + Channel::Mode mode, + Listener* listener, + base::SingleThreadTaskRunner* ipc_task_runner); virtual ~ChannelProxy(); @@ -96,17 +75,8 @@ 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. - // 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); + void Init(const IPC::ChannelHandle& channel_handle, Channel::Mode mode, + 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 @@ -154,10 +124,6 @@ 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 32f8619..0e0018c 100644 --- a/ipc/ipc_sync_channel.cc +++ b/ipc/ipc_sync_channel.cc @@ -404,65 +404,19 @@ base::WaitableEventWatcher::EventCallback return base::Bind(&SyncChannel::SyncContext::OnWaitableEventSignaled, this); } -// static -scoped_ptr<SyncChannel> SyncChannel::CreateClient( - const IPC::ChannelHandle& channel_handle, - Listener* listener, - base::SingleThreadTaskRunner* ipc_task_runner, - bool create_pipe_now, - base::WaitableEvent* shutdown_event) { - scoped_ptr<SyncChannel> channel = Create( - listener, ipc_task_runner, shutdown_event); - channel->InitClient(channel_handle, create_pipe_now); - return channel.Pass(); -} - -// static -scoped_ptr<SyncChannel> SyncChannel::CreateServer( - const IPC::ChannelHandle& channel_handle, - Listener* listener, - base::SingleThreadTaskRunner* ipc_task_runner, - bool create_pipe_now, - base::WaitableEvent* shutdown_event) { - scoped_ptr<SyncChannel> channel = Create( - listener, ipc_task_runner, shutdown_event); - channel->InitServer(channel_handle, create_pipe_now); - return channel.Pass(); -} - -// static -scoped_ptr<SyncChannel> SyncChannel::CreateNamedClient( - const IPC::ChannelHandle& channel_handle, - Listener* listener, - base::SingleThreadTaskRunner* ipc_task_runner, - bool create_pipe_now, - base::WaitableEvent* shutdown_event) { - scoped_ptr<SyncChannel> channel = Create( - listener, ipc_task_runner, shutdown_event); - channel->InitNamedClient(channel_handle, create_pipe_now); - return channel.Pass(); -} - -// static -scoped_ptr<SyncChannel> SyncChannel::CreateNamedServer( +SyncChannel::SyncChannel( const IPC::ChannelHandle& channel_handle, + Channel::Mode mode, Listener* listener, base::SingleThreadTaskRunner* ipc_task_runner, bool create_pipe_now, - base::WaitableEvent* shutdown_event) { - scoped_ptr<SyncChannel> channel = Create( - listener, ipc_task_runner, shutdown_event); - channel->InitNamedServer(channel_handle, 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)); + 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(); } SyncChannel::SyncChannel( diff --git a/ipc/ipc_sync_channel.h b/ipc/ipc_sync_channel.h index 9ae3fd9..f18fcff9 100644 --- a/ipc/ipc_sync_channel.h +++ b/ipc/ipc_sync_channel.h @@ -66,42 +66,19 @@ class IPC_EXPORT SyncChannel : public ChannelProxy { // Creates and initializes a sync channel. If create_pipe_now is specified, // the channel will be initialized synchronously. - // The naming pattern follows IPC::Channel. - 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); - - static scoped_ptr<SyncChannel> CreateServer( - const IPC::ChannelHandle& channel_handle, - Listener* listener, - base::SingleThreadTaskRunner* ipc_task_runner, - bool create_pipe_now, - base::WaitableEvent* shutdown_event); - - 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); - - 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); + SyncChannel(const IPC::ChannelHandle& channel_handle, + 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. - static scoped_ptr<SyncChannel> Create( - Listener* listener, - base::SingleThreadTaskRunner* ipc_task_runner, - base::WaitableEvent* shutdown_event); + SyncChannel(Listener* listener, + base::SingleThreadTaskRunner* ipc_task_runner, + base::WaitableEvent* shutdown_event); virtual ~SyncChannel(); @@ -211,10 +188,6 @@ 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 33653c7..ca8d5d7 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() { - scoped_ptr<SyncChannel> channel = SyncChannel::Create( - this, - ipc_thread_.message_loop_proxy().get(), - &shutdown_event_); - channel->InitByMode(channel_name_, mode_, true); - return channel.release(); + return new SyncChannel(channel_name_, + mode_, + this, + ipc_thread_.message_loop_proxy().get(), + true, + &shutdown_event_); } base::Thread* ListenerThread() { @@ -324,10 +324,9 @@ class TwoStepServer : public Worker { } virtual SyncChannel* CreateChannel() OVERRIDE { - SyncChannel* channel = SyncChannel::Create( - this, ipc_thread().message_loop_proxy().get(), - shutdown_event()).release(); - channel->InitByMode(channel_name(), mode(), create_pipe_now_); + SyncChannel* channel = new SyncChannel( + this, ipc_thread().message_loop_proxy().get(), shutdown_event()); + channel->Init(channel_name(), mode(), create_pipe_now_); return channel; } @@ -346,10 +345,9 @@ class TwoStepClient : public Worker { } virtual SyncChannel* CreateChannel() OVERRIDE { - SyncChannel* channel = SyncChannel::Create( - this, ipc_thread().message_loop_proxy().get(), - shutdown_event()).release(); - channel->InitByMode(channel_name(), mode(), create_pipe_now_); + SyncChannel* channel = new SyncChannel( + this, ipc_thread().message_loop_proxy().get(), shutdown_event()); + channel->Init(channel_name(), mode(), create_pipe_now_); return channel; } @@ -1137,12 +1135,13 @@ class RestrictedDispatchClient : public Worker { else LOG(ERROR) << "Send failed to dispatch incoming message on same channel"; - non_restricted_channel_ = - SyncChannel::CreateClient("non_restricted_channel", - this, - ipc_thread().message_loop_proxy().get(), - true, - shutdown_event()); + non_restricted_channel_.reset( + new SyncChannel("non_restricted_channel", + 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)); @@ -1527,12 +1526,13 @@ class RestrictedDispatchPipeWorker : public Worker { if (is_first()) event1_->Signal(); event2_->Wait(); - other_channel_ = SyncChannel::CreateClient( - other_channel_name_, - this, - ipc_thread().message_loop_proxy().get(), - true, - shutdown_event()); + other_channel_.reset( + new SyncChannel(other_channel_name_, + Channel::MODE_CLIENT, + this, + ipc_thread().message_loop_proxy().get(), + true, + shutdown_event())); other_channel_->SetRestrictDispatchChannelGroup(group_); if (!is_first()) { event1_->Signal(); @@ -1606,12 +1606,13 @@ class ReentrantReplyServer1 : public Worker { server_ready_(server_ready) { } virtual void Run() OVERRIDE { - server2_channel_ = SyncChannel::CreateClient( - "reentrant_reply2", - this, - ipc_thread().message_loop_proxy().get(), - true, - shutdown_event()); + server2_channel_.reset( + new SyncChannel("reentrant_reply2", + 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 3d4ca88..ca45d16 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_ = IPC::ChannelProxy::CreateServer( - GetChannelName(test_client_name_), - listener, - ipc_task_runner); + channel_proxy_.reset(new IPC::ChannelProxy(GetChannelName(test_client_name_), + IPC::Channel::MODE_SERVER, + listener, + ipc_task_runner)); } void IPCTestBase::DestroyChannelProxy() { diff --git a/ppapi/nacl_irt/manifest_service.cc b/ppapi/nacl_irt/manifest_service.cc index 79da286..0afa217 100644 --- a/ppapi/nacl_irt/manifest_service.cc +++ b/ppapi/nacl_irt/manifest_service.cc @@ -22,9 +22,10 @@ ManifestService::ManifestService( scoped_refptr<base::MessageLoopProxy> io_message_loop, base::WaitableEvent* shutdown_event) { filter_ = new IPC::SyncMessageFilter(shutdown_event); - channel_ = IPC::ChannelProxy::CreateServer(handle, - NULL, // Listener - io_message_loop); + channel_.reset(new IPC::ChannelProxy(handle, + IPC::Channel::MODE_SERVER, + 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 e01114e..9ca76b2 100644 --- a/ppapi/nacl_irt/ppapi_dispatcher.cc +++ b/ppapi/nacl_irt/ppapi_dispatcher.cc @@ -63,13 +63,13 @@ 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_ =IPC::SyncChannel::Create( - this, GetIPCMessageLoop(), GetShutdownEvent()); + channel_.reset(new IPC::SyncChannel( + 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_->InitServer(channel_handle, true); + channel_->Init(channel_handle, IPC::Channel::MODE_SERVER, true); } base::MessageLoopProxy* PpapiDispatcher::GetIPCMessageLoop() { diff --git a/ppapi/proxy/proxy_channel.cc b/ppapi/proxy/proxy_channel.cc index db2a30f..b7f8a82 100644 --- a/ppapi/proxy/proxy_channel.cc +++ b/ppapi/proxy/proxy_channel.cc @@ -31,14 +31,11 @@ bool ProxyChannel::InitWithChannel(Delegate* delegate, bool is_client) { delegate_ = delegate; peer_pid_ = peer_pid; - channel_ = IPC::SyncChannel::Create( - this, - delegate->GetIPCMessageLoop(), - delegate->GetShutdownEvent()); - if (is_client) - channel_->InitClient(channel_handle, true); - else - channel_->InitServer(channel_handle, true); + 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())); return true; } diff --git a/remoting/host/desktop_process.cc b/remoting/host/desktop_process.cc index 53bb336..4592bfd 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_ = IPC::ChannelProxy::CreateClient( - daemon_channel_name_, - this, - io_task_runner.get()); + daemon_channel_.reset(new IPC::ChannelProxy(daemon_channel_name_, + IPC::Channel::MODE_CLIENT, + 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 6b08c9f..d83d803 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_ = IPC::ChannelProxy::CreateClient( - channel_handle, - &network_listener_, - io_task_runner_.get()); + network_channel_.reset(new IPC::ChannelProxy(channel_handle, + IPC::Channel::MODE_CLIENT, + &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_ = IPC::ChannelProxy::CreateServer( - IPC::ChannelHandle(channel_name), - &daemon_listener_, - io_task_runner_.get()); + daemon_channel_.reset(new IPC::ChannelProxy(IPC::ChannelHandle(channel_name), + IPC::Channel::MODE_SERVER, + &daemon_listener_, + 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 f34dd04..73497f9 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_ = IPC::ChannelProxy::CreateClient( - desktop_channel_handle, - this, - io_task_runner_.get()); + desktop_channel_.reset(new IPC::ChannelProxy(desktop_channel_handle, + IPC::Channel::MODE_CLIENT, + 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 32ce885..7e31688 100644 --- a/remoting/host/ipc_desktop_environment_unittest.cc +++ b/remoting/host/ipc_desktop_environment_unittest.cc @@ -367,10 +367,11 @@ void IpcDesktopEnvironmentTest::CreateDesktopProcess() { // Create the daemon end of the daemon-to-desktop channel. desktop_channel_name_ = IPC::Channel::GenerateUniqueRandomChannelID(); - desktop_channel_ = IPC::ChannelProxy::CreateServer( - IPC::ChannelHandle(desktop_channel_name_), - &desktop_listener_, - io_task_runner_.get()); + desktop_channel_.reset( + new IPC::ChannelProxy(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 0b423cd..d7c6a5d 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 = IPC::ChannelProxy::CreateServer( - IPC::ChannelHandle(socket_name, fd), - listener, - io_task_runner.get()); + server_out->reset(new IPC::ChannelProxy(IPC::ChannelHandle(socket_name, fd), + IPC::Channel::MODE_SERVER, + 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 452c7bd..37c3383 100644 --- a/remoting/host/ipc_util_win.cc +++ b/remoting/host/ipc_util_win.cc @@ -51,10 +51,11 @@ bool CreateConnectedIpcChannel( } // Wrap the pipe into an IPC channel. - scoped_ptr<IPC::ChannelProxy> server = IPC::ChannelProxy::CreateServer( + scoped_ptr<IPC::ChannelProxy> server(new IPC::ChannelProxy( 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 5eefaad..22f5da0 100644 --- a/remoting/host/remoting_me2me_host.cc +++ b/remoting/host/remoting_me2me_host.cc @@ -384,19 +384,21 @@ bool HostProcess::InitWithCommandLine(const base::CommandLine* cmd_line) { #endif // defined(OS_POSIX) // Connect to the daemon process. - daemon_channel_ = IPC::ChannelProxy::CreateClient( + daemon_channel_.reset(new IPC::ChannelProxy( 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_= IPC::ChannelProxy::CreateClient( - channel_name, - this, - context_->network_task_runner().get()); + daemon_channel_.reset( + new IPC::ChannelProxy(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 fc3ef60..5503ab9 100644 --- a/remoting/host/win/worker_process_launcher_unittest.cc +++ b/remoting/host/win/worker_process_launcher_unittest.cc @@ -273,10 +273,11 @@ void WorkerProcessLauncherTest::TerminateWorker(DWORD exit_code) { } void WorkerProcessLauncherTest::ConnectClient() { - channel_client_ = IPC::ChannelProxy::CreateClient( + channel_client_.reset(new IPC::ChannelProxy( 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 @@ -360,10 +361,11 @@ void WorkerProcessLauncherTest::DoLaunchProcess() { ASSERT_TRUE(CreateIpcChannel(channel_name_, kIpcSecurityDescriptor, &pipe)); // Wrap the pipe into an IPC channel. - channel_server_ = IPC::ChannelProxy::CreateServer( + channel_server_.reset(new IPC::ChannelProxy( 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 1db6f18..b141cd0 100644 --- a/tools/ipc_fuzzer/replay/replay_process.cc +++ b/tools/ipc_fuzzer/replay/replay_process.cc @@ -55,8 +55,11 @@ void ReplayProcess::OpenChannel() { CommandLine::ForCurrentProcess()->GetSwitchValueASCII( switches::kProcessChannelID); - channel_ = IPC::ChannelProxy::CreateClient( - channel_name, this, io_thread_.message_loop_proxy()); + channel_.reset( + new IPC::ChannelProxy(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 2ade77a..c104a15 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); - scoped_ptr<IPC::ChannelProxy> channel = IPC::ChannelProxy::CreateNamedClient( - win8::kMetroViewerIPCChannelName, - &ui_channel_listener, - io_thread.message_loop_proxy()); - ui_channel_ = channel.get(); + IPC::ChannelProxy ui_channel(win8::kMetroViewerIPCChannelName, + IPC::Channel::MODE_NAMED_CLIENT, + &ui_channel_listener, + io_thread.message_loop_proxy()); + ui_channel_ = &ui_channel; // 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 eaeaedf..70b6b35 100644 --- a/win8/viewer/metro_viewer_process_host.cc +++ b/win8/viewer/metro_viewer_process_host.cc @@ -51,10 +51,11 @@ MetroViewerProcessHost::MetroViewerProcessHost( DCHECK(!instance_); instance_ = this; - channel_ = IPC::ChannelProxy::CreateNamedServer( + channel_.reset(new IPC::ChannelProxy( kMetroViewerIPCChannelName, + IPC::Channel::MODE_NAMED_SERVER, this, - ipc_task_runner); + ipc_task_runner)); } MetroViewerProcessHost::~MetroViewerProcessHost() { |