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; mSerial = ++gSerialCounter;
#ifdef DEBUG #ifdef DEBUG
@ -945,29 +941,35 @@ nsGlobalWindow::nsGlobalWindow(nsGlobalWindow *aOuterWindow)
#endif #endif
#ifdef PR_LOGGING #ifdef PR_LOGGING
if (!gDOMLeakPRLog)
gDOMLeakPRLog = PR_NewLogModule("DOMLeak");
if (gDOMLeakPRLog) if (gDOMLeakPRLog)
PR_LOG(gDOMLeakPRLog, PR_LOG_DEBUG, PR_LOG(gDOMLeakPRLog, PR_LOG_DEBUG,
("DOMWINDOW %p created outer=%p", this, aOuterWindow)); ("DOMWINDOW %p created outer=%p", this, aOuterWindow));
#endif #endif
// TODO: could be moved to a ::Init() method, see bug 667183. NS_ASSERTION(sWindowsById, "Windows hash table must be created!");
if (!sWindowsById) { NS_ASSERTION(!sWindowsById->Get(mWindowID),
sWindowsById = new WindowByIdTable(); "This window shouldn't be in the hash table yet!");
if (!sWindowsById->Init()) { sWindowsById->Put(mWindowID, this);
delete sWindowsById; }
sWindowsById = nsnull;
NS_ERROR("sWindowsById initialization failed!");
}
}
if (sWindowsById) { /* static */
NS_ASSERTION(!sWindowsById->Get(mWindowID), void
"This window shouldn't be in the hash table yet!"); nsGlobalWindow::Init()
sWindowsById->Put(mWindowID, this); {
} 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() nsGlobalWindow::~nsGlobalWindow()
@ -979,9 +981,7 @@ nsGlobalWindow::~nsGlobalWindow()
"This window should be in the hash table"); "This window should be in the hash table");
sWindowsById->Remove(mWindowID); sWindowsById->Remove(mWindowID);
} }
if (!--gRefCnt) {
NS_IF_RELEASE(gEntropyCollector);
}
#ifdef DEBUG #ifdef DEBUG
if (!PR_GetEnv("MOZ_QUIET")) { if (!PR_GetEnv("MOZ_QUIET")) {
nsCAutoString url; nsCAutoString url;
@ -1062,6 +1062,8 @@ nsGlobalWindow::ShutDown()
} }
gDumpFile = nsnull; gDumpFile = nsnull;
NS_IF_RELEASE(gEntropyCollector);
delete sWindowsById; delete sWindowsById;
sWindowsById = nsnull; sWindowsById = nsnull;
} }

View File

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

View File

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