Rework chromium initialization

This commit is contained in:
Ben Turner 2009-08-27 14:11:10 -07:00
parent 187a34a633
commit 8e88b405d2
4 changed files with 24 additions and 51 deletions

View File

@ -108,6 +108,7 @@ BrowserProcessSubThread::BrowserProcessSubThread(ID aId) :
mIdentifier(aId),
mNotificationService(NULL)
{
Init();
AutoLock lock(sLock);
DCHECK(aId >= 0 && aId < ID_COUNT);
DCHECK(sBrowserThreads[aId] == NULL);
@ -117,6 +118,7 @@ BrowserProcessSubThread::BrowserProcessSubThread(ID aId) :
BrowserProcessSubThread::~BrowserProcessSubThread()
{
Stop();
CleanUp();
{AutoLock lock(sLock);
sBrowserThreads[mIdentifier] = NULL;
}

View File

@ -209,11 +209,6 @@
#ifdef MOZ_IPC
#include "base/command_line.h"
#include "base/thread.h"
#include "mozilla/ipc/GeckoThread.h"
using mozilla::ipc::BrowserProcessSubThread;
using mozilla::ipc::GeckoThread;
#endif
#ifdef WINCE
@ -3053,7 +3048,7 @@ XRE_main(int argc, char* argv[], const nsXREAppData* aAppData)
MOZ_SPLASHSCREEN_UPDATE(20);
#ifdef MOZ_IPC
#if defined(MOZ_IPC) && !defined(OS_WIN)
// FIXME: this and its constituents leak
char** canonArgs = new char*[gArgc];
@ -3530,27 +3525,6 @@ XRE_main(int argc, char* argv[], const nsXREAppData* aAppData)
MOZ_SPLASHSCREEN_UPDATE(90);
{
#if 0 && defined(OS_LINUX)
// The lifetime of the BACKGROUND_X11 thread is a subset
// of the IO thread so we start it now.
scoped_ptr<base::Thread> x11Thread(
new BrowserProcessSubThread(BrowserProcessSubThread::BACKGROUND_X11));
if (NS_UNLIKELY(!x11Thread->Start())) {
NS_ERROR("Failed to create chromium's X11 thread!");
return NS_ERROR_FAILURE;
}
#endif
#ifdef MOZ_IPC
scoped_ptr<base::Thread> ipcThread(
new BrowserProcessSubThread(BrowserProcessSubThread::IO));
base::Thread::Options options;
options.message_loop_type = MessageLoop::TYPE_IO;
if (NS_UNLIKELY(!ipcThread->StartWithOptions(options))) {
NS_ERROR("Failed to create chromium's IO thread!");
return NS_ERROR_FAILURE;
}
#endif
NS_TIMELINE_ENTER("appStartup->Run");
rv = appStartup->Run();
NS_TIMELINE_LEAVE("appStartup->Run");

View File

@ -64,7 +64,6 @@
#include "base/at_exit.h"
#include "base/command_line.h"
#include "base/message_loop.h"
#include "base/thread.h"
#include "chrome/common/child_process.h"
#include "mozilla/ipc/GeckoChildProcessHost.h"
@ -82,7 +81,6 @@
#include "mozilla/test/TestThreadChild.h"
#include "mozilla/Monitor.h"
using mozilla::ipc::BrowserProcessSubThread;
using mozilla::ipc::GeckoChildProcessHost;
using mozilla::ipc::GeckoThread;
using mozilla::ipc::ScopedXREEmbed;
@ -337,32 +335,11 @@ XRE_InitParentProcess(int aArgc,
NS_ENSURE_ARG_POINTER(aArgv);
NS_ENSURE_ARG_POINTER(aArgv[0]);
base::AtExitManager exitManager;
CommandLine::Init(aArgc, aArgv);
MessageLoopForUI mainMessageLoop;
ScopedXREEmbed embed;
{
// Make chromium's IPC thread
#if defined(OS_LINUX)
// The lifetime of the BACKGROUND_X11 thread is a subset of the IO thread so
// we start it now.
scoped_ptr<base::Thread> x11Thread(
new BrowserProcessSubThread(BrowserProcessSubThread::BACKGROUND_X11));
if (NS_UNLIKELY(!x11Thread->Start())) {
NS_ERROR("Failed to create chromium's X11 thread!");
return NS_ERROR_FAILURE;
}
#endif
scoped_ptr<base::Thread> ipcThread(
new BrowserProcessSubThread(BrowserProcessSubThread::IO));
base::Thread::Options options;
options.message_loop_type = MessageLoop::TYPE_IO;
if (NS_UNLIKELY(!ipcThread->StartWithOptions(options))) {
NS_ERROR("Failed to create chromium's IO thread!");
return NS_ERROR_FAILURE;
}
embed.Start();
nsCOMPtr<nsIAppShell> appShell(do_GetService(kAppShellCID));

View File

@ -150,13 +150,17 @@ NS_DECL_CLASSINFO(nsStringInputStream)
#include "base/command_line.h"
#include "base/message_loop.h"
#include "mozilla/ipc/GeckoThread.h"
using base::AtExitManager;
using mozilla::ipc::BrowserProcessSubThread;
namespace {
static AtExitManager* sExitManager;
static MessageLoop* sMessageLoop;
static bool sCommandLineWasInitialized;
static BrowserProcessSubThread* sIOThread;
} /* anonymous namespace */
#endif
@ -587,6 +591,18 @@ NS_InitXPCOM3(nsIServiceManager* *result,
sMessageLoop = new MessageLoopForUI();
NS_ENSURE_STATE(sMessageLoop);
}
if (!BrowserProcessSubThread::GetMessageLoop(BrowserProcessSubThread::IO)) {
scoped_ptr<BrowserProcessSubThread> ioThread(
new BrowserProcessSubThread(BrowserProcessSubThread::IO));
NS_ENSURE_TRUE(ioThread.get(), NS_ERROR_OUT_OF_MEMORY);
base::Thread::Options options;
options.message_loop_type = MessageLoop::TYPE_IO;
NS_ENSURE_TRUE(ioThread->StartWithOptions(options), NS_ERROR_FAILURE);
sIOThread = ioThread.release();
}
#endif
NS_LogInit();
@ -962,6 +978,10 @@ ShutdownXPCOM(nsIServiceManager* servMgr)
#endif
#ifdef MOZ_IPC
if (sIOThread) {
delete sIOThread;
sIOThread = nsnull;
}
if (sMessageLoop) {
delete sMessageLoop;
sMessageLoop = nsnull;