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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 CFOptionFlags callback_types = 0; | 92 CFOptionFlags callback_types = 0; |
93 if (mode & WATCH_READ) { | 93 if (mode & WATCH_READ) { |
94 callback_types |= kCFFileDescriptorReadCallBack; | 94 callback_types |= kCFFileDescriptorReadCallBack; |
95 } | 95 } |
96 if (mode & WATCH_WRITE) { | 96 if (mode & WATCH_WRITE) { |
97 callback_types |= kCFFileDescriptorWriteCallBack; | 97 callback_types |= kCFFileDescriptorWriteCallBack; |
98 } | 98 } |
99 | 99 |
100 CFFileDescriptorRef fdref = controller->fdref_; | 100 CFFileDescriptorRef fdref = controller->fdref_; |
101 if (fdref == NULL) { | 101 if (fdref == NULL) { |
102 base::mac::ScopedCFTypeRef<CFFileDescriptorRef> scoped_fdref( | 102 base::ScopedCFTypeRef<CFFileDescriptorRef> scoped_fdref( |
103 CFFileDescriptorCreate(kCFAllocatorDefault, fd, false, HandleFdIOEvent, | 103 CFFileDescriptorCreate( |
104 &source_context)); | 104 kCFAllocatorDefault, fd, false, HandleFdIOEvent, &source_context)); |
105 if (scoped_fdref == NULL) { | 105 if (scoped_fdref == NULL) { |
106 NOTREACHED() << "CFFileDescriptorCreate failed"; | 106 NOTREACHED() << "CFFileDescriptorCreate failed"; |
107 return false; | 107 return false; |
108 } | 108 } |
109 | 109 |
110 CFFileDescriptorEnableCallBacks(scoped_fdref, callback_types); | 110 CFFileDescriptorEnableCallBacks(scoped_fdref, callback_types); |
111 | 111 |
112 // TODO(wtc): what should the 'order' argument be? | 112 // TODO(wtc): what should the 'order' argument be? |
113 base::mac::ScopedCFTypeRef<CFRunLoopSourceRef> scoped_fd_source( | 113 base::ScopedCFTypeRef<CFRunLoopSourceRef> scoped_fd_source( |
114 CFFileDescriptorCreateRunLoopSource(kCFAllocatorDefault, | 114 CFFileDescriptorCreateRunLoopSource( |
115 scoped_fdref, | 115 kCFAllocatorDefault, scoped_fdref, 0)); |
116 0)); | |
117 if (scoped_fd_source == NULL) { | 116 if (scoped_fd_source == NULL) { |
118 NOTREACHED() << "CFFileDescriptorCreateRunLoopSource failed"; | 117 NOTREACHED() << "CFFileDescriptorCreateRunLoopSource failed"; |
119 return false; | 118 return false; |
120 } | 119 } |
121 CFRunLoopAddSource(run_loop(), scoped_fd_source, kCFRunLoopCommonModes); | 120 CFRunLoopAddSource(run_loop(), scoped_fd_source, kCFRunLoopCommonModes); |
122 | 121 |
123 // Transfer ownership of scoped_fdref and fd_source to controller. | 122 // Transfer ownership of scoped_fdref and fd_source to controller. |
124 controller->Init(scoped_fdref.release(), callback_types, | 123 controller->Init(scoped_fdref.release(), callback_types, |
125 scoped_fd_source.release(), persistent); | 124 scoped_fd_source.release(), persistent); |
126 } else { | 125 } else { |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 | 199 |
201 // 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 |
202 // valid and the controller is persistent. | 201 // valid and the controller is persistent. |
203 if (CFFileDescriptorIsValid(fdref) && controller->is_persistent_) { | 202 if (CFFileDescriptorIsValid(fdref) && controller->is_persistent_) { |
204 DCHECK_EQ(fdref, controller->fdref_); | 203 DCHECK_EQ(fdref, controller->fdref_); |
205 CFFileDescriptorEnableCallBacks(fdref, callback_types); | 204 CFFileDescriptorEnableCallBacks(fdref, callback_types); |
206 } | 205 } |
207 } | 206 } |
208 | 207 |
209 } // namespace base | 208 } // namespace base |
OLD | NEW |