Commit 92e27196 authored by Etienne Pierre-Doray's avatar Etienne Pierre-Doray Committed by Commit Bot

[ObjectWatcher]: Add from_here to ObjectWatcher::StartWatching*

To investigate BLOCK_SHUTDOWN tasks posted after shutdown (see bug).

Bug: 997754
Change-Id: Ie939ee242f56ab4ba25e6a67d640ad7873d3ad4b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1827938Reviewed-by: default avatarBruce Dawson <brucedawson@chromium.org>
Commit-Queue: Etienne Pierre-Doray <etiennep@chromium.org>
Cr-Commit-Position: refs/heads/master@{#701680}
parent 30fceda0
...@@ -21,13 +21,16 @@ ObjectWatcher::~ObjectWatcher() { ...@@ -21,13 +21,16 @@ ObjectWatcher::~ObjectWatcher() {
StopWatching(); StopWatching();
} }
bool ObjectWatcher::StartWatchingOnce(HANDLE object, Delegate* delegate) { bool ObjectWatcher::StartWatchingOnce(HANDLE object,
return StartWatchingInternal(object, delegate, true); Delegate* delegate,
const Location& from_here) {
return StartWatchingInternal(object, delegate, true, from_here);
} }
bool ObjectWatcher::StartWatchingMultipleTimes(HANDLE object, bool ObjectWatcher::StartWatchingMultipleTimes(HANDLE object,
Delegate* delegate) { Delegate* delegate,
return StartWatchingInternal(object, delegate, false); const Location& from_here) {
return StartWatchingInternal(object, delegate, false, from_here);
} }
bool ObjectWatcher::StopWatching() { bool ObjectWatcher::StopWatching() {
...@@ -63,17 +66,20 @@ void CALLBACK ObjectWatcher::DoneWaiting(void* param, BOOLEAN timed_out) { ...@@ -63,17 +66,20 @@ void CALLBACK ObjectWatcher::DoneWaiting(void* param, BOOLEAN timed_out) {
// The destructor blocks on any callbacks that are in flight, so we know that // The destructor blocks on any callbacks that are in flight, so we know that
// that is always a pointer to a valid ObjectWater. // that is always a pointer to a valid ObjectWater.
ObjectWatcher* that = static_cast<ObjectWatcher*>(param); ObjectWatcher* that = static_cast<ObjectWatcher*>(param);
that->task_runner_->PostTask(FROM_HERE, that->callback_); that->task_runner_->PostTask(that->location_, that->callback_);
if (that->run_once_) if (that->run_once_)
that->callback_.Reset(); that->callback_.Reset();
} }
bool ObjectWatcher::StartWatchingInternal(HANDLE object, Delegate* delegate, bool ObjectWatcher::StartWatchingInternal(HANDLE object,
bool execute_only_once) { Delegate* delegate,
bool execute_only_once,
const Location& from_here) {
DCHECK(delegate); DCHECK(delegate);
DCHECK(!wait_object_) << "Already watching an object"; DCHECK(!wait_object_) << "Already watching an object";
DCHECK(SequencedTaskRunnerHandle::IsSet()); DCHECK(SequencedTaskRunnerHandle::IsSet());
location_ = from_here;
task_runner_ = SequencedTaskRunnerHandle::Get(); task_runner_ = SequencedTaskRunnerHandle::Get();
run_once_ = execute_only_once; run_once_ = execute_only_once;
...@@ -112,6 +118,7 @@ void ObjectWatcher::Signal(Delegate* delegate) { ...@@ -112,6 +118,7 @@ void ObjectWatcher::Signal(Delegate* delegate) {
void ObjectWatcher::Reset() { void ObjectWatcher::Reset() {
callback_.Reset(); callback_.Reset();
location_ = {};
object_ = nullptr; object_ = nullptr;
wait_object_ = nullptr; wait_object_ = nullptr;
task_runner_ = nullptr; task_runner_ = nullptr;
......
...@@ -71,14 +71,19 @@ class BASE_EXPORT ObjectWatcher { ...@@ -71,14 +71,19 @@ class BASE_EXPORT ObjectWatcher {
// where StartWatchingOnce is called. The ObjectWatcher is not responsible for // where StartWatchingOnce is called. The ObjectWatcher is not responsible for
// deleting the delegate. // deleting the delegate.
// Returns whether watching was successfully initiated. // Returns whether watching was successfully initiated.
bool StartWatchingOnce(HANDLE object, Delegate* delegate); bool StartWatchingOnce(HANDLE object,
Delegate* delegate,
const Location& from_here = Location::Current());
// Notifies the delegate, on the sequence where this method is called, each // Notifies the delegate, on the sequence where this method is called, each
// time the object is set. By definition, the handle must be an auto-reset // time the object is set. By definition, the handle must be an auto-reset
// object. The caller must ensure that it (or any Windows system code) doesn't // object. The caller must ensure that it (or any Windows system code) doesn't
// reset the event or else the delegate won't be called. // reset the event or else the delegate won't be called.
// Returns whether watching was successfully initiated. // Returns whether watching was successfully initiated.
bool StartWatchingMultipleTimes(HANDLE object, Delegate* delegate); bool StartWatchingMultipleTimes(
HANDLE object,
Delegate* delegate,
const Location& from_here = Location::Current());
// Stops watching. Does nothing if the watch has already completed. If the // Stops watching. Does nothing if the watch has already completed. If the
// watch is still active, then it is canceled, and the associated delegate is // watch is still active, then it is canceled, and the associated delegate is
...@@ -98,13 +103,17 @@ class BASE_EXPORT ObjectWatcher { ...@@ -98,13 +103,17 @@ class BASE_EXPORT ObjectWatcher {
static void CALLBACK DoneWaiting(void* param, BOOLEAN timed_out); static void CALLBACK DoneWaiting(void* param, BOOLEAN timed_out);
// Helper used by StartWatchingOnce and StartWatchingMultipleTimes. // Helper used by StartWatchingOnce and StartWatchingMultipleTimes.
bool StartWatchingInternal(HANDLE object, Delegate* delegate, bool StartWatchingInternal(HANDLE object,
bool execute_only_once); Delegate* delegate,
bool execute_only_once,
const Location& from_here);
void Signal(Delegate* delegate); void Signal(Delegate* delegate);
void Reset(); void Reset();
Location location_;
// A callback pre-bound to Signal() that is posted to the caller's task runner // A callback pre-bound to Signal() that is posted to the caller's task runner
// when the wait completes. // when the wait completes.
RepeatingClosure callback_; RepeatingClosure callback_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment