Commit ab52b0cd authored by amistry's avatar amistry Committed by Commit bot

Use ChannelMojo for the utility process.

BUG=604282,597124

Review-Url: https://codereview.chromium.org/1959313002
Cr-Commit-Position: refs/heads/master@{#398221}
parent 5dd617d1
......@@ -256,8 +256,9 @@ bool UtilityProcessHostImpl::StartProcess() {
child_token_));
process_->SetName(name_);
std::string channel_id = process_->GetHost()->CreateChannel();
if (channel_id.empty()) {
std::string mojo_channel_token =
process_->GetHost()->CreateChannelMojo(child_token_);
if (mojo_channel_token.empty()) {
NotifyAndDelete(LAUNCH_RESULT_FAILURE);
return false;
}
......@@ -268,9 +269,9 @@ bool UtilityProcessHostImpl::StartProcess() {
// support single process mode this way.
in_process_thread_.reset(
g_utility_main_thread_factory(InProcessChildThreadParams(
channel_id, BrowserThread::UnsafeGetMessageLoopForThread(
std::string(), BrowserThread::UnsafeGetMessageLoopForThread(
BrowserThread::IO)->task_runner(),
std::string(), mojo_application_host_->GetToken())));
mojo_channel_token, mojo_application_host_->GetToken())));
in_process_thread_->Start();
} else {
const base::CommandLine& browser_command_line =
......@@ -307,7 +308,8 @@ bool UtilityProcessHostImpl::StartProcess() {
cmd_line->AppendSwitchASCII(switches::kProcessType,
switches::kUtilityProcess);
cmd_line->AppendSwitchASCII(switches::kProcessChannelID, channel_id);
cmd_line->AppendSwitchASCII(switches::kMojoChannelToken,
mojo_channel_token);
std::string locale = GetContentClient()->browser()->GetApplicationLocale();
cmd_line->AppendSwitchASCII(switches::kLang, locale);
......
......@@ -262,7 +262,8 @@ ChildThread* ChildThread::Get() {
ChildThreadImpl::Options::Options()
: channel_name(base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
switches::kProcessChannelID)),
use_mojo_channel(false) {
use_mojo_channel(base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kMojoChannelToken)) {
}
ChildThreadImpl::Options::Options(const Options& other) = default;
......
......@@ -31,6 +31,8 @@
#include "ipc/ipc_channel.h"
#include "ipc/ipc_logging.h"
#include "ipc/message_filter.h"
#include "ipc/mojo/ipc_channel_mojo.h"
#include "mojo/edk/embedder/embedder.h"
#if defined(OS_LINUX)
#include "base/linux_util.h"
......@@ -130,9 +132,31 @@ void ChildProcessHostImpl::ForceShutdown() {
Send(new ChildProcessMsg_Shutdown());
}
std::string ChildProcessHostImpl::CreateChannelMojo(
const std::string& child_token) {
DCHECK(channel_id_.empty());
channel_id_ = mojo::edk::GenerateRandomToken();
mojo::ScopedMessagePipeHandle host_handle =
mojo::edk::CreateParentMessagePipe(channel_id_, child_token);
channel_ = IPC::ChannelMojo::Create(std::move(host_handle),
IPC::Channel::MODE_SERVER, this);
if (!channel_ || !InitChannel())
return std::string();
return channel_id_;
}
std::string ChildProcessHostImpl::CreateChannel() {
DCHECK(channel_id_.empty());
channel_id_ = IPC::Channel::GenerateVerifiedChannelID(std::string());
channel_ = IPC::Channel::CreateServer(channel_id_, this);
if (!channel_ || !InitChannel())
return std::string();
return channel_id_;
}
bool ChildProcessHostImpl::InitChannel() {
#if USE_ATTACHMENT_BROKER
IPC::AttachmentBroker::GetGlobal()->RegisterCommunicationChannel(
channel_.get(), base::MessageLoopForIO::current()->task_runner());
......@@ -142,7 +166,7 @@ std::string ChildProcessHostImpl::CreateChannel() {
IPC::AttachmentBroker::GetGlobal()->DeregisterCommunicationChannel(
channel_.get());
#endif
return std::string();
return false;
}
for (size_t i = 0; i < filters_.size(); ++i)
......@@ -156,7 +180,7 @@ std::string ChildProcessHostImpl::CreateChannel() {
opening_channel_ = true;
return channel_id_;
return true;
}
bool ChildProcessHostImpl::IsChannelOpening() {
......
......@@ -79,6 +79,7 @@ class CONTENT_EXPORT ChildProcessHostImpl : public ChildProcessHost,
bool Send(IPC::Message* message) override;
void ForceShutdown() override;
std::string CreateChannel() override;
std::string CreateChannelMojo(const std::string& child_token) override;
bool IsChannelOpening() override;
void AddFilter(IPC::MessageFilter* filter) override;
#if defined(OS_POSIX)
......@@ -109,6 +110,10 @@ class CONTENT_EXPORT ChildProcessHostImpl : public ChildProcessHost,
void OnDeletedGpuMemoryBuffer(gfx::GpuMemoryBufferId id,
const gpu::SyncToken& sync_token);
// Initializes the IPC channel and returns true on success. |channel_| must be
// non-null.
bool InitChannel();
ChildProcessHostDelegate* delegate_;
base::Process peer_process_;
bool opening_channel_; // True while we're waiting the channel to be opened.
......
......@@ -81,6 +81,10 @@ class CONTENT_EXPORT ChildProcessHost : public IPC::Sender {
// empty string otherwise
virtual std::string CreateChannel() = 0;
// Creates the IPC channel on top of Mojo. Returns the Mojo channel token if
// succeeded, or an empty string on failure.
virtual std::string CreateChannelMojo(const std::string& child_token) = 0;
// Returns true iff the IPC channel is currently being opened;
virtual bool IsChannelOpening() = 0;
......
......@@ -46,6 +46,7 @@ UtilityThreadImpl::UtilityThreadImpl()
UtilityThreadImpl::UtilityThreadImpl(const InProcessChildThreadParams& params)
: ChildThreadImpl(ChildThreadImpl::Options::Builder()
.InBrowserProcess(params)
.UseMojoChannel(true)
.Build()) {
Init();
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment