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

Unified Diff: base/files/file_path_watcher_kqueue.cc

Issue 2517323002: Remove destruction observer from base::FilePathWatcherKQueue. (Closed)
Patch Set: document that this must be called from a thread that supports FileDescriptorWatcher Created 4 years, 1 month 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/files/file_path_watcher_kqueue.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/files/file_path_watcher_kqueue.cc
diff --git a/base/files/file_path_watcher_kqueue.cc b/base/files/file_path_watcher_kqueue.cc
index 8a7b5c54fd7b7e69d28aa03ae74b3bca6b312b24..6879a26202eccd1d75e3fe2db44efc2bfd2ab297 100644
--- a/base/files/file_path_watcher_kqueue.cc
+++ b/base/files/file_path_watcher_kqueue.cc
@@ -229,10 +229,6 @@ bool FilePathWatcherKQueue::UpdateWatches(bool* target_file_affected) {
return true;
}
-void FilePathWatcherKQueue::WillDestroyCurrentMessageLoop() {
- CancelOnMessageLoopThread();
-}
-
bool FilePathWatcherKQueue::Watch(const FilePath& path,
bool recursive,
const FilePathWatcher::Callback& callback) {
@@ -245,7 +241,6 @@ bool FilePathWatcherKQueue::Watch(const FilePath& path,
callback_ = callback;
target_ = path;
- MessageLoop::current()->AddDestructionObserver(this);
set_task_runner(ThreadTaskRunnerHandle::Get());
kqueue_ = kqueue();
@@ -272,7 +267,7 @@ bool FilePathWatcherKQueue::Watch(const FilePath& path,
// This creates an ownership cycle (|this| owns |kqueue_watch_controller_|
// which owns a callback which owns |this|). The cycle is broken when
- // |kqueue_watch_controller_| is reset in CancelOnMessageLoopThread().
+ // |kqueue_watch_controller_| is reset in Cancel().
kqueue_watch_controller_ = FileDescriptorWatcher::WatchReadable(
kqueue_, Bind(&FilePathWatcherKQueue::OnKQueueReadable, this));
return true;
@@ -283,12 +278,19 @@ void FilePathWatcherKQueue::Cancel() {
set_cancelled();
return;
}
- if (!task_runner()->BelongsToCurrentThread()) {
- task_runner()->PostTask(FROM_HERE,
- base::Bind(&FilePathWatcherKQueue::Cancel, this));
- return;
+
+ DCHECK(task_runner()->BelongsToCurrentThread());
+ if (!is_cancelled()) {
+ set_cancelled();
+ kqueue_watch_controller_.reset();
+ if (IGNORE_EINTR(close(kqueue_)) != 0) {
+ DPLOG(ERROR) << "close kqueue";
+ }
+ kqueue_ = -1;
+ std::for_each(events_.begin(), events_.end(), ReleaseEvent);
+ events_.clear();
+ callback_.Reset();
}
- CancelOnMessageLoopThread();
}
void FilePathWatcherKQueue::OnKQueueReadable() {
@@ -363,20 +365,4 @@ void FilePathWatcherKQueue::OnKQueueReadable() {
}
}
-void FilePathWatcherKQueue::CancelOnMessageLoopThread() {
- DCHECK(!task_runner() || task_runner()->BelongsToCurrentThread());
- if (!is_cancelled()) {
- set_cancelled();
- kqueue_watch_controller_.reset();
- if (IGNORE_EINTR(close(kqueue_)) != 0) {
- DPLOG(ERROR) << "close kqueue";
- }
- kqueue_ = -1;
- std::for_each(events_.begin(), events_.end(), ReleaseEvent);
- events_.clear();
- MessageLoop::current()->RemoveDestructionObserver(this);
- callback_.Reset();
- }
-}
-
} // namespace base
« no previous file with comments | « base/files/file_path_watcher_kqueue.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698