| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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/message_loop/message_pump_io_ios.h" | 5 #include "base/message_loop/message_pump_io_ios.h" |
| 6 | 6 |
| 7 namespace base { | 7 namespace base { |
| 8 | 8 |
| 9 MessagePumpIOSForIO::FileDescriptorWatcher::FileDescriptorWatcher() | 9 MessagePumpIOSForIO::FileDescriptorWatcher::FileDescriptorWatcher() |
| 10 : is_persistent_(false), | 10 : is_persistent_(false), |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 void MessagePumpIOSForIO::HandleFdIOEvent(CFFileDescriptorRef fdref, | 172 void MessagePumpIOSForIO::HandleFdIOEvent(CFFileDescriptorRef fdref, |
| 173 CFOptionFlags callback_types, | 173 CFOptionFlags callback_types, |
| 174 void* context) { | 174 void* context) { |
| 175 FileDescriptorWatcher* controller = | 175 FileDescriptorWatcher* controller = |
| 176 static_cast<FileDescriptorWatcher*>(context); | 176 static_cast<FileDescriptorWatcher*>(context); |
| 177 DCHECK_EQ(fdref, controller->fdref_); | 177 DCHECK_EQ(fdref, controller->fdref_); |
| 178 | 178 |
| 179 // Ensure that |fdref| will remain live for the duration of this function | 179 // Ensure that |fdref| will remain live for the duration of this function |
| 180 // call even if |controller| is deleted or |StopWatchingFileDescriptor()| is | 180 // call even if |controller| is deleted or |StopWatchingFileDescriptor()| is |
| 181 // called, either of which will cause |fdref| to be released. | 181 // called, either of which will cause |fdref| to be released. |
| 182 mac::ScopedCFTypeRef<CFFileDescriptorRef> scoped_fdref( | 182 ScopedCFTypeRef<CFFileDescriptorRef> scoped_fdref( |
| 183 fdref, base::scoped_policy::RETAIN); | 183 fdref, base::scoped_policy::RETAIN); |
| 184 | 184 |
| 185 int fd = CFFileDescriptorGetNativeDescriptor(fdref); | 185 int fd = CFFileDescriptorGetNativeDescriptor(fdref); |
| 186 MessagePumpIOSForIO* pump = controller->pump(); | 186 MessagePumpIOSForIO* pump = controller->pump(); |
| 187 if (callback_types & kCFFileDescriptorWriteCallBack) | 187 if (callback_types & kCFFileDescriptorWriteCallBack) |
| 188 controller->OnFileCanWriteWithoutBlocking(fd, pump); | 188 controller->OnFileCanWriteWithoutBlocking(fd, pump); |
| 189 | 189 |
| 190 // Perform the read callback only if the file descriptor has not been | 190 // Perform the read callback only if the file descriptor has not been |
| 191 // invalidated in the write callback. As |FileDescriptorWatcher| invalidates | 191 // invalidated in the write callback. As |FileDescriptorWatcher| invalidates |
| 192 // its file descriptor on destruction, the file descriptor being valid also | 192 // its file descriptor on destruction, the file descriptor being valid also |
| 193 // guarantees that |controller| has not been deleted. | 193 // guarantees that |controller| has not been deleted. |
| 194 if (callback_types & kCFFileDescriptorReadCallBack && | 194 if (callback_types & kCFFileDescriptorReadCallBack && |
| 195 CFFileDescriptorIsValid(fdref)) { | 195 CFFileDescriptorIsValid(fdref)) { |
| 196 DCHECK_EQ(fdref, controller->fdref_); | 196 DCHECK_EQ(fdref, controller->fdref_); |
| 197 controller->OnFileCanReadWithoutBlocking(fd, pump); | 197 controller->OnFileCanReadWithoutBlocking(fd, pump); |
| 198 } | 198 } |
| 199 | 199 |
| 200 // Re-enable callbacks after the read/write if the file descriptor is still | 200 // Re-enable callbacks after the read/write if the file descriptor is still |
| 201 // valid and the controller is persistent. | 201 // valid and the controller is persistent. |
| 202 if (CFFileDescriptorIsValid(fdref) && controller->is_persistent_) { | 202 if (CFFileDescriptorIsValid(fdref) && controller->is_persistent_) { |
| 203 DCHECK_EQ(fdref, controller->fdref_); | 203 DCHECK_EQ(fdref, controller->fdref_); |
| 204 CFFileDescriptorEnableCallBacks(fdref, callback_types); | 204 CFFileDescriptorEnableCallBacks(fdref, callback_types); |
| 205 } | 205 } |
| 206 } | 206 } |
| 207 | 207 |
| 208 } // namespace base | 208 } // namespace base |
| OLD | NEW |