Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3032)

Unified Diff: base/win/object_watcher.h

Issue 2125763003: Remove MessageLoop::current() from base::win::ObjectWatcher. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: CR grt #12 (comments) Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/process/kill_win.cc ('k') | base/win/object_watcher.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
« no previous file with comments | « base/process/kill_win.cc ('k') | base/win/object_watcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698