Chromium Code Reviews| Index: chrome/common/file_path_watcher/file_path_watcher_inotify.cc |
| diff --git a/chrome/browser/file_path_watcher/file_path_watcher_inotify.cc b/chrome/common/file_path_watcher/file_path_watcher_inotify.cc |
| similarity index 94% |
| rename from chrome/browser/file_path_watcher/file_path_watcher_inotify.cc |
| rename to chrome/common/file_path_watcher/file_path_watcher_inotify.cc |
| index f067481e2de529721beea130c2f48f6b98227f69..b899048d6faa3377d21afd3ce2abd9bc2bab183a 100644 |
| --- a/chrome/browser/file_path_watcher/file_path_watcher_inotify.cc |
| +++ b/chrome/common/file_path_watcher/file_path_watcher_inotify.cc |
| @@ -2,7 +2,7 @@ |
| // 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 "chrome/common/file_path_watcher/file_path_watcher.h" |
| #include <errno.h> |
| #include <string.h> |
| @@ -23,6 +23,7 @@ |
| #include "base/lazy_instance.h" |
| #include "base/logging.h" |
| #include "base/message_loop.h" |
| +#include "base/message_loop_proxy.h" |
| #include "base/scoped_ptr.h" |
| #include "base/synchronization/lock.h" |
| #include "base/task.h" |
| @@ -95,10 +96,12 @@ class FilePathWatcherImpl : public FilePathWatcher::PlatformDelegate { |
| // Start watching |path| for changes and notify |delegate| on each change. |
| // Returns true if watch for |path| has been added successfully. |
| - virtual bool Watch(const FilePath& path, FilePathWatcher::Delegate* delegate); |
| + virtual bool Watch(const FilePath& path, |
| + FilePathWatcher::Delegate* delegate, |
| + scoped_refptr<base::MessageLoopProxy> loop) OVERRIDE; |
| // Cancel the watch. This unregisters the instance with InotifyReader. |
| - virtual void Cancel(); |
| + virtual void Cancel() OVERRIDE; |
| private: |
| virtual ~FilePathWatcherImpl() {} |
| @@ -280,7 +283,7 @@ void InotifyReader::OnInotifyEvent(const inotify_event* event) { |
| for (WatcherSet::iterator watcher = watchers_[event->wd].begin(); |
| watcher != watchers_[event->wd].end(); |
| ++watcher) { |
| - BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| + (*watcher)->message_loop()->PostTask(FROM_HERE, |
| NewRunnableMethod(*watcher, |
| &FilePathWatcherImpl::OnFilePathChanged, |
| event->wd, |
| @@ -298,7 +301,7 @@ void FilePathWatcherImpl::OnFilePathChanged(InotifyReader::Watch fired_watch, |
| const FilePath::StringType& child, |
| bool created, |
| bool is_directory) { |
| - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| + DCHECK(MessageLoopForIO::current()); |
| // Find the entry in |watches_| that corresponds to |fired_watch|. |
| WatchVector::const_iterator watch_entry(watches_.begin()); |
| @@ -341,9 +344,10 @@ void FilePathWatcherImpl::OnFilePathChanged(InotifyReader::Watch fired_watch, |
| } |
| bool FilePathWatcherImpl::Watch(const FilePath& path, |
| - FilePathWatcher::Delegate* delegate) { |
| - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| + FilePathWatcher::Delegate* delegate, |
| + scoped_refptr<base::MessageLoopProxy>) { |
| DCHECK(target_.empty()); |
| + DCHECK(MessageLoopForIO::current()); |
|
Mattias Nissler (ping if slow)
2011/03/17 10:37:56
Why do you have MessageLoopForIO::current() here w
dmac
2011/03/17 17:16:48
This is the check to make sure that Watch is being
|
| delegate_ = delegate; |
| target_ = path; |
| @@ -361,8 +365,9 @@ bool FilePathWatcherImpl::Watch(const FilePath& path, |
| void FilePathWatcherImpl::Cancel() { |
| // Switch to the file thread if necessary so we can access |watches_|. |
| - if (!BrowserThread::CurrentlyOn(BrowserThread::FILE)) { |
| - BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| + if (message_loop().get() && |
| + !message_loop()->BelongsToCurrentThread()) { |
| + message_loop()->PostTask(FROM_HERE, |
| NewRunnableMethod(this, &FilePathWatcherImpl::Cancel)); |
| return; |
| } |
| @@ -380,7 +385,7 @@ void FilePathWatcherImpl::Cancel() { |
| bool FilePathWatcherImpl::UpdateWatches() { |
| // Ensure this runs on the file thread exclusively in order to avoid |
| // concurrency issues. |
| - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| + DCHECK(message_loop()->BelongsToCurrentThread()); |
| // Walk the list of watches and update them as we go. |
| FilePath path(FILE_PATH_LITERAL("/")); |