Worker: Initiate worker thread shutdown always on the main thread

In the current implementation, worker shutdown can be initiated twice on
WorkerMicrotaskRunner::didProcessTask() when close() is called on
{Dedicated,Shared}WorkerGlobalScope:

  1. WorkerReportingProxy::workerGlobalScopeClosed() eventually calls
     WorkerThread::terminate() on the main thread (see call pathes below).
  2. WorkerThread::terminateFromWorkerThread() is directly called on the worker
     thread.

These are valid because the shutdown sequence actually does not run twice thanks
to the thread-safe WorkerThread::m_shutdown flag. However, to achieve the thread
shutdown observation mechanism (see the issue), it would be better to initiate
the shutdown always on the main thread. For that, this CL removes the shutdown
call from the worker thread and just prepare shutdown instead.

APPENDIX: Thread termination sequence via workerGlobalScopeClosed() on each
worker mechanism:

// DedicatedWorker
InProcessWorkerObjectProxy::workerGlobalScopeClosed()
  InProcessWorkerMessagingProxy::terminateWorkerGlobalScope()
    m_workerThread->terminate();

// SharedWorker
WebSharedWorkerImpl::workerGlobalScopeClosed()
  WebSharedWorkerImpl::workerGlobalScopeClosedOnMainThread()
    WebSharedWorkerImpl::terminateWorkerThread()
      m_workerThread->terminate();

// ServiceWorker does not support close()
ServiceWorkerGlobalScopeProxy::workerGlobalScopeClosed()
  NOTREACHED()

BUG=487050, 575532

Review-Url: https://codereview.chromium.org/1978163002
Cr-Commit-Position: refs/heads/master@{#395600}
2 files changed