Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(216)

Side by Side Diff: base/message_loop/message_pump_io_ios.cc

Issue 1950633002: Remove IOObservers from MessageLoopForIO. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: self review Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/message_loop/message_pump_io_ios.h ('k') | base/message_loop/message_pump_libevent.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 is_persistent_ = is_persistent; 44 is_persistent_ = is_persistent;
45 fdref_.reset(fdref); 45 fdref_.reset(fdref);
46 callback_types_ = callback_types; 46 callback_types_ = callback_types;
47 fd_source_.reset(fd_source); 47 fd_source_.reset(fd_source);
48 } 48 }
49 49
50 void MessagePumpIOSForIO::FileDescriptorWatcher::OnFileCanReadWithoutBlocking( 50 void MessagePumpIOSForIO::FileDescriptorWatcher::OnFileCanReadWithoutBlocking(
51 int fd, 51 int fd,
52 MessagePumpIOSForIO* pump) { 52 MessagePumpIOSForIO* pump) {
53 DCHECK(callback_types_ & kCFFileDescriptorReadCallBack); 53 DCHECK(callback_types_ & kCFFileDescriptorReadCallBack);
54 pump->WillProcessIOEvent();
55 watcher_->OnFileCanReadWithoutBlocking(fd); 54 watcher_->OnFileCanReadWithoutBlocking(fd);
56 pump->DidProcessIOEvent();
57 } 55 }
58 56
59 void MessagePumpIOSForIO::FileDescriptorWatcher::OnFileCanWriteWithoutBlocking( 57 void MessagePumpIOSForIO::FileDescriptorWatcher::OnFileCanWriteWithoutBlocking(
60 int fd, 58 int fd,
61 MessagePumpIOSForIO* pump) { 59 MessagePumpIOSForIO* pump) {
62 DCHECK(callback_types_ & kCFFileDescriptorWriteCallBack); 60 DCHECK(callback_types_ & kCFFileDescriptorWriteCallBack);
63 pump->WillProcessIOEvent();
64 watcher_->OnFileCanWriteWithoutBlocking(fd); 61 watcher_->OnFileCanWriteWithoutBlocking(fd);
65 pump->DidProcessIOEvent();
66 } 62 }
67 63
68 MessagePumpIOSForIO::MessagePumpIOSForIO() : weak_factory_(this) { 64 MessagePumpIOSForIO::MessagePumpIOSForIO() : weak_factory_(this) {
69 } 65 }
70 66
71 MessagePumpIOSForIO::~MessagePumpIOSForIO() { 67 MessagePumpIOSForIO::~MessagePumpIOSForIO() {
72 } 68 }
73 69
74 bool MessagePumpIOSForIO::WatchFileDescriptor( 70 bool MessagePumpIOSForIO::WatchFileDescriptor(
75 int fd, 71 int fd,
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 controller->set_watcher(delegate); 141 controller->set_watcher(delegate);
146 controller->set_pump(weak_factory_.GetWeakPtr()); 142 controller->set_pump(weak_factory_.GetWeakPtr());
147 143
148 return true; 144 return true;
149 } 145 }
150 146
151 void MessagePumpIOSForIO::RemoveRunLoopSource(CFRunLoopSourceRef source) { 147 void MessagePumpIOSForIO::RemoveRunLoopSource(CFRunLoopSourceRef source) {
152 CFRunLoopRemoveSource(run_loop(), source, kCFRunLoopCommonModes); 148 CFRunLoopRemoveSource(run_loop(), source, kCFRunLoopCommonModes);
153 } 149 }
154 150
155 void MessagePumpIOSForIO::AddIOObserver(IOObserver *obs) {
156 io_observers_.AddObserver(obs);
157 }
158
159 void MessagePumpIOSForIO::RemoveIOObserver(IOObserver *obs) {
160 io_observers_.RemoveObserver(obs);
161 }
162
163 void MessagePumpIOSForIO::WillProcessIOEvent() {
164 FOR_EACH_OBSERVER(IOObserver, io_observers_, WillProcessIOEvent());
165 }
166
167 void MessagePumpIOSForIO::DidProcessIOEvent() {
168 FOR_EACH_OBSERVER(IOObserver, io_observers_, DidProcessIOEvent());
169 }
170
171 // static 151 // static
172 void MessagePumpIOSForIO::HandleFdIOEvent(CFFileDescriptorRef fdref, 152 void MessagePumpIOSForIO::HandleFdIOEvent(CFFileDescriptorRef fdref,
173 CFOptionFlags callback_types, 153 CFOptionFlags callback_types,
174 void* context) { 154 void* context) {
175 FileDescriptorWatcher* controller = 155 FileDescriptorWatcher* controller =
176 static_cast<FileDescriptorWatcher*>(context); 156 static_cast<FileDescriptorWatcher*>(context);
177 DCHECK_EQ(fdref, controller->fdref_.get()); 157 DCHECK_EQ(fdref, controller->fdref_.get());
178 158
179 // Ensure that |fdref| will remain live for the duration of this function 159 // Ensure that |fdref| will remain live for the duration of this function
180 // call even if |controller| is deleted or |StopWatchingFileDescriptor()| is 160 // call even if |controller| is deleted or |StopWatchingFileDescriptor()| is
(...skipping 19 matching lines...) Expand all
200 180
201 // Re-enable callbacks after the read/write if the file descriptor is still 181 // Re-enable callbacks after the read/write if the file descriptor is still
202 // valid and the controller is persistent. 182 // valid and the controller is persistent.
203 if (CFFileDescriptorIsValid(fdref) && controller->is_persistent_) { 183 if (CFFileDescriptorIsValid(fdref) && controller->is_persistent_) {
204 DCHECK_EQ(fdref, controller->fdref_.get()); 184 DCHECK_EQ(fdref, controller->fdref_.get());
205 CFFileDescriptorEnableCallBacks(fdref, callback_types); 185 CFFileDescriptorEnableCallBacks(fdref, callback_types);
206 } 186 }
207 } 187 }
208 188
209 } // namespace base 189 } // namespace base
OLDNEW
« no previous file with comments | « base/message_loop/message_pump_io_ios.h ('k') | base/message_loop/message_pump_libevent.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698