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

Side by Side Diff: base/files/file_path_watcher_fsevents.h

Issue 2596273003: Remove ref-counting from FilePathWatcher. (Closed)
Patch Set: fix mac build error Created 3 years, 11 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 unified diff | Download patch
« no previous file with comments | « base/files/file_path_watcher.h ('k') | base/files/file_path_watcher_fsevents.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef BASE_FILES_FILE_PATH_WATCHER_FSEVENTS_H_ 5 #ifndef BASE_FILES_FILE_PATH_WATCHER_FSEVENTS_H_
6 #define BASE_FILES_FILE_PATH_WATCHER_FSEVENTS_H_ 6 #define BASE_FILES_FILE_PATH_WATCHER_FSEVENTS_H_
7 7
8 #include <CoreServices/CoreServices.h> 8 #include <CoreServices/CoreServices.h>
9 #include <stddef.h> 9 #include <stddef.h>
10 10
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/files/file_path.h" 13 #include "base/files/file_path.h"
14 #include "base/files/file_path_watcher.h" 14 #include "base/files/file_path_watcher.h"
15 #include "base/mac/scoped_dispatch_object.h" 15 #include "base/mac/scoped_dispatch_object.h"
16 #include "base/macros.h" 16 #include "base/macros.h"
17 #include "base/memory/weak_ptr.h"
17 18
18 namespace base { 19 namespace base {
19 20
20 // Mac-specific file watcher implementation based on FSEvents. 21 // Mac-specific file watcher implementation based on FSEvents.
21 // There are trade-offs between the FSEvents implementation and a kqueue 22 // There are trade-offs between the FSEvents implementation and a kqueue
22 // implementation. The biggest issues are that FSEvents on 10.6 sometimes drops 23 // implementation. The biggest issues are that FSEvents on 10.6 sometimes drops
23 // events and kqueue does not trigger for modifications to a file in a watched 24 // events and kqueue does not trigger for modifications to a file in a watched
24 // directory. See file_path_watcher_mac.cc for the code that decides when to 25 // directory. See file_path_watcher_mac.cc for the code that decides when to
25 // use which one. 26 // use which one.
26 class FilePathWatcherFSEvents : public FilePathWatcher::PlatformDelegate { 27 class FilePathWatcherFSEvents : public FilePathWatcher::PlatformDelegate {
27 public: 28 public:
28 FilePathWatcherFSEvents(); 29 FilePathWatcherFSEvents();
30 ~FilePathWatcherFSEvents() override;
29 31
30 // FilePathWatcher::PlatformDelegate overrides. 32 // FilePathWatcher::PlatformDelegate overrides.
31 bool Watch(const FilePath& path, 33 bool Watch(const FilePath& path,
32 bool recursive, 34 bool recursive,
33 const FilePathWatcher::Callback& callback) override; 35 const FilePathWatcher::Callback& callback) override;
34 void Cancel() override; 36 void Cancel() override;
35 37
36 private: 38 private:
37 static void FSEventsCallback(ConstFSEventStreamRef stream, 39 static void FSEventsCallback(ConstFSEventStreamRef stream,
38 void* event_watcher, 40 void* event_watcher,
39 size_t num_events, 41 size_t num_events,
40 void* event_paths, 42 void* event_paths,
41 const FSEventStreamEventFlags flags[], 43 const FSEventStreamEventFlags flags[],
42 const FSEventStreamEventId event_ids[]); 44 const FSEventStreamEventId event_ids[]);
43 45
44 ~FilePathWatcherFSEvents() override;
45
46 // Called from FSEventsCallback whenever there is a change to the paths. 46 // Called from FSEventsCallback whenever there is a change to the paths.
47 void OnFilePathsChanged(const std::vector<FilePath>& paths); 47 void OnFilePathsChanged(const std::vector<FilePath>& paths);
48 48
49 // Called on the message_loop() thread to dispatch path events. Can't access 49 // Called on the message_loop() thread to dispatch path events. Can't access
50 // target_ and resolved_target_ directly as those are modified on the 50 // target_ and resolved_target_ directly as those are modified on the
51 // libdispatch thread. 51 // libdispatch thread.
52 void DispatchEvents(const std::vector<FilePath>& paths, 52 void DispatchEvents(const std::vector<FilePath>& paths,
53 const FilePath& target, 53 const FilePath& target,
54 const FilePath& resolved_target); 54 const FilePath& resolved_target);
55 55
56 // Cleans up and stops the event stream.
57 void CancelOnMessageLoopThread();
58
59 // (Re-)Initialize the event stream to start reporting events from 56 // (Re-)Initialize the event stream to start reporting events from
60 // |start_event|. 57 // |start_event|.
61 void UpdateEventStream(FSEventStreamEventId start_event); 58 void UpdateEventStream(FSEventStreamEventId start_event);
62 59
63 // Returns true if resolving the target path got a different result than 60 // Returns true if resolving the target path got a different result than
64 // last time it was done. 61 // last time it was done.
65 bool ResolveTargetPath(); 62 bool ResolveTargetPath();
66 63
67 // Report an error watching the given target. 64 // Report an error watching the given target.
68 void ReportError(const FilePath& target); 65 void ReportError(const FilePath& target);
(...skipping 16 matching lines...) Expand all
85 FilePath target_; 82 FilePath target_;
86 83
87 // Target path with all symbolic links resolved. 84 // Target path with all symbolic links resolved.
88 // (Only accessed from the libdispatch queue.) 85 // (Only accessed from the libdispatch queue.)
89 FilePath resolved_target_; 86 FilePath resolved_target_;
90 87
91 // Backend stream we receive event callbacks from (strong reference). 88 // Backend stream we receive event callbacks from (strong reference).
92 // (Only accessed from the libdispatch queue.) 89 // (Only accessed from the libdispatch queue.)
93 FSEventStreamRef fsevent_stream_; 90 FSEventStreamRef fsevent_stream_;
94 91
92 WeakPtrFactory<FilePathWatcherFSEvents> weak_factory_;
93
95 DISALLOW_COPY_AND_ASSIGN(FilePathWatcherFSEvents); 94 DISALLOW_COPY_AND_ASSIGN(FilePathWatcherFSEvents);
96 }; 95 };
97 96
98 } // namespace base 97 } // namespace base
99 98
100 #endif // BASE_FILES_FILE_PATH_WATCHER_FSEVENTS_H_ 99 #endif // BASE_FILES_FILE_PATH_WATCHER_FSEVENTS_H_
OLDNEW
« no previous file with comments | « base/files/file_path_watcher.h ('k') | base/files/file_path_watcher_fsevents.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698