Skip to content

Commit

Permalink
Introduce IPC::ChannelProxy::Create*() and IPC::SynChannel::Create*()
Browse files Browse the repository at this point in the history
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
  • Loading branch information
morrita@chromium.org committed Jun 2, 2014
1 parent 7d1c92a commit cf178fb
Show file tree
Hide file tree
Showing 37 changed files with 359 additions and 208 deletions.
5 changes: 2 additions & 3 deletions apps/app_shim/app_shim_host_mac.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions apps/app_shim/app_shim_host_manager_browsertest_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
Expand Down
7 changes: 2 additions & 5 deletions apps/app_shim/chrome_main_app_mode_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,11 +266,10 @@ 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::CreateClient(
startup_channel_name,
&listener,
service_process.IOMessageLoopProxy());

main_message_loop.Run();
if (!Mock::VerifyAndClearExpectations(&server))
Expand Down Expand Up @@ -442,9 +441,8 @@ 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::CreateServer(
startup_channel_id_, this, IOMessageLoopProxy());

#if defined(OS_POSIX)
base::FileHandleMappingVector ipc_file_list;
Expand All @@ -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) {
Expand Down
7 changes: 3 additions & 4 deletions chrome/browser/service_process/service_process_control.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<IPC::ChannelProxy> channel) {
channel_ = channel.Pass();
}

void ServiceProcessControl::RunConnectDoneTasks() {
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/service_process/service_process_control.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
5 changes: 2 additions & 3 deletions chrome/service/service_ipc_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
9 changes: 4 additions & 5 deletions components/nacl/browser/nacl_process_host.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
6 changes: 3 additions & 3 deletions components/nacl/loader/nacl_listener.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
5 changes: 2 additions & 3 deletions components/nacl/loader/nacl_trusted_listener.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
4 changes: 2 additions & 2 deletions components/nacl/renderer/manifest_service_channel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions components/nacl/renderer/trusted_plugin_channel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ 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,
channel_(IPC::SyncChannel::CreateClient(
handle, this,
content::RenderThread::Get()->GetIOMessageLoopProxy(), true,
waitable_event)) {
}
Expand Down
11 changes: 5 additions & 6 deletions content/browser/renderer_host/render_process_host_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
13 changes: 6 additions & 7 deletions content/child/child_thread.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions content/child/npapi/np_channel_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 2 additions & 6 deletions content/common/gpu/client/gpu_channel_host.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<base::MessageLoopProxy> 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);

Expand Down
5 changes: 2 additions & 3 deletions content/common/gpu/gpu_channel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
90 changes: 80 additions & 10 deletions ipc/ipc_channel_proxy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -304,29 +304,79 @@ 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(
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(Context* context)
: 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)
Expand Down Expand Up @@ -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());

Expand Down
Loading

0 comments on commit cf178fb

Please sign in to comment.