Skip to content

Commit

Permalink
Remove FilePathWatcher::PlatformDelegate::CancelOnMessageLoopThread().
Browse files Browse the repository at this point in the history
There is no reason to have this method in the PlatformDelegate
interface it can simply be declared in subclasses that need it.

BUG=650318

Review-Url: https://codereview.chromium.org/2372513005
Cr-Commit-Position: refs/heads/master@{#421583}
  • Loading branch information
fdoray authored and Commit bot committed Sep 28, 2016
1 parent 3bf8b59 commit 4430f9e
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 36 deletions.
6 changes: 0 additions & 6 deletions base/files/file_path_watcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@ FilePathWatcher::~FilePathWatcher() {
impl_->Cancel();
}

// static
void FilePathWatcher::CancelWatch(
const scoped_refptr<PlatformDelegate>& delegate) {
delegate->CancelOnMessageLoopThread();
}

// static
bool FilePathWatcher::RecursiveWatchAvailable() {
#if (defined(OS_MACOSX) && !defined(OS_IOS)) || defined(OS_WIN) || \
Expand Down
5 changes: 0 additions & 5 deletions base/files/file_path_watcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,6 @@ class BASE_EXPORT FilePathWatcher {

virtual ~PlatformDelegate();

// Stop watching. This is only called on the thread of the appropriate
// message loop. Since it can also be called more than once, it should
// check |is_cancelled()| to avoid duplicate work.
virtual void CancelOnMessageLoopThread() = 0;

scoped_refptr<base::SingleThreadTaskRunner> task_runner() const {
return task_runner_;
}
Expand Down
2 changes: 1 addition & 1 deletion base/files/file_path_watcher_fsevents.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class FilePathWatcherFSEvents : public FilePathWatcher::PlatformDelegate {
const FilePath& resolved_target);

// Cleans up and stops the event stream.
void CancelOnMessageLoopThread() override;
void CancelOnMessageLoopThread();

// (Re-)Initialize the event stream to start reporting events from
// |start_event|.
Expand Down
2 changes: 1 addition & 1 deletion base/files/file_path_watcher_kqueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class FilePathWatcherKQueue : public FilePathWatcher::PlatformDelegate,
typedef std::vector<struct kevent> EventVector;

// Can only be called on |io_task_runner_|'s thread.
void CancelOnMessageLoopThread() override;
void CancelOnMessageLoopThread();

// Returns true if the kevent values are error free.
bool AreKeventValuesValid(struct kevent* kevents, int count);
Expand Down
21 changes: 9 additions & 12 deletions base/files/file_path_watcher_linux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ class FilePathWatcherImpl : public FilePathWatcher::PlatformDelegate {

// Cancel the watch. This unregisters the instance with InotifyReader.
void Cancel() override;
void CancelOnMessageLoopThread() override;
void CancelOnMessageLoopThreadOrInDestructor();

// Inotify watches are installed for all directory components of |target_|.
Expand Down Expand Up @@ -329,8 +328,8 @@ void FilePathWatcherImpl::OnFilePathChanged(InotifyReader::Watch fired_watch,
return;
}

// Check to see if CancelOnMessageLoopThread() has already been called.
// May happen when code flow reaches here from the PostTask() above.
// Check to see if CancelOnMessageLoopThreadOrInDestructor() has already been
// called. May happen when code flow reaches here from the PostTask() above.
if (watches_.empty()) {
DCHECK(target_.empty());
return;
Expand Down Expand Up @@ -445,19 +444,17 @@ void FilePathWatcherImpl::Cancel() {
return;
}

// Switch to the message_loop() if necessary so we can access |watches_|.
// Switch to the task_runner() if necessary so we can access |watches_|.
if (!task_runner()->BelongsToCurrentThread()) {
task_runner()->PostTask(FROM_HERE, Bind(&FilePathWatcher::CancelWatch,
make_scoped_refptr(this)));
task_runner()->PostTask(
FROM_HERE,
Bind(&FilePathWatcherImpl::CancelOnMessageLoopThreadOrInDestructor,
this));
} else {
CancelOnMessageLoopThread();
CancelOnMessageLoopThreadOrInDestructor();
}
}

void FilePathWatcherImpl::CancelOnMessageLoopThread() {
CancelOnMessageLoopThreadOrInDestructor();
}

void FilePathWatcherImpl::CancelOnMessageLoopThreadOrInDestructor() {
DCHECK(in_destructor_ || task_runner()->BelongsToCurrentThread());

Expand All @@ -479,7 +476,7 @@ void FilePathWatcherImpl::CancelOnMessageLoopThreadOrInDestructor() {
}

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(task_runner()->BelongsToCurrentThread());
DCHECK(HasValidWatchVector());
Expand Down
6 changes: 0 additions & 6 deletions base/files/file_path_watcher_mac.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,6 @@ class FilePathWatcherImpl : public FilePathWatcher::PlatformDelegate {
set_cancelled();
}

void CancelOnMessageLoopThread() override {
if (impl_.get())
impl_->Cancel();
set_cancelled();
}

protected:
~FilePathWatcherImpl() override {}

Expand Down
2 changes: 0 additions & 2 deletions base/files/file_path_watcher_stub.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ class FilePathWatcherImpl : public FilePathWatcher::PlatformDelegate {

void Cancel() override {}

void CancelOnMessageLoopThread() override {}

protected:
~FilePathWatcherImpl() override {}
};
Expand Down
6 changes: 3 additions & 3 deletions base/files/file_path_watcher_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class FilePathWatcherImpl : public FilePathWatcher::PlatformDelegate,
void DestroyWatch();

// Cleans up and stops observing the |task_runner_| thread.
void CancelOnMessageLoopThread() override;
void CancelOnMessageLoopThread();

// Callback to notify upon changes.
FilePathWatcher::Callback callback_;
Expand Down Expand Up @@ -122,8 +122,8 @@ void FilePathWatcherImpl::Cancel() {

// Switch to the file thread if necessary so we can stop |watcher_|.
if (!task_runner()->BelongsToCurrentThread()) {
task_runner()->PostTask(FROM_HERE, Bind(&FilePathWatcher::CancelWatch,
make_scoped_refptr(this)));
task_runner()->PostTask(
FROM_HERE, Bind(&FilePathWatcherImpl::CancelOnMessageLoopThread, this));
} else {
CancelOnMessageLoopThread();
}
Expand Down

0 comments on commit 4430f9e

Please sign in to comment.