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

Unified Diff: content/renderer/render_process_impl.cc

Issue 2491823005: Initialize TaskScheduler in renderers. (Closed)
Patch Set: add dcheck Created 4 years, 1 month 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/renderer/render_process_impl.cc
diff --git a/content/renderer/render_process_impl.cc b/content/renderer/render_process_impl.cc
index 0ad4d1b0066be8c76af12461a3d9c798bd51371a..83ec8c5a4fe1ad899a1e2ac1ba4e17c4183779f5 100644
--- a/content/renderer/render_process_impl.cc
+++ b/content/renderer/render_process_impl.cc
@@ -12,10 +12,18 @@
#include <mlang.h>
#endif
+#include <stddef.h>
+
+#include <vector>
+
+#include "base/callback.h"
#include "base/command_line.h"
#include "base/compiler_specific.h"
#include "base/feature_list.h"
#include "base/sys_info.h"
+#include "base/task_scheduler/scheduler_worker_pool_params.h"
+#include "base/task_scheduler/task_scheduler.h"
+#include "base/threading/sequenced_worker_pool.h"
#include "content/child/site_isolation_stats_gatherer.h"
#include "content/public/common/content_features.h"
#include "content/public/common/content_switches.h"
@@ -23,6 +31,10 @@
#include "third_party/WebKit/public/web/WebFrame.h"
#include "v8/include/v8.h"
+namespace base {
+class TaskTraits;
+} // namespace
+
namespace {
const base::Feature kV8_ES2015_TailCalls_Feature {
@@ -50,6 +62,40 @@ void SetV8FlagIfHasSwitch(const char* switch_name, const char* v8_flag) {
}
}
+bool IsSingleProcess() {
+ return base::CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kSingleProcess);
+}
+
+void InitializeTaskScheduler() {
+ if (IsSingleProcess()) {
+ // If this renderer runs in the browser process, there should already be a
+ // TaskScheduler and redirection settings shouldn't be changed.
+ DCHECK(base::TaskScheduler::GetInstance());
+ return;
+ }
+ DCHECK(!base::TaskScheduler::GetInstance());
+
+ std::vector<base::SchedulerWorkerPoolParams> worker_pool_params_vector;
+ base::Callback<size_t(const base::TaskTraits& traits)>
gab 2016/11/18 18:32:00 Feels like this type should be defined somewhere.
+ worker_pool_index_for_traits_callback;
+ bool redirect_sequenced_worker_pool = false;
+
+ content::GetContentClient()
+ ->renderer()
+ ->GetTaskSchedulerInitializationArguments(
+ &worker_pool_params_vector, &worker_pool_index_for_traits_callback,
+ &redirect_sequenced_worker_pool);
+ DCHECK(!worker_pool_params_vector.empty());
+ DCHECK(worker_pool_index_for_traits_callback);
+
+ base::TaskScheduler::CreateAndSetDefaultTaskScheduler(
+ worker_pool_params_vector, worker_pool_index_for_traits_callback);
+
+ if (redirect_sequenced_worker_pool)
+ base::SequencedWorkerPool::RedirectToTaskSchedulerForProcess();
gab 2016/11/18 18:32:00 else EnableForProcess? (won't there be a clash wi
+}
+
} // namespace
namespace content {
@@ -103,6 +149,8 @@ RenderProcessImpl::RenderProcessImpl()
SiteIsolationStatsGatherer::SetEnabled(
GetContentClient()->renderer()->ShouldGatherSiteIsolationStats());
+
+ InitializeTaskScheduler();
}
RenderProcessImpl::~RenderProcessImpl() {
@@ -112,6 +160,11 @@ RenderProcessImpl::~RenderProcessImpl() {
DLOG(ERROR) << "WebFrame LEAKED " << count << " TIMES";
#endif
+ if (!IsSingleProcess()) {
+ DCHECK(base::TaskScheduler::GetInstance());
+ base::TaskScheduler::GetInstance()->Shutdown();
+ }
+
GetShutDownEvent()->Signal();
}

Powered by Google App Engine
This is Rietveld 408576698