Index: content/common/file_path_watcher/file_path_watcher_win.cc |
diff --git a/chrome/browser/file_path_watcher/file_path_watcher_win.cc b/content/common/file_path_watcher/file_path_watcher_win.cc |
similarity index 92% |
rename from chrome/browser/file_path_watcher/file_path_watcher_win.cc |
rename to content/common/file_path_watcher/file_path_watcher_win.cc |
index c2f49b937ca55a352853e9b79e44a2ffcad28e2e..cf0318dd71cbde3267bf75c57a8bcd56289f17c7 100644 |
--- a/chrome/browser/file_path_watcher/file_path_watcher_win.cc |
+++ b/content/common/file_path_watcher/file_path_watcher_win.cc |
@@ -2,11 +2,12 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#include "chrome/browser/file_path_watcher/file_path_watcher.h" |
+#include "content/common/file_path_watcher/file_path_watcher.h" |
#include "base/file_path.h" |
#include "base/file_util.h" |
#include "base/logging.h" |
+#include "base/message_loop_proxy.h" |
#include "base/ref_counted.h" |
#include "base/time.h" |
#include "base/win/object_watcher.h" |
@@ -18,8 +19,11 @@ class FilePathWatcherImpl : public FilePathWatcher::PlatformDelegate, |
public: |
FilePathWatcherImpl() : delegate_(NULL), handle_(INVALID_HANDLE_VALUE) {} |
- virtual bool Watch(const FilePath& path, FilePathWatcher::Delegate* delegate); |
- virtual void Cancel(); |
+ // FilePathWatcher::PlatformDelegate overrides. |
+ virtual bool Watch(const FilePath& path, |
+ FilePathWatcher::Delegate* delegate, |
+ scoped_refptr<base::MessageLoopProxy> loop) OVERRIDE; |
+ virtual void Cancel() OVERRIDE; |
// Callback from MessageLoopForIO. |
virtual void OnObjectSignaled(HANDLE object); |
@@ -63,7 +67,8 @@ class FilePathWatcherImpl : public FilePathWatcher::PlatformDelegate, |
}; |
bool FilePathWatcherImpl::Watch(const FilePath& path, |
- FilePathWatcher::Delegate* delegate) { |
+ FilePathWatcher::Delegate* delegate, |
+ scoped_refptr<base::MessageLoopProxy>) { |
DCHECK(target_.value().empty()); // Can only watch one path. |
delegate_ = delegate; |
target_ = path; |
@@ -77,9 +82,13 @@ bool FilePathWatcherImpl::Watch(const FilePath& path, |
} |
void FilePathWatcherImpl::Cancel() { |
- // Switch to the file thread if necessary so we can stop |watcher_|. |
- if (!BrowserThread::CurrentlyOn(BrowserThread::FILE)) { |
- BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
+ if (!message_loop().get()) { |
+ // Watch was never called, so exit. |
+ return; |
+ } |
+ // Switch to the file thread if necessary so we can stop |watcher_|. |
Mattias Nissler (ping if slow)
2011/03/17 18:14:27
indentation
|
+ if (!message_loop()->BelongsToCurrentThread()) { |
+ message_loop()->PostTask(FROM_HERE, |
NewRunnableMethod(this, &FilePathWatcherImpl::Cancel)); |
return; |
} |