Bug 517963 - New-tab opening should not launch the content process synchronously r=cjones

This commit is contained in:
Josh Matthews 2009-11-18 16:43:53 -05:00
parent 36bdecc47f
commit 2414bcabb4
3 changed files with 47 additions and 4 deletions

View File

@ -105,9 +105,8 @@ ContentProcessParent::ContentProcessParent()
: mMonitor("ContentProcessParent::mMonitor")
{
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
// TODO: async launching!
mSubprocess = new GeckoChildProcessHost(GeckoProcessType_Content, this);
mSubprocess->SyncLaunch();
mSubprocess->AsyncLaunch();
Open(mSubprocess->GetChannel(), mSubprocess->GetChildProcessHandle());
}

View File

@ -1,3 +1,4 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
@ -61,10 +62,17 @@ GeckoChildProcessHost::GeckoChildProcessHost(GeckoProcessType aProcessType,
mProcessType(aProcessType),
mMonitor("mozilla.ipc.GeckChildProcessHost.mMonitor"),
mLaunched(false),
mChannelInitialized(false),
mDelegate(aDelegate),
mChildProcessHandle(0)
{
MOZ_COUNT_CTOR(GeckoChildProcessHost);
MessageLoop* ioLoop =
BrowserProcessSubThread::GetMessageLoop(BrowserProcessSubThread::IO);
ioLoop->PostTask(FROM_HERE,
NewRunnableMethod(this,
&GeckoChildProcessHost::InitializeChannel));
}
GeckoChildProcessHost::~GeckoChildProcessHost()
@ -81,7 +89,7 @@ GeckoChildProcessHost::SyncLaunch(std::vector<std::string> aExtraOpts)
ioLoop->PostTask(FROM_HERE,
NewRunnableMethod(this,
&GeckoChildProcessHost::AsyncLaunch,
&GeckoChildProcessHost::PerformAsyncLaunch,
aExtraOpts));
// NB: this uses a different mechanism than the chromium parent
@ -96,10 +104,42 @@ GeckoChildProcessHost::SyncLaunch(std::vector<std::string> aExtraOpts)
bool
GeckoChildProcessHost::AsyncLaunch(std::vector<std::string> aExtraOpts)
{
MessageLoop* ioLoop =
BrowserProcessSubThread::GetMessageLoop(BrowserProcessSubThread::IO);
ioLoop->PostTask(FROM_HERE,
NewRunnableMethod(this,
&GeckoChildProcessHost::PerformAsyncLaunch,
aExtraOpts));
// This may look like the sync launch wait, but we only delay as
// long as it takes to create the channel.
MonitorAutoEnter mon(mMonitor);
while (!mChannelInitialized) {
mon.Wait();
}
return true;
}
void
GeckoChildProcessHost::InitializeChannel()
{
CreateChannel();
MonitorAutoEnter mon(mMonitor);
mChannelInitialized = true;
mon.Notify();
}
bool
GeckoChildProcessHost::PerformAsyncLaunch(std::vector<std::string> aExtraOpts)
{
// FIXME/cjones: make this work from non-IO threads, too
if (!CreateChannel()) {
// We rely on the fact that InitializeChannel() has already been processed
// on the IO thread before this point is reached.
if (!GetChannel()) {
return false;
}

View File

@ -65,11 +65,14 @@ public:
bool SyncLaunch(std::vector<std::string> aExtraOpts=std::vector<std::string>());
bool AsyncLaunch(std::vector<std::string> aExtraOpts=std::vector<std::string>());
bool PerformAsyncLaunch(std::vector<std::string> aExtraOpts=std::vector<std::string>());
virtual void OnChannelConnected(int32 peer_pid);
virtual void OnMessageReceived(const IPC::Message& aMsg);
virtual void OnChannelError();
void InitializeChannel();
virtual bool CanShutdown() { return true; }
virtual void OnWaitableEventSignaled(base::WaitableEvent *event);
@ -90,6 +93,7 @@ protected:
GeckoProcessType mProcessType;
Monitor mMonitor;
bool mLaunched;
bool mChannelInitialized;
FilePath mProcessPath;
#if defined(OS_POSIX)