Have Device Service observe MessageLoop destruction

The Device Service needs to clean up parts of its internal state as part
of browser shutdown. However, it also needs to run on the UI thread,
and embedded services that run on the UI thread are not guaranteed to
be destroyed as part of browser shutdown (tasks to destroy these
services are posted from the IO thread by
ServiceManagerConnectionImpl::ShutDownOnIOThread, but the UI thread is
typically shut down before these posted tasks are run).

To solve this issue we discussed adding plumbing wherein embedded
services could inform //content that they wanted to be notified when
shutdown was occurring on the main thread. However, on investigation
this plumbing would be painful to implement: it is only
EmbeddedInstanceManager that has direct information of these service
instances, and that object lives far away from //content's
ServiceManagerContext, the object that knows when shutdown is occurring
on the main thread.

This CL takes an alternative approach of having the Device Service
implementation observe the destruction of its MessageLoop. I have
verified that the observation is triggered on shutdown of Chrome.

Bug: 794105
Change-Id: I3b383871679d42f544812be4bcb13c872cf276ff
Reviewed-on: https://chromium-review.googlesource.com/1099245
Commit-Queue: Colin Blundell <blundell@chromium.org>
Reviewed-by: Ken Rockot <rockot@chromium.org>
Cr-Commit-Position: refs/heads/master@{#567260}
2 files changed