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

Unified Diff: base/files/file_path_watcher_win.cc

Issue 2523573002: Remove destruction observer from file_path_watcher_win.cc (Closed)
Patch Set: self-review 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 | « no previous file | 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_win.cc
diff --git a/base/files/file_path_watcher_win.cc b/base/files/file_path_watcher_win.cc
index 48470b6b3dbb05381a6cde56d47bdcc53dbcc211..2309947fab401e6b3cc44846c5a158eb62b022c9 100644
--- a/base/files/file_path_watcher_win.cc
+++ b/base/files/file_path_watcher_win.cc
@@ -11,7 +11,6 @@
#include "base/logging.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
-#include "base/message_loop/message_loop.h"
#include "base/threading/thread_task_runner_handle.h"
#include "base/time/time.h"
#include "base/win/object_watcher.h"
@@ -21,25 +20,19 @@ namespace base {
namespace {
class FilePathWatcherImpl : public FilePathWatcher::PlatformDelegate,
- public base::win::ObjectWatcher::Delegate,
- public MessageLoop::DestructionObserver {
+ public base::win::ObjectWatcher::Delegate {
public:
FilePathWatcherImpl()
: handle_(INVALID_HANDLE_VALUE),
recursive_watch_(false) {}
- // FilePathWatcher::PlatformDelegate overrides.
+ // FilePathWatcher::PlatformDelegate:
bool Watch(const FilePath& path,
bool recursive,
const FilePathWatcher::Callback& callback) override;
void Cancel() override;
- // Deletion of the FilePathWatcher will call Cancel() to dispose of this
- // object in the right thread. This also observes destruction of the required
- // cleanup thread, in case it quits before Cancel() is called.
- void WillDestroyCurrentMessageLoop() override;
-
- // Callback from MessageLoopForIO.
+ // base::win::ObjectWatcher::Delegate:
void OnObjectSignaled(HANDLE object) override;
private:
@@ -59,9 +52,6 @@ class FilePathWatcherImpl : public FilePathWatcher::PlatformDelegate,
// Destroy the watch handle.
void DestroyWatch();
- // Cleans up and stops observing the |task_runner_| thread.
- void CancelOnMessageLoopThread();
-
// Callback to notify upon changes.
FilePathWatcher::Callback callback_;
@@ -97,7 +87,6 @@ bool FilePathWatcherImpl::Watch(const FilePath& path,
callback_ = callback;
target_ = path;
recursive_watch_ = recursive;
- MessageLoop::current()->AddDestructionObserver(this);
File::Info file_info;
if (GetFileInfo(target_, &file_info)) {
@@ -120,30 +109,13 @@ void FilePathWatcherImpl::Cancel() {
return;
}
- // Switch to the file thread if necessary so we can stop |watcher_|.
- if (!task_runner()->BelongsToCurrentThread()) {
- task_runner()->PostTask(
- FROM_HERE, Bind(&FilePathWatcherImpl::CancelOnMessageLoopThread, this));
- } else {
- CancelOnMessageLoopThread();
- }
-}
-
-void FilePathWatcherImpl::CancelOnMessageLoopThread() {
DCHECK(task_runner()->BelongsToCurrentThread());
set_cancelled();
if (handle_ != INVALID_HANDLE_VALUE)
DestroyWatch();
- if (!callback_.is_null()) {
- MessageLoop::current()->RemoveDestructionObserver(this);
- callback_.Reset();
- }
-}
-
-void FilePathWatcherImpl::WillDestroyCurrentMessageLoop() {
- CancelOnMessageLoopThread();
+ callback_.Reset();
}
void FilePathWatcherImpl::OnObjectSignaled(HANDLE object) {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698