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

Unified Diff: base/files/file_path_watcher_linux.cc

Issue 369703003: Reduce usage of MessageLoopProxy in base/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 6 years, 2 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/files/file_path_watcher_kqueue.cc ('k') | base/files/file_path_watcher_win.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/files/file_path_watcher_linux.cc
diff --git a/base/files/file_path_watcher_linux.cc b/base/files/file_path_watcher_linux.cc
index fb5ba6202ae29a8266d9d1685e1d29f15af06b9c..94b155e4c1df0d9f85d7117b7f9efaa168251bca 100644
--- a/base/files/file_path_watcher_linux.cc
+++ b/base/files/file_path_watcher_linux.cc
@@ -28,9 +28,9 @@
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "base/message_loop/message_loop.h"
-#include "base/message_loop/message_loop_proxy.h"
#include "base/posix/eintr_wrapper.h"
#include "base/synchronization/lock.h"
+#include "base/thread_task_runner_handle.h"
#include "base/threading/thread.h"
namespace base {
@@ -117,7 +117,7 @@ class FilePathWatcherImpl : public FilePathWatcher::PlatformDelegate,
// Cancel the watch. This unregisters the instance with InotifyReader.
virtual void Cancel() override;
- // Cleans up and stops observing the message_loop() thread.
+ // Cleans up and stops observing the task_runner() thread.
virtual void CancelOnMessageLoopThread() override;
// Deletion of the FilePathWatcher will call Cancel() to dispose of this
@@ -346,12 +346,16 @@ void FilePathWatcherImpl::OnFilePathChanged(InotifyReader::Watch fired_watch,
bool created,
bool deleted,
bool is_dir) {
- if (!message_loop()->BelongsToCurrentThread()) {
- // Switch to message_loop() to access |watches_| safely.
- message_loop()->PostTask(
- FROM_HERE,
- Bind(&FilePathWatcherImpl::OnFilePathChanged, this,
- fired_watch, child, created, deleted, is_dir));
+ if (!task_runner()->RunsTasksOnCurrentThread()) {
+ // Switch to task_runner() to access |watches_| safely.
+ task_runner()->PostTask(FROM_HERE,
+ Bind(&FilePathWatcherImpl::OnFilePathChanged,
+ this,
+ fired_watch,
+ child,
+ created,
+ deleted,
+ is_dir));
return;
}
@@ -429,7 +433,7 @@ bool FilePathWatcherImpl::Watch(const FilePath& path,
DCHECK(target_.empty());
DCHECK(MessageLoopForIO::current());
- set_message_loop(MessageLoopProxy::current());
+ set_task_runner(ThreadTaskRunnerHandle::Get());
callback_ = callback;
target_ = path;
recursive_ = recursive;
@@ -447,23 +451,23 @@ bool FilePathWatcherImpl::Watch(const FilePath& path,
void FilePathWatcherImpl::Cancel() {
if (callback_.is_null()) {
- // Watch was never called, or the message_loop() thread is already gone.
+ // Watch was never called, or the task_runner() thread is already gone.
set_cancelled();
return;
}
- // Switch to the message_loop() if necessary so we can access |watches_|.
- if (!message_loop()->BelongsToCurrentThread()) {
- message_loop()->PostTask(FROM_HERE,
- Bind(&FilePathWatcher::CancelWatch,
- make_scoped_refptr(this)));
+ // Switch to the task_runner() if necessary so we can access |watches_|.
+ if (!task_runner()->RunsTasksOnCurrentThread()) {
+ task_runner()->PostTask(
+ FROM_HERE,
+ Bind(&FilePathWatcher::CancelWatch, make_scoped_refptr(this)));
} else {
CancelOnMessageLoopThread();
}
}
void FilePathWatcherImpl::CancelOnMessageLoopThread() {
- DCHECK(message_loop()->BelongsToCurrentThread());
+ DCHECK(task_runner()->RunsTasksOnCurrentThread());
set_cancelled();
if (!callback_.is_null()) {
@@ -485,9 +489,9 @@ void FilePathWatcherImpl::WillDestroyCurrentMessageLoop() {
}
void FilePathWatcherImpl::UpdateWatches() {
- // Ensure this runs on the message_loop() exclusively in order to avoid
+ // Ensure this runs on the task_runner() exclusively in order to avoid
// concurrency issues.
- DCHECK(message_loop()->BelongsToCurrentThread());
+ DCHECK(task_runner()->RunsTasksOnCurrentThread());
DCHECK(HasValidWatchVector());
// Walk the list of watches and update them as we go.
« no previous file with comments | « base/files/file_path_watcher_kqueue.cc ('k') | base/files/file_path_watcher_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698