Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / base / files / file_path_watcher_fsevents.h
blob5640b4d54972aa8fe3feb06867df822bcf9fa7dd
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef BASE_FILES_FILE_PATH_WATCHER_FSEVENTS_H_
6 #define BASE_FILES_FILE_PATH_WATCHER_FSEVENTS_H_
8 #include <CoreServices/CoreServices.h>
10 #include <vector>
12 #include "base/files/file_path.h"
13 #include "base/files/file_path_watcher.h"
15 namespace base {
17 // Mac-specific file watcher implementation based on FSEvents.
18 // There are trade-offs between the FSEvents implementation and a kqueue
19 // implementation. The biggest issues are that FSEvents on 10.6 sometimes drops
20 // events and kqueue does not trigger for modifications to a file in a watched
21 // directory. See file_path_watcher_mac.cc for the code that decides when to
22 // use which one.
23 class FilePathWatcherFSEvents : public FilePathWatcher::PlatformDelegate {
24 public:
25 FilePathWatcherFSEvents();
27 // Called from the FSEvents callback whenever there is a change to the paths.
28 void OnFilePathsChanged(const std::vector<FilePath>& paths);
30 // (Re-)Initialize the event stream to start reporting events from
31 // |start_event|.
32 void UpdateEventStream(FSEventStreamEventId start_event);
34 // Returns true if resolving the target path got a different result than
35 // last time it was done.
36 bool ResolveTargetPath();
38 // FilePathWatcher::PlatformDelegate overrides.
39 virtual bool Watch(const FilePath& path,
40 bool recursive,
41 const FilePathWatcher::Callback& callback) OVERRIDE;
42 virtual void Cancel() OVERRIDE;
44 private:
45 virtual ~FilePathWatcherFSEvents();
47 // Destroy the event stream.
48 void DestroyEventStream();
50 // Start watching the FSEventStream.
51 void StartEventStream(FSEventStreamEventId start_event);
53 // Cleans up and stops the event stream.
54 virtual void CancelOnMessageLoopThread() OVERRIDE;
56 // Callback to notify upon changes.
57 FilePathWatcher::Callback callback_;
59 // Target path to watch (passed to callback).
60 FilePath target_;
62 // Target path with all symbolic links resolved.
63 FilePath resolved_target_;
65 // Backend stream we receive event callbacks from (strong reference).
66 FSEventStreamRef fsevent_stream_;
68 DISALLOW_COPY_AND_ASSIGN(FilePathWatcherFSEvents);
71 } // namespace base
73 #endif // BASE_FILES_FILE_PATH_WATCHER_FSEVENTS_H_