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

Unified Diff: components/scheduler/child/webthread_impl_for_worker_scheduler.cc

Issue 1589463002: compositor worker: Use a WebThread for the compositor thread. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: self.nit Created 4 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: components/scheduler/child/webthread_impl_for_worker_scheduler.cc
diff --git a/components/scheduler/child/webthread_impl_for_worker_scheduler.cc b/components/scheduler/child/webthread_impl_for_worker_scheduler.cc
index afdcb6d50322a49b1a1a1f83c594086ac5b3f467..345ecef9690b20b189084f190bcf708e2f0ead33 100644
--- a/components/scheduler/child/webthread_impl_for_worker_scheduler.cc
+++ b/components/scheduler/child/webthread_impl_for_worker_scheduler.cc
@@ -29,7 +29,9 @@ WebThreadImplForWorkerScheduler::WebThreadImplForWorkerScheduler(
bool started = thread_->StartWithOptions(options);
CHECK(started);
thread_task_runner_ = thread_->task_runner();
+}
+void WebThreadImplForWorkerScheduler::Init() {
base::WaitableEvent completion(false, false);
thread_task_runner_->PostTask(
FROM_HERE, base::Bind(&WebThreadImplForWorkerScheduler::InitOnThread,
@@ -38,13 +40,15 @@ WebThreadImplForWorkerScheduler::WebThreadImplForWorkerScheduler(
}
WebThreadImplForWorkerScheduler::~WebThreadImplForWorkerScheduler() {
- base::WaitableEvent completion(false, false);
- // Restore the original task runner so that the thread can tear itself down.
- thread_task_runner_->PostTask(
- FROM_HERE,
- base::Bind(&WebThreadImplForWorkerScheduler::RestoreTaskRunnerOnThread,
- base::Unretained(this), &completion));
- completion.Wait();
+ if (task_runner_delegate_) {
+ base::WaitableEvent completion(false, false);
+ // Restore the original task runner so that the thread can tear itself down.
+ thread_task_runner_->PostTask(
+ FROM_HERE,
+ base::Bind(&WebThreadImplForWorkerScheduler::RestoreTaskRunnerOnThread,
+ base::Unretained(this), &completion));
+ completion.Wait();
+ }
thread_->Stop();
}
@@ -52,9 +56,7 @@ void WebThreadImplForWorkerScheduler::InitOnThread(
base::WaitableEvent* completion) {
// TODO(alexclarke): Do we need to unify virtual time for workers and the
// main thread?
- task_runner_delegate_ = SchedulerTqmDelegateImpl::Create(
- thread_->message_loop(), make_scoped_ptr(new base::DefaultTickClock()));
- worker_scheduler_ = WorkerScheduler::Create(task_runner_delegate_);
+ worker_scheduler_ = CreateWorkerScheduler();
worker_scheduler_->Init();
task_runner_ = worker_scheduler_->DefaultTaskRunner();
idle_task_runner_ = worker_scheduler_->IdleTaskRunner();
@@ -80,6 +82,13 @@ void WebThreadImplForWorkerScheduler::WillDestroyCurrentMessageLoop() {
worker_scheduler_.reset();
}
+scoped_ptr<scheduler::WorkerScheduler>
+WebThreadImplForWorkerScheduler::CreateWorkerScheduler() {
+ task_runner_delegate_ = SchedulerTqmDelegateImpl::Create(
+ thread_->message_loop(), make_scoped_ptr(new base::DefaultTickClock()));
+ return WorkerScheduler::Create(task_runner_delegate_);
+}
+
blink::PlatformThreadId WebThreadImplForWorkerScheduler::threadId() const {
return thread_->GetThreadId();
}

Powered by Google App Engine
This is Rietveld 408576698