Worker: Protect a running debugger task from forcible worker termination

A running debugger task must be protected from forcible worker termination, but
in the current implementation, there is a corner case where the debugger task
can suddenly be killed as follows:

1) performDebuggerTaskOnWorkerThread() is called almost at the same time as
   terminateInternal() on the main thread. terminateInternal() acquires
   |m_threadStateMutex| before performDebuggerTaskOnWorkerThread().
2) terminateInternal() checks a flag |m_runningDebuggerTask| before
   performDebuggerTaskOnWorkerThread() sets it, schedules a force termination
   task, and releases the lock.
3) performDebuggerTaskOnWorkerThread() acquires the lock, sets the flag, and
   runs the debugger task.
4) The scheduled task is fired while the debugger task is running and attempts
   to terminate it. This may cause crashes.

To avoid the case, this CL makes a scheduled task check the flag before
terminating the worker execution. In addition, this ensures that postTask() and
appendDebuggerTask() don't post new tasks after terminateInternal() or
prepareForShutdownOnWorkerThread() is called.

BUG=616775

Review-Url: https://codereview.chromium.org/2041753002
Cr-Commit-Position: refs/heads/master@{#398837}
5 files changed