Bug 542341 - Add RequestRunToCompletion method to ContentProcessParent. r=cjones

This commit is contained in:
Ben Newman 2010-02-01 17:53:52 -08:00
parent aa5990dd3e
commit be97bb7eeb
2 changed files with 99 additions and 3 deletions

View File

@ -78,11 +78,34 @@ ContentProcessParent::GetSingleton()
gSingleton = parent;
}
}
nsCOMPtr<nsIThreadInternal>
threadInt(do_QueryInterface(NS_GetCurrentThread()));
if (threadInt) {
threadInt->GetObserver(getter_AddRefs(parent->mOldObserver));
threadInt->SetObserver(parent);
}
}
}
return gSingleton;
}
void
ContentProcessParent::ActorDestroy(ActorDestroyReason why)
{
nsCOMPtr<nsIThreadObserver>
kungFuDeathGrip(static_cast<nsIThreadObserver*>(this));
nsCOMPtr<nsIObserverService>
obs(do_GetService("@mozilla.org/observer-service;1"));
if (obs)
obs->RemoveObserver(static_cast<nsIObserver*>(this), "xpcom-shutdown");
nsCOMPtr<nsIThreadInternal>
threadInt(do_QueryInterface(NS_GetCurrentThread()));
if (threadInt)
threadInt->SetObserver(mOldObserver);
if (mRunToCompletionDepth)
mRunToCompletionDepth = 0;
}
TabParent*
ContentProcessParent::CreateTab()
{
@ -103,6 +126,7 @@ ContentProcessParent::DestroyTestShell(TestShellParent* aTestShell)
ContentProcessParent::ContentProcessParent()
: mMonitor("ContentProcessParent::mMonitor")
, mRunToCompletionDepth(0)
{
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
mSubprocess = new GeckoChildProcessHost(GeckoProcessType_Content);
@ -118,7 +142,9 @@ ContentProcessParent::~ContentProcessParent()
gSingleton = nsnull;
}
NS_IMPL_ISUPPORTS1(ContentProcessParent, nsIObserver)
NS_IMPL_THREADSAFE_ISUPPORTS2(ContentProcessParent,
nsIObserver,
nsIThreadObserver)
namespace {
void
@ -182,5 +208,63 @@ ContentProcessParent::DeallocPNecko(PNeckoParent* necko)
return true;
}
bool
ContentProcessParent::RequestRunToCompletion()
{
if (!mRunToCompletionDepth &&
BlockChild()) {
#ifdef DEBUG
printf("Running to completion...\n");
#endif
mRunToCompletionDepth = 1;
}
return !!mRunToCompletionDepth;
}
/* void onDispatchedEvent (in nsIThreadInternal thread); */
NS_IMETHODIMP
ContentProcessParent::OnDispatchedEvent(nsIThreadInternal *thread)
{
if (mOldObserver)
return mOldObserver->OnDispatchedEvent(thread);
return NS_OK;
}
/* void onProcessNextEvent (in nsIThreadInternal thread, in boolean mayWait, in unsigned long recursionDepth); */
NS_IMETHODIMP
ContentProcessParent::OnProcessNextEvent(nsIThreadInternal *thread,
PRBool mayWait,
PRUint32 recursionDepth)
{
if (mRunToCompletionDepth)
++mRunToCompletionDepth;
if (mOldObserver)
return mOldObserver->OnProcessNextEvent(thread, mayWait, recursionDepth);
return NS_OK;
}
/* void afterProcessNextEvent (in nsIThreadInternal thread, in unsigned long recursionDepth); */
NS_IMETHODIMP
ContentProcessParent::AfterProcessNextEvent(nsIThreadInternal *thread,
PRUint32 recursionDepth)
{
if (mRunToCompletionDepth &&
!--mRunToCompletionDepth) {
#ifdef DEBUG
printf("... ran to completion.\n");
#endif
UnblockChild();
}
if (mOldObserver)
return mOldObserver->AfterProcessNextEvent(thread, recursionDepth);
return NS_OK;
}
} // namespace dom
} // namespace mozilla

View File

@ -45,6 +45,7 @@
#include "mozilla/ipc/GeckoChildProcessHost.h"
#include "nsIObserver.h"
#include "nsIThreadInternal.h"
#include "mozilla/Monitor.h"
namespace mozilla {
@ -57,8 +58,9 @@ namespace dom {
class TabParent;
class ContentProcessParent : public PContentProcessParent,
public nsIObserver
class ContentProcessParent : public PContentProcessParent
, public nsIObserver
, public nsIThreadObserver
{
private:
typedef mozilla::ipc::GeckoChildProcessHost GeckoChildProcessHost;
@ -74,12 +76,18 @@ public:
NS_DECL_ISUPPORTS
NS_DECL_NSIOBSERVER
NS_DECL_NSITHREADOBSERVER
TabParent* CreateTab();
TestShellParent* CreateTestShell();
bool DestroyTestShell(TestShellParent* aTestShell);
bool RequestRunToCompletion();
protected:
virtual void ActorDestroy(ActorDestroyReason why);
private:
static ContentProcessParent* gSingleton;
@ -103,6 +111,10 @@ private:
mozilla::Monitor mMonitor;
GeckoChildProcessHost* mSubprocess;
int mRunToCompletionDepth;
nsCOMPtr<nsIThreadObserver> mOldObserver;
};
} // namespace dom