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(); |
} |