Bug 667183 - Create a static nsGlobalWindow::Init method to do one-shot initializations currently in nsGlobalWindow ctor. r=jst

This commit is contained in:
Mounir Lamouri 2011-08-31 01:36:07 +02:00
parent 07cb1444a2
commit 39eaa3695d
3 changed files with 29 additions and 24 deletions

View File

@ -930,10 +930,6 @@ nsGlobalWindow::nsGlobalWindow(nsGlobalWindow *aOuterWindow)
}
}
if (!gEntropyCollector) {
CallGetService(NS_ENTROPYCOLLECTOR_CONTRACTID, &gEntropyCollector);
}
mSerial = ++gSerialCounter;
#ifdef DEBUG
@ -945,29 +941,35 @@ nsGlobalWindow::nsGlobalWindow(nsGlobalWindow *aOuterWindow)
#endif
#ifdef PR_LOGGING
if (!gDOMLeakPRLog)
gDOMLeakPRLog = PR_NewLogModule("DOMLeak");
if (gDOMLeakPRLog)
PR_LOG(gDOMLeakPRLog, PR_LOG_DEBUG,
("DOMWINDOW %p created outer=%p", this, aOuterWindow));
#endif
// TODO: could be moved to a ::Init() method, see bug 667183.
if (!sWindowsById) {
sWindowsById = new WindowByIdTable();
if (!sWindowsById->Init()) {
delete sWindowsById;
sWindowsById = nsnull;
NS_ERROR("sWindowsById initialization failed!");
}
}
NS_ASSERTION(sWindowsById, "Windows hash table must be created!");
NS_ASSERTION(!sWindowsById->Get(mWindowID),
"This window shouldn't be in the hash table yet!");
sWindowsById->Put(mWindowID, this);
}
if (sWindowsById) {
NS_ASSERTION(!sWindowsById->Get(mWindowID),
"This window shouldn't be in the hash table yet!");
sWindowsById->Put(mWindowID, this);
}
/* static */
void
nsGlobalWindow::Init()
{
CallGetService(NS_ENTROPYCOLLECTOR_CONTRACTID, &gEntropyCollector);
NS_ASSERTION(gEntropyCollector,
"gEntropyCollector should have been initialized!");
#ifdef PR_LOGGING
gDOMLeakPRLog = PR_NewLogModule("DOMLeak");
NS_ASSERTION(gDOMLeakPRLog, "gDOMLeakPRLog should have been initialized!");
#endif
sWindowsById = new WindowByIdTable();
// There are two reasons to have Init() failing: if we were not able to
// alloc the memory or if the size we want to init is too high. None of them
// should happen.
NS_ASSERTION(sWindowsById->Init(), "Init() should not fail!");
}
nsGlobalWindow::~nsGlobalWindow()
@ -979,9 +981,7 @@ nsGlobalWindow::~nsGlobalWindow()
"This window should be in the hash table");
sWindowsById->Remove(mWindowID);
}
if (!--gRefCnt) {
NS_IF_RELEASE(gEntropyCollector);
}
#ifdef DEBUG
if (!PR_GetEnv("MOZ_QUIET")) {
nsCAutoString url;
@ -1062,6 +1062,8 @@ nsGlobalWindow::ShutDown()
}
gDumpFile = nsnull;
NS_IF_RELEASE(gEntropyCollector);
delete sWindowsById;
sWindowsById = nsnull;
}

View File

@ -486,6 +486,7 @@ public:
nsresult Observe(nsISupports* aSubject, const char* aTopic,
const PRUnichar* aData);
static void Init();
static void ShutDown();
static void CleanupCachedXBLHandlers(nsGlobalWindow* aWindow);
static PRBool IsCallerChrome();

View File

@ -159,6 +159,8 @@ nsLayoutStatics::Initialize()
return rv;
}
nsGlobalWindow::Init();
rv = nsContentUtils::Init();
if (NS_FAILED(rv)) {
NS_ERROR("Could not initialize nsContentUtils");