Skip to content

Commit

Permalink
Bug 939182 - Add 'eventWasProcessed' argument to nsIThreadObserver::a…
Browse files Browse the repository at this point in the history
…fterProcessNextEvent(), r=bsmedberg.

--HG--
extra : transplant_source : %5E%80p%D6%C6A%23%0AZ%06%23%16%155%DB%CE%F5%5CEx
  • Loading branch information
benturner committed Oct 23, 2013
1 parent 436bc9d commit 4d2b15f
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 28 deletions.
3 changes: 2 additions & 1 deletion dom/ipc/ContentParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2724,7 +2724,8 @@ ContentParent::OnProcessNextEvent(nsIThreadInternal *thread,
/* void afterProcessNextEvent (in nsIThreadInternal thread, in unsigned long recursionDepth); */
NS_IMETHODIMP
ContentParent::AfterProcessNextEvent(nsIThreadInternal *thread,
uint32_t recursionDepth)
uint32_t recursionDepth,
bool eventWasProcessed)
{
return NS_OK;
}
Expand Down
3 changes: 2 additions & 1 deletion js/xpconnect/src/nsXPConnect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1120,7 +1120,8 @@ nsXPConnect::OnProcessNextEvent(nsIThreadInternal *aThread, bool aMayWait,

NS_IMETHODIMP
nsXPConnect::AfterProcessNextEvent(nsIThreadInternal *aThread,
uint32_t aRecursionDepth)
uint32_t aRecursionDepth,
bool aEventWasProcessed)
{
// Watch out for unpaired events during observer registration.
if (MOZ_UNLIKELY(mEventDepth == 0))
Expand Down
3 changes: 2 additions & 1 deletion layout/style/Loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,8 @@ SheetLoadData::OnProcessNextEvent(nsIThreadInternal* aThread,

NS_IMETHODIMP
SheetLoadData::AfterProcessNextEvent(nsIThreadInternal* aThread,
uint32_t aRecursionDepth)
uint32_t aRecursionDepth,
bool aEventWasProcessed)
{
// We want to fire our load even before or after event processing,
// whichever comes first.
Expand Down
5 changes: 2 additions & 3 deletions netwerk/base/src/nsSocketTransportService2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,8 @@ nsSocketTransportService::OnProcessNextEvent(nsIThreadInternal *thread,

NS_IMETHODIMP
nsSocketTransportService::AfterProcessNextEvent(nsIThreadInternal* thread,
uint32_t depth)
uint32_t depth,
bool eventWasProcessed)
{
return NS_OK;
}
Expand Down Expand Up @@ -1128,5 +1129,3 @@ nsSocketTransportService::GetSocketConnections(nsTArray<SocketInfo> *data)
for (uint32_t i = 0; i < mIdleCount; i++)
AnalyzeConnection(data, &mIdleList[i], false);
}


3 changes: 2 additions & 1 deletion netwerk/cache2/CacheIOThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,8 @@ NS_IMETHODIMP CacheIOThread::OnProcessNextEvent(nsIThreadInternal *thread, bool
return NS_OK;
}

NS_IMETHODIMP CacheIOThread::AfterProcessNextEvent(nsIThreadInternal *thread, uint32_t recursionDepth)
NS_IMETHODIMP CacheIOThread::AfterProcessNextEvent(nsIThreadInternal *thread, uint32_t recursionDepth,
bool eventWasProcessed)
{
return NS_OK;
}
Expand Down
3 changes: 2 additions & 1 deletion widget/cocoa/nsAppShell.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ class nsAppShell : public nsBaseAppShell
NS_IMETHOD OnProcessNextEvent(nsIThreadInternal *aThread, bool aMayWait,
uint32_t aRecursionDepth);
NS_IMETHOD AfterProcessNextEvent(nsIThreadInternal *aThread,
uint32_t aRecursionDepth);
uint32_t aRecursionDepth,
bool aEventWasProcessed);

// public only to be visible to Objective-C code that must call it
void WillTerminate();
Expand Down
6 changes: 4 additions & 2 deletions widget/cocoa/nsAppShell.mm
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,8 @@ - (void)beginMenuTracking:(NSNotification*)aNotification;
// public
NS_IMETHODIMP
nsAppShell::AfterProcessNextEvent(nsIThreadInternal *aThread,
uint32_t aRecursionDepth)
uint32_t aRecursionDepth,
bool aEventWasProcessed)
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;

Expand All @@ -856,7 +857,8 @@ - (void)beginMenuTracking:(NSNotification*)aNotification;
::CFArrayRemoveValueAtIndex(mAutoreleasePools, count - 1);
[pool release];

return nsBaseAppShell::AfterProcessNextEvent(aThread, aRecursionDepth);
return nsBaseAppShell::AfterProcessNextEvent(aThread, aRecursionDepth,
aEventWasProcessed);

NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
}
Expand Down
3 changes: 2 additions & 1 deletion widget/xpwidgets/nsBaseAppShell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,8 @@ nsBaseAppShell::ScheduleSyncSection(nsIRunnable* aRunnable, bool aStable)
// Called from the main thread
NS_IMETHODIMP
nsBaseAppShell::AfterProcessNextEvent(nsIThreadInternal *thr,
uint32_t recursionDepth)
uint32_t recursionDepth,
bool eventWasProcessed)
{
// We've just finished running an event, so we're in a stable state.
RunSyncSections(true, recursionDepth);
Expand Down
9 changes: 6 additions & 3 deletions xpcom/threads/LazyIdleThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -501,14 +501,17 @@ LazyIdleThread::OnProcessNextEvent(nsIThreadInternal* /* aThread */,

NS_IMETHODIMP
LazyIdleThread::AfterProcessNextEvent(nsIThreadInternal* /* aThread */,
uint32_t /* aRecursionDepth */)
uint32_t /* aRecursionDepth */,
bool aEventWasProcessed)
{
bool shouldNotifyIdle;
{
MutexAutoLock lock(mMutex);

MOZ_ASSERT(mPendingEventCount, "Mismatched calls to observer methods!");
--mPendingEventCount;
if (aEventWasProcessed) {
MOZ_ASSERT(mPendingEventCount, "Mismatched calls to observer methods!");
--mPendingEventCount;
}

if (mThreadIsShuttingDown) {
// We're shutting down, no need to fire any timer.
Expand Down
30 changes: 19 additions & 11 deletions xpcom/threads/nsIThreadInternal.idl
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

#include "nsIThread.idl"

interface nsIRunnable;
interface nsIThreadObserver;
interface nsIThreadEventFilter;

/**
* The XPCOM thread object implements this interface, which allows a consumer
Expand All @@ -33,11 +33,12 @@ interface nsIThreadInternal : nsIThread
readonly attribute unsigned long recursionDepth;

/**
* Add an observer that will *only* receive onProcessNextEvent and
* afterProcessNextEvent callbacks. Always called on the target thread, and
* the implementation does not have to be threadsafe. Order of callbacks is
* not guaranteed (i.e. afterProcessNextEvent may be called first depending on
* whether or not the observer is added in a nested loop). Holds a strong ref.
* Add an observer that will *only* receive onProcessNextEvent,
* beforeProcessNextEvent. and afterProcessNextEvent callbacks. Always called
* on the target thread, and the implementation does not have to be
* threadsafe. Order of callbacks is not guaranteed (i.e.
* afterProcessNextEvent may be called first depending on whether or not the
* observer is added in a nested loop). Holds a strong ref.
*/
void addObserver(in nsIThreadObserver observer);

Expand Down Expand Up @@ -77,7 +78,7 @@ interface nsIThreadInternal : nsIThread
* afterProcessNextEvent, then another that inherits the first and adds
* onDispatchedEvent.
*/
[scriptable, uuid(81D0B509-F198-4417-8020-08EB4271491F)]
[scriptable, uuid(09b424c3-26b0-4128-9039-d66f85b02c63)]
interface nsIThreadObserver : nsISupports
{
/**
Expand All @@ -90,8 +91,9 @@ interface nsIThreadObserver : nsISupports
void onDispatchedEvent(in nsIThreadInternal thread);

/**
* This method is called (from nsIThread::ProcessNextEvent) before an event
* is processed. This method is only called on the target thread.
* This method is called when nsIThread::ProcessNextEvent is called. It does
* not guarantee that an event is actually going to be processed. This method
* is only called on the target thread.
*
* @param thread
* The thread being asked to process another event.
Expand All @@ -107,14 +109,20 @@ interface nsIThreadObserver : nsISupports

/**
* This method is called (from nsIThread::ProcessNextEvent) after an event
* is processed. This method is only called on the target thread.
* is processed. It does not guarantee that an event was actually processed
* (depends on the value of |eventWasProcessed|. This method is only called
* on the target thread.
*
* @param thread
* The thread that processed another event.
* @param recursionDepth
* Indicates the number of calls to ProcessNextEvent on the call stack in
* addition to the current call.
* @param eventWasProcessed
* Indicates whether an event was actually processed. May be false if the
* |mayWait| flag was false when calling nsIThread::ProcessNextEvent().
*/
void afterProcessNextEvent(in nsIThreadInternal thread,
in unsigned long recursionDepth);
in unsigned long recursionDepth,
in bool eventWasProcessed);
};
7 changes: 4 additions & 3 deletions xpcom/threads/nsThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -619,13 +619,14 @@ nsThread::ProcessNextEvent(bool mayWait, bool *result)

--mRunningEvent;

NOTIFY_EVENT_OBSERVERS(AfterProcessNextEvent, (this, mRunningEvent));
NOTIFY_EVENT_OBSERVERS(AfterProcessNextEvent,
(this, mRunningEvent, *result));

if (obs)
obs->AfterProcessNextEvent(this, mRunningEvent);
obs->AfterProcessNextEvent(this, mRunningEvent, *result);

if (notifyMainThreadObserver && sMainThreadObserver)
sMainThreadObserver->AfterProcessNextEvent(this, mRunningEvent);
sMainThreadObserver->AfterProcessNextEvent(this, mRunningEvent, *result);

return rv;
}
Expand Down

0 comments on commit 4d2b15f

Please sign in to comment.