Chromium Code Reviews| Index: base/win/object_watcher.h |
| diff --git a/base/win/object_watcher.h b/base/win/object_watcher.h |
| index e1e86fe73aa38e421ef40eaaead7d550bf14812f..1f5d067c441006c17d4887ab1f9f40dc31b4c433 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,19 @@ class BASE_EXPORT ObjectWatcher : public MessageLoop::DestructionObserver { |
| void Signal(Delegate* delegate); |
| - // MessageLoop::DestructionObserver implementation: |
| - void WillDestroyCurrentMessageLoop() override; |
| - |
| - // Internal state. |
| Closure callback_; |
|
grt (UTC plus 2)
2016/07/14 07:19:11
// A callback pre-bound to Signal() that is posted
fdoray
2016/07/18 16:05:18
Done.
|
| - 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; |
| + |
| + // Returned by RegisterWaitForSingleObject |
| + HANDLE wait_object_ = nullptr; |
| + |
| + // Used to get back to the origin thread |
| + scoped_refptr<SingleThreadTaskRunner> task_runner_; |
| + |
| + bool run_once_ = true; |
| + |
| WeakPtrFactory<ObjectWatcher> weak_factory_; |
| DISALLOW_COPY_AND_ASSIGN(ObjectWatcher); |