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

Side by Side Diff: base/message_pump_mac.mm

Issue 3805: autorelease message pumps (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 12 years, 3 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 | « base/message_pump_libevent.cc ('k') | base/platform_test_mac.mm » ('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 (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
11 #include "base/scoped_nsautorelease_pool.h"
12
11 namespace { 13 namespace {
12 14
13 void NoOp(void* info) { 15 void NoOp(void* info) {
14 } 16 }
15 17
16 } // namespace 18 } // namespace
17 19
18 namespace base { 20 namespace base {
19 21
20 // Must be called on the run loop thread. 22 // Must be called on the run loop thread.
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 // Called by CFRunLoopBase::DoRun. If other CFRunLoopRun loops were running 211 // Called by CFRunLoopBase::DoRun. If other CFRunLoopRun loops were running
210 // lower on the run loop thread's stack when this object was created, the same 212 // lower on the run loop thread's stack when this object was created, the same
211 // number of CFRunLoopRun loops must be running for the outermost call to Run. 213 // number of CFRunLoopRun loops must be running for the outermost call to Run.
212 // Run/DoRun are reentrant after that point. 214 // Run/DoRun are reentrant after that point.
213 void MessagePumpCFRunLoop::DoRun(Delegate* delegate) { 215 void MessagePumpCFRunLoop::DoRun(Delegate* delegate) {
214 // nesting_level_ will be incremented in EnterExitRunLoop, so set 216 // nesting_level_ will be incremented in EnterExitRunLoop, so set
215 // innermost_quittable_ accordingly. 217 // innermost_quittable_ accordingly.
216 int last_innermost_quittable = innermost_quittable_; 218 int last_innermost_quittable = innermost_quittable_;
217 innermost_quittable_ = nesting_level_ + 1; 219 innermost_quittable_ = nesting_level_ + 1;
218 220
219 CFRunLoopRun(); 221 // This is completely identical to calling CFRunLoopRun(), except autorelease
222 // pool management is introduced.
223 int result;
224 do {
225 ScopedNSAutoreleasePool autorelease_pool;
226 result = CFRunLoopRunInMode(kCFRunLoopDefaultMode, DBL_MAX, false);
227 } while (result != kCFRunLoopRunStopped && result != kCFRunLoopRunFinished);
220 228
221 // Restore the previous state of the object. 229 // Restore the previous state of the object.
222 innermost_quittable_ = last_innermost_quittable; 230 innermost_quittable_ = last_innermost_quittable;
223 } 231 }
224 232
225 // Must be called on the run loop thread. 233 // Must be called on the run loop thread.
226 void MessagePumpCFRunLoop::Quit() { 234 void MessagePumpCFRunLoop::Quit() {
227 // Stop the innermost run loop managed by this MessagePumpCFRunLoop object. 235 // Stop the innermost run loop managed by this MessagePumpCFRunLoop object.
228 if (nesting_level_ == innermost_quittable_) { 236 if (nesting_level_ == innermost_quittable_) {
229 // This object is running the innermost loop, just stop it. 237 // This object is running the innermost loop, just stop it.
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 316
309 [NSApplication sharedApplication]; 317 [NSApplication sharedApplication];
310 318
311 if (![NSApp isRunning]) { 319 if (![NSApp isRunning]) {
312 running_own_loop_ = false; 320 running_own_loop_ = false;
313 // NSApplication manages autorelease pools itself when run this way. 321 // NSApplication manages autorelease pools itself when run this way.
314 [NSApp run]; 322 [NSApp run];
315 } else { 323 } else {
316 running_own_loop_ = true; 324 running_own_loop_ = true;
317 while (keep_running_) { 325 while (keep_running_) {
318 NSAutoreleasePool* autorelease_pool = [[NSAutoreleasePool alloc] init]; 326 ScopedNSAutoreleasePool autorelease_pool;
319 NSEvent* event = [NSApp nextEventMatchingMask:NSAnyEventMask 327 NSEvent* event = [NSApp nextEventMatchingMask:NSAnyEventMask
320 untilDate:[NSDate distantFuture] 328 untilDate:[NSDate distantFuture]
321 inMode:NSDefaultRunLoopMode 329 inMode:NSDefaultRunLoopMode
322 dequeue:YES]; 330 dequeue:YES];
323 if (event) { 331 if (event) {
324 [NSApp sendEvent:event]; 332 [NSApp sendEvent:event];
325 } 333 }
326 [autorelease_pool drain];
327 } 334 }
328 keep_running_ = true; 335 keep_running_ = true;
329 } 336 }
330 337
331 running_own_loop_ = last_running_own_loop_; 338 running_own_loop_ = last_running_own_loop_;
332 } 339 }
333 340
334 void MessagePumpNSApplication::Quit() { 341 void MessagePumpNSApplication::Quit() {
335 if (!running_own_loop_) { 342 if (!running_own_loop_) {
336 [NSApp stop:nil]; 343 [NSApp stop:nil];
(...skipping 17 matching lines...) Expand all
354 // static 361 // static
355 MessagePump* MessagePumpMac::Create() { 362 MessagePump* MessagePumpMac::Create() {
356 if ([NSThread isMainThread]) { 363 if ([NSThread isMainThread]) {
357 return new MessagePumpNSApplication; 364 return new MessagePumpNSApplication;
358 } 365 }
359 366
360 return new MessagePumpNSRunLoop; 367 return new MessagePumpNSRunLoop;
361 } 368 }
362 369
363 } // namespace base 370 } // namespace base
OLDNEW
« no previous file with comments | « base/message_pump_libevent.cc ('k') | base/platform_test_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698