mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-23 10:54:33 +00:00
add SyncLaunch() method to GeckoChildProcess class. remove much newly obseleted code.
This commit is contained in:
parent
e516ddf1a1
commit
69604af50f
@ -49,7 +49,6 @@ EXPORT_LIBRARY = 1
|
||||
|
||||
CPPSRCS = \
|
||||
TabParent.cpp \
|
||||
TabProcessParent.cpp \
|
||||
TabChild.cpp \
|
||||
TabThread.cpp \
|
||||
$(NULL)
|
||||
|
@ -6,27 +6,13 @@
|
||||
|
||||
using mozilla::ipc::BrowserProcessSubThread;
|
||||
|
||||
template<>
|
||||
struct RunnableMethodTraits<mozilla::tabs::TabParent>
|
||||
{
|
||||
static void RetainCallee(mozilla::tabs::TabParent* obj) { }
|
||||
static void ReleaseCallee(mozilla::tabs::TabParent* obj) { }
|
||||
};
|
||||
|
||||
namespace mozilla {
|
||||
namespace tabs {
|
||||
|
||||
TabParent::TabParent(MagicWindowHandle parentWidget)
|
||||
: mSubprocess()
|
||||
, mMonitor("mozilla.dom.ipc.TabParent")
|
||||
: mSubprocess(GeckoChildProcess_Tab)
|
||||
{
|
||||
{
|
||||
MonitorAutoEnter mon(mMonitor);
|
||||
BrowserProcessSubThread::GetMessageLoop(BrowserProcessSubThread::IO)->
|
||||
PostTask(FROM_HERE, NewRunnableMethod(this, &TabParent::LaunchSubprocess));
|
||||
mon.Wait();
|
||||
}
|
||||
|
||||
mSubprocess.SyncLaunch();
|
||||
Open(mSubprocess.GetChannel());
|
||||
|
||||
Sendinit(parentWidget);
|
||||
@ -36,14 +22,6 @@ TabParent::~TabParent()
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
TabParent::LaunchSubprocess()
|
||||
{
|
||||
MonitorAutoEnter mon(mMonitor);
|
||||
mSubprocess.Launch();
|
||||
mon.Notify();
|
||||
}
|
||||
|
||||
void
|
||||
TabParent::LoadURL(nsIURI* aURI)
|
||||
{
|
||||
|
@ -7,9 +7,8 @@
|
||||
#include "TabTypes.h"
|
||||
#include "IFrameEmbeddingProtocol.h"
|
||||
#include "IFrameEmbeddingProtocolParent.h"
|
||||
#include "TabProcessParent.h"
|
||||
|
||||
#include "mozilla/Monitor.h"
|
||||
#include "mozilla/ipc/GeckoChildProcessHost.h"
|
||||
|
||||
class nsIURI;
|
||||
|
||||
@ -19,6 +18,9 @@ namespace tabs {
|
||||
class TabParent
|
||||
: private IFrameEmbeddingProtocolParent
|
||||
{
|
||||
private:
|
||||
typedef mozilla::ipc::GeckoChildProcessHost GeckoChildProcessHost;
|
||||
|
||||
public:
|
||||
TabParent(MagicWindowHandle parentWidget);
|
||||
virtual ~TabParent();
|
||||
@ -27,11 +29,7 @@ public:
|
||||
void Move(PRUint32 x, PRUint32 y, PRUint32 width, PRUint32 height);
|
||||
|
||||
private:
|
||||
void LaunchSubprocess();
|
||||
|
||||
TabProcessParent mSubprocess;
|
||||
|
||||
mozilla::Monitor mMonitor;
|
||||
GeckoChildProcessHost mSubprocess;
|
||||
};
|
||||
|
||||
} // namespace tabs
|
||||
|
@ -1,23 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* vim: sw=4 ts=4 et : */
|
||||
|
||||
#include "TabProcessParent.h"
|
||||
|
||||
using mozilla::ipc::GeckoChildProcessHost;
|
||||
|
||||
namespace mozilla {
|
||||
namespace tabs {
|
||||
|
||||
|
||||
TabProcessParent::TabProcessParent() :
|
||||
GeckoChildProcessHost(GeckoChildProcess_Tab)
|
||||
{
|
||||
}
|
||||
|
||||
TabProcessParent::~TabProcessParent()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
} // namespace tabs
|
||||
} // namespace mozilla
|
@ -1,38 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* vim: sw=4 ts=4 et : */
|
||||
|
||||
#ifndef mozilla_tabs_TabProcessParent_h
|
||||
#define mozilla_tabs_TabProcessParent_h
|
||||
|
||||
#include "mozilla/ipc/GeckoChildProcessHost.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace tabs {
|
||||
|
||||
class TabProcessParent
|
||||
: public mozilla::ipc::GeckoChildProcessHost
|
||||
{
|
||||
public:
|
||||
TabProcessParent();
|
||||
~TabProcessParent();
|
||||
|
||||
IPC::Channel* GetChannel() {
|
||||
return channelp();
|
||||
}
|
||||
|
||||
virtual bool CanShutdown() {
|
||||
return true;
|
||||
}
|
||||
|
||||
base::WaitableEvent* GetShutDownEvent() {
|
||||
return GetProcessEvent();
|
||||
}
|
||||
|
||||
private:
|
||||
DISALLOW_EVIL_CONSTRUCTORS(TabProcessParent);
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@ -38,21 +38,6 @@
|
||||
|
||||
#include "mozilla/plugins/NPAPIPluginParent.h"
|
||||
|
||||
#include "base/task.h"
|
||||
|
||||
#include "mozilla/ipc/GeckoThread.h"
|
||||
|
||||
using mozilla::Monitor;
|
||||
using mozilla::MonitorAutoEnter;
|
||||
using mozilla::ipc::BrowserProcessSubThread;
|
||||
|
||||
template<>
|
||||
struct RunnableMethodTraits<mozilla::plugins::NPAPIPluginParent>
|
||||
{
|
||||
static void RetainCallee(mozilla::plugins::NPAPIPluginParent* obj) { }
|
||||
static void ReleaseCallee(mozilla::plugins::NPAPIPluginParent* obj) { }
|
||||
};
|
||||
|
||||
namespace mozilla {
|
||||
namespace plugins {
|
||||
|
||||
@ -64,17 +49,7 @@ NPAPIPluginParent::LoadModule(const char* aFilePath, PRLibrary* aLibrary)
|
||||
|
||||
// Block on the child process being launched and initialized.
|
||||
NPAPIPluginParent* parent = new NPAPIPluginParent(aFilePath);
|
||||
|
||||
// launch the process synchronously
|
||||
{MonitorAutoEnter mon(parent->mMonitor);
|
||||
BrowserProcessSubThread::GetMessageLoop(BrowserProcessSubThread::IO)
|
||||
->PostTask(
|
||||
FROM_HERE,
|
||||
NewRunnableMethod(parent,
|
||||
&NPAPIPluginParent::LaunchSubprocess));
|
||||
mon.Wait();
|
||||
}
|
||||
|
||||
parent->mSubprocess.Launch();
|
||||
parent->Open(parent->mSubprocess.GetChannel());
|
||||
|
||||
// FIXME/cjones: leaking NPAPIPluginParents ...
|
||||
@ -85,7 +60,6 @@ NPAPIPluginParent::LoadModule(const char* aFilePath, PRLibrary* aLibrary)
|
||||
NPAPIPluginParent::NPAPIPluginParent(const char* aFilePath) :
|
||||
mFilePath(aFilePath),
|
||||
mSubprocess(aFilePath),
|
||||
mMonitor("mozilla.plugins.NPAPIPluginParent.LaunchPluginProcess"),
|
||||
ALLOW_THIS_IN_INITIALIZER_LIST(mShim(new Shim(this)))
|
||||
{
|
||||
}
|
||||
@ -96,14 +70,6 @@ NPAPIPluginParent::~NPAPIPluginParent()
|
||||
delete mShim;
|
||||
}
|
||||
|
||||
void
|
||||
NPAPIPluginParent::LaunchSubprocess()
|
||||
{
|
||||
MonitorAutoEnter mon(mMonitor);
|
||||
mSubprocess.Launch();
|
||||
mon.Notify();
|
||||
}
|
||||
|
||||
NPPProtocolParent*
|
||||
NPAPIPluginParent::NPPConstructor(const String& aMimeType,
|
||||
const uint16_t& aMode,
|
||||
|
@ -51,7 +51,6 @@
|
||||
|
||||
#include "base/string_util.h"
|
||||
|
||||
#include "mozilla/Monitor.h"
|
||||
#include "mozilla/SharedLibrary.h"
|
||||
#include "mozilla/plugins/NPAPIProtocol.h"
|
||||
#include "mozilla/plugins/NPAPIProtocolParent.h"
|
||||
@ -111,8 +110,6 @@ public:
|
||||
PRLibrary* aLibrary);
|
||||
|
||||
private:
|
||||
void LaunchSubprocess();
|
||||
|
||||
void SetPluginFuncs(NPPluginFuncs* aFuncs);
|
||||
|
||||
// Implement the module-level functions from NPAPI; these are
|
||||
@ -477,8 +474,6 @@ private:
|
||||
PluginProcessParent mSubprocess;
|
||||
const NPNetscapeFuncs* mNPNIface;
|
||||
|
||||
mozilla::Monitor mMonitor;
|
||||
|
||||
// NPObject interface
|
||||
|
||||
#if 0
|
||||
|
@ -62,7 +62,7 @@ PluginProcessParent::Launch()
|
||||
{
|
||||
std::vector<std::wstring> args;
|
||||
args.push_back(UTF8ToWide(mPluginFilePath));
|
||||
return mozilla::ipc::GeckoChildProcessHost::Launch(args);
|
||||
return SyncLaunch(args);
|
||||
}
|
||||
|
||||
|
||||
|
@ -41,17 +41,54 @@
|
||||
#include "base/string_util.h"
|
||||
#include "chrome/common/chrome_switches.h"
|
||||
|
||||
#include "mozilla/ipc/GeckoThread.h"
|
||||
|
||||
using mozilla::MonitorAutoEnter;
|
||||
using mozilla::ipc::GeckoChildProcessHost;
|
||||
|
||||
template<>
|
||||
struct RunnableMethodTraits<GeckoChildProcessHost>
|
||||
{
|
||||
static void RetainCallee(GeckoChildProcessHost* obj) { }
|
||||
static void ReleaseCallee(GeckoChildProcessHost* obj) { }
|
||||
};
|
||||
|
||||
GeckoChildProcessHost::GeckoChildProcessHost(GeckoChildProcessType aProcessType)
|
||||
: ChildProcessHost(RENDER_PROCESS), // FIXME/cjones: we should own this enum
|
||||
mProcessType(aProcessType)
|
||||
mProcessType(aProcessType),
|
||||
mMonitor("mozilla.ipc.GeckChildProcessHost.mMonitor"),
|
||||
mLaunched(false)
|
||||
{
|
||||
}
|
||||
|
||||
bool
|
||||
GeckoChildProcessHost::Launch(std::vector<std::wstring> aExtraOpts)
|
||||
GeckoChildProcessHost::SyncLaunch(std::vector<std::wstring> aExtraOpts)
|
||||
{
|
||||
MessageLoop* loop = MessageLoop::current();
|
||||
MessageLoop* ioLoop =
|
||||
BrowserProcessSubThread::GetMessageLoop(BrowserProcessSubThread::IO);
|
||||
NS_ASSERTION(loop != ioLoop, "sync launch from the IO thread NYI");
|
||||
|
||||
ioLoop->PostTask(FROM_HERE,
|
||||
NewRunnableMethod(this,
|
||||
&GeckoChildProcessHost::AsyncLaunch,
|
||||
aExtraOpts));
|
||||
|
||||
// NB: this uses a different mechanism than the chromium parent
|
||||
// class.
|
||||
MonitorAutoEnter mon(mMonitor);
|
||||
while (!mLaunched) {
|
||||
mon.Wait();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
GeckoChildProcessHost::AsyncLaunch(std::vector<std::wstring> aExtraOpts)
|
||||
{
|
||||
// FIXME/cjones: make this work from non-IO threads, too
|
||||
|
||||
if (!CreateChannel()) {
|
||||
return false;
|
||||
}
|
||||
@ -95,30 +132,24 @@ GeckoChildProcessHost::Launch(std::vector<std::wstring> aExtraOpts)
|
||||
}
|
||||
SetHandle(process);
|
||||
|
||||
// FIXME/cjones: should have the option for sync/async launch.
|
||||
// however, since most clients already expect this launch to be
|
||||
// synchronous wrt the channel connecting, we'll hack a bit here.
|
||||
// (at least we're on the IO thread and not blocking main ...)
|
||||
MessageLoop* loop = MessageLoop::current();
|
||||
bool old_state = loop->NestableTasksAllowed();
|
||||
loop->SetNestableTasksAllowed(true);
|
||||
// spin the loop until OnChannelConnected() comes in, which will Quit() us
|
||||
loop->Run();
|
||||
loop->SetNestableTasksAllowed(old_state);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
GeckoChildProcessHost::OnChannelConnected(int32 peer_pid)
|
||||
{
|
||||
MessageLoop::current()->Quit();
|
||||
MonitorAutoEnter mon(mMonitor);
|
||||
mLaunched = true;
|
||||
mon.Notify();
|
||||
}
|
||||
|
||||
// XXX/cjones: these next two methods should basically never be called.
|
||||
// after the process is launched, its channel will be used to create
|
||||
// one of our channels, AsyncChannel et al.
|
||||
void
|
||||
GeckoChildProcessHost::OnMessageReceived(const IPC::Message& aMsg)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
GeckoChildProcessHost::OnChannelError()
|
||||
{
|
||||
|
@ -43,6 +43,8 @@
|
||||
#include "base/waitable_event.h"
|
||||
#include "chrome/common/child_process_host.h"
|
||||
|
||||
#include "mozilla/Monitor.h"
|
||||
|
||||
#include "nsXULAppAPI.h" // for GeckoChildProcessType
|
||||
|
||||
namespace mozilla {
|
||||
@ -50,12 +52,15 @@ namespace ipc {
|
||||
|
||||
class GeckoChildProcessHost : public ChildProcessHost
|
||||
{
|
||||
protected:
|
||||
typedef mozilla::Monitor Monitor;
|
||||
|
||||
public:
|
||||
GeckoChildProcessHost(GeckoChildProcessType aProcessType=GeckoChildProcess_Default);
|
||||
|
||||
bool Launch(std::vector<std::wstring> aExtraOpts=std::vector<std::wstring>());
|
||||
bool SyncLaunch(std::vector<std::wstring> aExtraOpts=std::vector<std::wstring>());
|
||||
bool AsyncLaunch(std::vector<std::wstring> aExtraOpts=std::vector<std::wstring>());
|
||||
|
||||
// FIXME/cjones: these should probably disappear
|
||||
virtual void OnChannelConnected(int32 peer_pid);
|
||||
virtual void OnMessageReceived(const IPC::Message& aMsg);
|
||||
virtual void OnChannelError();
|
||||
@ -72,6 +77,8 @@ public:
|
||||
|
||||
protected:
|
||||
GeckoChildProcessType mProcessType;
|
||||
Monitor mMonitor;
|
||||
bool mLaunched;
|
||||
FilePath mProcessPath;
|
||||
|
||||
#if defined(OS_POSIX)
|
||||
|
@ -404,7 +404,8 @@ public:
|
||||
GeckoChildProcessHost* host =
|
||||
new GeckoChildProcessHost(GeckoChildProcess_TestShell);
|
||||
if (host) {
|
||||
if (!host->Launch()) {
|
||||
// FIXME/bent: use SyncLaunch() API to simplify this code
|
||||
if (!host->AsyncLaunch()) {
|
||||
delete host;
|
||||
}
|
||||
// ChildProcessHost deletes itself once the child process exits, on
|
||||
@ -525,42 +526,23 @@ XRE_RunTestShell(int aArgc, char* aArgv[])
|
||||
// TestHarness
|
||||
|
||||
static void
|
||||
IPCTestHarnessMain(TestProcessParent* subprocess)
|
||||
IPCTestHarnessMain(void* data)
|
||||
{
|
||||
TestParent* parent = new TestParent(); // leaks
|
||||
TestProcessParent* subprocess = new TestProcessParent(); // leaks
|
||||
bool launched = subprocess->SyncLaunch();
|
||||
NS_ASSERTION(launched, "can't launch subprocess");
|
||||
|
||||
TestParent* parent = new TestParent(); // leaks
|
||||
parent->Open(subprocess->GetChannel());
|
||||
parent->DoStuff();
|
||||
}
|
||||
|
||||
static void
|
||||
IPCTestHarnessLaunchSubprocess(TestProcessParent* subprocess,
|
||||
MessageLoop* mainLoop)
|
||||
{
|
||||
bool launched = subprocess->Launch();
|
||||
NS_ASSERTION(launched, "can't launch subprocess");
|
||||
mainLoop->PostTask(FROM_HERE,
|
||||
NewRunnableFunction(IPCTestHarnessMain, subprocess));
|
||||
}
|
||||
|
||||
static void
|
||||
IPCTestHarnessPostLaunchSubprocessTask(void* data)
|
||||
{
|
||||
TestProcessParent* subprocess = new TestProcessParent();
|
||||
MessageLoop* ioLoop =
|
||||
BrowserProcessSubThread::GetMessageLoop(BrowserProcessSubThread::IO);
|
||||
ioLoop->PostTask(FROM_HERE,
|
||||
NewRunnableFunction(IPCTestHarnessLaunchSubprocess,
|
||||
subprocess,
|
||||
MessageLoop::current()));
|
||||
}
|
||||
|
||||
int
|
||||
XRE_RunIPCTestHarness(int aArgc, char* aArgv[])
|
||||
{
|
||||
nsresult rv =
|
||||
XRE_InitParentProcess(
|
||||
aArgc, aArgv, IPCTestHarnessPostLaunchSubprocessTask, NULL);
|
||||
aArgc, aArgv, IPCTestHarnessMain, NULL);
|
||||
NS_ENSURE_SUCCESS(rv, 1);
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user