Fix some interleaving issues in EmbeddedWorkerInstance.
commitdd9485ea295f90cc0d95f2a8acd02dbf310fa3ea
authorfalken <falken@chromium.org>
Wed, 12 Aug 2015 09:55:21 +0000 (12 02:55 -0700)
committerCommit bot <commit-bot@chromium.org>
Wed, 12 Aug 2015 09:55:48 +0000 (12 09:55 +0000)
treea84cc6463b18727b776083d0a54a443442da1c16
parent04dfde123d21ac9cb872adc63bcaeba7d7532eba
Fix some interleaving issues in EmbeddedWorkerInstance.

The embedded worker startup sequence involves thread hopping and async
callbacks, so there's some cases that could cause bugs:

One is detach during startup:
(1) ProcessAllocated sets process_id_
(2) Hop to UI thread for RegisterDevToolsManagerOnUI
(3) The render process dies, detaching and clearing process_id_
(4) UI thread work completes, hops back to SendStartWorker
(5) SendStartWorker tries to send an IPC to process_id -1, hits DCHECK.

Another is calling Stop() during startup:
(1) Call Start()
(2) Hop to UI thread for AllocateProcess
(3) Call Stop()
(4) Stop tries to send an IPC to process_id -1, gets error.
(5) Stop sets status to STOPPING, and will remain in stopping forever.

The fix is to add checks to detect these conditions.

BUG=515759,509904

Review URL: https://codereview.chromium.org/1289443002

Cr-Commit-Position: refs/heads/master@{#342998}
content/browser/service_worker/embedded_worker_instance.cc
content/browser/service_worker/embedded_worker_instance.h
content/browser/service_worker/embedded_worker_instance_unittest.cc
content/browser/service_worker/service_worker_version.cc
content/browser/service_worker/service_worker_version.h