Commit 8e23c3ab authored by Ken Rockot's avatar Ken Rockot Committed by Commit Bot

ChildProcessLauncher without BrowserThread

This removes ChildProcessLauncher's nominal dependency on BrowserThread
initialization by capturing the client's current SequencedTaskRunner
rather than the current thread's BrowserThread::ID, which may not be
initialized yet.

Bug: 989769
Change-Id: Ia4b9cb0781540f6737be761c201b6440f7713ac6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1731473Reviewed-by: default avatarJohn Abd-El-Malek <jam@chromium.org>
Reviewed-by: default avatarClark DuVall <cduvall@chromium.org>
Commit-Queue: Ken Rockot <rockot@google.com>
Cr-Commit-Position: refs/heads/master@{#683390}
parent eeddf2de
......@@ -49,11 +49,10 @@ ChildProcessLauncher::ChildProcessLauncher(
#endif
{
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
CHECK(BrowserThread::GetCurrentThreadIdentifier(&client_thread_id_));
helper_ = new ChildProcessLauncherHelper(
child_process_id, client_thread_id_, std::move(command_line),
std::move(delegate), weak_factory_.GetWeakPtr(), terminate_on_shutdown,
helper_ = base::MakeRefCounted<ChildProcessLauncherHelper>(
child_process_id, std::move(command_line), std::move(delegate),
weak_factory_.GetWeakPtr(), terminate_on_shutdown,
#if defined(OS_ANDROID)
client_->CanUseWarmUpConnection(),
#endif
......
......@@ -226,7 +226,6 @@ class CONTENT_EXPORT ChildProcessLauncher {
int error_code);
Client* client_;
BrowserThread::ID client_thread_id_;
// The process associated with this ChildProcessLauncher. Set in Notify by
// ChildProcessLauncherHelper once the process was started.
......
......@@ -13,6 +13,7 @@
#include "base/task/post_task.h"
#include "base/task/single_thread_task_runner_thread_mode.h"
#include "base/task/task_traits.h"
#include "base/threading/sequenced_task_runner_handle.h"
#include "content/browser/child_process_launcher.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/child_process_launcher_utils.h"
......@@ -66,7 +67,6 @@ ChildProcessLauncherHelper::Process::Process::operator=(
ChildProcessLauncherHelper::ChildProcessLauncherHelper(
int child_process_id,
BrowserThread::ID client_thread_id,
std::unique_ptr<base::CommandLine> command_line,
std::unique_ptr<SandboxedProcessLauncherDelegate> delegate,
const base::WeakPtr<ChildProcessLauncher>& child_process_launcher,
......@@ -77,7 +77,7 @@ ChildProcessLauncherHelper::ChildProcessLauncherHelper(
mojo::OutgoingInvitation mojo_invitation,
const mojo::ProcessErrorCallback& process_error_callback)
: child_process_id_(child_process_id),
client_thread_id_(client_thread_id),
client_task_runner_(base::SequencedTaskRunnerHandle::Get()),
command_line_(std::move(command_line)),
delegate_(std::move(delegate)),
child_process_launcher_(child_process_launcher),
......@@ -94,7 +94,7 @@ ChildProcessLauncherHelper::ChildProcessLauncherHelper(
ChildProcessLauncherHelper::~ChildProcessLauncherHelper() = default;
void ChildProcessLauncherHelper::StartLaunchOnClientThread() {
DCHECK_CURRENTLY_ON(client_thread_id_);
DCHECK(client_task_runner_->RunsTasksInCurrentSequence());
BeforeLaunchOnClientThread();
......@@ -173,8 +173,8 @@ void ChildProcessLauncherHelper::PostLaunchOnLauncherThread(
}
}
base::PostTaskWithTraits(
FROM_HERE, {client_thread_id_},
client_task_runner_->PostTask(
FROM_HERE,
base::BindOnce(&ChildProcessLauncherHelper::PostLaunchOnClientThread,
this, std::move(process), launch_result));
}
......
......@@ -10,11 +10,12 @@
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
#include "base/optional.h"
#include "base/process/kill.h"
#include "base/process/process.h"
#include "base/sequenced_task_runner.h"
#include "build/build_config.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/common/result_codes.h"
#include "mojo/public/cpp/platform/platform_channel.h"
#include "mojo/public/cpp/system/invitation.h"
......@@ -93,7 +94,6 @@ class ChildProcessLauncherHelper :
ChildProcessLauncherHelper(
int child_process_id,
BrowserThread::ID client_thread_id,
std::unique_ptr<base::CommandLine> command_line,
std::unique_ptr<SandboxedProcessLauncherDelegate> delegate,
const base::WeakPtr<ChildProcessLauncher>& child_process_launcher,
......@@ -161,8 +161,6 @@ class ChildProcessLauncherHelper :
void PostLaunchOnClientThread(ChildProcessLauncherHelper::Process process,
int error_code);
int client_thread_id() const { return client_thread_id_; }
// See ChildProcessLauncher::GetChildTerminationInfo for more info.
ChildProcessTerminationInfo GetTerminationInfo(
const ChildProcessLauncherHelper::Process& process,
......@@ -221,7 +219,7 @@ class ChildProcessLauncherHelper :
#endif
const int child_process_id_;
const BrowserThread::ID client_thread_id_;
const scoped_refptr<base::SequencedTaskRunner> client_task_runner_;
base::TimeTicks begin_launch_time_;
std::unique_ptr<base::CommandLine> command_line_;
std::unique_ptr<SandboxedProcessLauncherDelegate> delegate_;
......
......@@ -140,8 +140,8 @@ ChildProcessLauncherHelper::LaunchProcessOnLauncherThread(
env, reinterpret_cast<intptr_t>(this), j_argv, j_file_infos,
can_use_warm_up_connection));
AddRef(); // Balanced by OnChildProcessStarted.
base::PostTaskWithTraits(
FROM_HERE, {client_thread_id_},
client_task_runner_->PostTask(
FROM_HERE,
base::BindOnce(
&ChildProcessLauncherHelper::set_java_peer_available_on_client_thread,
this));
......
......@@ -48,7 +48,7 @@ void ChildProcessLauncherHelper::ResetRegisteredFilesForTesting() {
}
void ChildProcessLauncherHelper::BeforeLaunchOnClientThread() {
DCHECK_CURRENTLY_ON(client_thread_id_);
DCHECK(client_task_runner_->RunsTasksInCurrentSequence());
sandbox_policy_.Initialize(delegate_->GetSandboxType());
}
......
......@@ -26,12 +26,12 @@ namespace internal {
base::Optional<mojo::NamedPlatformChannel>
ChildProcessLauncherHelper::CreateNamedPlatformChannelOnClientThread() {
DCHECK_CURRENTLY_ON(client_thread_id_);
DCHECK(client_task_runner_->RunsTasksInCurrentSequence());
return base::nullopt;
}
void ChildProcessLauncherHelper::BeforeLaunchOnClientThread() {
DCHECK_CURRENTLY_ON(client_thread_id_);
DCHECK(client_task_runner_->RunsTasksInCurrentSequence());
}
std::unique_ptr<FileMappedForLaunch>
......
......@@ -33,12 +33,12 @@ namespace internal {
base::Optional<mojo::NamedPlatformChannel>
ChildProcessLauncherHelper::CreateNamedPlatformChannelOnClientThread() {
DCHECK_CURRENTLY_ON(client_thread_id_);
DCHECK(client_task_runner_->RunsTasksInCurrentSequence());
return base::nullopt;
}
void ChildProcessLauncherHelper::BeforeLaunchOnClientThread() {
DCHECK_CURRENTLY_ON(client_thread_id_);
DCHECK(client_task_runner_->RunsTasksInCurrentSequence());
}
std::unique_ptr<PosixFileDescriptorInfo>
......
......@@ -24,12 +24,12 @@ namespace content {
namespace internal {
void ChildProcessLauncherHelper::BeforeLaunchOnClientThread() {
DCHECK_CURRENTLY_ON(client_thread_id_);
DCHECK(client_task_runner_->RunsTasksInCurrentSequence());
}
base::Optional<mojo::NamedPlatformChannel>
ChildProcessLauncherHelper::CreateNamedPlatformChannelOnClientThread() {
DCHECK_CURRENTLY_ON(client_thread_id_);
DCHECK(client_task_runner_->RunsTasksInCurrentSequence());
if (!delegate_->ShouldLaunchElevated())
return base::nullopt;
......
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