| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include "base/files/file_path_watcher.h" | 5 #include "base/files/file_path_watcher.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <string.h> | 8 #include <string.h> |
| 9 #include <sys/inotify.h> | 9 #include <sys/inotify.h> |
| 10 #include <sys/ioctl.h> | 10 #include <sys/ioctl.h> |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 | 151 |
| 152 DISALLOW_COPY_AND_ASSIGN(FilePathWatcherImpl); | 152 DISALLOW_COPY_AND_ASSIGN(FilePathWatcherImpl); |
| 153 }; | 153 }; |
| 154 | 154 |
| 155 class InotifyReaderTask : public Task { | 155 class InotifyReaderTask : public Task { |
| 156 public: | 156 public: |
| 157 InotifyReaderTask(InotifyReader* reader, int inotify_fd, int shutdown_fd) | 157 InotifyReaderTask(InotifyReader* reader, int inotify_fd, int shutdown_fd) |
| 158 : reader_(reader), | 158 : reader_(reader), |
| 159 inotify_fd_(inotify_fd), | 159 inotify_fd_(inotify_fd), |
| 160 shutdown_fd_(shutdown_fd) { | 160 shutdown_fd_(shutdown_fd) { |
| 161 // Make sure the file descriptors are good for use with select(). |
| 162 CHECK_LE(0, inotify_fd_); |
| 163 CHECK_GT(FD_SETSIZE, inotify_fd_); |
| 164 CHECK_LE(0, shutdown_fd_); |
| 165 CHECK_GT(FD_SETSIZE, shutdown_fd_); |
| 161 } | 166 } |
| 162 | 167 |
| 163 virtual void Run() { | 168 virtual void Run() { |
| 164 while (true) { | 169 while (true) { |
| 165 fd_set rfds; | 170 fd_set rfds; |
| 166 FD_ZERO(&rfds); | 171 FD_ZERO(&rfds); |
| 167 FD_SET(inotify_fd_, &rfds); | 172 FD_SET(inotify_fd_, &rfds); |
| 168 FD_SET(shutdown_fd_, &rfds); | 173 FD_SET(shutdown_fd_, &rfds); |
| 169 | 174 |
| 170 // Wait until some inotify events are available. | 175 // Wait until some inotify events are available. |
| (...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 487 } | 492 } |
| 488 | 493 |
| 489 } // namespace | 494 } // namespace |
| 490 | 495 |
| 491 FilePathWatcher::FilePathWatcher() { | 496 FilePathWatcher::FilePathWatcher() { |
| 492 impl_ = new FilePathWatcherImpl(); | 497 impl_ = new FilePathWatcherImpl(); |
| 493 } | 498 } |
| 494 | 499 |
| 495 } // namespace files | 500 } // namespace files |
| 496 } // namespace base | 501 } // namespace base |
| OLD | NEW |