Bug 528146: Run plug-in code on the thread that starts in main(). r=cjones

--HG--
rename : dom/plugins/PluginThreadChild.cpp => dom/plugins/PluginProcessChild.cpp
rename : dom/plugins/PluginThreadChild.h => dom/plugins/PluginProcessChild.h
rename : ipc/ipdl/test/cxx/IPDLUnitTestThreadChild.cpp => ipc/ipdl/test/cxx/IPDLUnitTestProcessChild.cpp
rename : ipc/ipdl/test/cxx/IPDLUnitTestThreadChild.h => ipc/ipdl/test/cxx/IPDLUnitTestProcessChild.h
This commit is contained in:
Benoit Girard 2010-05-10 23:18:00 -05:00
Родитель 2bc816b4ee
Коммит 7c3b2bbde3
19 изменённых файлов: 266 добавлений и 230 удалений

Просмотреть файл

@ -83,7 +83,7 @@ EXPORTS_mozilla/plugins = \
PluginStreamParent.h \
PluginMessageUtils.h \
PluginProcessParent.h \
PluginThreadChild.h \
PluginProcessChild.h \
StreamNotifyChild.h \
StreamNotifyParent.h \
$(NULL)
@ -103,6 +103,7 @@ CPPSRCS = \
PluginInstanceParent.cpp \
PluginModuleChild.cpp \
PluginModuleParent.cpp \
PluginProcessChild.cpp \
PluginProcessParent.cpp \
PluginScriptableObjectChild.cpp \
PluginScriptableObjectParent.cpp \
@ -110,7 +111,6 @@ CPPSRCS = \
BrowserStreamParent.cpp \
PluginStreamChild.cpp \
PluginStreamParent.cpp \
PluginThreadChild.cpp \
$(NULL)
LOCAL_INCLUDES = \

Просмотреть файл

@ -42,10 +42,11 @@
#include "BrowserStreamChild.h"
#include "PluginStreamChild.h"
#include "StreamNotifyChild.h"
#include "PluginThreadChild.h"
#include "PluginProcessChild.h"
#include "mozilla/ipc/SyncChannel.h"
using mozilla::ipc::ProcessChild;
using namespace mozilla::plugins;
#ifdef MOZ_WIDGET_GTK2
@ -1930,7 +1931,7 @@ PluginInstanceChild::AsyncCall(PluginThreadCallback aFunc, void* aUserData)
MutexAutoLock lock(mAsyncCallMutex);
mPendingAsyncCalls.AppendElement(task);
}
PluginThreadChild::current()->message_loop()->PostTask(FROM_HERE, task);
ProcessChild::message_loop()->PostTask(FROM_HERE, task);
}
static PLDHashOperator

Просмотреть файл

@ -59,7 +59,6 @@
#include "mozilla/plugins/StreamNotifyChild.h"
#include "mozilla/plugins/BrowserStreamChild.h"
#include "mozilla/plugins/PluginStreamChild.h"
#include "mozilla/plugins/PluginThreadChild.h"
#include "PluginIdentifierChild.h"
#include "nsNPAPIPlugin.h"

Просмотреть файл

@ -37,38 +37,35 @@
*
* ***** END LICENSE BLOCK ***** */
#include "mozilla/plugins/PluginThreadChild.h"
#include "mozilla/ipc/IOThreadChild.h"
#include "mozilla/plugins/PluginProcessChild.h"
#include "prlink.h"
#include "base/command_line.h"
#include "base/string_util.h"
#include "chrome/common/child_process.h"
#include "chrome/common/chrome_switches.h"
using mozilla::ipc::MozillaChildThread;
#ifdef XP_WIN
#include <objbase.h>
#endif
using mozilla::ipc::IOThreadChild;
namespace mozilla {
namespace plugins {
PluginThreadChild::PluginThreadChild(ProcessHandle aParentHandle) :
MozillaChildThread(aParentHandle, MessageLoop::TYPE_UI)
bool
PluginProcessChild::Init()
{
NS_ASSERTION(!gInstance, "Two PluginThreadChild?");
gInstance = this;
}
#ifdef XP_WIN
// Silverlight depends on the host calling CoInitialize.
::CoInitialize(NULL);
#endif
PluginThreadChild::~PluginThreadChild()
{
gInstance = NULL;
}
PluginThreadChild* PluginThreadChild::gInstance;
void
PluginThreadChild::Init()
{
MozillaChildThread::Init();
// Certain plugins, such as flash, steal the unhandled exception filter
// thus we never get crash reports when they fault. This call fixes it.
message_loop()->set_exception_restoration(true);
std::string pluginFilename;
@ -92,26 +89,30 @@ PluginThreadChild::Init()
# error Sorry
#endif
// FIXME owner_loop() is bad here
mPlugin.Init(pluginFilename,
GetParentProcessHandle(), owner_loop(), channel());
mPlugin.Init(pluginFilename, ParentHandle(),
IOThreadChild::message_loop(),
IOThreadChild::channel());
return true;
}
void
PluginThreadChild::CleanUp()
PluginProcessChild::CleanUp()
{
mPlugin.CleanUp();
MozillaChildThread::CleanUp();
#ifdef XP_WIN
::CoUninitialize();
#endif
}
/* static */
void
PluginThreadChild::AppendNotesToCrashReport(const nsCString& aNotes)
PluginProcessChild::AppendNotesToCrashReport(const nsCString& aNotes)
{
AssertPluginThread();
if (gInstance) {
gInstance->mPlugin.SendAppendNotesToCrashReport(aNotes);
PluginProcessChild* p = PluginProcessChild::current();
if (p) {
p->mPlugin.SendAppendNotesToCrashReport(aNotes);
}
}

Просмотреть файл

@ -37,49 +37,45 @@
*
* ***** END LICENSE BLOCK ***** */
#ifndef dom_plugins_PluginThreadChild_h
#define dom_plugins_PluginThreadChild_h 1
#include "base/basictypes.h"
#include "mozilla/ipc/MozillaChildThread.h"
#include "base/file_path.h"
#include "base/process.h"
#ifndef dom_plugins_PluginProcessChild_h
#define dom_plugins_PluginProcessChild_h 1
#include "mozilla/ipc/ProcessChild.h"
#include "mozilla/plugins/PluginModuleChild.h"
namespace mozilla {
namespace plugins {
//-----------------------------------------------------------------------------
// The PluginThreadChild class represents a background thread where plugin instances
// live.
class PluginThreadChild : public mozilla::ipc::MozillaChildThread {
public:
PluginThreadChild(ProcessHandle aParentHandle);
~PluginThreadChild();
class PluginProcessChild : public mozilla::ipc::ProcessChild {
protected:
typedef mozilla::ipc::ProcessChild ProcessChild;
static PluginThreadChild* current() {
return gInstance;
}
public:
PluginProcessChild(ProcessHandle parentHandle) : ProcessChild(parentHandle)
{ }
virtual ~PluginProcessChild()
{ }
NS_OVERRIDE virtual bool Init();
NS_OVERRIDE virtual void CleanUp();
// For use on the plugin thread.
static void AppendNotesToCrashReport(const nsCString& aNotes);
protected:
static PluginProcessChild* current() {
return static_cast<PluginProcessChild*>(ProcessChild::current());
}
private:
static PluginThreadChild* gInstance;
// Thread implementation:
virtual void Init();
virtual void CleanUp();
PluginModuleChild mPlugin;
IPC::Channel* mChannel;
DISALLOW_EVIL_CONSTRUCTORS(PluginThreadChild);
DISALLOW_EVIL_CONSTRUCTORS(PluginProcessChild);
};
} // namespace plugins
} // namespace mozilla
#endif // ifndef dom_plugins_PluginThreadChild_h
#endif // ifndef dom_plugins_PluginProcessChild_h

Просмотреть файл

@ -145,19 +145,10 @@ void Thread::ThreadMain() {
message_loop.set_thread_name(name_);
message_loop_ = &message_loop;
#if defined(CHROMIUM_MOZILLA_BUILD)
bool wait_for_init = startup_data_->options.wait_for_init;
if (!wait_for_init)
startup_data_->event.Signal();
#endif
// Let the thread do extra initialization.
// Let's do this before signaling we are started.
Init();
#if defined(CHROMIUM_MOZILLA_BUILD)
if (wait_for_init)
#endif
startup_data_->event.Signal();
// startup_data_ can't be touched anymore since the starting thread is now
// unlocked.

Просмотреть файл

@ -28,35 +28,9 @@ class Thread : PlatformThread::Delegate {
// A value of 0 indicates that the default maximum should be used.
size_t stack_size;
#if defined(CHROMIUM_MOZILLA_BUILD)
// Specifies whether the thread that launched this sub-thread
// should wait for the sub-thread's Init() routine to finish
// before dropping into the event loop. If it is false, the
// sub-thread will signal just before calling Init(). If true,
// the sub-thread will signal just after.
bool wait_for_init;
Options() :
message_loop_type(MessageLoop::TYPE_DEFAULT),
stack_size(0),
wait_for_init(true)
{}
Options(MessageLoop::Type type, size_t size) :
message_loop_type(type),
stack_size(size),
wait_for_init(true)
{}
Options(MessageLoop::Type type, size_t size, bool wait_init) :
message_loop_type(type),
stack_size(size),
wait_for_init(wait_init)
{}
#else
Options() : message_loop_type(MessageLoop::TYPE_DEFAULT), stack_size(0) {}
Options(MessageLoop::Type type, size_t size)
: message_loop_type(type), stack_size(size) {}
#endif
};
// Constructor.

Просмотреть файл

@ -80,6 +80,9 @@ void Channel::ChannelImpl::Close() {
output_queue_.pop();
delete m;
}
if (thread_check_.get())
thread_check_.reset();
}
bool Channel::ChannelImpl::Send(Message* message) {

Просмотреть файл

@ -20,7 +20,11 @@ class Channel::ChannelImpl : public MessageLoopForIO::IOHandler {
public:
// Mirror methods of Channel, see ipc_channel.h for description.
ChannelImpl(const std::wstring& channel_id, Mode mode, Listener* listener);
~ChannelImpl() { Close(); }
~ChannelImpl() {
if (pipe_ != INVALID_HANDLE_VALUE) {
Close();
}
}
bool Connect();
void Close();
void set_listener(Listener* listener) { listener_ = listener; }

82
ipc/glue/IOThreadChild.h Normal file
Просмотреть файл

@ -0,0 +1,82 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
* vim: sw=2 ts=2 et :
* ***** 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 Mozilla Plugin App.
*
* The Initial Developer of the Original Code is
* The Mozilla Foundation
* Portions created by the Initial Developer are Copyright (C) 2009
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Benoit Girard <b56girard@gmail.com>.
*
* 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 ***** */
#ifndef dom_plugins_IOThreadChild_h
#define dom_plugins_IOThreadChild_h 1
#include "chrome/common/child_thread.h"
namespace mozilla {
namespace ipc {
//-----------------------------------------------------------------------------
// The IOThreadChild class represents a background thread where the
// IPC IO MessageLoop lives.
class IOThreadChild : public ChildThread {
public:
IOThreadChild()
: ChildThread(base::Thread::Options(MessageLoop::TYPE_IO,
0)) // stack size
{ }
~IOThreadChild()
{ }
static MessageLoop* message_loop() {
return IOThreadChild::current()->Thread::message_loop();
}
// IOThreadChild owns the returned IPC::Channel.
static IPC::Channel* channel() {
return IOThreadChild::current()->ChildThread::channel();
}
protected:
static IOThreadChild* current() {
return static_cast<IOThreadChild*>(ChildThread::current());
}
private:
DISALLOW_EVIL_CONSTRUCTORS(IOThreadChild);
};
} // namespace plugins
} // namespace mozilla
#endif // ifndef dom_plugins_IOThreadChild_h

Просмотреть файл

@ -57,7 +57,8 @@ EXPORTS_mozilla/ipc = \
AsyncChannel.h \
BrowserProcessSubThread.h \
GeckoChildProcessHost.h \
MozillaChildThread.h \
IOThreadChild.h \
ProcessChild.h \
ProtocolUtils.h \
RPCChannel.h \
SharedMemory.h \
@ -74,8 +75,8 @@ CPPSRCS += \
AsyncChannel.cpp \
BrowserProcessSubThread.cpp \
GeckoChildProcessHost.cpp \
MozillaChildThread.cpp \
MessagePump.cpp \
ProcessChild.cpp \
RPCChannel.cpp \
ScopedXREEmbed.cpp \
Shmem.cpp \

Просмотреть файл

@ -6,7 +6,7 @@
*
* 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
* 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,
@ -14,11 +14,11 @@
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Plugin App.
* The Original Code is Mozilla Code.
*
* The Initial Developer of the Original Code is
* Ben Turner <bent.mozilla@gmail.com>.
* Portions created by the Initial Developer are Copyright (C) 2009
* The Mozilla Foundation
* Portions created by the Initial Developer are Copyright (C) 2010
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
@ -37,51 +37,29 @@
*
* ***** END LICENSE BLOCK ***** */
#include "mozilla/ipc/MozillaChildThread.h"
#include "nsDebug.h"
#include "nsXPCOM.h"
#ifdef XP_WIN
#include <objbase.h>
#endif
#include "mozilla/ipc/IOThreadChild.h"
#include "mozilla/ipc/ProcessChild.h"
namespace mozilla {
namespace ipc {
void
MozillaChildThread::OnControlMessageReceived(const IPC::Message& aMessage) {
/*
IPC_BEGIN_MESSAGE_MAP(MozillaChildThread, aMessage)
IPC_END_MESSAGE_MAP()
*/
ProcessChild* ProcessChild::gProcessChild;
ProcessChild::ProcessChild(ProcessHandle parentHandle)
: ChildProcess(new IOThreadChild())
, mUILoop(MessageLoop::current())
, mParentHandle(parentHandle)
{
NS_ABORT_IF_FALSE(mUILoop, "UILoop should be created by now");
NS_ABORT_IF_FALSE(!gProcessChild, "should only be one ProcessChild");
gProcessChild = this;
}
void
MozillaChildThread::Init()
ProcessChild::~ProcessChild()
{
ChildThread::Init();
#ifdef XP_WIN
// Silverlight depends on the host calling CoInitialize.
::CoInitialize(NULL);
#endif
// Add notification service here once bug 560630 is fixed
// Certain plugins, such as flash, steal the unhandled exception filter
// thus we never get crash reports when they fault. This call fixes it.
message_loop()->set_exception_restoration(true);
NS_LogInit();
}
void
MozillaChildThread::CleanUp()
{
NS_LogTerm();
#ifdef XP_WIN
::CoUninitialize();
#endif
gProcessChild = NULL;
}
} // namespace ipc

Просмотреть файл

@ -6,7 +6,7 @@
*
* 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
* 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,
@ -14,11 +14,11 @@
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Plugin App.
* The Original Code is Mozilla Code.
*
* The Initial Developer of the Original Code is
* Ben Turner <bent.mozilla@gmail.com>.
* Portions created by the Initial Developer are Copyright (C) 2009
* The Mozilla Foundation
* Portions created by the Initial Developer are Copyright (C) 2010
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
@ -37,53 +37,57 @@
*
* ***** END LICENSE BLOCK ***** */
#ifndef mozilla_ipc_MozillaChildThread_h
#define mozilla_ipc_MozillaChildThread_h
#ifndef mozilla_ipc_ProcessChild_h
#define mozilla_ipc_ProcessChild_h
#include "base/thread.h"
#include "base/message_loop.h"
#include "base/process.h"
#include "chrome/common/child_thread.h"
#include "chrome/common/child_process.h"
// ProcessChild is the base class for all subprocesses of the main
// browser process. Its code runs on the thread that started in
// main().
namespace mozilla {
namespace ipc {
/**
* A MozillaChildThread is the main thread in a child process. It will
* initialize XPCOM leak detectors (NS_LogInit) but it will not initialize
* XPCOM (see ContentProcessThread for a child which uses XPCOM).
*/
class MozillaChildThread : public ChildThread
{
public:
class ProcessChild : public ChildProcess {
protected:
typedef base::ProcessHandle ProcessHandle;
MozillaChildThread(ProcessHandle aParentProcessHandle,
MessageLoop::Type type=MessageLoop::TYPE_UI)
: ChildThread(base::Thread::Options(type, // message loop type
0, // stack size
false)), // wait for Init()?
mParentProcessHandle(aParentProcessHandle)
public:
ProcessChild(ProcessHandle parentHandle);
virtual ~ProcessChild();
virtual bool Init() = 0;
virtual void CleanUp()
{ }
protected:
virtual void OnControlMessageReceived(const IPC::Message& aMessage);
ProcessHandle GetParentProcessHandle() {
return mParentProcessHandle;
static MessageLoop* message_loop() {
return gProcessChild->mUILoop;
}
// Thread implementation:
virtual void Init();
virtual void CleanUp();
protected:
static ProcessChild* current() {
return gProcessChild;
}
ProcessHandle ParentHandle() {
return mParentHandle;
}
private:
ProcessHandle mParentProcessHandle;
static ProcessChild* gProcessChild;
DISALLOW_EVIL_CONSTRUCTORS(MozillaChildThread);
MessageLoop* mUILoop;
ProcessHandle mParentHandle;
DISALLOW_EVIL_CONSTRUCTORS(ProcessChild);
};
} /* namespace ipc */
} /* namespace mozilla */
} // namespace ipc
} // namespace mozilla
#endif /* mozilla_ipc_MozillaChildThread_h */
#endif // ifndef mozilla_ipc_ProcessChild_h

Просмотреть файл

@ -36,29 +36,23 @@
*
* ***** END LICENSE BLOCK ***** */
#include "IPDLUnitTestThreadChild.h"
#include "mozilla/ipc/IOThreadChild.h"
#include "IPDLUnitTestProcessChild.h"
#include "IPDLUnitTests.h"
using mozilla::ipc::MozillaChildThread;
using mozilla::ipc::IOThreadChild;
namespace mozilla {
namespace _ipdltest {
IPDLUnitTestThreadChild::IPDLUnitTestThreadChild(ProcessHandle aParentHandle) :
MozillaChildThread(aParentHandle)
bool
IPDLUnitTestProcessChild::Init()
{
}
IPDLUnitTestThreadChild::~IPDLUnitTestThreadChild()
{
}
void
IPDLUnitTestThreadChild::Init()
{
MozillaChildThread::Init();
IPDLUnitTestChildInit(channel(), GetParentProcessHandle(), owner_loop());
IPDLUnitTestChildInit(IOThreadChild::channel(),
ParentHandle(),
IOThreadChild::message_loop());
return true;
}
} // namespace _ipdltest

Просмотреть файл

@ -39,19 +39,24 @@
#ifndef mozilla__ipdltest_IPDLUnitTestThreadChild_h
#define mozilla__ipdltest_IPDLUnitTestThreadChild_h 1
#include "mozilla/ipc/MozillaChildThread.h"
#include "mozilla/ipc/ProcessChild.h"
namespace mozilla {
namespace _ipdltest {
class IPDLUnitTestThreadChild : public mozilla::ipc::MozillaChildThread
class IPDLUnitTestProcessChild : public mozilla::ipc::ProcessChild
{
public:
IPDLUnitTestThreadChild(ProcessHandle aParentHandle);
~IPDLUnitTestThreadChild();
typedef mozilla::ipc::ProcessChild ProcessChild;
protected:
virtual void Init();
public:
IPDLUnitTestProcessChild(ProcessHandle aParentHandle) :
ProcessChild(aParentHandle)
{ }
~IPDLUnitTestProcessChild()
{ }
virtual bool Init();
};
} // namespace _ipdltest

Просмотреть файл

@ -11,7 +11,6 @@
#include "base/string_util.h"
#include "IPDLUnitTestSubprocess.h"
#include "IPDLUnitTestThreadChild.h"
//-----------------------------------------------------------------------------
//===== TEMPLATED =====
@ -19,7 +18,6 @@ ${INCLUDES}
//-----------------------------------------------------------------------------
using mozilla::_ipdltest::IPDLUnitTestSubprocess;
using mozilla::_ipdltest::IPDLUnitTestThreadChild;
void* mozilla::_ipdltest::gParentActor;
IPDLUnitTestSubprocess* mozilla::_ipdltest::gSubprocess;

Просмотреть файл

@ -48,7 +48,7 @@ MODULE = ipdlunittest
EXPORTS_NAMESPACES = mozilla/_ipdltest
EXPORTS_mozilla/_ipdltest = \
IPDLUnitTests.h \
IPDLUnitTestThreadChild.h \
IPDLUnitTestProcessChild.h \
IPDLUnitTestTypes.h \
$(NULL)
@ -92,7 +92,7 @@ GENTESTER := $(srcdir)/genIPDLUnitTests.py
CPPSRCS = \
IPDLUnitTests.cpp \
IPDLUnitTestSubprocess.cpp \
IPDLUnitTestThreadChild.cpp \
IPDLUnitTestProcessChild.cpp \
$(IPDLTESTSRCS) \
$(NULL)

Просмотреть файл

@ -83,29 +83,28 @@
#include "chrome/common/child_process.h"
#include "chrome/common/notification_service.h"
#include "mozilla/ipc/GeckoChildProcessHost.h"
#include "mozilla/ipc/BrowserProcessSubThread.h"
#include "mozilla/ipc/GeckoChildProcessHost.h"
#include "mozilla/ipc/IOThreadChild.h"
#include "mozilla/ipc/ProcessChild.h"
#include "ScopedXREEmbed.h"
#include "mozilla/plugins/PluginThreadChild.h"
#include "mozilla/Monitor.h"
#include "mozilla/plugins/PluginProcessChild.h"
#ifdef MOZ_IPDL_TESTS
#include "mozilla/_ipdltest/IPDLUnitTests.h"
#include "mozilla/_ipdltest/IPDLUnitTestThreadChild.h"
#include "mozilla/_ipdltest/IPDLUnitTestProcessChild.h"
using mozilla::_ipdltest::IPDLUnitTestThreadChild;
using mozilla::_ipdltest::IPDLUnitTestProcessChild;
#endif // ifdef MOZ_IPDL_TESTS
using mozilla::ipc::GeckoChildProcessHost;
using mozilla::ipc::BrowserProcessSubThread;
using mozilla::ipc::GeckoChildProcessHost;
using mozilla::ipc::IOThreadChild;
using mozilla::ipc::ProcessChild;
using mozilla::ipc::ScopedXREEmbed;
using mozilla::plugins::PluginThreadChild;
using mozilla::Monitor;
using mozilla::MonitorAutoEnter;
using mozilla::plugins::PluginProcessChild;
using mozilla::startup::sChildProcessType;
#endif
@ -250,8 +249,6 @@ GeckoProcessType sChildProcessType = GeckoProcessType_Default;
}
}
static MessageLoop* sIOMessageLoop;
#if defined(MOZ_CRASHREPORTER)
// FIXME/bug 539522: this out-of-place function is stuck here because
// IPDL wants access to this crashreporter interface, and
@ -332,10 +329,10 @@ XRE_InitChildProcess(int aArgc,
return NS_ERROR_FAILURE;
}
MessageLoopForIO mainMessageLoop;
// Associate this thread with a UI MessageLoop
MessageLoopForUI uiMessageLoop;
{
ChildThread* mainThread;
nsAutoPtr<ProcessChild> process;
switch (aProcess) {
case GeckoProcessType_Default:
@ -343,13 +340,13 @@ XRE_InitChildProcess(int aArgc,
break;
case GeckoProcessType_Plugin:
mainThread = new PluginThreadChild(parentHandle);
process = new PluginProcessChild(parentHandle);
break;
case GeckoProcessType_IPDLUnitTest:
#ifdef MOZ_IPDL_TESTS
mainThread = new IPDLUnitTestThreadChild(parentHandle);
#else
process = new IPDLUnitTestProcessChild(parentHandle);
#else
NS_RUNTIMEABORT("rebuild with --enable-ipdl-tests");
#endif
break;
@ -358,14 +355,17 @@ XRE_InitChildProcess(int aArgc,
NS_RUNTIMEABORT("Unknown main thread class");
}
ChildProcess process(mainThread);
if (!process->Init()) {
NS_LogTerm();
return NS_ERROR_FAILURE;
}
// Do IPC event loop
sIOMessageLoop = MessageLoop::current();
// Run the UI event loop on the main thread.
uiMessageLoop.MessageLoop::Run();
sIOMessageLoop->Run();
sIOMessageLoop = nsnull;
// Allow ProcessChild to clean up after itself before going out of
// scope and being deleted
process->CleanUp();
}
NS_LogTerm();
@ -376,10 +376,9 @@ MessageLoop*
XRE_GetIOMessageLoop()
{
if (sChildProcessType == GeckoProcessType_Default) {
NS_ASSERTION(!sIOMessageLoop, "Shouldn't be set on parent process!");
return BrowserProcessSubThread::GetMessageLoop(BrowserProcessSubThread::IO);
}
return sIOMessageLoop;
return IOThreadChild::message_loop();
}
namespace {
@ -492,7 +491,13 @@ XRE_ShutdownChildProcess()
MessageLoop* ioLoop = XRE_GetIOMessageLoop();
NS_ABORT_IF_FALSE(!!ioLoop, "Bad shutdown order");
ioLoop->PostTask(FROM_HERE, new MessageLoop::QuitTask());
// Quit() sets off the following chain of events
// (1) UI loop starts quitting
// (2) UI loop returns from Run() in XRE_InitChildProcess()
// (3) ProcessChild goes out of scope and terminates the IO thread
// (4) ProcessChild joins the IO thread
// (5) exit()
MessageLoop::current()->Quit();
}
#ifdef MOZ_X11

Просмотреть файл

@ -39,8 +39,8 @@
#include "nsX11ErrorHandler.h"
#ifdef MOZ_IPC
#include "mozilla/plugins/PluginThreadChild.h"
using mozilla::plugins::PluginThreadChild;
#include "mozilla/plugins/PluginProcessChild.h"
using mozilla::plugins::PluginProcessChild;
#endif
#include "prenv.h"
@ -157,7 +157,7 @@ X11Error(Display *display, XErrorEvent *event) {
// This is assuming that X operations are performed on the plugin
// thread. If plugins are using X on another thread, then we'll need to
// handle that differently.
PluginThreadChild::AppendNotesToCrashReport(notes);
PluginProcessChild::AppendNotesToCrashReport(notes);
}
break;
#endif