| Index: base/win/object_watcher.h
|
| diff --git a/base/win/object_watcher.h b/base/win/object_watcher.h
|
| index a2821c114f18279a5cc4c9b57d77d23cfd35439f..e1e86fe73aa38e421ef40eaaead7d550bf14812f 100644
|
| --- a/base/win/object_watcher.h
|
| +++ b/base/win/object_watcher.h
|
| @@ -10,9 +10,8 @@
|
| #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/single_thread_task_runner.h"
|
| +#include "base/message_loop/message_loop.h"
|
|
|
| namespace base {
|
| namespace win {
|
| @@ -47,22 +46,22 @@
|
| // If the object is already signaled before being watched, OnObjectSignaled is
|
| // still called after (but not necessarily immediately after) watch is started.
|
| //
|
| -// 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 {
|
| +// 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 {
|
| public:
|
| class BASE_EXPORT Delegate {
|
| public:
|
| virtual ~Delegate() {}
|
| - // Called from the thread that started the watch when a signaled object is
|
| - // detected. To continue watching the object, StartWatching must be called
|
| - // again.
|
| + // Called from the MessageLoop when a signaled object is detected. To
|
| + // continue watching the object, StartWatching must be called again.
|
| virtual void OnObjectSignaled(HANDLE object) = 0;
|
| };
|
|
|
| ObjectWatcher();
|
| - ~ObjectWatcher();
|
| + ~ObjectWatcher() override;
|
|
|
| // When the object is signaled, the given delegate is notified on the thread
|
| // where StartWatchingOnce is called. The ObjectWatcher is not responsible for
|
| @@ -100,23 +99,15 @@
|
|
|
| void Signal(Delegate* delegate);
|
|
|
| - void Reset();
|
| + // MessageLoop::DestructionObserver implementation:
|
| + void WillDestroyCurrentMessageLoop() override;
|
|
|
| - // A callback pre-bound to Signal() that is posted to the caller's task runner
|
| - // when the wait completes.
|
| + // Internal state.
|
| Closure callback_;
|
| -
|
| - // 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;
|
| -
|
| + 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_;
|
| WeakPtrFactory<ObjectWatcher> weak_factory_;
|
|
|
| DISALLOW_COPY_AND_ASSIGN(ObjectWatcher);
|
|
|