2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: c++; tab-width: 2; indent-tabs-mode: nil; -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is Widget code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Google Inc.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2006
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Darin Fisher <darin@meer.net> (original author)
|
2008-02-26 05:36:40 -08:00
|
|
|
* Mats Palmgren <mats.palmgren@bredband.net>
|
2007-03-22 10:30:00 -07:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
2011-10-05 06:11:17 -07:00
|
|
|
#include "base/message_loop.h"
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsBaseAppShell.h"
|
|
|
|
#include "nsThreadUtils.h"
|
|
|
|
#include "nsIObserverService.h"
|
|
|
|
#include "nsServiceManagerUtils.h"
|
Bug 560095 - Use mozilla::services::GetObserverService(). r=biesi,dveditz,gavin,josh,jst,mrbkap,roc,sdwilsh,shaver,sicking,smontagu,surkov
2010-04-29 09:59:13 -07:00
|
|
|
#include "mozilla/Services.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// When processing the next thread event, the appshell may process native
|
|
|
|
// events (if not in performance mode), which can result in suppressing the
|
|
|
|
// next thread event for at most this many ticks:
|
|
|
|
#define THREAD_EVENT_STARVATION_LIMIT PR_MillisecondsToInterval(20)
|
|
|
|
|
|
|
|
NS_IMPL_THREADSAFE_ISUPPORTS3(nsBaseAppShell, nsIAppShell, nsIThreadObserver,
|
|
|
|
nsIObserver)
|
|
|
|
|
|
|
|
nsBaseAppShell::nsBaseAppShell()
|
2007-03-22 16:04:51 -07:00
|
|
|
: mSuspendNativeCount(0)
|
2011-03-28 14:18:44 -07:00
|
|
|
, mEventloopNestingLevel(0)
|
2008-02-26 05:36:40 -08:00
|
|
|
, mBlockedWait(nsnull)
|
2007-03-22 16:04:51 -07:00
|
|
|
, mFavorPerf(0)
|
2008-02-26 05:36:40 -08:00
|
|
|
, mNativeEventPending(0)
|
2007-03-22 10:30:00 -07:00
|
|
|
, mStarvationDelay(0)
|
|
|
|
, mSwitchTime(0)
|
|
|
|
, mLastNativeEventTime(0)
|
2008-02-26 05:36:40 -08:00
|
|
|
, mEventloopNestingState(eEventloopNone)
|
2011-10-17 07:59:28 -07:00
|
|
|
, mRunning(false)
|
|
|
|
, mExiting(false)
|
|
|
|
, mBlockNativeEvent(false)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-09-02 17:03:03 -07:00
|
|
|
nsBaseAppShell::~nsBaseAppShell()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mSyncSections.Count() == 0, "Must have run all sync sections");
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult
|
|
|
|
nsBaseAppShell::Init()
|
|
|
|
{
|
|
|
|
// Configure ourselves as an observer for the current thread:
|
|
|
|
|
|
|
|
nsCOMPtr<nsIThreadInternal> threadInt =
|
|
|
|
do_QueryInterface(NS_GetCurrentThread());
|
|
|
|
NS_ENSURE_STATE(threadInt);
|
|
|
|
|
|
|
|
threadInt->SetObserver(this);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIObserverService> obsSvc =
|
Bug 560095 - Use mozilla::services::GetObserverService(). r=biesi,dveditz,gavin,josh,jst,mrbkap,roc,sdwilsh,shaver,sicking,smontagu,surkov
2010-04-29 09:59:13 -07:00
|
|
|
mozilla::services::GetObserverService();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (obsSvc)
|
2011-10-17 07:59:28 -07:00
|
|
|
obsSvc->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, false);
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-01-27 15:27:39 -08:00
|
|
|
// Called by nsAppShell's native event callback
|
2007-03-22 10:30:00 -07:00
|
|
|
void
|
2011-01-27 15:27:39 -08:00
|
|
|
nsBaseAppShell::NativeEventCallback()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-03-28 12:58:49 -07:00
|
|
|
PRInt32 hasPending = PR_ATOMIC_SET(&mNativeEventPending, 0);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (hasPending == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// If DoProcessNextNativeEvent is on the stack, then we assume that we can
|
|
|
|
// just unwind and let nsThread::ProcessNextEvent process the next event.
|
|
|
|
// However, if we are called from a nested native event loop (maybe via some
|
2008-02-26 05:36:40 -08:00
|
|
|
// plug-in or library function), then go ahead and process Gecko events now.
|
|
|
|
if (mEventloopNestingState == eEventloopXPCOM) {
|
|
|
|
mEventloopNestingState = eEventloopOther;
|
|
|
|
// XXX there is a tiny risk we will never get a new NativeEventCallback,
|
|
|
|
// XXX see discussion in bug 389931.
|
2007-03-22 10:30:00 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// nsBaseAppShell::Run is not being used to pump events, so this may be
|
|
|
|
// our only opportunity to process pending gecko events.
|
|
|
|
|
|
|
|
nsIThread *thread = NS_GetCurrentThread();
|
2011-09-28 23:19:26 -07:00
|
|
|
bool prevBlockNativeEvent = mBlockNativeEvent;
|
2011-01-27 15:27:39 -08:00
|
|
|
if (mEventloopNestingState == eEventloopOther) {
|
2008-03-14 18:12:13 -07:00
|
|
|
if (!NS_HasPendingEvents(thread))
|
|
|
|
return;
|
|
|
|
// We're in a nested native event loop and have some gecko events to
|
|
|
|
// process. While doing that we block processing native events from the
|
|
|
|
// appshell - instead, we want to get back to the nested native event
|
|
|
|
// loop ASAP (bug 420148).
|
2011-10-17 07:59:28 -07:00
|
|
|
mBlockNativeEvent = true;
|
2008-03-14 18:12:13 -07:00
|
|
|
}
|
|
|
|
|
2008-03-25 09:56:04 -07:00
|
|
|
++mEventloopNestingLevel;
|
2008-03-14 18:12:13 -07:00
|
|
|
EventloopNestingState prevVal = mEventloopNestingState;
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ProcessPendingEvents(thread, THREAD_EVENT_STARVATION_LIMIT);
|
2011-10-17 07:59:28 -07:00
|
|
|
mProcessedGeckoEvents = true;
|
2008-02-26 05:36:40 -08:00
|
|
|
mEventloopNestingState = prevVal;
|
2008-03-14 18:12:13 -07:00
|
|
|
mBlockNativeEvent = prevBlockNativeEvent;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Continue processing pending events later (we don't want to starve the
|
|
|
|
// embedders event loop).
|
|
|
|
if (NS_HasPendingEvents(thread))
|
2010-11-29 08:25:16 -08:00
|
|
|
DoProcessMoreGeckoEvents();
|
2008-03-25 09:56:04 -07:00
|
|
|
|
|
|
|
--mEventloopNestingLevel;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-11-29 08:25:16 -08:00
|
|
|
// Note, this is currently overidden on windows, see comments in nsAppShell for
|
|
|
|
// details.
|
|
|
|
void
|
|
|
|
nsBaseAppShell::DoProcessMoreGeckoEvents()
|
|
|
|
{
|
|
|
|
OnDispatchedEvent(nsnull);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Main thread via OnProcessNextEvent below
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
|
|
|
nsBaseAppShell::DoProcessNextNativeEvent(bool mayWait)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// The next native event to be processed may trigger our NativeEventCallback,
|
|
|
|
// in which case we do not want it to process any thread events since we'll
|
|
|
|
// do that when this function returns.
|
|
|
|
//
|
|
|
|
// If the next native event is not our NativeEventCallback, then we may end
|
|
|
|
// up recursing into this function.
|
|
|
|
//
|
|
|
|
// However, if the next native event is not our NativeEventCallback, but it
|
|
|
|
// results in another native event loop, then our NativeEventCallback could
|
2008-02-26 05:36:40 -08:00
|
|
|
// fire and it will see mEventloopNestingState as eEventloopOther.
|
2007-03-22 10:30:00 -07:00
|
|
|
//
|
2008-02-26 05:36:40 -08:00
|
|
|
EventloopNestingState prevVal = mEventloopNestingState;
|
|
|
|
mEventloopNestingState = eEventloopXPCOM;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-03-25 09:56:04 -07:00
|
|
|
++mEventloopNestingLevel;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool result = ProcessNextNativeEvent(mayWait);
|
2008-03-25 09:56:04 -07:00
|
|
|
--mEventloopNestingLevel;
|
2008-02-26 05:36:40 -08:00
|
|
|
|
|
|
|
mEventloopNestingState = prevVal;
|
2007-03-22 10:30:00 -07:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
// nsIAppShell methods:
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBaseAppShell::Run(void)
|
|
|
|
{
|
2009-06-30 09:02:37 -07:00
|
|
|
NS_ENSURE_STATE(!mRunning); // should not call Run twice
|
2011-10-17 07:59:28 -07:00
|
|
|
mRunning = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-07-20 12:04:52 -07:00
|
|
|
nsIThread *thread = NS_GetCurrentThread();
|
|
|
|
|
2009-06-30 09:02:37 -07:00
|
|
|
MessageLoop::current()->Run();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-07-20 12:04:52 -07:00
|
|
|
NS_ProcessPendingEvents(thread);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
mRunning = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBaseAppShell::Exit(void)
|
|
|
|
{
|
2009-06-30 09:02:37 -07:00
|
|
|
if (mRunning && !mExiting) {
|
|
|
|
MessageLoop::current()->Quit();
|
|
|
|
}
|
2011-10-17 07:59:28 -07:00
|
|
|
mExiting = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-28 23:19:26 -07:00
|
|
|
nsBaseAppShell::FavorPerformanceHint(bool favorPerfOverStarvation,
|
2007-03-22 10:30:00 -07:00
|
|
|
PRUint32 starvationDelay)
|
|
|
|
{
|
|
|
|
mStarvationDelay = PR_MillisecondsToInterval(starvationDelay);
|
|
|
|
if (favorPerfOverStarvation) {
|
|
|
|
++mFavorPerf;
|
|
|
|
} else {
|
|
|
|
--mFavorPerf;
|
|
|
|
mSwitchTime = PR_IntervalNow();
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-03-22 16:04:51 -07:00
|
|
|
NS_IMETHODIMP
|
2008-03-25 09:56:04 -07:00
|
|
|
nsBaseAppShell::SuspendNative()
|
2007-03-22 16:04:51 -07:00
|
|
|
{
|
|
|
|
++mSuspendNativeCount;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2008-03-25 09:56:04 -07:00
|
|
|
nsBaseAppShell::ResumeNative()
|
2007-03-22 16:04:51 -07:00
|
|
|
{
|
|
|
|
--mSuspendNativeCount;
|
|
|
|
NS_ASSERTION(mSuspendNativeCount >= 0, "Unbalanced call to nsBaseAppShell::ResumeNative!");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-03-25 09:56:04 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBaseAppShell::GetEventloopNestingLevel(PRUint32* aNestingLevelResult)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aNestingLevelResult);
|
|
|
|
|
|
|
|
*aNestingLevelResult = mEventloopNestingLevel;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
// nsIThreadObserver methods:
|
|
|
|
|
|
|
|
// Called from any thread
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBaseAppShell::OnDispatchedEvent(nsIThreadInternal *thr)
|
|
|
|
{
|
2008-03-14 18:12:13 -07:00
|
|
|
if (mBlockNativeEvent)
|
|
|
|
return NS_OK;
|
|
|
|
|
2011-03-28 12:58:49 -07:00
|
|
|
PRInt32 lastVal = PR_ATOMIC_SET(&mNativeEventPending, 1);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (lastVal == 1)
|
|
|
|
return NS_OK;
|
2008-02-26 05:36:40 -08:00
|
|
|
|
2010-11-29 08:25:16 -08:00
|
|
|
// Returns on the main thread in NativeEventCallback above
|
2007-03-22 10:30:00 -07:00
|
|
|
ScheduleNativeEventCallback();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Called from the main thread
|
|
|
|
NS_IMETHODIMP
|
2011-09-28 23:19:26 -07:00
|
|
|
nsBaseAppShell::OnProcessNextEvent(nsIThreadInternal *thr, bool mayWait,
|
2007-03-22 10:30:00 -07:00
|
|
|
PRUint32 recursionDepth)
|
|
|
|
{
|
2008-03-14 18:12:13 -07:00
|
|
|
if (mBlockNativeEvent) {
|
|
|
|
if (!mayWait)
|
|
|
|
return NS_OK;
|
|
|
|
// Hmm, we're in a nested native event loop and would like to get
|
|
|
|
// back to it ASAP, but it seems a gecko event has caused us to
|
|
|
|
// spin up a nested XPCOM event loop (eg. modal window), so we
|
|
|
|
// really must start processing native events here again.
|
2011-10-17 07:59:28 -07:00
|
|
|
mBlockNativeEvent = false;
|
2008-03-14 18:12:13 -07:00
|
|
|
if (NS_HasPendingEvents(thr))
|
|
|
|
OnDispatchedEvent(thr); // in case we blocked it earlier
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
PRIntervalTime start = PR_IntervalNow();
|
|
|
|
PRIntervalTime limit = THREAD_EVENT_STARVATION_LIMIT;
|
|
|
|
|
2008-02-26 05:36:40 -08:00
|
|
|
// Unblock outer nested wait loop (below).
|
|
|
|
if (mBlockedWait)
|
2011-10-17 07:59:28 -07:00
|
|
|
*mBlockedWait = false;
|
2008-02-26 05:36:40 -08:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool *oldBlockedWait = mBlockedWait;
|
2008-02-26 05:36:40 -08:00
|
|
|
mBlockedWait = &mayWait;
|
|
|
|
|
|
|
|
// When mayWait is true, we need to make sure that there is an event in the
|
|
|
|
// thread's event queue before we return. Otherwise, the thread will block
|
|
|
|
// on its event queue waiting for an event.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool needEvent = mayWait;
|
2010-10-25 16:34:13 -07:00
|
|
|
// Reset prior to invoking DoProcessNextNativeEvent which might cause
|
|
|
|
// NativeEventCallback to process gecko events.
|
2011-10-17 07:59:28 -07:00
|
|
|
mProcessedGeckoEvents = false;
|
2008-02-26 05:36:40 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mFavorPerf <= 0 && start > mSwitchTime + mStarvationDelay) {
|
|
|
|
// Favor pending native events
|
|
|
|
PRIntervalTime now = start;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool keepGoing;
|
2007-03-22 10:30:00 -07:00
|
|
|
do {
|
|
|
|
mLastNativeEventTime = now;
|
2011-10-17 07:59:28 -07:00
|
|
|
keepGoing = DoProcessNextNativeEvent(false);
|
2007-03-22 10:30:00 -07:00
|
|
|
} while (keepGoing && ((now = PR_IntervalNow()) - start) < limit);
|
|
|
|
} else {
|
|
|
|
// Avoid starving native events completely when in performance mode
|
|
|
|
if (start - mLastNativeEventTime > limit) {
|
|
|
|
mLastNativeEventTime = start;
|
2011-10-17 07:59:28 -07:00
|
|
|
DoProcessNextNativeEvent(false);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-25 16:34:13 -07:00
|
|
|
while (!NS_HasPendingEvents(thr) && !mProcessedGeckoEvents) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// If we have been asked to exit from Run, then we should not wait for
|
2008-02-26 05:36:40 -08:00
|
|
|
// events to process. Note that an inner nested event loop causes
|
|
|
|
// 'mayWait' to become false too, through 'mBlockedWait'.
|
|
|
|
if (mExiting)
|
2011-10-17 07:59:28 -07:00
|
|
|
mayWait = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
mLastNativeEventTime = PR_IntervalNow();
|
|
|
|
if (!DoProcessNextNativeEvent(mayWait) || !mayWait)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-02-26 05:36:40 -08:00
|
|
|
mBlockedWait = oldBlockedWait;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Make sure that the thread event queue does not block on its monitor, as
|
|
|
|
// it normally would do if it did not have any pending events. To avoid
|
|
|
|
// that, we simply insert a dummy event into its queue during shutdown.
|
2010-10-19 13:01:27 -07:00
|
|
|
if (needEvent && !mExiting && !NS_HasPendingEvents(thr)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!mDummyEvent)
|
|
|
|
mDummyEvent = new nsRunnable();
|
|
|
|
thr->Dispatch(mDummyEvent, NS_DISPATCH_NORMAL);
|
|
|
|
}
|
|
|
|
|
2010-09-02 17:03:03 -07:00
|
|
|
// We're about to run an event, so we're in a stable state.
|
|
|
|
RunSyncSections();
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-09-02 17:03:03 -07:00
|
|
|
void
|
|
|
|
nsBaseAppShell::RunSyncSections()
|
|
|
|
{
|
|
|
|
if (mSyncSections.Count() == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// We've got synchronous sections awaiting a stable state. Run
|
|
|
|
// all the synchronous sections. Note that a synchronous section could
|
|
|
|
// add another synchronous section, so we don't remove elements from
|
|
|
|
// mSyncSections until all sections have been run, else we'll screw up
|
|
|
|
// our iteration.
|
2010-12-07 10:42:40 -08:00
|
|
|
for (PRInt32 i = 0; i < mSyncSections.Count(); i++) {
|
2010-09-02 17:03:03 -07:00
|
|
|
mSyncSections[i]->Run();
|
|
|
|
}
|
|
|
|
mSyncSections.Clear();
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Called from the main thread
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBaseAppShell::AfterProcessNextEvent(nsIThreadInternal *thr,
|
|
|
|
PRUint32 recursionDepth)
|
|
|
|
{
|
2010-09-02 17:03:03 -07:00
|
|
|
// We've just finished running an event, so we're in a stable state.
|
|
|
|
RunSyncSections();
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBaseAppShell::Observe(nsISupports *subject, const char *topic,
|
|
|
|
const PRUnichar *data)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(!strcmp(topic, NS_XPCOM_SHUTDOWN_OBSERVER_ID), "oops");
|
|
|
|
Exit();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2010-09-02 17:03:03 -07:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBaseAppShell::RunInStableState(nsIRunnable* aRunnable)
|
|
|
|
{
|
2010-09-02 17:03:03 -07:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Should be on main thread.");
|
|
|
|
// Record the synchronous section, and run it with any others once
|
|
|
|
// we reach a stable state.
|
2010-09-02 17:03:03 -07:00
|
|
|
mSyncSections.AppendObject(aRunnable);
|
2010-09-02 17:03:03 -07:00
|
|
|
|
|
|
|
// Ensure we've got a pending event, else the callbacks will never run.
|
|
|
|
nsIThread* thread = NS_GetCurrentThread();
|
|
|
|
if (!NS_HasPendingEvents(thread) &&
|
|
|
|
NS_FAILED(thread->Dispatch(new nsRunnable(), NS_DISPATCH_NORMAL)))
|
|
|
|
{
|
|
|
|
// Failed to dispatch dummy event to cause sync sections to run, thread
|
|
|
|
// is probably done processing events, just run the sync sections now.
|
|
|
|
RunSyncSections();
|
|
|
|
}
|
2010-09-02 17:03:03 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2010-09-02 17:03:03 -07:00
|
|
|
|