Fix sampling profiler shutdown logic with periodic sampling.

The logic was incorrect because the |finished| waitable event
(which corresponds to |profiling_inactive_|) was getting signaled
by the very first collection - and the dtor's Wait() on it did
not take into account that subsequent collections might be active.

This CL fixes that by not signaling the event on a finished
collection unless that collection was the last one (i.e. no new
params were provided by the callback).

In the case where there's a pending collection running, the Stop()
call in the dtor will schedule a RemoveCollectionTask() task which
will call FinishCollection() with a param telling it to signal the
event. This will let the SamplingProfiler's dtor Wait() call
unblock and let it finish its destruction.

A new unit test is added to test this scenario. (Without this CL,
it fails on Mac.)

BUG=763869

Change-Id: Iaa7e833323ce2429480c8b0ed5cceae3a74764a8
Reviewed-on: https://chromium-review.googlesource.com/697911
Reviewed-by: Mike Wittman <wittman@chromium.org>
Commit-Queue: Alexei Svitkine <asvitkine@chromium.org>
Cr-Commit-Position: refs/heads/master@{#506127}

CrOS-Libchrome-Original-Commit: c619c98571a07d6a891b7a769a2375acb59fc9b4
2 files changed
tree: 3870cce4b4fd1a0238b74573fa57ffdd3cab99ac
  1. base/
  2. build/
  3. components/
  4. dbus/
  5. device/
  6. ipc/
  7. mojo/
  8. testing/
  9. third_party/
  10. ui/