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/+/1731473
Reviewed-by: John Abd-El-Malek <jam@chromium.org>
Reviewed-by: Clark DuVall <cduvall@chromium.org>
Commit-Queue: Ken Rockot <rockot@google.com>
Cr-Commit-Position: refs/heads/master@{#683390}
diff --git a/content/browser/child_process_launcher.cc b/content/browser/child_process_launcher.cc
index 98ef88a..0dc44d6 100644
--- a/content/browser/child_process_launcher.cc
+++ b/content/browser/child_process_launcher.cc
@@ -49,11 +49,10 @@
#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
diff --git a/content/browser/child_process_launcher.h b/content/browser/child_process_launcher.h
index 79daec1..0e5f225 100644
--- a/content/browser/child_process_launcher.h
+++ b/content/browser/child_process_launcher.h
@@ -226,7 +226,6 @@
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.
diff --git a/content/browser/child_process_launcher_helper.cc b/content/browser/child_process_launcher_helper.cc
index 6ace0f9..ae11046 100644
--- a/content/browser/child_process_launcher_helper.cc
+++ b/content/browser/child_process_launcher_helper.cc
@@ -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::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 @@
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() = default;
void ChildProcessLauncherHelper::StartLaunchOnClientThread() {
- DCHECK_CURRENTLY_ON(client_thread_id_);
+ DCHECK(client_task_runner_->RunsTasksInCurrentSequence());
BeforeLaunchOnClientThread();
@@ -173,8 +173,8 @@
}
}
- base::PostTaskWithTraits(
- FROM_HERE, {client_thread_id_},
+ client_task_runner_->PostTask(
+ FROM_HERE,
base::BindOnce(&ChildProcessLauncherHelper::PostLaunchOnClientThread,
this, std::move(process), launch_result));
}
diff --git a/content/browser/child_process_launcher_helper.h b/content/browser/child_process_launcher_helper.h
index 3694dcd..9a7ca16 100644
--- a/content/browser/child_process_launcher_helper.h
+++ b/content/browser/child_process_launcher_helper.h
@@ -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 @@
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 @@
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 @@
#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_;
diff --git a/content/browser/child_process_launcher_helper_android.cc b/content/browser/child_process_launcher_helper_android.cc
index 81ff192..5557569 100644
--- a/content/browser/child_process_launcher_helper_android.cc
+++ b/content/browser/child_process_launcher_helper_android.cc
@@ -140,8 +140,8 @@
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));
diff --git a/content/browser/child_process_launcher_helper_fuchsia.cc b/content/browser/child_process_launcher_helper_fuchsia.cc
index 0d3f7adf..ea9bef7 100644
--- a/content/browser/child_process_launcher_helper_fuchsia.cc
+++ b/content/browser/child_process_launcher_helper_fuchsia.cc
@@ -48,7 +48,7 @@
}
void ChildProcessLauncherHelper::BeforeLaunchOnClientThread() {
- DCHECK_CURRENTLY_ON(client_thread_id_);
+ DCHECK(client_task_runner_->RunsTasksInCurrentSequence());
sandbox_policy_.Initialize(delegate_->GetSandboxType());
}
diff --git a/content/browser/child_process_launcher_helper_linux.cc b/content/browser/child_process_launcher_helper_linux.cc
index 5b82388..720b92a 100644
--- a/content/browser/child_process_launcher_helper_linux.cc
+++ b/content/browser/child_process_launcher_helper_linux.cc
@@ -26,12 +26,12 @@
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>
diff --git a/content/browser/child_process_launcher_helper_mac.cc b/content/browser/child_process_launcher_helper_mac.cc
index 4698c0f..7e3572ac 100644
--- a/content/browser/child_process_launcher_helper_mac.cc
+++ b/content/browser/child_process_launcher_helper_mac.cc
@@ -33,12 +33,12 @@
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>
diff --git a/content/browser/child_process_launcher_helper_win.cc b/content/browser/child_process_launcher_helper_win.cc
index 8e6b272d..c27d205 100644
--- a/content/browser/child_process_launcher_helper_win.cc
+++ b/content/browser/child_process_launcher_helper_win.cc
@@ -24,12 +24,12 @@
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;