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

Unified Diff: base/files/file_path_watcher_fsevents.h

Issue 283423003: Use FSEvents for recursive file watch on Mac (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: nits Created 6 years, 7 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: base/files/file_path_watcher_fsevents.h
diff --git a/base/files/file_path_watcher_fsevents.h b/base/files/file_path_watcher_fsevents.h
new file mode 100644
index 0000000000000000000000000000000000000000..c1ace20347927023878bec921b667410c372c4ff
--- /dev/null
+++ b/base/files/file_path_watcher_fsevents.h
@@ -0,0 +1,65 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef BASE_FILES_FILE_PATH_WATCHER_FSEVENTS_H_
+#define BASE_FILES_FILE_PATH_WATCHER_FSEVENTS_H_
+
+#include <CoreServices/CoreServices.h>
+
+#include <vector>
+
+#include "base/files/file_path.h"
+#include "base/files/file_path_watcher.h"
+
+namespace base {
+
+// There are trade-offs between the FSEvents implementation and a kqueue
+// implementation. The biggest issues are that FSEvents on 10.6 sometimes drops
+// events and kqueue does not trigger for modifications to a file in a watched
+// directory.
Mattias Nissler (ping if slow) 2014/05/26 07:39:37 Would be good to add a sentence explaining which s
vandebo (ex-Chrome) 2014/05/28 00:26:55 Done.
+class FilePathWatcherFSEvents : public FilePathWatcher::PlatformDelegate {
+ public:
+ FilePathWatcherFSEvents();
+
+ // Called from the FSEvents callback whenever there is a change to the paths
Mattias Nissler (ping if slow) 2014/05/26 07:39:37 Missing period.
vandebo (ex-Chrome) 2014/05/28 00:26:55 Done.
+ void OnFilePathChanged(const std::vector<FilePath>& paths);
Mattias Nissler (ping if slow) 2014/05/26 07:39:37 nit: Name is inconsistent, should probably be OnFi
vandebo (ex-Chrome) 2014/05/28 00:26:55 Done.
+
+ // (Re-)Initialize the event stream to start reporting events from
+ // |start_event|.
+ void UpdateEventStream(FSEventStreamEventId start_event);
+
+ // FilePathWatcher::PlatformDelegate overrides.
+ virtual bool Watch(const FilePath& path,
+ bool recursive,
+ const FilePathWatcher::Callback& callback) OVERRIDE;
+ virtual void Cancel() OVERRIDE;
+
+ private:
+ virtual ~FilePathWatcherFSEvents();
+
+ // Destroy the event stream.
+ void DestroyEventStream();
+
+ // Start watchign the FSEventStream.
Mattias Nissler (ping if slow) 2014/05/26 07:39:37 *watching
vandebo (ex-Chrome) 2014/05/28 00:26:55 Done.
+ void StartEventStream(const base::FilePath& target,
+ FSEventStreamEventId start_event);
+
+ // Cleans up and stops the event stream.
+ virtual void CancelOnMessageLoopThread() OVERRIDE;
+
+ // Callback to notify upon changes.
+ FilePathWatcher::Callback callback_;
+
+ // Target path to watch (passed to callback).
+ FilePath target_;
+
+ // Backend stream we receive event callbacks from (strong reference).
+ FSEventStreamRef fsevent_stream_;
+
+ DISALLOW_COPY_AND_ASSIGN(FilePathWatcherFSEvents);
+};
+
+} // namespace
+
+#endif // BASE_FILES_FILE_PATH_WATCHER_FSEVENTS_H_

Powered by Google App Engine
This is Rietveld 408576698