Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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. | |
| 4 | |
| 5 #ifndef BASE_FILES_FILE_PATH_WATCHER_FSEVENTS_H_ | |
| 6 #define BASE_FILES_FILE_PATH_WATCHER_FSEVENTS_H_ | |
| 7 | |
| 8 #include <CoreServices/CoreServices.h> | |
| 9 | |
| 10 #include <vector> | |
| 11 | |
| 12 #include "base/files/file_path.h" | |
| 13 #include "base/files/file_path_watcher.h" | |
| 14 | |
| 15 namespace base { | |
| 16 | |
| 17 // There are trade-offs between the FSEvents implementation and a kqueue | |
| 18 // implementation. The biggest issues are that FSEvents on 10.6 sometimes drops | |
| 19 // events and kqueue does not trigger for modifications to a file in a watched | |
| 20 // 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.
| |
| 21 class FilePathWatcherFSEvents : public FilePathWatcher::PlatformDelegate { | |
| 22 public: | |
| 23 FilePathWatcherFSEvents(); | |
| 24 | |
| 25 // 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.
| |
| 26 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.
| |
| 27 | |
| 28 // (Re-)Initialize the event stream to start reporting events from | |
| 29 // |start_event|. | |
| 30 void UpdateEventStream(FSEventStreamEventId start_event); | |
| 31 | |
| 32 // FilePathWatcher::PlatformDelegate overrides. | |
| 33 virtual bool Watch(const FilePath& path, | |
| 34 bool recursive, | |
| 35 const FilePathWatcher::Callback& callback) OVERRIDE; | |
| 36 virtual void Cancel() OVERRIDE; | |
| 37 | |
| 38 private: | |
| 39 virtual ~FilePathWatcherFSEvents(); | |
| 40 | |
| 41 // Destroy the event stream. | |
| 42 void DestroyEventStream(); | |
| 43 | |
| 44 // 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.
| |
| 45 void StartEventStream(const base::FilePath& target, | |
| 46 FSEventStreamEventId start_event); | |
| 47 | |
| 48 // Cleans up and stops the event stream. | |
| 49 virtual void CancelOnMessageLoopThread() OVERRIDE; | |
| 50 | |
| 51 // Callback to notify upon changes. | |
| 52 FilePathWatcher::Callback callback_; | |
| 53 | |
| 54 // Target path to watch (passed to callback). | |
| 55 FilePath target_; | |
| 56 | |
| 57 // Backend stream we receive event callbacks from (strong reference). | |
| 58 FSEventStreamRef fsevent_stream_; | |
| 59 | |
| 60 DISALLOW_COPY_AND_ASSIGN(FilePathWatcherFSEvents); | |
| 61 }; | |
| 62 | |
| 63 } // namespace | |
| 64 | |
| 65 #endif // BASE_FILES_FILE_PATH_WATCHER_FSEVENTS_H_ | |
| OLD | NEW |