Update broken references to image assets
[chromium-blink-merge.git] / base / files / file_path_watcher_fsevents.h
blob300aa761dfa05e6b7b907453119c6ac0fbf281f3
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 // FilePathWatcher::PlatformDelegate overrides.
28 bool Watch(const FilePath& path,
29 bool recursive,
30 const FilePathWatcher::Callback& callback) override;
31 void Cancel() override;
33 private:
34 static void FSEventsCallback(ConstFSEventStreamRef stream,
35 void* event_watcher,
36 size_t num_events,
37 void* event_paths,
38 const FSEventStreamEventFlags flags[],
39 const FSEventStreamEventId event_ids[]);
41 ~FilePathWatcherFSEvents() override;
43 // Called from FSEventsCallback whenever there is a change to the paths.
44 void OnFilePathsChanged(const std::vector<FilePath>& paths);
46 // Called on the message_loop() thread to dispatch path events. Can't access
47 // target_ and resolved_target_ directly as those are modified on the
48 // libdispatch thread.
49 void DispatchEvents(const std::vector<FilePath>& paths,
50 const FilePath& target,
51 const FilePath& resolved_target);
53 // Cleans up and stops the event stream.
54 void CancelOnMessageLoopThread() override;
56 // (Re-)Initialize the event stream to start reporting events from
57 // |start_event|.
58 void UpdateEventStream(FSEventStreamEventId start_event);
60 // Returns true if resolving the target path got a different result than
61 // last time it was done.
62 bool ResolveTargetPath();
64 // Report an error watching the given target.
65 void ReportError(const FilePath& target);
67 // Destroy the event stream.
68 void DestroyEventStream();
70 // Start watching the FSEventStream.
71 void StartEventStream(FSEventStreamEventId start_event, const FilePath& path);
73 // Callback to notify upon changes.
74 // (Only accessed from the message_loop() thread.)
75 FilePathWatcher::Callback callback_;
77 // Target path to watch (passed to callback).
78 // (Only accessed from the libdispatch thread.)
79 FilePath target_;
81 // Target path with all symbolic links resolved.
82 // (Only accessed from the libdispatch thread.)
83 FilePath resolved_target_;
85 // Backend stream we receive event callbacks from (strong reference).
86 // (Only accessed from the libdispatch thread.)
87 FSEventStreamRef fsevent_stream_;
89 DISALLOW_COPY_AND_ASSIGN(FilePathWatcherFSEvents);
92 } // namespace base
94 #endif // BASE_FILES_FILE_PATH_WATCHER_FSEVENTS_H_