summaryrefslogtreecommitdiffstats
path: root/base/files
diff options
context:
space:
mode:
authordominich@chromium.org <dominich@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-18 00:26:25 +0000
committerdominich@chromium.org <dominich@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-18 00:26:25 +0000
commitf8a3f1375a5571da9d061aaf5bb816cab7d6ba29 (patch)
tree6fc6660c13658621ff9c9b80cee12812e6a0e76c /base/files
parent384e905449c7567be260f2f66a12c2b39be7d3b1 (diff)
downloadchromium_src-f8a3f1375a5571da9d061aaf5bb816cab7d6ba29.zip
chromium_src-f8a3f1375a5571da9d061aaf5bb816cab7d6ba29.tar.gz
chromium_src-f8a3f1375a5571da9d061aaf5bb816cab7d6ba29.tar.bz2
Mirror Windows implementation of CancelOnMessageLoopThread.
Before this change, there was a code path where the FilePathWatcher could have been canceled but the delegate_ was not set to NULL. At exit, the destructor would then call Cancel() which would try to post a task to the message loop. With this change, the delegate is correctly set to NULL when the MessageLoop is destroyed even if the FilePathWatcher itself has been canceled. This allows Cancel() from the destructor to do the right thing and not call into the MessageLoop. This implementation matches the Windows version which does not crash. BUG=83190 TEST=FilePathWatcherTest.* Review URL: http://codereview.chromium.org/7655028 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@97248 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/files')
-rw-r--r--base/files/file_path_watcher_linux.cc20
1 files changed, 11 insertions, 9 deletions
diff --git a/base/files/file_path_watcher_linux.cc b/base/files/file_path_watcher_linux.cc
index aa116e3..265366b 100644
--- a/base/files/file_path_watcher_linux.cc
+++ b/base/files/file_path_watcher_linux.cc
@@ -404,19 +404,21 @@ void FilePathWatcherImpl::Cancel() {
}
void FilePathWatcherImpl::CancelOnMessageLoopThread() {
- if (!is_cancelled()) {
+ if (!is_cancelled())
set_cancelled();
- MessageLoop::current()->RemoveDestructionObserver(this);
- for (WatchVector::iterator watch_entry(watches_.begin());
- watch_entry != watches_.end(); ++watch_entry) {
- if (watch_entry->watch_ != InotifyReader::kInvalidWatch)
- g_inotify_reader.Get().RemoveWatch(watch_entry->watch_, this);
- }
- watches_.clear();
+ if (delegate_) {
+ MessageLoop::current()->RemoveDestructionObserver(this);
delegate_ = NULL;
- target_.clear();
}
+
+ for (WatchVector::iterator watch_entry(watches_.begin());
+ watch_entry != watches_.end(); ++watch_entry) {
+ if (watch_entry->watch_ != InotifyReader::kInvalidWatch)
+ g_inotify_reader.Get().RemoveWatch(watch_entry->watch_, this);
+ }
+ watches_.clear();
+ target_.clear();
}
void FilePathWatcherImpl::WillDestroyCurrentMessageLoop() {