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

Side by Side Diff: base/message_pump_mac.mm

Issue 149082: Handle message pump sources firing without delegates available (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 11 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2008 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_pump_mac.h" 5 #include "base/message_pump_mac.h"
6 6
7 #import <AppKit/AppKit.h> 7 #import <AppKit/AppKit.h>
8 #import <Foundation/Foundation.h> 8 #import <Foundation/Foundation.h>
9 #include <float.h> 9 #include <float.h>
10 10
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 174
175 // Called from the run loop. 175 // Called from the run loop.
176 // static 176 // static
177 void MessagePumpCFRunLoopBase::RunWorkSource(void* info) { 177 void MessagePumpCFRunLoopBase::RunWorkSource(void* info) {
178 MessagePumpCFRunLoopBase* self = static_cast<MessagePumpCFRunLoopBase*>(info); 178 MessagePumpCFRunLoopBase* self = static_cast<MessagePumpCFRunLoopBase*>(info);
179 self->RunWork(); 179 self->RunWork();
180 } 180 }
181 181
182 // Called by MessagePumpCFRunLoopBase::RunWorkSource. 182 // Called by MessagePumpCFRunLoopBase::RunWorkSource.
183 bool MessagePumpCFRunLoopBase::RunWork() { 183 bool MessagePumpCFRunLoopBase::RunWork() {
184 if (!delegate_) {
185 // This point can be reached with a NULL delegate_ if Run is not on the
186 // stack but foreign code is spinning the CFRunLoop.
187 return false;
188 }
189
184 // If we're on the main event loop, the NSApp runloop won't clean up the 190 // If we're on the main event loop, the NSApp runloop won't clean up the
185 // autorelease pool until there is a UI event, so use a local one for any 191 // autorelease pool until there is a UI event, so use a local one for any
186 // autoreleased objects to ensure they go away sooner. 192 // autoreleased objects to ensure they go away sooner.
187 ScopedNSAutoreleasePool autorelease_pool; 193 ScopedNSAutoreleasePool autorelease_pool;
188 194
189 // Call DoWork once, and if something was done, arrange to come back here 195 // Call DoWork once, and if something was done, arrange to come back here
190 // again as long as the loop is still running. 196 // again as long as the loop is still running.
191 bool did_work = delegate_->DoWork(); 197 bool did_work = delegate_->DoWork();
192 if (did_work) { 198 if (did_work) {
193 CFRunLoopSourceSignal(work_source_); 199 CFRunLoopSourceSignal(work_source_);
194 } 200 }
195 201
196 return did_work; 202 return did_work;
197 } 203 }
198 204
199 // Called from the run loop. 205 // Called from the run loop.
200 // static 206 // static
201 void MessagePumpCFRunLoopBase::RunDelayedWorkSource(void* info) { 207 void MessagePumpCFRunLoopBase::RunDelayedWorkSource(void* info) {
202 MessagePumpCFRunLoopBase* self = static_cast<MessagePumpCFRunLoopBase*>(info); 208 MessagePumpCFRunLoopBase* self = static_cast<MessagePumpCFRunLoopBase*>(info);
203 self->RunDelayedWork(); 209 self->RunDelayedWork();
204 } 210 }
205 211
206 // Called by MessagePumpCFRunLoopBase::RunDelayedWorkSource. 212 // Called by MessagePumpCFRunLoopBase::RunDelayedWorkSource.
207 bool MessagePumpCFRunLoopBase::RunDelayedWork() { 213 bool MessagePumpCFRunLoopBase::RunDelayedWork() {
214 if (!delegate_) {
215 // This point can be reached with a NULL delegate_ if Run is not on the
216 // stack but foreign code is spinning the CFRunLoop.
217 return false;
218 }
219
208 // If we're on the main event loop, the NSApp runloop won't clean up the 220 // If we're on the main event loop, the NSApp runloop won't clean up the
209 // autorelease pool until there is a UI event, so use a local one for any 221 // autorelease pool until there is a UI event, so use a local one for any
210 // autoreleased objects to ensure they go away sooner. 222 // autoreleased objects to ensure they go away sooner.
211 ScopedNSAutoreleasePool autorelease_pool; 223 ScopedNSAutoreleasePool autorelease_pool;
212 224
213 Time next_time; 225 Time next_time;
214 delegate_->DoDelayedWork(&next_time); 226 delegate_->DoDelayedWork(&next_time);
215 227
216 bool more_work = !next_time.is_null(); 228 bool more_work = !next_time.is_null();
217 if (more_work) { 229 if (more_work) {
(...skipping 14 matching lines...) Expand all
232 244
233 // Called from the run loop. 245 // Called from the run loop.
234 // static 246 // static
235 void MessagePumpCFRunLoopBase::RunIdleWorkSource(void* info) { 247 void MessagePumpCFRunLoopBase::RunIdleWorkSource(void* info) {
236 MessagePumpCFRunLoopBase* self = static_cast<MessagePumpCFRunLoopBase*>(info); 248 MessagePumpCFRunLoopBase* self = static_cast<MessagePumpCFRunLoopBase*>(info);
237 self->RunIdleWork(); 249 self->RunIdleWork();
238 } 250 }
239 251
240 // Called by MessagePumpCFRunLoopBase::RunIdleWorkSource. 252 // Called by MessagePumpCFRunLoopBase::RunIdleWorkSource.
241 bool MessagePumpCFRunLoopBase::RunIdleWork() { 253 bool MessagePumpCFRunLoopBase::RunIdleWork() {
254 if (!delegate_) {
255 // This point can be reached with a NULL delegate_ if Run is not on the
256 // stack but foreign code is spinning the CFRunLoop.
257 return false;
258 }
259
242 // If we're on the main event loop, the NSApp runloop won't clean up the 260 // If we're on the main event loop, the NSApp runloop won't clean up the
243 // autorelease pool until there is a UI event, so use a local one for any 261 // autorelease pool until there is a UI event, so use a local one for any
244 // autoreleased objects to ensure they go away sooner. 262 // autoreleased objects to ensure they go away sooner.
245 ScopedNSAutoreleasePool autorelease_pool; 263 ScopedNSAutoreleasePool autorelease_pool;
246 264
247 // Call DoIdleWork once, and if something was done, arrange to come back here 265 // Call DoIdleWork once, and if something was done, arrange to come back here
248 // again as long as the loop is still running. 266 // again as long as the loop is still running.
249 bool did_work = delegate_->DoIdleWork(); 267 bool did_work = delegate_->DoIdleWork();
250 if (did_work) { 268 if (did_work) {
251 CFRunLoopSourceSignal(idle_work_source_); 269 CFRunLoopSourceSignal(idle_work_source_);
252 } 270 }
253 271
254 return did_work; 272 return did_work;
255 } 273 }
256 274
257 // Called from the run loop. 275 // Called from the run loop.
258 // static 276 // static
259 void MessagePumpCFRunLoopBase::RunNestingDeferredWorkSource(void* info) { 277 void MessagePumpCFRunLoopBase::RunNestingDeferredWorkSource(void* info) {
260 MessagePumpCFRunLoopBase* self = static_cast<MessagePumpCFRunLoopBase*>(info); 278 MessagePumpCFRunLoopBase* self = static_cast<MessagePumpCFRunLoopBase*>(info);
261 self->RunNestingDeferredWork(); 279 self->RunNestingDeferredWork();
262 } 280 }
263 281
264 // Called by MessagePumpCFRunLoopBase::RunNestingDeferredWorkSource. 282 // Called by MessagePumpCFRunLoopBase::RunNestingDeferredWorkSource.
265 bool MessagePumpCFRunLoopBase::RunNestingDeferredWork() { 283 bool MessagePumpCFRunLoopBase::RunNestingDeferredWork() {
284 if (!delegate_) {
285 // This point can be reached with a NULL delegate_ if Run is not on the
286 // stack but foreign code is spinning the CFRunLoop. There's no sense in
287 // attempting to do any work or signalling the work sources because
288 // without a delegate, work is not possible.
289 return false;
290 }
291
266 // Immediately try work in priority order. 292 // Immediately try work in priority order.
267 if (!RunWork()) { 293 if (!RunWork()) {
268 if (!RunDelayedWork()) { 294 if (!RunDelayedWork()) {
269 if (!RunIdleWork()) { 295 if (!RunIdleWork()) {
270 return false; 296 return false;
271 } 297 }
272 } else { 298 } else {
273 // There was no work, and delayed work was done. Arrange for the loop 299 // There was no work, and delayed work was done. Arrange for the loop
274 // to try non-nestable idle work on a subsequent pass. 300 // to try non-nestable idle work on a subsequent pass.
275 CFRunLoopSourceSignal(idle_work_source_); 301 CFRunLoopSourceSignal(idle_work_source_);
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 // static 497 // static
472 MessagePump* MessagePumpMac::Create() { 498 MessagePump* MessagePumpMac::Create() {
473 if ([NSThread isMainThread]) { 499 if ([NSThread isMainThread]) {
474 return new MessagePumpNSApplication; 500 return new MessagePumpNSApplication;
475 } 501 }
476 502
477 return new MessagePumpNSRunLoop; 503 return new MessagePumpNSRunLoop;
478 } 504 }
479 505
480 } // namespace base 506 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698