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