Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2174)

Unified Diff: content/child/child_process.cc

Issue 2627953002: Initialize TaskScheduler in all child processes. (Closed)
Patch Set: fix test error Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/child/child_process.cc
diff --git a/content/child/child_process.cc b/content/child/child_process.cc
index 7c5b408e842e328c5f0b8c2edc1abe0beb91a41b..19b28b7c5118efff1e539df86169f824dd1bdd69 100644
--- a/content/child/child_process.cc
+++ b/content/child/child_process.cc
@@ -13,6 +13,7 @@
#include "base/single_thread_task_runner.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h"
+#include "base/task_scheduler/task_scheduler.h"
#include "base/threading/thread.h"
#include "base/threading/thread_local.h"
#include "build/build_config.h"
@@ -47,6 +48,15 @@ ChildProcess::ChildProcess(base::ThreadPriority io_thread_priority)
base::StatisticsRecorder::Initialize();
+ // Initialize TaskScheduler if not already done. A TaskScheduler may already
+ // exist when ChildProcess is instantiated in the browser process or in a
+ // test process.
+ if (!base::TaskScheduler::GetInstance()) {
+ InitializeTaskScheduler();
+ DCHECK(base::TaskScheduler::GetInstance());
+ initialized_task_scheduler_ = true;
+ }
+
// We can't recover from failing to start the IO thread.
base::Thread::Options thread_options(base::MessageLoop::TYPE_IO, 0);
thread_options.priority = io_thread_priority;
@@ -80,6 +90,11 @@ ChildProcess::~ChildProcess() {
g_lazy_tls.Pointer()->Set(NULL);
io_thread_.Stop();
+
+ if (initialized_task_scheduler_) {
+ DCHECK(base::TaskScheduler::GetInstance());
+ base::TaskScheduler::GetInstance()->Shutdown();
+ }
}
ChildThreadImpl* ChildProcess::main_thread() {
@@ -162,4 +177,9 @@ void ChildProcess::WaitForDebugger(const std::string& label) {
#endif // defined(OS_POSIX)
}
+void ChildProcess::InitializeTaskScheduler() {
+ constexpr int kMaxThreads = 2;
+ base::TaskScheduler::CreateAndSetSimpleTaskScheduler(kMaxThreads);
+}
+
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698