| Index: base/win/object_watcher.h
|
| diff --git a/base/win/object_watcher.h b/base/win/object_watcher.h
|
| index e1e86fe73aa38e421ef40eaaead7d550bf14812f..a2821c114f18279a5cc4c9b57d77d23cfd35439f 100644
|
| --- a/base/win/object_watcher.h
|
| +++ b/base/win/object_watcher.h
|
| @@ -10,8 +10,9 @@
|
| #include "base/base_export.h"
|
| #include "base/callback.h"
|
| #include "base/macros.h"
|
| +#include "base/memory/ref_counted.h"
|
| #include "base/memory/weak_ptr.h"
|
| -#include "base/message_loop/message_loop.h"
|
| +#include "base/single_thread_task_runner.h"
|
|
|
| namespace base {
|
| namespace win {
|
| @@ -46,22 +47,22 @@ namespace win {
|
| // If the object is already signaled before being watched, OnObjectSignaled is
|
| // still called after (but not necessarily immediately after) watch is started.
|
| //
|
| -// NOTE: Use of this class requires that there be a current message loop;
|
| -// otherwise, when the object is signaled, there would be no loop to post the
|
| -// callback task to. This means that you cannot use ObjectWatcher in test code
|
| -// that doesn't create a message loop (unless you add such a loop).
|
| -class BASE_EXPORT ObjectWatcher : public MessageLoop::DestructionObserver {
|
| +// NOTE: Except for the constructor, all public methods of this class must be
|
| +// called on the same thread. A ThreadTaskRunnerHandle must be set on that
|
| +// thread.
|
| +class BASE_EXPORT ObjectWatcher {
|
| public:
|
| class BASE_EXPORT Delegate {
|
| public:
|
| virtual ~Delegate() {}
|
| - // Called from the MessageLoop when a signaled object is detected. To
|
| - // continue watching the object, StartWatching must be called again.
|
| + // Called from the thread that started the watch when a signaled object is
|
| + // detected. To continue watching the object, StartWatching must be called
|
| + // again.
|
| virtual void OnObjectSignaled(HANDLE object) = 0;
|
| };
|
|
|
| ObjectWatcher();
|
| - ~ObjectWatcher() override;
|
| + ~ObjectWatcher();
|
|
|
| // When the object is signaled, the given delegate is notified on the thread
|
| // where StartWatchingOnce is called. The ObjectWatcher is not responsible for
|
| @@ -99,15 +100,23 @@ class BASE_EXPORT ObjectWatcher : public MessageLoop::DestructionObserver {
|
|
|
| void Signal(Delegate* delegate);
|
|
|
| - // MessageLoop::DestructionObserver implementation:
|
| - void WillDestroyCurrentMessageLoop() override;
|
| + void Reset();
|
|
|
| - // Internal state.
|
| + // A callback pre-bound to Signal() that is posted to the caller's task runner
|
| + // when the wait completes.
|
| Closure callback_;
|
| - HANDLE object_; // The object being watched
|
| - HANDLE wait_object_; // Returned by RegisterWaitForSingleObject
|
| - MessageLoop* origin_loop_; // Used to get back to the origin thread
|
| - bool run_once_;
|
| +
|
| + // The object being watched.
|
| + HANDLE object_ = nullptr;
|
| +
|
| + // The wait handle returned by RegisterWaitForSingleObject.
|
| + HANDLE wait_object_ = nullptr;
|
| +
|
| + // The task runner of the thread on which the watch was started.
|
| + scoped_refptr<SingleThreadTaskRunner> task_runner_;
|
| +
|
| + bool run_once_ = true;
|
| +
|
| WeakPtrFactory<ObjectWatcher> weak_factory_;
|
|
|
| DISALLOW_COPY_AND_ASSIGN(ObjectWatcher);
|
|
|