Bug 1185988 - Don't hold the observer service alive from nsHttpHandler; r=mcmanus

This commit is contained in:
Ehsan Akhgari 2015-07-21 09:11:32 -04:00
parent 3cb7efe847
commit f3b065306e
2 changed files with 20 additions and 21 deletions

View File

@ -354,21 +354,20 @@ nsHttpHandler::Init()
NS_HTTP_STARTUP_TOPIC);
nsCOMPtr<nsIObserverService> obsService = services::GetObserverService();
mObserverService = new nsMainThreadPtrHolder<nsIObserverService>(obsService);
if (mObserverService) {
if (obsService) {
// register the handler object as a weak callback as we don't need to worry
// about shutdown ordering.
mObserverService->AddObserver(this, "profile-change-net-teardown", true);
mObserverService->AddObserver(this, "profile-change-net-restore", true);
mObserverService->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, true);
mObserverService->AddObserver(this, "net:clear-active-logins", true);
mObserverService->AddObserver(this, "net:prune-dead-connections", true);
mObserverService->AddObserver(this, "net:failed-to-process-uri-content", true);
mObserverService->AddObserver(this, "last-pb-context-exited", true);
mObserverService->AddObserver(this, "webapps-clear-data", true);
mObserverService->AddObserver(this, "browser:purge-session-history", true);
mObserverService->AddObserver(this, NS_NETWORK_LINK_TOPIC, true);
mObserverService->AddObserver(this, "application-background", true);
obsService->AddObserver(this, "profile-change-net-teardown", true);
obsService->AddObserver(this, "profile-change-net-restore", true);
obsService->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, true);
obsService->AddObserver(this, "net:clear-active-logins", true);
obsService->AddObserver(this, "net:prune-dead-connections", true);
obsService->AddObserver(this, "net:failed-to-process-uri-content", true);
obsService->AddObserver(this, "last-pb-context-exited", true);
obsService->AddObserver(this, "webapps-clear-data", true);
obsService->AddObserver(this, "browser:purge-session-history", true);
obsService->AddObserver(this, NS_NETWORK_LINK_TOPIC, true);
obsService->AddObserver(this, "application-background", true);
}
MakeNewRequestTokenBucket();
@ -564,8 +563,9 @@ void
nsHttpHandler::NotifyObservers(nsIHttpChannel *chan, const char *event)
{
LOG(("nsHttpHandler::NotifyObservers [chan=%x event=\"%s\"]\n", chan, event));
if (mObserverService)
mObserverService->NotifyObservers(chan, event, nullptr);
nsCOMPtr<nsIObserverService> obsService = services::GetObserverService();
if (obsService)
obsService->NotifyObservers(chan, event, nullptr);
}
nsresult
@ -2066,14 +2066,15 @@ nsHttpHandler::SpeculativeConnectInternal(nsIURI *aURI,
return NS_OK;
MOZ_ASSERT(NS_IsMainThread());
if (mDebugObservations && mObserverService) {
nsCOMPtr<nsIObserverService> obsService = services::GetObserverService();
if (mDebugObservations && obsService) {
// this is basically used for test coverage of an otherwise 'hintable' feature
nsAutoCString spec;
aURI->GetSpec(spec);
spec.Append(anonymous ? NS_LITERAL_CSTRING("[A]") : NS_LITERAL_CSTRING("[.]"));
mObserverService->NotifyObservers(nullptr,
"speculative-connect-request",
NS_ConvertUTF8toUTF16(spec).get());
obsService->NotifyObservers(nullptr,
"speculative-connect-request",
NS_ConvertUTF8toUTF16(spec).get());
}
nsISiteSecurityService* sss = gHttpHandler->GetSSService();

View File

@ -24,7 +24,6 @@ class nsIPrefBranch;
class nsICancelable;
class nsICookieService;
class nsIIOService;
class nsIObserverService;
class nsISiteSecurityService;
class nsIStreamConverterService;
class nsITimer;
@ -361,7 +360,6 @@ private:
// cached services
nsMainThreadPtrHandle<nsIIOService> mIOService;
nsMainThreadPtrHandle<nsIStreamConverterService> mStreamConvSvc;
nsMainThreadPtrHandle<nsIObserverService> mObserverService;
nsMainThreadPtrHandle<nsICookieService> mCookieService;
nsMainThreadPtrHandle<nsISiteSecurityService> mSSService;