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

Unified Diff: content/common/file_path_watcher/file_path_watcher_inotify.cc

Issue 6670081: Move FilePathWatcher class from browser/... to common/... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments Created 9 years, 9 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
Index: content/common/file_path_watcher/file_path_watcher_inotify.cc
diff --git a/chrome/browser/file_path_watcher/file_path_watcher_inotify.cc b/content/common/file_path_watcher/file_path_watcher_inotify.cc
similarity index 93%
rename from chrome/browser/file_path_watcher/file_path_watcher_inotify.cc
rename to content/common/file_path_watcher/file_path_watcher_inotify.cc
index f067481e2de529721beea130c2f48f6b98227f69..bab1a0f6d8c595cd1a0d532499cbde3e206cd9db 100644
--- a/chrome/browser/file_path_watcher/file_path_watcher_inotify.cc
+++ b/content/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 "content/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,
Mattias Nissler (ping if slow) 2011/03/17 18:14:27 This is what I was referring to in my other commen
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());
delegate_ = delegate;
target_ = path;
@@ -360,9 +364,13 @@ 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()) {
+ // Watch was never called, so exit.
+ return;
+ }
+ // Switch to the file thread if necessary so we can access |watches_|.
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;
}
@@ -380,7 +388,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("/"));

Powered by Google App Engine
This is Rietveld 408576698