OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <fcntl.h> | 7 #include <fcntl.h> |
8 #include <sys/event.h> | 8 #include <sys/event.h> |
9 #include <sys/param.h> | 9 #include <sys/param.h> |
10 | 10 |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 if (fd == -1) | 203 if (fd == -1) |
204 return kNoFileDescriptor; | 204 return kNoFileDescriptor; |
205 return fd; | 205 return fd; |
206 } | 206 } |
207 | 207 |
208 void FilePathWatcherImpl::CloseFileDescriptor(uintptr_t* fd) { | 208 void FilePathWatcherImpl::CloseFileDescriptor(uintptr_t* fd) { |
209 if (*fd == kNoFileDescriptor) { | 209 if (*fd == kNoFileDescriptor) { |
210 return; | 210 return; |
211 } | 211 } |
212 | 212 |
213 if (HANDLE_EINTR(close(*fd)) != 0) { | 213 if (IGNORE_EINTR(close(*fd)) != 0) { |
214 DPLOG(ERROR) << "close"; | 214 DPLOG(ERROR) << "close"; |
215 } | 215 } |
216 *fd = kNoFileDescriptor; | 216 *fd = kNoFileDescriptor; |
217 } | 217 } |
218 | 218 |
219 bool FilePathWatcherImpl::AreKeventValuesValid(struct kevent* kevents, | 219 bool FilePathWatcherImpl::AreKeventValuesValid(struct kevent* kevents, |
220 int count) { | 220 int count) { |
221 if (count < 0) { | 221 if (count < 0) { |
222 DPLOG(ERROR) << "kevent"; | 222 DPLOG(ERROR) << "kevent"; |
223 return false; | 223 return false; |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
490 return; | 490 return; |
491 } | 491 } |
492 CancelOnMessageLoopThread(); | 492 CancelOnMessageLoopThread(); |
493 } | 493 } |
494 | 494 |
495 void FilePathWatcherImpl::CancelOnMessageLoopThread() { | 495 void FilePathWatcherImpl::CancelOnMessageLoopThread() { |
496 DCHECK(MessageLoopForIO::current()); | 496 DCHECK(MessageLoopForIO::current()); |
497 if (!is_cancelled()) { | 497 if (!is_cancelled()) { |
498 set_cancelled(); | 498 set_cancelled(); |
499 kqueue_watcher_.StopWatchingFileDescriptor(); | 499 kqueue_watcher_.StopWatchingFileDescriptor(); |
500 if (HANDLE_EINTR(close(kqueue_)) != 0) { | 500 if (IGNORE_EINTR(close(kqueue_)) != 0) { |
501 DPLOG(ERROR) << "close kqueue"; | 501 DPLOG(ERROR) << "close kqueue"; |
502 } | 502 } |
503 kqueue_ = -1; | 503 kqueue_ = -1; |
504 std::for_each(events_.begin(), events_.end(), ReleaseEvent); | 504 std::for_each(events_.begin(), events_.end(), ReleaseEvent); |
505 events_.clear(); | 505 events_.clear(); |
506 io_message_loop_ = NULL; | 506 io_message_loop_ = NULL; |
507 MessageLoop::current()->RemoveDestructionObserver(this); | 507 MessageLoop::current()->RemoveDestructionObserver(this); |
508 callback_.Reset(); | 508 callback_.Reset(); |
509 } | 509 } |
510 } | 510 } |
511 | 511 |
512 } // namespace | 512 } // namespace |
513 | 513 |
514 FilePathWatcher::FilePathWatcher() { | 514 FilePathWatcher::FilePathWatcher() { |
515 impl_ = new FilePathWatcherImpl(); | 515 impl_ = new FilePathWatcherImpl(); |
516 } | 516 } |
517 | 517 |
518 } // namespace base | 518 } // namespace base |
OLD | NEW |