OLD | NEW |
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_KQUEUE_H_ | 5 #ifndef BASE_FILES_FILE_PATH_WATCHER_KQUEUE_H_ |
6 #define BASE_FILES_FILE_PATH_WATCHER_KQUEUE_H_ | 6 #define BASE_FILES_FILE_PATH_WATCHER_KQUEUE_H_ |
7 | 7 |
8 #include <sys/event.h> | 8 #include <sys/event.h> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
12 #include "base/files/file_path_watcher.h" | 12 #include "base/files/file_path_watcher.h" |
13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
14 #include "base/message_loop/message_loop_proxy.h" | |
15 | 14 |
16 namespace base { | 15 namespace base { |
17 | 16 |
18 // Mac-specific file watcher implementation based on kqueue. | 17 // Mac-specific file watcher implementation based on kqueue. |
19 // The Linux and Windows versions are able to detect: | 18 // The Linux and Windows versions are able to detect: |
20 // - file creation/deletion/modification in a watched directory | 19 // - file creation/deletion/modification in a watched directory |
21 // - file creation/deletion/modification for a watched file | 20 // - file creation/deletion/modification for a watched file |
22 // - modifications to the paths to a watched object that would affect the | 21 // - modifications to the paths to a watched object that would affect the |
23 // object such as renaming/attibute changes etc. | 22 // object such as renaming/attibute changes etc. |
24 // The kqueue implementation will handle all of the items in the list above | 23 // The kqueue implementation will handle all of the items in the list above |
(...skipping 27 matching lines...) Expand all Loading... |
52 class EventData { | 51 class EventData { |
53 public: | 52 public: |
54 EventData(const FilePath& path, const FilePath::StringType& subdir) | 53 EventData(const FilePath& path, const FilePath::StringType& subdir) |
55 : path_(path), subdir_(subdir) { } | 54 : path_(path), subdir_(subdir) { } |
56 FilePath path_; // Full path to this item. | 55 FilePath path_; // Full path to this item. |
57 FilePath::StringType subdir_; // Path to any sub item. | 56 FilePath::StringType subdir_; // Path to any sub item. |
58 }; | 57 }; |
59 | 58 |
60 typedef std::vector<struct kevent> EventVector; | 59 typedef std::vector<struct kevent> EventVector; |
61 | 60 |
62 // Can only be called on |io_message_loop_|'s thread. | 61 // Can only be called on |io_task_runner_|'s thread. |
63 virtual void CancelOnMessageLoopThread() override; | 62 virtual void CancelOnMessageLoopThread() override; |
64 | 63 |
65 // Returns true if the kevent values are error free. | 64 // Returns true if the kevent values are error free. |
66 bool AreKeventValuesValid(struct kevent* kevents, int count); | 65 bool AreKeventValuesValid(struct kevent* kevents, int count); |
67 | 66 |
68 // Respond to a change of attributes of the path component represented by | 67 // Respond to a change of attributes of the path component represented by |
69 // |event|. Sets |target_file_affected| to true if |target_| is affected. | 68 // |event|. Sets |target_file_affected| to true if |target_| is affected. |
70 // Sets |update_watches| to true if |events_| need to be updated. | 69 // Sets |update_watches| to true if |events_| need to be updated. |
71 void HandleAttributesChange(const EventVector::iterator& event, | 70 void HandleAttributesChange(const EventVector::iterator& event, |
72 bool* target_file_affected, | 71 bool* target_file_affected, |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 // Returns true if kevent has open file descriptor. | 110 // Returns true if kevent has open file descriptor. |
112 static bool IsKeventFileDescriptorOpen(const struct kevent& event) { | 111 static bool IsKeventFileDescriptorOpen(const struct kevent& event) { |
113 return event.ident != kNoFileDescriptor; | 112 return event.ident != kNoFileDescriptor; |
114 } | 113 } |
115 | 114 |
116 static EventData* EventDataForKevent(const struct kevent& event) { | 115 static EventData* EventDataForKevent(const struct kevent& event) { |
117 return reinterpret_cast<EventData*>(event.udata); | 116 return reinterpret_cast<EventData*>(event.udata); |
118 } | 117 } |
119 | 118 |
120 EventVector events_; | 119 EventVector events_; |
121 scoped_refptr<base::MessageLoopProxy> io_message_loop_; | 120 scoped_refptr<base::SequencedTaskRunner> io_task_runner_; |
122 MessageLoopForIO::FileDescriptorWatcher kqueue_watcher_; | 121 MessageLoopForIO::FileDescriptorWatcher kqueue_watcher_; |
123 FilePathWatcher::Callback callback_; | 122 FilePathWatcher::Callback callback_; |
124 FilePath target_; | 123 FilePath target_; |
125 int kqueue_; | 124 int kqueue_; |
126 | 125 |
127 DISALLOW_COPY_AND_ASSIGN(FilePathWatcherKQueue); | 126 DISALLOW_COPY_AND_ASSIGN(FilePathWatcherKQueue); |
128 }; | 127 }; |
129 | 128 |
130 } // namespace base | 129 } // namespace base |
131 | 130 |
132 #endif // BASE_FILES_FILE_PATH_WATCHER_KQUEUE_H_ | 131 #endif // BASE_FILES_FILE_PATH_WATCHER_KQUEUE_H_ |
OLD | NEW |