| 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 "net/dns/notify_watcher_mac.h" | 5 #include "net/dns/notify_watcher_mac.h" |
| 6 | 6 |
| 7 #include <notify.h> | 7 #include <notify.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/posix/eintr_wrapper.h" | 10 #include "base/posix/eintr_wrapper.h" |
| 11 | 11 |
| 12 namespace net { | 12 namespace net { |
| 13 | 13 |
| 14 NotifyWatcherMac::NotifyWatcherMac() : notify_fd_(-1), notify_token_(-1) {} | 14 NotifyWatcherMac::NotifyWatcherMac() : notify_fd_(-1), notify_token_(-1) { |
| 15 } |
| 15 | 16 |
| 16 NotifyWatcherMac::~NotifyWatcherMac() { | 17 NotifyWatcherMac::~NotifyWatcherMac() { |
| 17 Cancel(); | 18 Cancel(); |
| 18 } | 19 } |
| 19 | 20 |
| 20 bool NotifyWatcherMac::Watch(const char* key, const CallbackType& callback) { | 21 bool NotifyWatcherMac::Watch(const char* key, const CallbackType& callback) { |
| 21 DCHECK(key); | 22 DCHECK(key); |
| 22 DCHECK(!callback.is_null()); | 23 DCHECK(!callback.is_null()); |
| 23 Cancel(); | 24 Cancel(); |
| 24 uint32_t status = notify_register_file_descriptor( | 25 uint32_t status = |
| 25 key, ¬ify_fd_, 0, ¬ify_token_); | 26 notify_register_file_descriptor(key, ¬ify_fd_, 0, ¬ify_token_); |
| 26 if (status != NOTIFY_STATUS_OK) | 27 if (status != NOTIFY_STATUS_OK) |
| 27 return false; | 28 return false; |
| 28 DCHECK_GE(notify_fd_, 0); | 29 DCHECK_GE(notify_fd_, 0); |
| 29 if (!base::MessageLoopForIO::current()->WatchFileDescriptor( | 30 if (!base::MessageLoopForIO::current()->WatchFileDescriptor( |
| 30 notify_fd_, | 31 notify_fd_, |
| 31 true, | 32 true, |
| 32 base::MessageLoopForIO::WATCH_READ, | 33 base::MessageLoopForIO::WATCH_READ, |
| 33 &watcher_, | 34 &watcher_, |
| 34 this)) { | 35 this)) { |
| 35 Cancel(); | 36 Cancel(); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 55 Cancel(); | 56 Cancel(); |
| 56 callback_.Run(false); | 57 callback_.Run(false); |
| 57 return; | 58 return; |
| 58 } | 59 } |
| 59 // Ignoring |token| value to avoid possible endianness mismatch: | 60 // Ignoring |token| value to avoid possible endianness mismatch: |
| 60 // http://openradar.appspot.com/8821081 | 61 // http://openradar.appspot.com/8821081 |
| 61 callback_.Run(true); | 62 callback_.Run(true); |
| 62 } | 63 } |
| 63 | 64 |
| 64 } // namespace net | 65 } // namespace net |
| OLD | NEW |