chaps: refactor D-Bus/threading utilities

dbus::Bus is held as a scoped_refptr by dbus::ObjectProxy, and
dbus::Bus holds a reference to a dbus::ObjectProxy. Since we get
an ObjectProxy as a weak pointer, we have to make sure the bus
gets rid of it when we no longer need it anymore.

We know we want everything to be cleaned up when our reference
to dbus::Bus goes out of scope, so introduce a wrapper which
calls ShutdownAndBlock on the correct thread when that reference
is cleaned up.

On top of that, since this threading code can be a bit confusing,
split some of these utilities out so they can be tested.

BUG=chromium:757921
TEST=FEATURES=test USE="asan clang" emerge-cyan cryptohome, tests
  on DUT with p11_replay

Change-Id: I5b3e888e5b0b88a5c706563a23ba998ef5aab090
Reviewed-on: https://chromium-review.googlesource.com/627035
Commit-Ready: Andrey Pronin <apronin@chromium.org>
Tested-by: Eric Caruso <ejcaruso@chromium.org>
Reviewed-by: Andrey Pronin <apronin@chromium.org>
8 files changed