summaryrefslogtreecommitdiffstats
path: root/base/message_pump_mac.h
diff options
context:
space:
mode:
authordmaclach@chromium.org <dmaclach@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-30 23:05:27 +0000
committerdmaclach@chromium.org <dmaclach@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-30 23:05:27 +0000
commit16808e0de6bf05d814563d4d6712e52d6edaef54 (patch)
tree60a990e6035887ee14cbf7ee7fbd12a6dbb38558 /base/message_pump_mac.h
parent7644b965283ce3fe0374d5af51ee9710ab86f8db (diff)
downloadchromium_src-16808e0de6bf05d814563d4d6712e52d6edaef54.zip
chromium_src-16808e0de6bf05d814563d4d6712e52d6edaef54.tar.gz
chromium_src-16808e0de6bf05d814563d4d6712e52d6edaef54.tar.bz2
Cleans up our autorelease handling so that we don't create a layered
autorelease pool in our run loop source if there is one already on the stack above us. This allows Cocoa to clean up all the objects at the same time as it expects to do. There may be more "interesting" code that can be removed now that this is in. Initially we were going to implement it by checking the nesting levels of the runloops, but it turns out by the time sendEvent is called at the upper level we are already out of the "CFRunloopRun" call so our nesting count isn't a valid indicator of our state. TEST=1) See bug 25857. 2) Start up. Open 3+ windows. Quit. BUG=25857 Review URL: http://codereview.chromium.org/343024 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@30647 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/message_pump_mac.h')
-rw-r--r--base/message_pump_mac.h39
1 files changed, 38 insertions, 1 deletions
diff --git a/base/message_pump_mac.h b/base/message_pump_mac.h
index 3d06c17..d7f723b 100644
--- a/base/message_pump_mac.h
+++ b/base/message_pump_mac.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -35,6 +35,13 @@
#include <CoreFoundation/CoreFoundation.h>
#include <IOKit/IOKitLib.h>
+#if defined(__OBJC__)
+@class NSAutoreleasePool;
+#else // __OBJC__
+class NSAutoreleasePool;
+#endif // __OBJC__
+
+
namespace base {
class Time;
@@ -60,6 +67,10 @@ class MessagePumpCFRunLoopBase : public MessagePump {
int nesting_level() const { return nesting_level_; }
int run_nesting_level() const { return run_nesting_level_; }
+ // Factory method for creating an autorelease pool. Not all message
+ // pumps work with autorelease pools in the same way.
+ virtual NSAutoreleasePool* CreateAutoreleasePool();
+
private:
// Timer callback scheduled by ScheduleDelayedWork. This does not do any
// work, but it signals delayed_work_source_ so that delayed work can be
@@ -223,13 +234,35 @@ class MessagePumpNSRunLoop : public MessagePumpCFRunLoopBase {
};
class MessagePumpNSApplication : public MessagePumpCFRunLoopBase {
+ // ObjC objects and C++ objects can't be friends, so this function
+ // will act as a friendly trampoline for
+ // MessagePumpNSAppDeferredAutoReleasePool to call
+ // set_needs_event_loop_wakeup.
+ friend void SetNeedsEventLoopWakeUpTrue(MessagePumpNSApplication* pump);
+
public:
MessagePumpNSApplication();
virtual void DoRun(Delegate* delegate);
virtual void Quit();
+ protected:
+ // MessagePumpNSApplications need a special autorelease pool that works
+ // correctly when nested inside another autorelease pool.
+ virtual NSAutoreleasePool* CreateAutoreleasePool();
+
+ // Sets a flag that will trigger the sending of an NSEvent to wake up the
+ // NSApplication event loop when the run loop exits.
+ void set_needs_event_loop_wake_up_true() {
+ needs_event_loop_wake_up_ = true;
+ }
+
private:
+ virtual void EnterExitRunLoop(CFRunLoopActivity activity);
+
+ // Send a null event through to the event loop if necessary.
+ void WakeUpEventLoop();
+
// False after Quit is called.
bool keep_running_;
@@ -239,6 +272,10 @@ class MessagePumpNSApplication : public MessagePumpCFRunLoopBase {
// in DoRun.
bool running_own_loop_;
+ // True if an event should be sent to the event loop to cause it to spin
+ // when the run loop is exiting.
+ bool needs_event_loop_wake_up_;
+
DISALLOW_COPY_AND_ASSIGN(MessagePumpNSApplication);
};