Chromium Code Reviews| Index: base/files/file_path_watcher_linux.cc |
| diff --git a/base/files/file_path_watcher_linux.cc b/base/files/file_path_watcher_linux.cc |
| index 86c963c4fc60a20f3a4be1f79873cc6495d07cb6..c44135b8e22a99a1943c7c05689b9c5d4544fcce 100644 |
| --- a/base/files/file_path_watcher_linux.cc |
| +++ b/base/files/file_path_watcher_linux.cc |
| @@ -152,76 +152,62 @@ class FilePathWatcherImpl : public FilePathWatcher::PlatformDelegate, |
| DISALLOW_COPY_AND_ASSIGN(FilePathWatcherImpl); |
| }; |
| -class InotifyReaderTask : public Task { |
| - public: |
| - InotifyReaderTask(InotifyReader* reader, int inotify_fd, int shutdown_fd) |
| - : reader_(reader), |
| - inotify_fd_(inotify_fd), |
| - shutdown_fd_(shutdown_fd) { |
| - // Make sure the file descriptors are good for use with select(). |
| - CHECK_LE(0, inotify_fd_); |
| - CHECK_GT(FD_SETSIZE, inotify_fd_); |
| - CHECK_LE(0, shutdown_fd_); |
| - CHECK_GT(FD_SETSIZE, shutdown_fd_); |
| - } |
| - |
| - virtual void Run() { |
| - while (true) { |
| - fd_set rfds; |
| - FD_ZERO(&rfds); |
| - FD_SET(inotify_fd_, &rfds); |
| - FD_SET(shutdown_fd_, &rfds); |
| - |
| - // Wait until some inotify events are available. |
| - int select_result = |
| - HANDLE_EINTR(select(std::max(inotify_fd_, shutdown_fd_) + 1, |
| - &rfds, NULL, NULL, NULL)); |
| - if (select_result < 0) { |
| - DPLOG(WARNING) << "select failed"; |
| - return; |
| - } |
| +void InotifyReaderCallback( |
|
awong
2012/01/04 02:17:28
Move the parameters up to the ( and align there?
James Hawkins
2012/01/04 02:24:18
Give the same number of lines required, I prefer k
|
| + InotifyReader* reader, int inotify_fd, int shutdown_fd) { |
| + // Make sure the file descriptors are good for use with select(). |
| + CHECK_LE(0, inotify_fd); |
| + CHECK_GT(FD_SETSIZE, inotify_fd); |
| + CHECK_LE(0, shutdown_fd); |
| + CHECK_GT(FD_SETSIZE, shutdown_fd); |
| + |
| + while (true) { |
| + fd_set rfds; |
| + FD_ZERO(&rfds); |
| + FD_SET(inotify_fd, &rfds); |
| + FD_SET(shutdown_fd, &rfds); |
| + |
| + // Wait until some inotify events are available. |
| + int select_result = |
| + HANDLE_EINTR(select(std::max(inotify_fd, shutdown_fd) + 1, |
| + &rfds, NULL, NULL, NULL)); |
| + if (select_result < 0) { |
| + DPLOG(WARNING) << "select failed"; |
| + return; |
| + } |
| - if (FD_ISSET(shutdown_fd_, &rfds)) |
| - return; |
| + if (FD_ISSET(shutdown_fd, &rfds)) |
| + return; |
| - // Adjust buffer size to current event queue size. |
| - int buffer_size; |
| - int ioctl_result = HANDLE_EINTR(ioctl(inotify_fd_, FIONREAD, |
| - &buffer_size)); |
| + // Adjust buffer size to current event queue size. |
| + int buffer_size; |
| + int ioctl_result = HANDLE_EINTR(ioctl(inotify_fd, FIONREAD, |
| + &buffer_size)); |
| - if (ioctl_result != 0) { |
| - DPLOG(WARNING) << "ioctl failed"; |
| - return; |
| - } |
| + if (ioctl_result != 0) { |
| + DPLOG(WARNING) << "ioctl failed"; |
| + return; |
| + } |
| - std::vector<char> buffer(buffer_size); |
| + std::vector<char> buffer(buffer_size); |
| - ssize_t bytes_read = HANDLE_EINTR(read(inotify_fd_, &buffer[0], |
| - buffer_size)); |
| + ssize_t bytes_read = HANDLE_EINTR(read(inotify_fd, &buffer[0], |
| + buffer_size)); |
| - if (bytes_read < 0) { |
| - DPLOG(WARNING) << "read from inotify fd failed"; |
| - return; |
| - } |
| + if (bytes_read < 0) { |
| + DPLOG(WARNING) << "read from inotify fd failed"; |
| + return; |
| + } |
| - ssize_t i = 0; |
| - while (i < bytes_read) { |
| - inotify_event* event = reinterpret_cast<inotify_event*>(&buffer[i]); |
| - size_t event_size = sizeof(inotify_event) + event->len; |
| - DCHECK(i + event_size <= static_cast<size_t>(bytes_read)); |
| - reader_->OnInotifyEvent(event); |
| - i += event_size; |
| - } |
| + ssize_t i = 0; |
| + while (i < bytes_read) { |
| + inotify_event* event = reinterpret_cast<inotify_event*>(&buffer[i]); |
| + size_t event_size = sizeof(inotify_event) + event->len; |
| + DCHECK(i + event_size <= static_cast<size_t>(bytes_read)); |
| + reader->OnInotifyEvent(event); |
| + i += event_size; |
| } |
| } |
| - |
| - private: |
| - InotifyReader* reader_; |
| - int inotify_fd_; |
| - int shutdown_fd_; |
| - |
| - DISALLOW_COPY_AND_ASSIGN(InotifyReaderTask); |
| -}; |
| +} |
| static base::LazyInstance<InotifyReader> g_inotify_reader = |
| LAZY_INSTANCE_INITIALIZER; |
| @@ -234,7 +220,8 @@ InotifyReader::InotifyReader() |
| shutdown_pipe_[1] = -1; |
| if (inotify_fd_ >= 0 && pipe(shutdown_pipe_) == 0 && thread_.Start()) { |
| thread_.message_loop()->PostTask( |
| - FROM_HERE, new InotifyReaderTask(this, inotify_fd_, shutdown_pipe_[0])); |
| + FROM_HERE, base::Bind(&InotifyReaderCallback, this, inotify_fd_, |
| + shutdown_pipe_[0])); |
| valid_ = true; |
| } |
| } |