Commit 89d93df2 authored by Xi Han's avatar Xi Han Committed by Commit Bot

Move the TaskRunner for process launching to ChildProcessLauncherHelper.

ServiceManager may need to launch child processes before a BrowserMainLoop
has been created, and therefore before any BrowserThreads exists. We
therefore replace the BrowserThread::PROCESS_LAUNCHER with a global
TaskScheduler sequence, created on-demand when the ServiceManager or
ChildProcessLauncherHelper first need it.

Under Windows we must use a single-thread TaskRunner, while on other
platforms we are able to use a normal TaskScheduler sequence. File
crbug.com/820200 to track that.

Bug: 815225
Change-Id: Ia0f46461fb9cc92fddacf81ee96b764de8477d11
Reviewed-on: https://chromium-review.googlesource.com/941264
Commit-Queue: Xi Han <hanxi@chromium.org>
Reviewed-by: default avatarKen Rockot <rockot@chromium.org>
Reviewed-by: default avatarJohn Abd-El-Malek <jam@chromium.org>
Reviewed-by: default avatarWez <wez@chromium.org>
Cr-Commit-Position: refs/heads/master@{#542212}
parent d2aa77c3
......@@ -17,6 +17,7 @@
#include "base/task_scheduler/post_task.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/child_process_data.h"
#include "content/public/browser/child_process_launcher_utils.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/notification_types.h"
#include "content/public/browser/render_process_host.h"
......@@ -106,7 +107,7 @@ AwBrowserTerminator::~AwBrowserTerminator() {}
void AwBrowserTerminator::OnChildStart(
int process_host_id,
content::PosixFileDescriptorInfo* mappings) {
DCHECK_CURRENTLY_ON(content::BrowserThread::PROCESS_LAUNCHER);
DCHECK(content::CurrentlyOnProcessLauncherTaskRunner());
base::AutoLock auto_lock(process_host_id_to_pipe_lock_);
DCHECK(!ContainsKey(process_host_id_to_pipe_, process_host_id));
......
......@@ -50,12 +50,6 @@ NOINLINE void ThreadUnresponsive_UI() {
ReportThreadHang();
}
NOINLINE void ThreadUnresponsive_PROCESS_LAUNCHER() {
volatile int inhibit_comdat = __LINE__;
ALLOW_UNUSED_LOCAL(inhibit_comdat);
ReportThreadHang();
}
NOINLINE void ThreadUnresponsive_IO() {
volatile int inhibit_comdat = __LINE__;
ALLOW_UNUSED_LOCAL(inhibit_comdat);
......@@ -67,8 +61,6 @@ NOINLINE void CrashBecauseThreadWasUnresponsive(
switch (thread_id) {
case content::BrowserThread::UI:
return ThreadUnresponsive_UI();
case content::BrowserThread::PROCESS_LAUNCHER:
return ThreadUnresponsive_PROCESS_LAUNCHER();
case content::BrowserThread::IO:
return ThreadUnresponsive_IO();
case content::BrowserThread::ID_COUNT:
......
......@@ -22,6 +22,7 @@
#include "chrome/common/url_constants.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "content/public/browser/child_process_launcher_utils.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h"
......@@ -130,9 +131,8 @@ class ChromeRenderProcessHostTest : public ExtensionBrowserTest {
// Ensures that the backgrounding / foregrounding gets a chance to run.
void WaitForLauncherThread() {
base::RunLoop run_loop;
content::BrowserThread::PostTaskAndReply(
content::BrowserThread::PROCESS_LAUNCHER, FROM_HERE, base::DoNothing(),
run_loop.QuitWhenIdleClosure());
content::GetProcessLauncherTaskRunner()->PostTaskAndReply(
FROM_HERE, base::DoNothing(), run_loop.QuitWhenIdleClosure());
run_loop.Run();
}
......
......@@ -28,6 +28,7 @@
#include "chrome/browser/upgrade_detector.h"
#include "chrome/common/service_process_util.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/child_process_launcher_utils.h"
#include "mojo/edk/embedder/embedder.h"
#include "mojo/edk/embedder/named_platform_handle.h"
#include "mojo/edk/embedder/named_platform_handle_utils.h"
......@@ -338,8 +339,8 @@ ServiceProcessControl::Launcher::Launcher(
void ServiceProcessControl::Launcher::Run(const base::Closure& task) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
notify_task_ = task;
BrowserThread::PostTask(BrowserThread::PROCESS_LAUNCHER, FROM_HERE,
base::Bind(&Launcher::DoRun, this));
content::GetProcessLauncherTaskRunner()->PostTask(
FROM_HERE, base::BindOnce(&Launcher::DoRun, this));
}
ServiceProcessControl::Launcher::~Launcher() {
......
......@@ -374,21 +374,6 @@ void OnStoppedStartupTracing(const base::FilePath& trace_file) {
MSVC_DISABLE_OPTIMIZE()
MSVC_PUSH_DISABLE_WARNING(4748)
#if defined(OS_ANDROID)
NOINLINE void ResetThread_PROCESS_LAUNCHER(
std::unique_ptr<BrowserProcessSubThread> thread) {
volatile int inhibit_comdat = __LINE__;
ALLOW_UNUSED_LOCAL(inhibit_comdat);
thread.reset();
}
#else // defined(OS_ANDROID)
NOINLINE void ResetThread_PROCESS_LAUNCHER() {
volatile int inhibit_comdat = __LINE__;
ALLOW_UNUSED_LOCAL(inhibit_comdat);
BrowserThreadImpl::StopRedirectionOfThreadID(BrowserThread::PROCESS_LAUNCHER);
}
#endif // defined(OS_ANDROID)
NOINLINE void ResetThread_IO(std::unique_ptr<BrowserProcessSubThread> thread) {
volatile int inhibit_comdat = __LINE__;
ALLOW_UNUSED_LOCAL(inhibit_comdat);
......@@ -1022,37 +1007,6 @@ int BrowserMainLoop::CreateThreads() {
*task_scheduler_init_params.get());
}
TRACE_EVENT_BEGIN1("startup", "BrowserMainLoop::CreateThreads:start",
"Thread", "BrowserThread::PROCESS_LAUNCHER");
#if defined(OS_ANDROID)
// Android specializes Launcher thread so it is accessible in java.
// Note Android never does clean shutdown, so shutdown use-after-free
// concerns are not a problem in practice.
base::MessageLoop* message_loop = android::LauncherThread::GetMessageLoop();
DCHECK(message_loop);
// This BrowserThread will use this message loop instead of creating a new
// thread. Note that means this/ thread will not be joined on shutdown, and
// may cause use-after-free if anything tries to access objects deleted by
// AtExitManager, such as non-leaky LazyInstance.
process_launcher_thread_.reset(new BrowserProcessSubThread(
BrowserThread::PROCESS_LAUNCHER, message_loop));
#else // defined(OS_ANDROID)
// This thread ID will be backed by a SingleThreadTaskRunner using
// |task_traits|.
// TODO(gab): WithBaseSyncPrimitives() is likely not required here.
base::TaskTraits task_traits = {base::MayBlock(),
base::WithBaseSyncPrimitives(),
base::TaskPriority::USER_BLOCKING,
base::TaskShutdownBehavior::BLOCK_SHUTDOWN};
scoped_refptr<base::SingleThreadTaskRunner> redirection_task_runner =
base::CreateSingleThreadTaskRunnerWithTraits(
task_traits, base::SingleThreadTaskRunnerThreadMode::DEDICATED);
DCHECK(redirection_task_runner);
BrowserThreadImpl::RedirectThreadIDToTaskRunner(
BrowserThread::PROCESS_LAUNCHER, std::move(redirection_task_runner));
#endif // defined(OS_ANDROID)
// |io_thread_| is created by |PostMainMessageLoopStart()|, but its
// full initialization is deferred until this point because it requires
// several dependencies we don't want to depend on so early in startup.
......@@ -1205,39 +1159,9 @@ void BrowserMainLoop::ShutdownThreadsAndCleanUp() {
{
base::ThreadRestrictions::ScopedAllowWait allow_wait_for_join;
// Must be size_t so we can subtract from it.
for (size_t thread_id = BrowserThread::ID_COUNT - 1;
thread_id >= (BrowserThread::UI + 1); --thread_id) {
// Find the thread object we want to stop. Looping over all valid
// BrowserThread IDs and DCHECKing on a missing case in the switch
// statement helps avoid a mismatch between this code and the
// BrowserThread::ID enumeration.
//
// The destruction order is the reverse order of occurrence in the
// BrowserThread::ID list. The rationale for the order is that he
// PROCESS_LAUNCHER thread must be stopped after IO in case the IO thread
// posted a task to terminate a process on the process launcher thread.
switch (thread_id) {
case BrowserThread::PROCESS_LAUNCHER: {
TRACE_EVENT0("shutdown", "BrowserMainLoop::Subsystem:LauncherThread");
#if defined(OS_ANDROID)
ResetThread_PROCESS_LAUNCHER(std::move(process_launcher_thread_));
#else // defined(OS_ANDROID)
ResetThread_PROCESS_LAUNCHER();
#endif // defined(OS_ANDROID)
break;
}
case BrowserThread::IO: {
TRACE_EVENT0("shutdown", "BrowserMainLoop::Subsystem:IOThread");
ResetThread_IO(std::move(io_thread_));
break;
}
case BrowserThread::UI:
case BrowserThread::ID_COUNT:
NOTREACHED();
break;
}
{
TRACE_EVENT0("shutdown", "BrowserMainLoop::Subsystem:IOThread");
ResetThread_IO(std::move(io_thread_));
}
{
......
......@@ -339,11 +339,7 @@ class CONTENT_EXPORT BrowserMainLoop {
// Only the IO thread is a real thread by default, other BrowserThreads are
// redirected to TaskScheduler under the hood.
std::unique_ptr<BrowserProcessSubThread> io_thread_;
#if defined(OS_ANDROID)
// On Android, the PROCESS_LAUNCHER thread is handled by Java,
// |process_launcher_thread_| is merely a proxy to the real message loop.
std::unique_ptr<BrowserProcessSubThread> process_launcher_thread_;
#elif defined(OS_WIN)
#if defined(OS_WIN)
// TaskScheduler doesn't support async I/O on Windows as CACHE thread is
// the only user and this use case is going away in
// https://codereview.chromium.org/2216583003/.
......
......@@ -32,7 +32,6 @@ namespace {
// Friendly names for the well-known threads.
static const char* const g_browser_thread_names[BrowserThread::ID_COUNT] = {
"", // UI (name assembled in browser_main.cc).
"Chrome_ProcessLauncherThread", // PROCESS_LAUNCHER
"Chrome_IOThread", // IO
};
......@@ -202,12 +201,6 @@ void BrowserThreadImpl::Init() {
DCHECK(globals.task_runners[identifier_]->RunsTasksInCurrentSequence());
}
#endif // DCHECK_IS_ON()
if (identifier_ == BrowserThread::PROCESS_LAUNCHER) {
// Nesting and task observers are not allowed on redirected threads.
base::RunLoop::DisallowNestingOnCurrentThread();
message_loop()->DisallowTaskObservers();
}
}
// We disable optimizations for this block of functions so the compiler doesn't
......@@ -221,13 +214,6 @@ NOINLINE void BrowserThreadImpl::UIThreadRun(base::RunLoop* run_loop) {
CHECK_GT(line_number, 0);
}
NOINLINE void BrowserThreadImpl::ProcessLauncherThreadRun(
base::RunLoop* run_loop) {
volatile int line_number = __LINE__;
Thread::Run(run_loop);
CHECK_GT(line_number, 0);
}
NOINLINE void BrowserThreadImpl::IOThreadRun(base::RunLoop* run_loop) {
volatile int line_number = __LINE__;
Thread::Run(run_loop);
......@@ -254,8 +240,6 @@ void BrowserThreadImpl::Run(base::RunLoop* run_loop) {
switch (identifier_) {
case BrowserThread::UI:
return UIThreadRun(run_loop);
case BrowserThread::PROCESS_LAUNCHER:
return ProcessLauncherThreadRun(run_loop);
case BrowserThread::IO:
return IOThreadRun(run_loop);
case BrowserThread::ID_COUNT:
......
......@@ -11,6 +11,7 @@
#include "base/logging.h"
#include "base/process/launch.h"
#include "build/build_config.h"
#include "content/public/browser/child_process_launcher_utils.h"
#include "content/public/common/result_codes.h"
#include "content/public/common/sandboxed_process_launcher_delegate.h"
......@@ -62,8 +63,8 @@ void ChildProcessLauncher::SetProcessPriority(
const ChildProcessLauncherPriority& priority) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
base::Process to_pass = process_.process.Duplicate();
BrowserThread::PostTask(
BrowserThread::PROCESS_LAUNCHER, FROM_HERE,
GetProcessLauncherTaskRunner()->PostTask(
FROM_HERE,
base::BindOnce(
&ChildProcessLauncherHelper::SetProcessPriorityOnLauncherThread,
helper_, std::move(to_pass), priority));
......
......@@ -6,18 +6,28 @@
#include "base/command_line.h"
#include "base/metrics/histogram_macros.h"
#include "base/no_destructor.h"
#include "base/single_thread_task_runner.h"
#include "base/task_scheduler/post_task.h"
#include "base/task_scheduler/single_thread_task_runner_thread_mode.h"
#include "base/task_scheduler/task_traits.h"
#include "content/browser/child_process_launcher.h"
#include "content/public/browser/child_process_launcher_utils.h"
#include "content/public/common/content_switches.h"
#include "content/public/common/sandboxed_process_launcher_delegate.h"
#include "mojo/edk/embedder/platform_channel_pair.h"
#if defined(OS_ANDROID)
#include "content/browser/android/launcher_thread.h"
#endif
namespace content {
namespace internal {
namespace {
void RecordHistogramsOnLauncherThread(base::TimeDelta launch_time) {
DCHECK_CURRENTLY_ON(BrowserThread::PROCESS_LAUNCHER);
DCHECK(CurrentlyOnProcessLauncherTaskRunner());
// Log the launch time, separating out the first one (which will likely be
// slower due to the rest of the browser initializing at the same time).
static bool done_first_launch = false;
......@@ -85,14 +95,14 @@ void ChildProcessLauncherHelper::StartLaunchOnClientThread() {
mojo_client_handle_ = channel_pair.PassClientHandle();
}
BrowserThread::PostTask(
BrowserThread::PROCESS_LAUNCHER, FROM_HERE,
GetProcessLauncherTaskRunner()->PostTask(
FROM_HERE,
base::BindOnce(&ChildProcessLauncherHelper::LaunchOnLauncherThread,
this));
}
void ChildProcessLauncherHelper::LaunchOnLauncherThread() {
DCHECK_CURRENTLY_ON(BrowserThread::PROCESS_LAUNCHER);
DCHECK(CurrentlyOnProcessLauncherTaskRunner());
begin_launch_time_ = base::TimeTicks::Now();
......@@ -167,18 +177,52 @@ std::string ChildProcessLauncherHelper::GetProcessType() {
// static
void ChildProcessLauncherHelper::ForceNormalProcessTerminationAsync(
ChildProcessLauncherHelper::Process process) {
if (BrowserThread::CurrentlyOn(BrowserThread::PROCESS_LAUNCHER)) {
if (CurrentlyOnProcessLauncherTaskRunner()) {
ForceNormalProcessTerminationSync(std::move(process));
return;
}
// On Posix, EnsureProcessTerminated can lead to 2 seconds of sleep!
// So don't do this on the UI/IO threads.
BrowserThread::PostTask(
BrowserThread::PROCESS_LAUNCHER, FROM_HERE,
GetProcessLauncherTaskRunner()->PostTask(
FROM_HERE,
base::BindOnce(
&ChildProcessLauncherHelper::ForceNormalProcessTerminationSync,
std::move(process)));
}
} // namespace internal
// static
base::SingleThreadTaskRunner* GetProcessLauncherTaskRunner() {
#if defined(OS_ANDROID)
// Android specializes Launcher thread so it is accessible in java.
// Note Android never does clean shutdown, so shutdown use-after-free
// concerns are not a problem in practice.
// This process launcher thread will use the Java-side process-launching
// thread, instead of creating its own separate thread on C++ side. Note
// that means this thread will not be joined on shutdown, and may cause
// use-after-free if anything tries to access objects deleted by
// AtExitManager, such as non-leaky LazyInstance.
static base::NoDestructor<scoped_refptr<base::SingleThreadTaskRunner>>
launcher_task_runner(
android::LauncherThread::GetMessageLoop()->task_runner());
#else // defined(OS_ANDROID)
constexpr base::TaskTraits task_traits = {
base::MayBlock(), base::WithBaseSyncPrimitives(),
base::TaskPriority::USER_BLOCKING,
base::TaskShutdownBehavior::BLOCK_SHUTDOWN};
// TODO(wez): Investigates whether we could use SequencedTaskRunner on
// platforms other than Windows. http://crbug.com/820200.
static base::NoDestructor<scoped_refptr<base::SingleThreadTaskRunner>>
launcher_task_runner(base::CreateSingleThreadTaskRunnerWithTraits(
task_traits, base::SingleThreadTaskRunnerThreadMode::DEDICATED));
#endif // defined(OS_ANDROID)
return (*launcher_task_runner).get();
}
// static
bool CurrentlyOnProcessLauncherTaskRunner() {
return GetProcessLauncherTaskRunner()->RunsTasksInCurrentSequence();
}
} // namespace content
......@@ -15,6 +15,7 @@
#include "content/browser/posix_file_descriptor_info_impl.h"
#include "content/browser/web_contents/web_contents_impl.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/child_process_launcher_utils.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/common/content_descriptors.h"
#include "content/public/common/content_switches.h"
......@@ -32,7 +33,7 @@ namespace {
// Stops a child process based on the handle returned from StartChildProcess.
void StopChildProcess(base::ProcessHandle handle) {
DCHECK_CURRENTLY_ON(BrowserThread::PROCESS_LAUNCHER);
DCHECK(CurrentlyOnProcessLauncherTaskRunner());
JNIEnv* env = AttachCurrentThread();
DCHECK(env);
Java_ChildProcessLauncherHelper_stop(env, static_cast<jint>(handle));
......@@ -64,7 +65,7 @@ ChildProcessLauncherHelper::PrepareMojoPipeHandlesOnClientThread() {
std::unique_ptr<PosixFileDescriptorInfo>
ChildProcessLauncherHelper::GetFilesToMap() {
DCHECK_CURRENTLY_ON(BrowserThread::PROCESS_LAUNCHER);
DCHECK(CurrentlyOnProcessLauncherTaskRunner());
// Android WebView runs in single process, ensure that we never get here when
// running in single process mode.
......@@ -162,15 +163,15 @@ base::TerminationStatus ChildProcessLauncherHelper::GetTerminationStatus(
// static
bool ChildProcessLauncherHelper::TerminateProcess(const base::Process& process,
int exit_code) {
BrowserThread::PostTask(BrowserThread::PROCESS_LAUNCHER, FROM_HERE,
base::Bind(&StopChildProcess, process.Handle()));
GetProcessLauncherTaskRunner()->PostTask(
FROM_HERE, base::BindOnce(&StopChildProcess, process.Handle()));
return true;
}
// static
void ChildProcessLauncherHelper::ForceNormalProcessTerminationSync(
ChildProcessLauncherHelper::Process process) {
DCHECK_CURRENTLY_ON(BrowserThread::PROCESS_LAUNCHER);
DCHECK(CurrentlyOnProcessLauncherTaskRunner());
VLOG(1) << "ChromeProcess: Stopping process with handle "
<< process.process.Handle();
StopChildProcess(process.process.Handle());
......@@ -211,7 +212,7 @@ void ChildProcessLauncherHelper::OnChildProcessStarted(
JNIEnv*,
const base::android::JavaParamRef<jobject>& obj,
jint handle) {
DCHECK_CURRENTLY_ON(BrowserThread::PROCESS_LAUNCHER);
DCHECK(CurrentlyOnProcessLauncherTaskRunner());
scoped_refptr<ChildProcessLauncherHelper> ref(this);
Release(); // Balances with LaunchProcessOnLauncherThread.
......
......@@ -8,6 +8,7 @@
#include "base/process/launch.h"
#include "content/browser/child_process_launcher.h"
#include "content/common/sandbox_policy_fuchsia.h"
#include "content/public/browser/child_process_launcher_utils.h"
#include "content/public/common/sandboxed_process_launcher_delegate.h"
#include "mojo/edk/embedder/platform_channel_pair.h"
......@@ -17,7 +18,7 @@ namespace internal {
void ChildProcessLauncherHelper::SetProcessPriorityOnLauncherThread(
base::Process process,
const ChildProcessLauncherPriority& priority) {
DCHECK_CURRENTLY_ON(BrowserThread::PROCESS_LAUNCHER);
DCHECK(CurrentlyOnProcessLauncherTaskRunner());
// TODO(fuchsia): Implement this. (crbug.com/707031)
NOTIMPLEMENTED();
}
......@@ -64,14 +65,14 @@ ChildProcessLauncherHelper::PrepareMojoPipeHandlesOnClientThread() {
std::unique_ptr<FileMappedForLaunch>
ChildProcessLauncherHelper::GetFilesToMap() {
DCHECK_CURRENTLY_ON(BrowserThread::PROCESS_LAUNCHER);
DCHECK(CurrentlyOnProcessLauncherTaskRunner());
return std::unique_ptr<FileMappedForLaunch>();
}
bool ChildProcessLauncherHelper::BeforeLaunchOnLauncherThread(
const PosixFileDescriptorInfo& files_to_register,
base::LaunchOptions* options) {
DCHECK_CURRENTLY_ON(BrowserThread::PROCESS_LAUNCHER);
DCHECK(CurrentlyOnProcessLauncherTaskRunner());
mojo::edk::PlatformChannelPair::PrepareToPassHandleToChildProcess(
mojo_client_handle(), command_line(), &options->handles_to_transfer);
......@@ -87,7 +88,7 @@ ChildProcessLauncherHelper::LaunchProcessOnLauncherThread(
std::unique_ptr<FileMappedForLaunch> files_to_register,
bool* is_synchronous_launch,
int* launch_result) {
DCHECK_CURRENTLY_ON(BrowserThread::PROCESS_LAUNCHER);
DCHECK(CurrentlyOnProcessLauncherTaskRunner());
DCHECK(mojo_client_handle().is_valid());
// TODO(750938): Implement sandboxed/isolated subprocess launching.
......@@ -99,7 +100,7 @@ ChildProcessLauncherHelper::LaunchProcessOnLauncherThread(
void ChildProcessLauncherHelper::AfterLaunchOnLauncherThread(
const ChildProcessLauncherHelper::Process& process,
const base::LaunchOptions& options) {
DCHECK_CURRENTLY_ON(BrowserThread::PROCESS_LAUNCHER);
DCHECK(CurrentlyOnProcessLauncherTaskRunner());
if (process.process.IsValid()) {
// |mojo_client_handle_| has already been transferred to the child process
......@@ -112,7 +113,7 @@ void ChildProcessLauncherHelper::AfterLaunchOnLauncherThread(
// static
void ChildProcessLauncherHelper::ForceNormalProcessTerminationSync(
ChildProcessLauncherHelper::Process process) {
DCHECK_CURRENTLY_ON(BrowserThread::PROCESS_LAUNCHER);
DCHECK(CurrentlyOnProcessLauncherTaskRunner());
process.process.Terminate(RESULT_CODE_NORMAL_EXIT, true);
}
......
......@@ -11,6 +11,7 @@
#include "content/browser/sandbox_host_linux.h"
#include "content/browser/zygote_host/zygote_communication_linux.h"
#include "content/browser/zygote_host/zygote_host_impl_linux.h"
#include "content/public/browser/child_process_launcher_utils.h"
#include "content/public/browser/content_browser_client.h"
#include "content/public/common/common_sandbox_support_linux.h"
#include "content/public/common/content_client.h"
......@@ -36,7 +37,7 @@ void ChildProcessLauncherHelper::BeforeLaunchOnClientThread() {
std::unique_ptr<FileMappedForLaunch>
ChildProcessLauncherHelper::GetFilesToMap() {
DCHECK_CURRENTLY_ON(BrowserThread::PROCESS_LAUNCHER);
DCHECK(CurrentlyOnProcessLauncherTaskRunner());
return CreateDefaultPosixFilesToMap(child_process_id(), mojo_client_handle(),
true /* include_service_required_files */,
GetProcessType(), command_line());
......@@ -154,7 +155,7 @@ void ChildProcessLauncherHelper::ForceNormalProcessTerminationSync(
void ChildProcessLauncherHelper::SetProcessPriorityOnLauncherThread(
base::Process process,
const ChildProcessLauncherPriority& priority) {
DCHECK_CURRENTLY_ON(BrowserThread::PROCESS_LAUNCHER);
DCHECK(CurrentlyOnProcessLauncherTaskRunner());
if (process.CanBackgroundProcesses())
process.SetProcessBackgrounded(priority.background);
}
......
......@@ -13,6 +13,7 @@
#include "content/browser/mach_broker_mac.h"
#include "content/browser/sandbox_parameters_mac.h"
#include "content/grit/content_resources.h"
#include "content/public/browser/child_process_launcher_utils.h"
#include "content/public/browser/content_browser_client.h"
#include "content/public/common/content_features.h"
#include "content/public/common/content_paths.h"
......@@ -47,7 +48,7 @@ void ChildProcessLauncherHelper::BeforeLaunchOnClientThread() {
std::unique_ptr<PosixFileDescriptorInfo>
ChildProcessLauncherHelper::GetFilesToMap() {
DCHECK_CURRENTLY_ON(BrowserThread::PROCESS_LAUNCHER);
DCHECK(CurrentlyOnProcessLauncherTaskRunner());
return CreateDefaultPosixFilesToMap(
child_process_id(), mojo_client_handle(),
false /* include_service_required_files */, GetProcessType(),
......@@ -242,7 +243,7 @@ bool ChildProcessLauncherHelper::TerminateProcess(const base::Process& process,
// static
void ChildProcessLauncherHelper::ForceNormalProcessTerminationSync(
ChildProcessLauncherHelper::Process process) {
DCHECK_CURRENTLY_ON(BrowserThread::PROCESS_LAUNCHER);
DCHECK(CurrentlyOnProcessLauncherTaskRunner());
// Client has gone away, so just kill the process. Using exit code 0 means
// that UMA won't treat this as a crash.
process.process.Terminate(RESULT_CODE_NORMAL_EXIT, false);
......
......@@ -10,6 +10,7 @@
#include "base/win/win_util.h"
#include "content/browser/child_process_launcher.h"
#include "content/browser/child_process_launcher_helper.h"
#include "content/public/browser/child_process_launcher_utils.h"
#include "content/public/common/result_codes.h"
#include "content/public/common/sandbox_init.h"
#include "content/public/common/sandboxed_process_launcher_delegate.h"
......@@ -46,7 +47,7 @@ ChildProcessLauncherHelper::GetFilesToMap() {
bool ChildProcessLauncherHelper::BeforeLaunchOnLauncherThread(
const FileMappedForLaunch& files_to_register,
base::LaunchOptions* options) {
DCHECK_CURRENTLY_ON(BrowserThread::PROCESS_LAUNCHER);
DCHECK(CurrentlyOnProcessLauncherTaskRunner());
return true;
}
......@@ -56,7 +57,7 @@ ChildProcessLauncherHelper::LaunchProcessOnLauncherThread(
std::unique_ptr<FileMappedForLaunch> files_to_register,
bool* is_synchronous_launch,
int* launch_result) {
DCHECK_CURRENTLY_ON(BrowserThread::PROCESS_LAUNCHER);
DCHECK(CurrentlyOnProcessLauncherTaskRunner());
*is_synchronous_launch = true;
if (delegate_->ShouldLaunchElevated()) {
// When establishing a Mojo connection, the pipe path has already been added
......@@ -85,7 +86,7 @@ ChildProcessLauncherHelper::LaunchProcessOnLauncherThread(
void ChildProcessLauncherHelper::AfterLaunchOnLauncherThread(
const ChildProcessLauncherHelper::Process& process,
const base::LaunchOptions& options) {
DCHECK_CURRENTLY_ON(BrowserThread::PROCESS_LAUNCHER);
DCHECK(CurrentlyOnProcessLauncherTaskRunner());
}
base::TerminationStatus ChildProcessLauncherHelper::GetTerminationStatus(
......@@ -103,7 +104,7 @@ bool ChildProcessLauncherHelper::TerminateProcess(const base::Process& process,
void ChildProcessLauncherHelper::ForceNormalProcessTerminationSync(
ChildProcessLauncherHelper::Process process) {
DCHECK_CURRENTLY_ON(BrowserThread::PROCESS_LAUNCHER);
DCHECK(CurrentlyOnProcessLauncherTaskRunner());
// Client has gone away, so just kill the process. Using exit code 0 means
// that UMA won't treat this as a crash.
process.process.Terminate(RESULT_CODE_NORMAL_EXIT, false);
......@@ -112,7 +113,7 @@ void ChildProcessLauncherHelper::ForceNormalProcessTerminationSync(
void ChildProcessLauncherHelper::SetProcessPriorityOnLauncherThread(
base::Process process,
const ChildProcessLauncherPriority& priority) {
DCHECK_CURRENTLY_ON(BrowserThread::PROCESS_LAUNCHER);
DCHECK(CurrentlyOnProcessLauncherTaskRunner());
if (process.CanBackgroundProcesses())
process.SetProcessBackgrounded(priority.background);
}
......
......@@ -11,6 +11,7 @@
#include "build/build_config.h"
#include "content/browser/frame_host/render_frame_host_impl.h"
#include "content/browser/renderer_host/render_process_host_impl.h"
#include "content/public/browser/child_process_launcher_utils.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/render_process_host_observer.h"
......@@ -356,8 +357,8 @@ IN_PROC_BROWSER_TEST_F(RenderProcessHostTest, SpareRendererOnProcessReuse) {
base::WaitableEvent launcher_thread_done(
base::WaitableEvent::ResetPolicy::MANUAL,
base::WaitableEvent::InitialState::NOT_SIGNALED);
BrowserThread::PostTask(
BrowserThread::PROCESS_LAUNCHER, FROM_HERE,
GetProcessLauncherTaskRunner()->PostTask(
FROM_HERE,
base::BindOnce([](base::WaitableEvent* done) { done->Signal(); },
base::Unretained(&launcher_thread_done)));
ASSERT_TRUE(launcher_thread_done.TimedWait(TestTimeouts::action_timeout()));
......
......@@ -12,7 +12,7 @@ import org.chromium.base.VisibleForTesting;
import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace;
/** This is BrowserThread::PROCESS_LAUNCHER. It is available before native library is loaded. */
/** This is the process launcher thread. It is available before native library is loaded. */
@JNINamespace("content::android")
public final class LauncherThread {
private static final JavaHandlerThread sThread =
......
......@@ -84,6 +84,7 @@ jumbo_source_set("browser_sources") {
"cdm_registry.h",
"certificate_request_result_type.h",
"child_process_data.h",
"child_process_launcher_utils.h",
"child_process_security_policy.h",
"client_certificate_delegate.h",
"color_chooser.h",
......
......@@ -67,9 +67,6 @@ class CONTENT_EXPORT BrowserThread {
// The main thread in the browser.
UI,
// Used to launch and terminate Chrome processes.
PROCESS_LAUNCHER,
// This is the thread that processes non-blocking IO, i.e. IPC and network.
// Blocking IO should happen in TaskScheduler.
IO,
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CONTENT_PUBLIC_BROWSER_CHILD_PROCESS_LAUNCHER_UTILS_H_
#define CONTENT_PUBLIC_BROWSER_CHILD_PROCESS_LAUNCHER_UTILS_H_
#include "content/common/content_export.h"
namespace base {
class SingleThreadTaskRunner;
}
namespace content {
// The caller must take a reference to the returned TaskRunner pointer if it
// wants to use the pointer directly.
CONTENT_EXPORT base::SingleThreadTaskRunner* GetProcessLauncherTaskRunner();
CONTENT_EXPORT bool CurrentlyOnProcessLauncherTaskRunner();
} // namespace content
#endif // CONTENT_PUBLIC_BROWSER_CHILD_PROCESS_LAUNCHER_UTILES_H_
......@@ -39,8 +39,6 @@ TestBrowserThreadBundle::~TestBrowserThreadBundle() {
base::RunLoop().RunUntilIdle();
io_thread_->Stop();
base::RunLoop().RunUntilIdle();
process_launcher_thread_->Stop();
base::RunLoop().RunUntilIdle();
ui_thread_->Stop();
base::RunLoop().RunUntilIdle();
......@@ -116,9 +114,6 @@ void TestBrowserThreadBundle::Init() {
void TestBrowserThreadBundle::CreateBrowserThreads() {
CHECK(!threads_created_);
process_launcher_thread_ = std::make_unique<TestBrowserThread>(
BrowserThread::PROCESS_LAUNCHER, base::MessageLoop::current());
if (options_ & REAL_IO_THREAD) {
io_thread_ = std::make_unique<TestBrowserThread>(BrowserThread::IO);
io_thread_->StartIOThread();
......
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