Service Worker: Cleanup on a renderer crash before the dispatcher host is destroyed
commitdd4c8043fcb65e523f59e0b6e30fba322bf4c4f0
authorfalken <falken@chromium.org>
Fri, 7 Nov 2014 05:02:14 +0000 (6 21:02 -0800)
committerCommit bot <commit-bot@chromium.org>
Fri, 7 Nov 2014 05:02:38 +0000 (7 05:02 +0000)
tree53ecc81451d17599ff9d57bec5c52097a74a09e3
parent9da298e189db8751ca75039d4db49e9d5dab7247
Service Worker: Cleanup on a renderer crash before the dispatcher host is destroyed

This fixes a broken state that can occur when a render process crashes but its
corresponding ServiceWorkerDispatcherHost does not get destructed immediately after.
That can happen if something holds a reference to the ServiceWorkerDispatcherHost,
for example, if it's waiting for a result from a ServiceWorkerRegisterJob.

This patch:
1) Has ServiceWorkerDispatcherHost tear down state associated with its render process
in OnFilterRemoved instead of in its destructor. This is needed because the browser
will create a new ServiceWorkerDispatcherHost when reusing the render process host
(yes it can reuse the RPH! see comment in RenderProcessHostImpl::ProcessDied():
"This object is not deleted at this point and might be reused later."), but the
old one may not have been destructed yet if something holds a reference to it.

2) Allows ServiceWorkerVersion::Start to call its callback with failure if the
render process crashed before the embedded worker could start up. It does this
by immediately inserting a starting worker in the EmbeddedWorkerRegistry, instead
of waiting for start to complete. Now, on a renderer crash, when
ServiceWorkerDispatcherHost tears down state, the registry will call OnStopped on
both starting and running embedded workers in that process.

This makes it less likely for ServiceWorkerRegisterJob to hang indefinitely,
though it's still possible with crbug.com/404111.

BUG=428463

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

Cr-Commit-Position: refs/heads/master@{#303189}
content/browser/service_worker/embedded_worker_registry.cc
content/browser/service_worker/embedded_worker_registry.h
content/browser/service_worker/service_worker_dispatcher_host.cc
content/browser/service_worker/service_worker_dispatcher_host.h
content/browser/service_worker/service_worker_dispatcher_host_unittest.cc
content/browser/service_worker/service_worker_version_unittest.cc