| Index: base/task_scheduler/scheduler_worker.cc | 
| diff --git a/base/task_scheduler/scheduler_worker.cc b/base/task_scheduler/scheduler_worker.cc | 
| index e64ca61de00600db5cc08b2d7b7937f742db860f..054227193bbad5a82c3bbe6830736b80d9919dbb 100644 | 
| --- a/base/task_scheduler/scheduler_worker.cc | 
| +++ b/base/task_scheduler/scheduler_worker.cc | 
| @@ -36,10 +36,7 @@ class SchedulerWorker::Thread : public PlatformThread::Delegate { | 
| // Set if this thread was detached. | 
| std::unique_ptr<Thread> detached_thread; | 
|  | 
| -    outer_->delegate_->OnMainEntry( | 
| -        outer_, outer_->last_detach_time_.is_null() | 
| -                    ? TimeDelta::Max() | 
| -                    : TimeTicks::Now() - outer_->last_detach_time_); | 
| +    outer_->delegate_->OnMainEntry(outer_); | 
|  | 
| // A SchedulerWorker starts out waiting for work. | 
| WaitForWork(); | 
| @@ -60,9 +57,9 @@ class SchedulerWorker::Thread : public PlatformThread::Delegate { | 
| if (outer_->delegate_->CanDetach(outer_)) { | 
| detached_thread = outer_->Detach(); | 
| if (detached_thread) { | 
| +            outer_ = nullptr; | 
| DCHECK_EQ(detached_thread.get(), this); | 
| PlatformThread::Detach(thread_handle_); | 
| -            outer_ = nullptr; | 
| break; | 
| } | 
| } | 
| @@ -256,7 +253,11 @@ std::unique_ptr<SchedulerWorker::Thread> SchedulerWorker::Detach() { | 
| // guarantee that we call GetWork() after a successful wakeup. | 
| if (thread_->IsWakeUpPending()) | 
| return nullptr; | 
| -  last_detach_time_ = TimeTicks::Now(); | 
| + | 
| +  // Call OnDetach() within the scope of |thread_lock_| to prevent the delegate | 
| +  // from being used concurrently from an old and a new thread. | 
| +  delegate_->OnDetach(); | 
| + | 
| return std::move(thread_); | 
| } | 
|  | 
|  |