summaryrefslogtreecommitdiffstats
path: root/base/object_watcher.cc
diff options
context:
space:
mode:
Diffstat (limited to 'base/object_watcher.cc')
-rw-r--r--base/object_watcher.cc13
1 files changed, 12 insertions, 1 deletions
diff --git a/base/object_watcher.cc b/base/object_watcher.cc
index 5e8c27b..9872a4c 100644
--- a/base/object_watcher.cc
+++ b/base/object_watcher.cc
@@ -29,7 +29,6 @@
#include "base/object_watcher.h"
-#include "base/message_loop.h"
#include "base/logging.h"
namespace base {
@@ -91,6 +90,10 @@ bool ObjectWatcher::StartWatching(HANDLE object, Delegate* delegate) {
}
watch_ = watch;
+
+ // We need to know if the current message loop is going away so we can
+ // prevent the wait thread from trying to access a dead message loop.
+ MessageLoop::current()->AddDestructionObserver(this);
return true;
}
@@ -124,6 +127,8 @@ bool ObjectWatcher::StopWatching() {
delete watch_;
watch_ = NULL;
+
+ MessageLoop::current()->RemoveDestructionObserver(this);
return true;
}
@@ -142,4 +147,10 @@ void CALLBACK ObjectWatcher::DoneWaiting(void* param, BOOLEAN timed_out) {
watch->origin_loop->PostTask(FROM_HERE, watch);
}
+void ObjectWatcher::WillDestroyCurrentMessageLoop() {
+ // Need to shutdown the watch so that we don't try to access the MessageLoop
+ // after this point.
+ StopWatching();
+}
+
} // namespace base