diff --git a/accessible/src/base/nsAccessNode.cpp b/accessible/src/base/nsAccessNode.cpp index 9e9f0abcf302..dbfd479e6ba5 100644 --- a/accessible/src/base/nsAccessNode.cpp +++ b/accessible/src/base/nsAccessNode.cpp @@ -72,6 +72,7 @@ #include "nsRootAccessible.h" #include "nsFocusManager.h" #include "nsIObserverService.h" +#include "mozilla/Services.h" /* For documentation of the accessibility architecture, * see http://lxr.mozilla.org/seamonkey/source/accessible/accessible-docs.html @@ -281,14 +282,15 @@ void nsAccessNode::InitXPAccessibility() void nsAccessNode::NotifyA11yInitOrShutdown(PRBool aIsInit) { nsCOMPtr obsService = - do_GetService("@mozilla.org/observer-service;1"); + mozilla::services::GetObserverService(); NS_ASSERTION(obsService, "No observer service to notify of a11y init/shutdown"); - if (obsService) { - static const PRUnichar kInitIndicator[] = { '1', 0 }; - static const PRUnichar kShutdownIndicator[] = { '0', 0 }; - obsService->NotifyObservers(nsnull, "a11y-init-or-shutdown", - aIsInit ? kInitIndicator : kShutdownIndicator); - } + if (!obsService) + return; + + static const PRUnichar kInitIndicator[] = { '1', 0 }; + static const PRUnichar kShutdownIndicator[] = { '0', 0 }; + obsService->NotifyObservers(nsnull, "a11y-init-or-shutdown", + aIsInit ? kInitIndicator : kShutdownIndicator); } void nsAccessNode::ShutdownXPAccessibility() diff --git a/accessible/src/base/nsAccessibilityService.cpp b/accessible/src/base/nsAccessibilityService.cpp index 81e5408cd0f9..7b18354c9e69 100644 --- a/accessible/src/base/nsAccessibilityService.cpp +++ b/accessible/src/base/nsAccessibilityService.cpp @@ -85,6 +85,7 @@ #include "nsIWebProgress.h" #include "nsNetError.h" #include "nsDocShellLoadTypes.h" +#include "mozilla/Services.h" #ifdef MOZ_XUL #include "nsXULAlertAccessible.h" @@ -119,8 +120,8 @@ PRBool nsAccessibilityService::gIsShutdown = PR_TRUE; nsAccessibilityService::nsAccessibilityService() { // Add observers. - nsCOMPtr observerService = - do_GetService("@mozilla.org/observer-service;1"); + nsCOMPtr observerService = + mozilla::services::GetObserverService(); if (!observerService) return; @@ -155,11 +156,11 @@ nsAccessibilityService::Observe(nsISupports *aSubject, const char *aTopic, if (!nsCRT::strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID)) { // Remove observers. - nsCOMPtr observerService = - do_GetService("@mozilla.org/observer-service;1"); - if (observerService) { + nsCOMPtr observerService = + mozilla::services::GetObserverService(); + if (observerService) observerService->RemoveObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID); - } + nsCOMPtr progress(do_GetService(NS_DOCUMENTLOADER_SERVICE_CONTRACTID)); if (progress) progress->RemoveProgressListener(static_cast(this)); diff --git a/accessible/src/base/nsAccessible.cpp b/accessible/src/base/nsAccessible.cpp index 3aa0ff71d0ba..ec9359a12460 100644 --- a/accessible/src/base/nsAccessible.cpp +++ b/accessible/src/base/nsAccessible.cpp @@ -1305,7 +1305,7 @@ nsAccessible::HandleAccEvent(nsAccEvent *aEvent) NS_ENSURE_TRUE(nsAccUtils::IsNodeRelevant(eventNode), NS_ERROR_FAILURE); nsCOMPtr obsService = - do_GetService("@mozilla.org/observer-service;1"); + mozilla::services::GetObserverService(); NS_ENSURE_TRUE(obsService, NS_ERROR_FAILURE); return obsService->NotifyObservers(aEvent, NS_ACCESSIBLE_EVENT_TOPIC, nsnull); diff --git a/chrome/src/nsChromeRegistry.cpp b/chrome/src/nsChromeRegistry.cpp index db6170743b40..8b02600d3a87 100644 --- a/chrome/src/nsChromeRegistry.cpp +++ b/chrome/src/nsChromeRegistry.cpp @@ -524,7 +524,8 @@ nsChromeRegistry::Init() } } - nsCOMPtr obsService (do_GetService("@mozilla.org/observer-service;1")); + nsCOMPtr obsService = + mozilla::services::GetObserverService(); if (obsService) { obsService->AddObserver(this, "command-line-startup", PR_TRUE); obsService->AddObserver(this, "profile-initial-state", PR_TRUE); @@ -904,7 +905,7 @@ void nsChromeRegistry::FlushSkinCaches() { nsCOMPtr obsSvc = - do_GetService("@mozilla.org/observer-service;1"); + mozilla::services::GetObserverService(); NS_ASSERTION(obsSvc, "Couldn't get observer service."); obsSvc->NotifyObservers(static_cast(this), @@ -1030,7 +1031,7 @@ void nsChromeRegistry::FlushAllCaches() { nsCOMPtr obsSvc = - do_GetService("@mozilla.org/observer-service;1"); + mozilla::services::GetObserverService(); NS_ASSERTION(obsSvc, "Couldn't get observer service."); obsSvc->NotifyObservers((nsIChromeRegistry*) this, diff --git a/content/base/src/nsCCUncollectableMarker.cpp b/content/base/src/nsCCUncollectableMarker.cpp index f8008d47e195..dc164595268b 100644 --- a/content/base/src/nsCCUncollectableMarker.cpp +++ b/content/base/src/nsCCUncollectableMarker.cpp @@ -50,6 +50,7 @@ #include "nsISHEntry.h" #include "nsISHContainer.h" #include "nsIWindowWatcher.h" +#include "mozilla/Services.h" static PRBool sInited = 0; PRUint32 nsCCUncollectableMarker::sGeneration = 0; @@ -67,10 +68,12 @@ nsCCUncollectableMarker::Init() nsCOMPtr marker = new nsCCUncollectableMarker; NS_ENSURE_TRUE(marker, NS_ERROR_OUT_OF_MEMORY); - nsresult rv; nsCOMPtr obs = - do_GetService("@mozilla.org/observer-service;1", &rv); - NS_ENSURE_SUCCESS(rv, rv); + mozilla::services::GetObserverService(); + if (!obs) + return NS_ERROR_FAILURE; + + nsresult rv; // This makes the observer service hold an owning reference to the marker rv = obs->AddObserver(marker, "xpcom-shutdown", PR_FALSE); @@ -186,12 +189,11 @@ nsresult nsCCUncollectableMarker::Observe(nsISupports* aSubject, const char* aTopic, const PRUnichar* aData) { - nsresult rv; - if (!strcmp(aTopic, "xpcom-shutdown")) { nsCOMPtr obs = - do_GetService("@mozilla.org/observer-service;1", &rv); - NS_ENSURE_SUCCESS(rv, rv); + mozilla::services::GetObserverService(); + if (!obs) + return NS_ERROR_FAILURE; // No need for kungFuDeathGrip here, yay observerservice! obs->RemoveObserver(this, "xpcom-shutdown"); @@ -209,6 +211,8 @@ nsCCUncollectableMarker::Observe(nsISupports* aSubject, const char* aTopic, ++sGeneration; } + nsresult rv; + // Iterate all toplevel windows nsCOMPtr windowList; nsCOMPtr med = diff --git a/content/base/src/nsContentUtils.cpp b/content/base/src/nsContentUtils.cpp index e09caab7b5e7..25f52e748e7c 100644 --- a/content/base/src/nsContentUtils.cpp +++ b/content/base/src/nsContentUtils.cpp @@ -3494,7 +3494,7 @@ void nsContentUtils::RegisterShutdownObserver(nsIObserver* aObserver) { nsCOMPtr observerService = - do_GetService("@mozilla.org/observer-service;1"); + mozilla::services::GetObserverService(); if (observerService) { observerService->AddObserver(aObserver, NS_XPCOM_SHUTDOWN_OBSERVER_ID, @@ -3507,7 +3507,7 @@ void nsContentUtils::UnregisterShutdownObserver(nsIObserver* aObserver) { nsCOMPtr observerService = - do_GetService("@mozilla.org/observer-service;1"); + mozilla::services::GetObserverService(); if (observerService) { observerService->RemoveObserver(aObserver, NS_XPCOM_SHUTDOWN_OBSERVER_ID); } diff --git a/content/events/src/nsEventStateManager.cpp b/content/events/src/nsEventStateManager.cpp index 55c25f07e352..f3f3e3c95b72 100644 --- a/content/events/src/nsEventStateManager.cpp +++ b/content/events/src/nsEventStateManager.cpp @@ -153,6 +153,7 @@ #endif #include "nsIController.h" #include "nsICommandParams.h" +#include "mozilla/Services.h" #ifdef XP_MACOSX #import @@ -272,10 +273,10 @@ NS_IMPL_ISUPPORTS1(nsUITimerCallback, nsITimerCallback) NS_IMETHODIMP nsUITimerCallback::Notify(nsITimer* aTimer) { - nsresult rv; nsCOMPtr obs = - do_GetService("@mozilla.org/observer-service;1", &rv); - NS_ENSURE_SUCCESS(rv, rv); + mozilla::services::GetObserverService(); + if (!obs) + return NS_ERROR_FAILURE; if ((gMouseOrKeyboardEventCounter == mPreviousCount) || !aTimer) { gMouseOrKeyboardEventCounter = 0; obs->NotifyObservers(nsnull, "user-interaction-inactive", nsnull); @@ -789,10 +790,10 @@ nsEventStateManager::nsEventStateManager() NS_IMETHODIMP nsEventStateManager::Init() { - nsresult rv; nsCOMPtr observerService = - do_GetService("@mozilla.org/observer-service;1", &rv); - NS_ENSURE_SUCCESS(rv, rv); + mozilla::services::GetObserverService(); + if (!observerService) + return NS_ERROR_FAILURE; observerService->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, PR_TRUE); @@ -832,7 +833,7 @@ nsEventStateManager::Init() prefBranch->AddObserver("dom.popup_allowed_events", this, PR_TRUE); } - return rv; + return NS_OK; } nsEventStateManager::~nsEventStateManager() @@ -861,11 +862,9 @@ nsEventStateManager::~nsEventStateManager() // gets called from xpcom shutdown observer. And we don't want to remove // from the service in that case. - nsresult rv; - nsCOMPtr observerService = - do_GetService("@mozilla.org/observer-service;1", &rv); - if (NS_SUCCEEDED(rv)) { + mozilla::services::GetObserverService(); + if (observerService) { observerService->RemoveObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID); } } @@ -1047,7 +1046,7 @@ nsEventStateManager::PreHandleEvent(nsPresContext* aPresContext, aEvent->eventStructType == NS_KEY_EVENT)) { if (gMouseOrKeyboardEventCounter == 0) { nsCOMPtr obs = - do_GetService("@mozilla.org/observer-service;1"); + mozilla::services::GetObserverService(); if (obs) { obs->NotifyObservers(nsnull, "user-interaction-active", nsnull); } diff --git a/content/html/content/src/nsHTMLDNSPrefetch.cpp b/content/html/content/src/nsHTMLDNSPrefetch.cpp index 356cbbb0c61f..0a6c141be99f 100644 --- a/content/html/content/src/nsHTMLDNSPrefetch.cpp +++ b/content/html/content/src/nsHTMLDNSPrefetch.cpp @@ -295,10 +295,9 @@ nsHTMLDNSPrefetch::nsDeferrals::Activate() progress->AddProgressListener(this, nsIWebProgress::NOTIFY_STATE_DOCUMENT); // Register as an observer for xpcom shutdown events so we can drop any element refs - nsresult rv; nsCOMPtr observerService = - do_GetService("@mozilla.org/observer-service;1", &rv); - if (NS_SUCCEEDED(rv)) + mozilla::services::GetObserverService(); + if (observerService) observerService->AddObserver(this, "xpcom-shutdown", PR_TRUE); } diff --git a/content/html/content/src/nsHTMLFormElement.cpp b/content/html/content/src/nsHTMLFormElement.cpp index 3b914afae0b7..e7d2d9c0f70b 100644 --- a/content/html/content/src/nsHTMLFormElement.cpp +++ b/content/html/content/src/nsHTMLFormElement.cpp @@ -906,16 +906,16 @@ nsHTMLFormElement::NotifySubmitObservers(nsIURI* aActionURL, } // Notify observers that the form is being submitted. - nsresult rv = NS_OK; nsCOMPtr service = - do_GetService("@mozilla.org/observer-service;1", &rv); - NS_ENSURE_SUCCESS(rv, rv); + mozilla::services::GetObserverService(); + if (!service) + return NS_ERROR_FAILURE; nsCOMPtr theEnum; - rv = service->EnumerateObservers(aEarlyNotify ? - NS_EARLYFORMSUBMIT_SUBJECT : - NS_FORMSUBMIT_SUBJECT, - getter_AddRefs(theEnum)); + nsresult rv = service->EnumerateObservers(aEarlyNotify ? + NS_EARLYFORMSUBMIT_SUBJECT : + NS_FORMSUBMIT_SUBJECT, + getter_AddRefs(theEnum)); NS_ENSURE_SUCCESS(rv, rv); if (theEnum) { diff --git a/content/xbl/src/nsXBLService.cpp b/content/xbl/src/nsXBLService.cpp index c1e39926d8ec..e4d46bd0180b 100644 --- a/content/xbl/src/nsXBLService.cpp +++ b/content/xbl/src/nsXBLService.cpp @@ -1321,7 +1321,7 @@ NS_NewXBLService(nsIXBLService** aResult) // Register the first (and only) nsXBLService as a memory pressure observer // so it can flush the LRU list in low-memory situations. - nsCOMPtr os = do_GetService("@mozilla.org/observer-service;1"); + nsCOMPtr os = mozilla::services::GetObserverService(); if (os) os->AddObserver(result, "memory-pressure", PR_TRUE); diff --git a/content/xul/document/src/nsXULDocument.cpp b/content/xul/document/src/nsXULDocument.cpp index 1542b5a8f6ba..4e7d5e44c7da 100644 --- a/content/xul/document/src/nsXULDocument.cpp +++ b/content/xul/document/src/nsXULDocument.cpp @@ -642,8 +642,8 @@ nsXULDocument::OnDocumentParserError() if (mCurrentPrototype && mMasterPrototype != mCurrentPrototype) { nsCOMPtr uri = mCurrentPrototype->GetURI(); if (IsChromeURI(uri)) { - nsCOMPtr os( - do_GetService("@mozilla.org/observer-service;1")); + nsCOMPtr os = + mozilla::services::GetObserverService(); if (os) os->NotifyObservers(uri, "xul-overlay-parsererror", EmptyString().get()); diff --git a/content/xul/document/src/nsXULPrototypeCache.cpp b/content/xul/document/src/nsXULPrototypeCache.cpp index ef926610150b..025024ef0946 100644 --- a/content/xul/document/src/nsXULPrototypeCache.cpp +++ b/content/xul/document/src/nsXULPrototypeCache.cpp @@ -140,7 +140,8 @@ NS_NewXULPrototypeCache(nsISupports* aOuter, REFNSIID aIID, void** aResult) nsresult rv = result->QueryInterface(aIID, aResult); - nsCOMPtr obsSvc(do_GetService("@mozilla.org/observer-service;1")); + nsCOMPtr obsSvc = + mozilla::services::GetObserverService(); if (obsSvc && NS_SUCCEEDED(rv)) { nsXULPrototypeCache *p = result; obsSvc->AddObserver(p, "chrome-flush-skin-caches", PR_FALSE); diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp index 1226757f1877..134bfe988246 100644 --- a/docshell/base/nsDocShell.cpp +++ b/docshell/base/nsDocShell.cpp @@ -10123,7 +10123,7 @@ nsDocShell::AddToGlobalHistory(nsIURI * aURI, PRBool aRedirect, if (!visited) { nsCOMPtr obsService = - do_GetService("@mozilla.org/observer-service;1"); + mozilla::services::GetObserverService(); if (obsService) { obsService->NotifyObservers(aURI, NS_LINK_VISITED_EVENT_TOPIC, nsnull); } diff --git a/docshell/shistory/src/nsSHistory.cpp b/docshell/shistory/src/nsSHistory.cpp index 9b946b96d148..854606ecbc5e 100644 --- a/docshell/shistory/src/nsSHistory.cpp +++ b/docshell/shistory/src/nsSHistory.cpp @@ -60,6 +60,7 @@ #include "nsICacheService.h" #include "nsIObserverService.h" #include "prclist.h" +#include "mozilla/Services.h" // For calculating max history entries and max cachable contentviewers #include "nspr.h" @@ -253,7 +254,7 @@ nsSHistory::Startup() obs, PR_FALSE); nsCOMPtr obsSvc = - do_GetService("@mozilla.org/observer-service;1"); + mozilla::services::GetObserverService(); if (obsSvc) { // Observe empty-cache notifications so tahat clearing the disk/memory // cache will also evict all content viewers. diff --git a/dom/base/nsDOMScriptObjectFactory.cpp b/dom/base/nsDOMScriptObjectFactory.cpp index dd013554fb62..bf631c71f3c3 100644 --- a/dom/base/nsDOMScriptObjectFactory.cpp +++ b/dom/base/nsDOMScriptObjectFactory.cpp @@ -75,8 +75,7 @@ nsDOMScriptObjectFactory::nsDOMScriptObjectFactory() : mLoadedAllLanguages(PR_FALSE) { nsCOMPtr observerService = - do_GetService("@mozilla.org/observer-service;1"); - + mozilla::services::GetObserverService(); if (observerService) { observerService->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, PR_FALSE); } diff --git a/dom/base/nsGlobalWindow.cpp b/dom/base/nsGlobalWindow.cpp index c93a0e0da94d..f65cd279ec61 100644 --- a/dom/base/nsGlobalWindow.cpp +++ b/dom/base/nsGlobalWindow.cpp @@ -680,8 +680,7 @@ nsGlobalWindow::nsGlobalWindow(nsGlobalWindow *aOuterWindow) mObserver = new nsGlobalWindowObserver(this); if (mObserver) { NS_ADDREF(mObserver); - nsCOMPtr os = - do_GetService("@mozilla.org/observer-service;1"); + nsCOMPtr os = mozilla::services::GetObserverService(); if (os) { // Watch for online/offline status changes so we can fire events. Use // a strong reference. @@ -773,8 +772,7 @@ nsGlobalWindow::~nsGlobalWindow() #endif if (mObserver) { - nsCOMPtr os = - do_GetService("@mozilla.org/observer-service;1"); + nsCOMPtr os = mozilla::services::GetObserverService(); if (os) { os->RemoveObserver(mObserver, NS_IOSERVICE_OFFLINE_STATUS_TOPIC); os->RemoveObserver(mObserver, "dom-storage2-changed"); @@ -2114,7 +2112,7 @@ nsGlobalWindow::SetNewDocument(nsIDocument* aDocument, } nsCOMPtr observerService = - do_GetService("@mozilla.org/observer-service;1"); + mozilla::services::GetObserverService(); if (observerService) { nsAutoString origin; nsIPrincipal* principal = aDocument->NodePrincipal(); diff --git a/dom/base/nsJSEnvironment.cpp b/dom/base/nsJSEnvironment.cpp index 0e57c701f7d1..5ce5e9a35e87 100644 --- a/dom/base/nsJSEnvironment.cpp +++ b/dom/base/nsJSEnvironment.cpp @@ -277,8 +277,7 @@ nsUserActivityObserver::Observe(nsISupports* aSubject, const char* aTopic, sUserIsActive = PR_TRUE; higherProbability = (mUserActivityCounter > NS_CC_SOFT_LIMIT_ACTIVE); } else if (!strcmp(aTopic, "xpcom-shutdown")) { - nsCOMPtr obs = - do_GetService("@mozilla.org/observer-service;1"); + nsCOMPtr obs = mozilla::services::GetObserverService(); if (obs) { obs->RemoveObserver(this, "user-interaction-active"); obs->RemoveObserver(this, "user-interaction-inactive"); @@ -4020,9 +4019,9 @@ nsJSRuntime::Init() SetMemoryGCFrequencyPrefChangedCallback("javascript.options.mem.gc_frequency", nsnull); - nsCOMPtr obs = - do_GetService("@mozilla.org/observer-service;1", &rv); - NS_ENSURE_SUCCESS(rv, rv); + nsCOMPtr obs = mozilla::services::GetObserverService(); + if (!obs) + return NS_ERROR_FAILURE; nsIObserver* activityObserver = new nsUserActivityObserver(); NS_ENSURE_TRUE(activityObserver, NS_ERROR_OUT_OF_MEMORY); obs->AddObserver(activityObserver, "user-interaction-inactive", PR_FALSE); @@ -4035,7 +4034,7 @@ nsJSRuntime::Init() sIsInitialized = PR_TRUE; - return rv; + return NS_OK; } //static diff --git a/dom/src/geolocation/nsGeolocation.cpp b/dom/src/geolocation/nsGeolocation.cpp index 5f42a8967d29..2a2e989ea048 100644 --- a/dom/src/geolocation/nsGeolocation.cpp +++ b/dom/src/geolocation/nsGeolocation.cpp @@ -50,6 +50,7 @@ #include "nsIPrefService.h" #include "nsIPrefBranch2.h" #include "nsIJSContextStack.h" +#include "mozilla/Services.h" #include @@ -383,7 +384,7 @@ nsresult nsGeolocationService::Init() return NS_ERROR_FAILURE; // geolocation service can be enabled -> now register observer - nsCOMPtr obs = do_GetService("@mozilla.org/observer-service;1"); + nsCOMPtr obs = mozilla::services::GetObserverService(); if (!obs) return NS_ERROR_FAILURE; @@ -439,7 +440,7 @@ nsGeolocationService::Observe(nsISupports* aSubject, { if (!strcmp("quit-application", aTopic)) { - nsCOMPtr obs = do_GetService("@mozilla.org/observer-service;1"); + nsCOMPtr obs = mozilla::services::GetObserverService(); if (obs) { obs->RemoveObserver(this, "quit-application"); } diff --git a/dom/src/offline/nsDOMOfflineResourceList.cpp b/dom/src/offline/nsDOMOfflineResourceList.cpp index 68008779d1e2..361777da7955 100644 --- a/dom/src/offline/nsDOMOfflineResourceList.cpp +++ b/dom/src/offline/nsDOMOfflineResourceList.cpp @@ -193,13 +193,14 @@ nsDOMOfflineResourceList::Init() } // watch for new offline cache updates - nsCOMPtr observerServ = - do_GetService("@mozilla.org/observer-service;1", &rv); - NS_ENSURE_SUCCESS(rv, rv); + nsCOMPtr observerService = + mozilla::services::GetObserverService(); + if (!observerService) + return NS_ERROR_FAILURE; - rv = observerServ->AddObserver(this, "offline-cache-update-added", PR_TRUE); + rv = observerService->AddObserver(this, "offline-cache-update-added", PR_TRUE); NS_ENSURE_SUCCESS(rv, rv); - rv = observerServ->AddObserver(this, "offline-cache-update-completed", PR_TRUE); + rv = observerService->AddObserver(this, "offline-cache-update-completed", PR_TRUE); NS_ENSURE_SUCCESS(rv, rv); mInitialized = PR_TRUE; diff --git a/dom/src/storage/nsDOMStorage.cpp b/dom/src/storage/nsDOMStorage.cpp index a5afe0bf312c..11c300c68bff 100644 --- a/dom/src/storage/nsDOMStorage.cpp +++ b/dom/src/storage/nsDOMStorage.cpp @@ -255,18 +255,19 @@ nsDOMStorageManager::Initialize() NS_ADDREF(gStorageManager); - nsCOMPtr os = do_GetService("@mozilla.org/observer-service;1"); - if (os) { - os->AddObserver(gStorageManager, "cookie-changed", PR_FALSE); - os->AddObserver(gStorageManager, "offline-app-removed", PR_FALSE); - os->AddObserver(gStorageManager, NS_PRIVATE_BROWSING_SWITCH_TOPIC, PR_FALSE); - os->AddObserver(gStorageManager, "perm-changed", PR_FALSE); + nsCOMPtr os = mozilla::services::GetObserverService(); + if (!os) + return NS_OK; - nsCOMPtr pbs = - do_GetService(NS_PRIVATE_BROWSING_SERVICE_CONTRACTID); - if (pbs) - pbs->GetPrivateBrowsingEnabled(&gStorageManager->mInPrivateBrowsing); - } + os->AddObserver(gStorageManager, "cookie-changed", PR_FALSE); + os->AddObserver(gStorageManager, "offline-app-removed", PR_FALSE); + os->AddObserver(gStorageManager, NS_PRIVATE_BROWSING_SWITCH_TOPIC, PR_FALSE); + os->AddObserver(gStorageManager, "perm-changed", PR_FALSE); + + nsCOMPtr pbs = + do_GetService(NS_PRIVATE_BROWSING_SERVICE_CONTRACTID); + if (pbs) + pbs->GetPrivateBrowsingEnabled(&gStorageManager->mInPrivateBrowsing); return NS_OK; } @@ -1273,8 +1274,7 @@ nsDOMStorage::SetDBValue(const nsAString& aKey, } } - nsCOMPtr os = - do_GetService("@mozilla.org/observer-service;1"); + nsCOMPtr os = mozilla::services::GetObserverService(); os->NotifyObservers(window, "dom-storage-warn-quota-exceeded", NS_ConvertUTF8toUTF16(mDomain).get()); } @@ -1423,10 +1423,9 @@ nsDOMStorage::BroadcastChangeNotification(const nsSubstring &aKey, const nsSubstring &aOldValue, const nsSubstring &aNewValue) { - nsresult rv; nsCOMPtr observerService = - do_GetService("@mozilla.org/observer-service;1", &rv); - if (NS_FAILED(rv)) { + mozilla::services::GetObserverService(); + if (!observerService) { return; } @@ -1616,8 +1615,8 @@ nsDOMStorage2::BroadcastChangeNotification(const nsSubstring &aKey, } nsCOMPtr observerService = - do_GetService("@mozilla.org/observer-service;1", &rv); - if (NS_FAILED(rv)) { + mozilla::services::GetObserverService(); + if (!observerService) { return; } diff --git a/embedding/components/find/src/nsWebBrowserFind.cpp b/embedding/components/find/src/nsWebBrowserFind.cpp index 059d2d7cecdd..5f99c92acdea 100644 --- a/embedding/components/find/src/nsWebBrowserFind.cpp +++ b/embedding/components/find/src/nsWebBrowserFind.cpp @@ -75,6 +75,7 @@ #include "nsFind.h" #include "nsDOMError.h" #include "nsFocusManager.h" +#include "mozilla/Services.h" #if DEBUG #include "nsIWebNavigation.h" @@ -130,7 +131,7 @@ NS_IMETHODIMP nsWebBrowserFind::FindNext(PRBool *outDidFind) // this is used by nsTypeAheadFind, which controls find again when it was // the last executed find in the current window. nsCOMPtr observerSvc = - do_GetService("@mozilla.org/observer-service;1"); + mozilla::services::GetObserverService(); if (observerSvc) { nsCOMPtr windowSupportsData = do_CreateInstance(NS_SUPPORTS_INTERFACE_POINTER_CONTRACTID, &rv); diff --git a/embedding/components/windowwatcher/src/nsWindowWatcher.cpp b/embedding/components/windowwatcher/src/nsWindowWatcher.cpp index 9c1b54d0e215..99ed6a358ad4 100644 --- a/embedding/components/windowwatcher/src/nsWindowWatcher.cpp +++ b/embedding/components/windowwatcher/src/nsWindowWatcher.cpp @@ -839,10 +839,9 @@ nsWindowWatcher::OpenWindowJSInternal(nsIDOMWindow *aParent, // Notify observers that the window is open and ready. // The window has not yet started to load a document. nsCOMPtr obsSvc = - do_GetService("@mozilla.org/observer-service;1"); - if (obsSvc) { + mozilla::services::GetObserverService(); + if (obsSvc) obsSvc->NotifyObservers(*_retval, "toplevel-window-ready", nsnull); - } } // Now we have to set the right opener principal on the new window. Note @@ -1016,17 +1015,18 @@ NS_IMETHODIMP nsWindowWatcher::RegisterNotification(nsIObserver *aObserver) { // just a convenience method; it delegates to nsIObserverService - nsresult rv; if (!aObserver) return NS_ERROR_INVALID_ARG; - nsCOMPtr os(do_GetService("@mozilla.org/observer-service;1", &rv)); - if (os) { - rv = os->AddObserver(aObserver, "domwindowopened", PR_FALSE); - if (NS_SUCCEEDED(rv)) - rv = os->AddObserver(aObserver, "domwindowclosed", PR_FALSE); - } + nsCOMPtr os = mozilla::services::GetObserverService(); + if (!os) + return NS_ERROR_FAILURE; + + nsresult rv = os->AddObserver(aObserver, "domwindowopened", PR_FALSE); + if (NS_SUCCEEDED(rv)) + rv = os->AddObserver(aObserver, "domwindowclosed", PR_FALSE); + return rv; } @@ -1034,17 +1034,18 @@ NS_IMETHODIMP nsWindowWatcher::UnregisterNotification(nsIObserver *aObserver) { // just a convenience method; it delegates to nsIObserverService - nsresult rv; if (!aObserver) return NS_ERROR_INVALID_ARG; - nsCOMPtr os(do_GetService("@mozilla.org/observer-service;1", &rv)); - if (os) { - os->RemoveObserver(aObserver, "domwindowopened"); - os->RemoveObserver(aObserver, "domwindowclosed"); - } - return rv; + nsCOMPtr os = mozilla::services::GetObserverService(); + if (!os) + return NS_ERROR_FAILURE; + + os->RemoveObserver(aObserver, "domwindowopened"); + os->RemoveObserver(aObserver, "domwindowclosed"); + + return NS_OK; } NS_IMETHODIMP @@ -1143,8 +1144,6 @@ nsWindowWatcher::SetActiveWindow(nsIDOMWindow *aActiveWindow) NS_IMETHODIMP nsWindowWatcher::AddWindow(nsIDOMWindow *aWindow, nsIWebBrowserChrome *aChrome) { - nsresult rv; - if (!aWindow) return NS_ERROR_INVALID_ARG; @@ -1188,13 +1187,12 @@ nsWindowWatcher::AddWindow(nsIDOMWindow *aWindow, nsIWebBrowserChrome *aChrome) // a window being added to us signifies a newly opened window. // send notifications. - nsCOMPtr os(do_GetService("@mozilla.org/observer-service;1", &rv)); - if (os) { - nsCOMPtr domwin(do_QueryInterface(aWindow)); - rv = os->NotifyObservers(domwin, "domwindowopened", 0); - } + nsCOMPtr os = mozilla::services::GetObserverService(); + if (!os) + return NS_ERROR_FAILURE; - return rv; + nsCOMPtr domwin(do_QueryInterface(aWindow)); + return os->NotifyObservers(domwin, "domwindowopened", 0); } NS_IMETHODIMP @@ -1257,7 +1255,6 @@ nsresult nsWindowWatcher::RemoveWindow(nsWatcherWindowEntry *inInfo) { PRUint32 ctr, count = mEnumeratorList.Length(); - nsresult rv; { // notify the enumerators @@ -1273,16 +1270,16 @@ nsresult nsWindowWatcher::RemoveWindow(nsWatcherWindowEntry *inInfo) // a window being removed from us signifies a newly closed window. // send notifications. - nsCOMPtr os(do_GetService("@mozilla.org/observer-service;1", &rv)); + nsCOMPtr os = mozilla::services::GetObserverService(); if (os) { #ifdef USEWEAKREFS nsCOMPtr domwin(do_QueryReferent(inInfo->mWindow)); if (domwin) - rv = os->NotifyObservers(domwin, "domwindowclosed", 0); + os->NotifyObservers(domwin, "domwindowclosed", 0); // else bummer. since the window is gone, there's nothing to notify with. #else nsCOMPtr domwin(do_QueryInterface(inInfo->mWindow)); - rv = os->NotifyObservers(domwin, "domwindowclosed", 0); + os->NotifyObservers(domwin, "domwindowclosed", 0); #endif } diff --git a/gfx/src/thebes/nsThebesDeviceContext.cpp b/gfx/src/thebes/nsThebesDeviceContext.cpp index 4e5dbdb143ba..c5201e59cfbf 100644 --- a/gfx/src/thebes/nsThebesDeviceContext.cpp +++ b/gfx/src/thebes/nsThebesDeviceContext.cpp @@ -47,6 +47,7 @@ #include "nsIServiceManager.h" #include "nsIPrefService.h" #include "nsCRT.h" +#include "mozilla/Services.h" #include "nsThebesDeviceContext.h" #include "nsThebesRenderingContext.h" @@ -307,7 +308,7 @@ static PRBool DeleteValue(nsHashKey* aKey, void* aValue, void* closure) nsThebesDeviceContext::~nsThebesDeviceContext() { - nsCOMPtr obs(do_GetService("@mozilla.org/observer-service;1")); + nsCOMPtr obs = mozilla::services::GetObserverService(); if (obs) obs->RemoveObserver(this, "memory-pressure"); @@ -709,7 +710,7 @@ nsThebesDeviceContext::Init(nsIWidget *aWidget) // register as a memory-pressure observer to free font resources // in low-memory situations. - nsCOMPtr obs(do_GetService("@mozilla.org/observer-service;1")); + nsCOMPtr obs = mozilla::services::GetObserverService(); if (obs) obs->AddObserver(this, "memory-pressure", PR_TRUE); diff --git a/intl/chardet/src/nsXMLEncodingObserver.cpp b/intl/chardet/src/nsXMLEncodingObserver.cpp index e367c9ed8e48..c39382599085 100644 --- a/intl/chardet/src/nsXMLEncodingObserver.cpp +++ b/intl/chardet/src/nsXMLEncodingObserver.cpp @@ -51,6 +51,7 @@ #include "nsWeakReference.h" #include "nsReadableUtils.h" #include "nsUnicharUtils.h" +#include "mozilla/Services.h" static NS_DEFINE_CID(kCharsetAliasCID, NS_CHARSETALIAS_CID); @@ -203,13 +204,13 @@ NS_IMETHODIMP nsXMLEncodingObserver::Start() if (bXMLEncodingObserverStarted) return res; - nsCOMPtr anObserverService = do_GetService("@mozilla.org/observer-service;1", &res); + nsCOMPtr obs = mozilla::services::GetObserverService(); + if (!obs) + return NS_ERROR_FAILURE; - if (NS_SUCCEEDED(res)) { - res = anObserverService->AddObserver(this, "xmlparser", PR_TRUE); + res = obs->AddObserver(this, "xmlparser", PR_TRUE); - bXMLEncodingObserverStarted = PR_TRUE; - } + bXMLEncodingObserverStarted = PR_TRUE; return res; } @@ -221,12 +222,13 @@ NS_IMETHODIMP nsXMLEncodingObserver::End() if (!bXMLEncodingObserverStarted) return res; - nsCOMPtr anObserverService = do_GetService("@mozilla.org/observer-service;1", &res); - if (NS_SUCCEEDED(res)) { - res = anObserverService->RemoveObserver(this, "xmlparser"); + nsCOMPtr obs = mozilla::services::GetObserverService(); + if (!obs) + return NS_ERROR_FAILURE; - bXMLEncodingObserverStarted = PR_FALSE; - } + res = obs->RemoveObserver(this, "xmlparser"); + + bXMLEncodingObserverStarted = PR_FALSE; return res; } diff --git a/intl/strres/src/nsStringBundle.cpp b/intl/strres/src/nsStringBundle.cpp index fe977b9c9b7a..05c83f8e4678 100644 --- a/intl/strres/src/nsStringBundle.cpp +++ b/intl/strres/src/nsStringBundle.cpp @@ -582,7 +582,7 @@ nsStringBundleService::~nsStringBundleService() nsresult nsStringBundleService::Init() { - nsCOMPtr os = do_GetService("@mozilla.org/observer-service;1"); + nsCOMPtr os = mozilla::services::GetObserverService(); if (os) { os->AddObserver(this, "memory-pressure", PR_TRUE); os->AddObserver(this, "profile-do-change", PR_TRUE); diff --git a/layout/base/nsPresShell.cpp b/layout/base/nsPresShell.cpp index 2bf97d14cb7f..3b7d7de3a863 100644 --- a/layout/base/nsPresShell.cpp +++ b/layout/base/nsPresShell.cpp @@ -1647,8 +1647,7 @@ PresShell::Init(nsIDocument* aDocument, } { - nsCOMPtr os = - do_GetService("@mozilla.org/observer-service;1", &result); + nsCOMPtr os = mozilla::services::GetObserverService(); if (os) { os->AddObserver(this, "agent-sheet-added", PR_FALSE); os->AddObserver(this, "user-sheet-added", PR_FALSE); @@ -1723,8 +1722,7 @@ PresShell::Destroy() } { - nsCOMPtr os = - do_GetService("@mozilla.org/observer-service;1"); + nsCOMPtr os = mozilla::services::GetObserverService(); if (os) { os->RemoveObserver(this, "agent-sheet-added"); os->RemoveObserver(this, "user-sheet-added"); diff --git a/layout/base/nsStyleSheetService.cpp b/layout/base/nsStyleSheetService.cpp index 55379d0cf55b..de37590d23c5 100644 --- a/layout/base/nsStyleSheetService.cpp +++ b/layout/base/nsStyleSheetService.cpp @@ -151,7 +151,7 @@ nsStyleSheetService::LoadAndRegisterSheet(nsIURI *aSheetURI, const char* message = (aSheetType == AGENT_SHEET) ? "agent-sheet-added" : "user-sheet-added"; nsCOMPtr serv = - do_GetService("@mozilla.org/observer-service;1"); + mozilla::services::GetObserverService(); if (serv) { // We're guaranteed that the new sheet is the last sheet in // mSheets[aSheetType] @@ -212,10 +212,9 @@ nsStyleSheetService::UnregisterSheet(nsIURI *sheetURI, PRUint32 aSheetType) const char* message = (aSheetType == AGENT_SHEET) ? "agent-sheet-removed" : "user-sheet-removed"; nsCOMPtr serv = - do_GetService("@mozilla.org/observer-service;1"); - if (serv) { + mozilla::services::GetObserverService(); + if (serv) serv->NotifyObservers(sheet, message, nsnull); - } - + return NS_OK; } diff --git a/layout/build/nsLayoutModule.cpp b/layout/build/nsLayoutModule.cpp index e689561aafdb..ad22f2ce7adf 100644 --- a/layout/build/nsLayoutModule.cpp +++ b/layout/build/nsLayoutModule.cpp @@ -95,6 +95,7 @@ #include "nsXULPopupManager.h" #include "nsFocusManager.h" #include "nsIContentUtils.h" +#include "mozilla/Services.h" #include "nsIEventListenerService.h" // Transformiix stuff @@ -355,7 +356,7 @@ Initialize(nsIModule* aSelf) // Add our shutdown observer. nsCOMPtr observerService = - do_GetService("@mozilla.org/observer-service;1"); + mozilla::services::GetObserverService(); if (observerService) { LayoutShutdownObserver* observer = new LayoutShutdownObserver(); diff --git a/layout/forms/nsFileControlFrame.cpp b/layout/forms/nsFileControlFrame.cpp index 22c93b4716c7..d8c226617b5d 100644 --- a/layout/forms/nsFileControlFrame.cpp +++ b/layout/forms/nsFileControlFrame.cpp @@ -90,6 +90,7 @@ #include "nsIVariant.h" #include "nsIContentPrefService.h" #include "nsIContentURIGrouper.h" +#include "mozilla/Services.h" #define SYNC_TEXT 0x1 #define SYNC_BUTTON 0x2 @@ -493,7 +494,7 @@ void nsFileControlFrame::InitUploadLastDir() { NS_IF_ADDREF(gUploadLastDir); nsCOMPtr observerService = - do_GetService("@mozilla.org/observer-service;1"); + mozilla::services::GetObserverService(); if (observerService && gUploadLastDir) { observerService->AddObserver(gUploadLastDir, NS_PRIVATE_BROWSING_SWITCH_TOPIC, PR_TRUE); observerService->AddObserver(gUploadLastDir, "browser:purge-session-history", PR_TRUE); @@ -843,12 +844,10 @@ NS_IMETHODIMP nsFileControlFrame::GetAccessible(nsIAccessible** aAccessible) { // Accessible object exists just to hold onto its children, for later shutdown nsCOMPtr accService = do_GetService("@mozilla.org/accessibilityService;1"); + if (!accService) + return NS_ERROR_FAILURE; - if (accService) { - return accService->CreateHTMLGenericAccessible(static_cast(this), aAccessible); - } - - return NS_ERROR_FAILURE; + return accService->CreateHTMLGenericAccessible(static_cast(this), aAccessible); } #endif diff --git a/layout/generic/nsObjectFrame.cpp b/layout/generic/nsObjectFrame.cpp index 3bad287dd434..17f60d3ee830 100644 --- a/layout/generic/nsObjectFrame.cpp +++ b/layout/generic/nsObjectFrame.cpp @@ -1263,7 +1263,8 @@ nsObjectFrame::SetAbsoluteScreenPosition(nsIDOMElement* element, nsresult nsObjectFrame::PluginEventNotifier::Run() { - nsCOMPtr obsSvc = do_GetService("@mozilla.org/observer-service;1"); + nsCOMPtr obsSvc = + mozilla::services::GetObserverService(); obsSvc->NotifyObservers(nsnull, "plugin-changed-event", mEventType.get()); return NS_OK; } diff --git a/layout/mathml/nsMathMLChar.cpp b/layout/mathml/nsMathMLChar.cpp index 2a20794a54f9..eed9b191039a 100644 --- a/layout/mathml/nsMathMLChar.cpp +++ b/layout/mathml/nsMathMLChar.cpp @@ -579,12 +579,11 @@ nsGlyphTableList::Observe(nsISupports* aSubject, nsresult nsGlyphTableList::Initialize() { - nsresult rv; - nsCOMPtr obs = - do_GetService("@mozilla.org/observer-service;1", &rv); - NS_ENSURE_SUCCESS(rv, rv); + nsCOMPtr obs = mozilla::services::GetObserverService(); + if (!obs) + return NS_ERROR_FAILURE; - rv = obs->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, PR_FALSE); + nsresult rv = obs->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, PR_FALSE); NS_ENSURE_SUCCESS(rv, rv); return NS_OK; @@ -596,11 +595,12 @@ nsGlyphTableList::Finalize() { // Remove our observer from the observer service nsresult rv = NS_OK; - nsCOMPtr obs = - do_GetService("@mozilla.org/observer-service;1", &rv); - if (NS_SUCCEEDED(rv)) { + nsCOMPtr obs = mozilla::services::GetObserverService(); + if (obs) rv = obs->RemoveObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID); - } + else + rv = NS_ERROR_FAILURE; + gInitialized = PR_FALSE; // our oneself will be destroyed when our |Release| is called by the observer return rv; diff --git a/layout/style/nsCSSRuleProcessor.cpp b/layout/style/nsCSSRuleProcessor.cpp index 73ab15832813..6ec4b6be68b3 100644 --- a/layout/style/nsCSSRuleProcessor.cpp +++ b/layout/style/nsCSSRuleProcessor.cpp @@ -90,6 +90,7 @@ #include "nsIObserverService.h" #include "nsIPrivateBrowsingService.h" #include "nsNetCID.h" +#include "mozilla/Services.h" #define VISITED_PSEUDO_PREF "layout.css.visited_links_enabled" @@ -803,15 +804,15 @@ nsPrivateBrowsingObserver::Init() { nsCOMPtr pbService = do_GetService(NS_PRIVATE_BROWSING_SERVICE_CONTRACTID); - if (pbService) { - pbService->GetPrivateBrowsingEnabled(&mInPrivateBrowsing); + if (!pbService) + return; - nsCOMPtr observerService = - do_GetService("@mozilla.org/observer-service;1"); - if (observerService) { - observerService->AddObserver(this, NS_PRIVATE_BROWSING_SWITCH_TOPIC, PR_TRUE); - } - } + pbService->GetPrivateBrowsingEnabled(&mInPrivateBrowsing); + + nsCOMPtr observerService = + mozilla::services::GetObserverService(); + if (observerService) + observerService->AddObserver(this, NS_PRIVATE_BROWSING_SWITCH_TOPIC, PR_TRUE); } nsresult diff --git a/layout/style/nsLayoutStylesheetCache.cpp b/layout/style/nsLayoutStylesheetCache.cpp index 99aeed070f48..6c527dd02029 100644 --- a/layout/style/nsLayoutStylesheetCache.cpp +++ b/layout/style/nsLayoutStylesheetCache.cpp @@ -164,7 +164,7 @@ nsLayoutStylesheetCache::Shutdown() nsLayoutStylesheetCache::nsLayoutStylesheetCache() { nsCOMPtr obsSvc = - do_GetService("@mozilla.org/observer-service;1"); + mozilla::services::GetObserverService(); NS_ASSERTION(obsSvc, "No global observer service?"); if (obsSvc) { diff --git a/modules/libpr0n/src/imgLoader.cpp b/modules/libpr0n/src/imgLoader.cpp index bfb9b0041911..b54a36a4f7b6 100644 --- a/modules/libpr0n/src/imgLoader.cpp +++ b/modules/libpr0n/src/imgLoader.cpp @@ -665,9 +665,9 @@ imgCacheQueue & imgLoader::GetCacheQueue(nsIURI *aURI) nsresult imgLoader::InitCache() { nsresult rv; - nsCOMPtr os = do_GetService("@mozilla.org/observer-service;1", &rv); - if (NS_FAILED(rv)) - return rv; + nsCOMPtr os = mozilla::services::GetObserverService(); + if (!os) + return NS_ERROR_FAILURE; gCacheObserver = new imgCacheObserver(); if (!gCacheObserver) diff --git a/modules/libpref/src/nsPrefBranch.cpp b/modules/libpref/src/nsPrefBranch.cpp index b3a1b30feb17..086b9f671ea7 100644 --- a/modules/libpref/src/nsPrefBranch.cpp +++ b/modules/libpref/src/nsPrefBranch.cpp @@ -54,6 +54,7 @@ #include "plstr.h" #include "nsCRT.h" +#include "mozilla/Services.h" #include "prefapi_private_data.h" @@ -89,8 +90,8 @@ nsPrefBranch::nsPrefBranch(const char *aPrefRoot, PRBool aDefaultBranch) mPrefRootLength = mPrefRoot.Length(); mIsDefault = aDefaultBranch; - nsCOMPtr observerService = - do_GetService("@mozilla.org/observer-service;1"); + nsCOMPtr observerService = + mozilla::services::GetObserverService(); if (observerService) { ++mRefCnt; // Our refcnt must be > 0 when we call this, or we'll get deleted! // add weak so we don't have to clean up at shutdown diff --git a/modules/libpref/src/nsPrefService.cpp b/modules/libpref/src/nsPrefService.cpp index 747ca503af12..1f6654540c31 100644 --- a/modules/libpref/src/nsPrefService.cpp +++ b/modules/libpref/src/nsPrefService.cpp @@ -139,14 +139,15 @@ nsresult nsPrefService::Init() static_cast(static_cast(this)), "pref-config-startup"); - nsCOMPtr observerService = - do_GetService("@mozilla.org/observer-service;1", &rv); - if (observerService) { - rv = observerService->AddObserver(this, "profile-before-change", PR_TRUE); - if (NS_SUCCEEDED(rv)) { - rv = observerService->AddObserver(this, "profile-do-change", PR_TRUE); - } - } + nsCOMPtr observerService = + mozilla::services::GetObserverService(); + if (!observerService) + return NS_ERROR_FAILURE; + + rv = observerService->AddObserver(this, "profile-before-change", PR_TRUE); + + if (NS_SUCCEEDED(rv)) + rv = observerService->AddObserver(this, "profile-do-change", PR_TRUE); return(rv); } @@ -247,12 +248,10 @@ NS_IMETHODIMP nsPrefService::GetDefaultBranch(const char *aPrefRoot, nsIPrefBran nsresult nsPrefService::NotifyServiceObservers(const char *aTopic) { - nsresult rv; nsCOMPtr observerService = - do_GetService("@mozilla.org/observer-service;1", &rv); - - if (NS_FAILED(rv) || !observerService) - return rv; + mozilla::services::GetObserverService(); + if (!observerService) + return NS_ERROR_FAILURE; nsISupports *subject = (nsISupports *)((nsIPrefService *)this); observerService->NotifyObservers(subject, aTopic, nsnull); @@ -704,11 +703,10 @@ static nsresult pref_InitInitialObjects() NS_CreateServicesFromCategory(NS_PREFSERVICE_APPDEFAULTS_TOPIC_ID, nsnull, NS_PREFSERVICE_APPDEFAULTS_TOPIC_ID); - nsCOMPtr observerService = - do_GetService("@mozilla.org/observer-service;1", &rv); - - if (NS_FAILED(rv) || !observerService) - return rv; + nsCOMPtr observerService = + mozilla::services::GetObserverService(); + if (!observerService) + return NS_ERROR_FAILURE; observerService->NotifyObservers(nsnull, NS_PREFSERVICE_APPDEFAULTS_TOPIC_ID, nsnull); diff --git a/modules/plugin/base/src/nsNPAPIPlugin.cpp b/modules/plugin/base/src/nsNPAPIPlugin.cpp index 82f8465647d1..e1d466bc3b93 100644 --- a/modules/plugin/base/src/nsNPAPIPlugin.cpp +++ b/modules/plugin/base/src/nsNPAPIPlugin.cpp @@ -195,7 +195,7 @@ void NS_NotifyPluginCall(PRIntervalTime startTime) { PRIntervalTime endTime = PR_IntervalNow() - startTime; nsCOMPtr notifyUIService = - do_GetService("@mozilla.org/observer-service;1"); + mozilla::services::GetObserverService(); if (!notifyUIService) return; diff --git a/modules/plugin/base/src/nsPluginHost.cpp b/modules/plugin/base/src/nsPluginHost.cpp index 6cbf477e8dc6..3f17a20f7da2 100644 --- a/modules/plugin/base/src/nsPluginHost.cpp +++ b/modules/plugin/base/src/nsPluginHost.cpp @@ -1533,7 +1533,8 @@ nsPluginHost::nsPluginHost() #endif } - nsCOMPtr obsService = do_GetService("@mozilla.org/observer-service;1"); + nsCOMPtr obsService = + mozilla::services::GetObserverService(); if (obsService) { obsService->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, PR_FALSE); obsService->AddObserver(this, NS_PRIVATE_BROWSING_SWITCH_TOPIC, PR_FALSE); @@ -3555,8 +3556,8 @@ NS_IMETHODIMP nsPluginHost::LoadPlugins() // only if plugins have changed will we notify plugin-change observers if (pluginschanged) { - nsCOMPtr - obsService(do_GetService("@mozilla.org/observer-service;1")); + nsCOMPtr obsService = + mozilla::services::GetObserverService(); if (obsService) obsService->NotifyObservers(nsnull, "plugins-list-updated", nsnull); } @@ -5068,7 +5069,7 @@ nsPluginHost::PluginCrashed(nsNPAPIPlugin* aPlugin, // a crashreport. PRBool submittedCrashReport = PR_FALSE; nsCOMPtr obsService = - do_GetService("@mozilla.org/observer-service;1"); + mozilla::services::GetObserverService(); nsCOMPtr propbag = do_CreateInstance("@mozilla.org/hash-property-bag;1"); if (obsService && propbag) { diff --git a/netwerk/base/src/nsIOService.cpp b/netwerk/base/src/nsIOService.cpp index afaa4d02af82..23a08f00f91b 100644 --- a/netwerk/base/src/nsIOService.cpp +++ b/netwerk/base/src/nsIOService.cpp @@ -229,7 +229,7 @@ nsIOService::Init() // Register for profile change notifications nsCOMPtr observerService = - do_GetService("@mozilla.org/observer-service;1"); + mozilla::services::GetObserverService(); if (observerService) { observerService->AddObserver(this, kProfileChangeNetTeardownTopic, PR_TRUE); observerService->AddObserver(this, kProfileChangeNetRestoreTopic, PR_TRUE); @@ -665,7 +665,7 @@ nsIOService::SetOffline(PRBool offline) mSettingOffline = PR_TRUE; nsCOMPtr observerService = - do_GetService("@mozilla.org/observer-service;1"); + mozilla::services::GetObserverService(); while (mSetOfflineValue != mOffline) { offline = mSetOfflineValue; diff --git a/netwerk/base/src/nsIOThreadPool.cpp b/netwerk/base/src/nsIOThreadPool.cpp index e52961b2564f..d15c6270a043 100644 --- a/netwerk/base/src/nsIOThreadPool.cpp +++ b/netwerk/base/src/nsIOThreadPool.cpp @@ -126,7 +126,7 @@ nsIOThreadPool::Init() PR_INIT_CLIST(&mEventQ); // We want to shutdown the i/o thread pool at xpcom-shutdown-threads time. - nsCOMPtr os = do_GetService("@mozilla.org/observer-service;1"); + nsCOMPtr os = mozilla::services::GetObserverService(); if (os) os->AddObserver(this, "xpcom-shutdown-threads", PR_FALSE); return NS_OK; diff --git a/netwerk/base/src/nsIncrementalDownload.cpp b/netwerk/base/src/nsIncrementalDownload.cpp index 7516999f25f2..c45841fd8c3d 100644 --- a/netwerk/base/src/nsIncrementalDownload.cpp +++ b/netwerk/base/src/nsIncrementalDownload.cpp @@ -504,8 +504,7 @@ nsIncrementalDownload::Start(nsIRequestObserver *observer, // between ourselves and the timer. We have the observer service hold a weak // reference to us, so that we don't have to worry about calling // RemoveObserver. XXX(darin): The timer code should do this for us. - nsCOMPtr obs = - do_GetService("@mozilla.org/observer-service;1"); + nsCOMPtr obs = mozilla::services::GetObserverService(); if (obs) obs->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, PR_TRUE); diff --git a/netwerk/base/src/nsProtocolProxyService.cpp b/netwerk/base/src/nsProtocolProxyService.cpp index c72f4e1f017b..3b0479af834d 100644 --- a/netwerk/base/src/nsProtocolProxyService.cpp +++ b/netwerk/base/src/nsProtocolProxyService.cpp @@ -338,8 +338,7 @@ nsProtocolProxyService::Init() } // register for shutdown notification so we can clean ourselves up properly. - nsCOMPtr obs = - do_GetService("@mozilla.org/observer-service;1"); + nsCOMPtr obs = mozilla::services::GetObserverService(); if (obs) obs->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, PR_FALSE); diff --git a/netwerk/base/src/nsStreamTransportService.cpp b/netwerk/base/src/nsStreamTransportService.cpp index 69ef9509bdf3..e8e31ef0746b 100644 --- a/netwerk/base/src/nsStreamTransportService.cpp +++ b/netwerk/base/src/nsStreamTransportService.cpp @@ -53,6 +53,7 @@ #include "nsITransport.h" #include "nsIRunnable.h" #include "nsIObserverService.h" +#include "mozilla/Services.h" //----------------------------------------------------------------------------- // nsInputStreamTransport @@ -481,7 +482,7 @@ nsStreamTransportService::Init() mPool->SetIdleThreadTimeout(PR_SecondsToInterval(60)); nsCOMPtr obsSvc = - do_GetService("@mozilla.org/observer-service;1"); + mozilla::services::GetObserverService(); if (obsSvc) obsSvc->AddObserver(this, "xpcom-shutdown-threads", PR_FALSE); return NS_OK; diff --git a/netwerk/cache/src/nsCacheService.cpp b/netwerk/cache/src/nsCacheService.cpp index 668b5d251f95..e5c55578b4e6 100644 --- a/netwerk/cache/src/nsCacheService.cpp +++ b/netwerk/cache/src/nsCacheService.cpp @@ -71,6 +71,7 @@ #include "nsIPrivateBrowsingService.h" #include "nsNetCID.h" #include // for log() +#include "mozilla/Services.h" /****************************************************************************** @@ -174,13 +175,13 @@ NS_IMPL_ISUPPORTS1(nsCacheProfilePrefObserver, nsIObserver) nsresult nsCacheProfilePrefObserver::Install() { - nsresult rv, rv2 = NS_OK; - // install profile-change observer - nsCOMPtr observerService = do_GetService("@mozilla.org/observer-service;1", &rv); - NS_ENSURE_SUCCESS(rv, rv); - NS_ENSURE_ARG(observerService); + nsCOMPtr observerService = + mozilla::services::GetObserverService(); + if (!observerService) + return NS_ERROR_FAILURE; + nsresult rv, rv2 = NS_OK; for (unsigned int i=0; iAddObserver(this, observerList[i], PR_FALSE); if (NS_FAILED(rv)) @@ -210,12 +211,11 @@ nsCacheProfilePrefObserver::Install() // In that case, we detect the presence of a profile by the existence // of the NS_APP_USER_PROFILE_50_DIR directory. - nsCOMPtr directory; + nsCOMPtr directory; rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, getter_AddRefs(directory)); - if (NS_SUCCEEDED(rv)) { + if (NS_SUCCEEDED(rv)) mHaveProfile = PR_TRUE; - } rv = ReadPrefs(branch); NS_ENSURE_SUCCESS(rv, rv); @@ -229,7 +229,7 @@ nsCacheProfilePrefObserver::Remove() { // remove Observer Service observers nsCOMPtr obs = - do_GetService("@mozilla.org/observer-service;1"); + mozilla::services::GetObserverService(); if (obs) { for (unsigned int i=0; iRemoveObserver(this, observerList[i]); @@ -238,13 +238,11 @@ nsCacheProfilePrefObserver::Remove() // remove Pref Service observers nsCOMPtr prefs = - do_GetService(NS_PREFSERVICE_CONTRACTID); - if (prefs) { - for (unsigned int i=0; iRemoveObserver(prefList[i], this); - } - } + do_GetService(NS_PREFSERVICE_CONTRACTID); + if (!prefs) + return; + for (unsigned int i=0; iRemoveObserver(prefList[i], this); // remove cache pref observers } @@ -794,7 +792,7 @@ nsCacheService::EvictEntriesForClient(const char * clientID, if (this == nsnull) return NS_ERROR_NOT_AVAILABLE; // XXX eh? nsCOMPtr obsSvc = - do_GetService("@mozilla.org/observer-service;1"); + mozilla::services::GetObserverService(); if (obsSvc) { // Proxy to the UI thread since the observer service isn't thredsafe. // We use an async proxy, since this it's not important whether this diff --git a/netwerk/cookie/src/nsCookieService.cpp b/netwerk/cookie/src/nsCookieService.cpp index 8958d0c33631..e3fa449a5859 100644 --- a/netwerk/cookie/src/nsCookieService.cpp +++ b/netwerk/cookie/src/nsCookieService.cpp @@ -545,7 +545,7 @@ nsCookieService::Init() if (NS_FAILED(rv)) COOKIE_LOGSTRING(PR_LOG_WARNING, ("Init(): InitDB() gave error %x", rv)); - mObserverService = do_GetService("@mozilla.org/observer-service;1"); + mObserverService = mozilla::services::GetObserverService(); if (mObserverService) { mObserverService->AddObserver(this, "profile-before-change", PR_TRUE); mObserverService->AddObserver(this, "profile-do-change", PR_TRUE); diff --git a/netwerk/protocol/ftp/src/nsFtpProtocolHandler.cpp b/netwerk/protocol/ftp/src/nsFtpProtocolHandler.cpp index 6290a0b0d500..af984a22e5a6 100644 --- a/netwerk/protocol/ftp/src/nsFtpProtocolHandler.cpp +++ b/netwerk/protocol/ftp/src/nsFtpProtocolHandler.cpp @@ -123,9 +123,8 @@ NS_IMPL_THREADSAFE_ISUPPORTS4(nsFtpProtocolHandler, nsresult nsFtpProtocolHandler::Init() { - nsresult rv; - if (mIdleTimeout == -1) { + nsresult rv; nsCOMPtr branch = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv); if (NS_FAILED(rv)) return rv; @@ -138,7 +137,7 @@ nsFtpProtocolHandler::Init() } nsCOMPtr observerService = - do_GetService("@mozilla.org/observer-service;1"); + mozilla::services::GetObserverService(); if (observerService) { observerService->AddObserver(this, "network:offline-about-to-go-offline", diff --git a/netwerk/protocol/http/src/nsHttpHandler.cpp b/netwerk/protocol/http/src/nsHttpHandler.cpp index fe8aeb0613a2..997245f383a5 100644 --- a/netwerk/protocol/http/src/nsHttpHandler.cpp +++ b/netwerk/protocol/http/src/nsHttpHandler.cpp @@ -291,7 +291,7 @@ nsHttpHandler::Init() static_cast(static_cast(this)), NS_HTTP_STARTUP_TOPIC); - mObserverService = do_GetService("@mozilla.org/observer-service;1"); + mObserverService = mozilla::services::GetObserverService(); if (mObserverService) { mObserverService->AddObserver(this, "profile-change-net-teardown", PR_TRUE); mObserverService->AddObserver(this, "profile-change-net-restore", PR_TRUE); diff --git a/netwerk/system/maemo/nsMaemoNetworkLinkService.cpp b/netwerk/system/maemo/nsMaemoNetworkLinkService.cpp index bca9e9563eb8..10976c275dfc 100644 --- a/netwerk/system/maemo/nsMaemoNetworkLinkService.cpp +++ b/netwerk/system/maemo/nsMaemoNetworkLinkService.cpp @@ -29,6 +29,7 @@ #include "nsServiceManagerUtils.h" #include "nsString.h" #include "nsMaemoNetworkManager.h" +#include "mozilla/Services.h" NS_IMPL_ISUPPORTS2(nsMaemoNetworkLinkService, nsINetworkLinkService, @@ -70,13 +71,12 @@ nsMaemoNetworkLinkService::Observe(nsISupports *aSubject, nsresult nsMaemoNetworkLinkService::Init(void) { - nsresult rv; - nsCOMPtr observerService = - do_GetService("@mozilla.org/observer-service;1", &rv); - NS_ENSURE_SUCCESS(rv, rv); + mozilla::services::GetObserverService(); + if (!observerService) + return NS_ERROR_FAILURE; - rv = observerService->AddObserver(this, "xpcom-shutdown", PR_FALSE); + nsresult rv = observerService->AddObserver(this, "xpcom-shutdown", PR_FALSE); NS_ENSURE_SUCCESS(rv, rv); if (!nsMaemoNetworkManager::Startup()) diff --git a/netwerk/system/win32/nsNotifyAddrListener.cpp b/netwerk/system/win32/nsNotifyAddrListener.cpp index c8ae22b36721..2b091842e02d 100644 --- a/netwerk/system/win32/nsNotifyAddrListener.cpp +++ b/netwerk/system/win32/nsNotifyAddrListener.cpp @@ -53,6 +53,7 @@ #include "nsNotifyAddrListener.h" #include "nsString.h" #include "nsAutoPtr.h" +#include "mozilla/Services.h" #include #include @@ -229,13 +230,13 @@ nsNotifyAddrListener::Init(void) mOSVerInfo.dwMajorVersion < 5) return NS_OK; - nsresult rv; nsCOMPtr observerService = - do_GetService("@mozilla.org/observer-service;1", &rv); - NS_ENSURE_SUCCESS(rv, rv); + mozilla::services::GetObserverService(); + if (!observerService) + return NS_ERROR_FAILURE; - rv = observerService->AddObserver(this, "xpcom-shutdown-threads", - PR_FALSE); + nsresult rv = observerService->AddObserver(this, "xpcom-shutdown-threads", + PR_FALSE); NS_ENSURE_SUCCESS(rv, rv); mShutdownEvent = CreateEvent(NULL, FALSE, FALSE, NULL); @@ -252,7 +253,7 @@ nsNotifyAddrListener::Shutdown(void) { // remove xpcom shutdown observer nsCOMPtr observerService = - do_GetService("@mozilla.org/observer-service;1"); + mozilla::services::GetObserverService(); if (observerService) observerService->RemoveObserver(this, "xpcom-shutdown-threads"); @@ -294,7 +295,7 @@ NS_IMETHODIMP nsNotifyAddrListener::ChangeEvent::Run() { nsCOMPtr observerService = - do_GetService("@mozilla.org/observer-service;1"); + mozilla::services::GetObserverService(); if (observerService) observerService->NotifyObservers( mService, NS_NETWORK_LINK_TOPIC, diff --git a/netwerk/wifi/src/nsWifiMonitor.cpp b/netwerk/wifi/src/nsWifiMonitor.cpp index adcfe4bfb090..ecd78c676dae 100644 --- a/netwerk/wifi/src/nsWifiMonitor.cpp +++ b/netwerk/wifi/src/nsWifiMonitor.cpp @@ -52,6 +52,7 @@ #include "nsIProxyObjectManager.h" #include "nsServiceManagerUtils.h" #include "nsComponentManagerUtils.h" +#include "mozilla/Services.h" #if defined(PR_LOGGING) PRLogModuleInfo *gWifiMonitorLog; @@ -71,7 +72,7 @@ nsWifiMonitor::nsWifiMonitor() mMonitor = nsAutoMonitor::NewMonitor("nsWifiMonitor"); - nsCOMPtr obsSvc = do_GetService("@mozilla.org/observer-service;1"); + nsCOMPtr obsSvc = mozilla::services::GetObserverService(); if (obsSvc) obsSvc->AddObserver(this, "xpcom-shutdown", PR_FALSE); diff --git a/parser/html/nsHtml5Module.cpp b/parser/html/nsHtml5Module.cpp index bdf462253c38..b6325009392c 100644 --- a/parser/html/nsHtml5Module.cpp +++ b/parser/html/nsHtml5Module.cpp @@ -48,6 +48,7 @@ #include "nsHtml5Module.h" #include "nsIObserverService.h" #include "nsIServiceManager.h" +#include "mozilla/Services.h" // static PRBool nsHtml5Module::sEnabled = PR_FALSE; @@ -147,7 +148,7 @@ nsHtml5Module::GetStreamParserThread() if (!sStreamParserThread) { NS_NewThread(&sStreamParserThread); NS_ASSERTION(sStreamParserThread, "Thread creation failed!"); - nsCOMPtr os = do_GetService("@mozilla.org/observer-service;1"); + nsCOMPtr os = mozilla::services::GetObserverService(); NS_ASSERTION(os, "do_GetService failed"); os->AddObserver(new nsHtml5ParserThreadTerminator(sStreamParserThread), "xpcom-shutdown-threads", diff --git a/profile/dirserviceprovider/src/nsProfileDirServiceProvider.cpp b/profile/dirserviceprovider/src/nsProfileDirServiceProvider.cpp index e439f87fccac..a7d9bde005a8 100644 --- a/profile/dirserviceprovider/src/nsProfileDirServiceProvider.cpp +++ b/profile/dirserviceprovider/src/nsProfileDirServiceProvider.cpp @@ -45,6 +45,7 @@ #include "nsISupportsUtils.h" #include "nsISimpleEnumerator.h" #include "nsIObserverService.h" +#include "mozilla/Services.h" // File Name Defines @@ -127,7 +128,7 @@ nsProfileDirServiceProvider::SetProfileDir(nsIFile* aProfileDir, if (mNotifyObservers) { nsCOMPtr observerService = - do_GetService("@mozilla.org/observer-service;1"); + mozilla::services::GetObserverService(); if (!observerService) return NS_ERROR_FAILURE; @@ -158,7 +159,7 @@ nsProfileDirServiceProvider::Shutdown() return NS_OK; nsCOMPtr observerService = - do_GetService("@mozilla.org/observer-service;1"); + mozilla::services::GetObserverService(); if (!observerService) return NS_ERROR_FAILURE; diff --git a/storage/src/mozStorageService.cpp b/storage/src/mozStorageService.cpp index 1d4804651d0c..fc72e514eef5 100644 --- a/storage/src/mozStorageService.cpp +++ b/storage/src/mozStorageService.cpp @@ -51,6 +51,7 @@ #include "nsILocaleService.h" #include "nsIXPConnect.h" #include "nsIObserverService.h" +#include "mozilla/Services.h" #include "sqlite3.h" @@ -170,7 +171,7 @@ Service::initialize() return convertResultCode(rc); nsCOMPtr os = - do_GetService("@mozilla.org/observer-service;1"); + mozilla::services::GetObserverService(); NS_ENSURE_TRUE(os, NS_ERROR_FAILURE); nsresult rv = os->AddObserver(this, "xpcom-shutdown", PR_FALSE); diff --git a/toolkit/components/autocomplete/src/nsAutoCompleteController.cpp b/toolkit/components/autocomplete/src/nsAutoCompleteController.cpp index 5371619caf65..a977407c6912 100644 --- a/toolkit/components/autocomplete/src/nsAutoCompleteController.cpp +++ b/toolkit/components/autocomplete/src/nsAutoCompleteController.cpp @@ -53,6 +53,7 @@ #include "nsIGenericFactory.h" #include "nsIObserverService.h" #include "nsIDOMKeyEvent.h" +#include "mozilla/Services.h" static const char *kAutoCompleteSearchCID = "@mozilla.org/autocomplete/search;1?name="; @@ -1133,7 +1134,7 @@ nsAutoCompleteController::EnterMatch(PRBool aIsPopupSelection) } nsCOMPtr obsSvc = - do_GetService("@mozilla.org/observer-service;1"); + mozilla::services::GetObserverService(); NS_ENSURE_STATE(obsSvc); obsSvc->NotifyObservers(input, "autocomplete-will-enter-text", nsnull); @@ -1169,7 +1170,7 @@ nsAutoCompleteController::RevertTextValue() if (!cancel) { nsCOMPtr obsSvc = - do_GetService("@mozilla.org/observer-service;1"); + mozilla::services::GetObserverService(); NS_ENSURE_STATE(obsSvc); obsSvc->NotifyObservers(input, "autocomplete-will-revert-text", nsnull); diff --git a/toolkit/components/downloads/src/nsDownloadManager.cpp b/toolkit/components/downloads/src/nsDownloadManager.cpp index 64655822798a..c31cd0333657 100644 --- a/toolkit/components/downloads/src/nsDownloadManager.cpp +++ b/toolkit/components/downloads/src/nsDownloadManager.cpp @@ -842,9 +842,11 @@ nsDownloadManager::Init() } } + mObserverService = mozilla::services::GetObserverService(); + if (!mObserverService) + return NS_ERROR_FAILURE; + nsresult rv; - mObserverService = do_GetService("@mozilla.org/observer-service;1", &rv); - NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr bundleService = do_GetService(NS_STRINGBUNDLE_CONTRACTID, &rv); diff --git a/toolkit/components/places/src/nsFaviconService.cpp b/toolkit/components/places/src/nsFaviconService.cpp index 62663404ca4e..db709ef10752 100644 --- a/toolkit/components/places/src/nsFaviconService.cpp +++ b/toolkit/components/places/src/nsFaviconService.cpp @@ -1060,7 +1060,7 @@ ExpireFaviconsStatementCallbackNotifier::HandleCompletion(PRUint16 aReason) return NS_OK; nsCOMPtr observerService = - do_GetService("@mozilla.org/observer-service;1"); + mozilla::services::GetObserverService(); if (observerService) { (void)observerService->NotifyObservers(nsnull, NS_PLACES_FAVICONS_EXPIRED_TOPIC_ID, diff --git a/toolkit/components/satchel/src/nsStorageFormHistory.cpp b/toolkit/components/satchel/src/nsStorageFormHistory.cpp index d6a5ca68f681..5a191e5a3e1b 100644 --- a/toolkit/components/satchel/src/nsStorageFormHistory.cpp +++ b/toolkit/components/satchel/src/nsStorageFormHistory.cpp @@ -72,6 +72,7 @@ #include "nsIMutableArray.h" #include "nsIPrivateBrowsingService.h" #include "nsNetCID.h" +#include "mozilla/Services.h" #define DB_SCHEMA_VERSION 3 #define DB_FILENAME NS_LITERAL_STRING("formhistory.sqlite") @@ -141,7 +142,7 @@ nsFormHistory::Init() } NS_ENSURE_SUCCESS(rv, rv); - mObserverService = do_GetService("@mozilla.org/observer-service;1"); + mObserverService = mozilla::services::GetObserverService(); if (mObserverService) { mObserverService->AddObserver(this, NS_EARLYFORMSUBMIT_SUBJECT, PR_TRUE); mObserverService->AddObserver(this, "idle-daily", PR_TRUE); diff --git a/toolkit/components/startup/src/nsAppStartup.cpp b/toolkit/components/startup/src/nsAppStartup.cpp index 822e8825c252..d9cf8dd33602 100644 --- a/toolkit/components/startup/src/nsAppStartup.cpp +++ b/toolkit/components/startup/src/nsAppStartup.cpp @@ -68,6 +68,7 @@ #include "nsIInterfaceRequestorUtils.h" #include "nsWidgetsCID.h" #include "nsAppShellCID.h" +#include "mozilla/Services.h" static NS_DEFINE_CID(kAppShellCID, NS_APPSHELL_CID); @@ -111,9 +112,10 @@ nsAppStartup::Init() mAppShell = do_GetService(kAppShellCID, &rv); NS_ENSURE_SUCCESS(rv, rv); - nsCOMPtr os - (do_GetService("@mozilla.org/observer-service;1", &rv)); - NS_ENSURE_SUCCESS(rv, rv); + nsCOMPtr os = + mozilla::services::GetObserverService(); + if (!os) + return NS_ERROR_FAILURE; os->AddObserver(this, "quit-application-forced", PR_TRUE); os->AddObserver(this, "profile-change-teardown", PR_TRUE); @@ -256,7 +258,7 @@ nsAppStartup::Quit(PRUint32 aMode) if (!mRestart) mRestart = (aMode & eRestart) != 0; - obsService = do_GetService("@mozilla.org/observer-service;1"); + obsService = mozilla::services::GetObserverService(); if (!mAttemptingQuit) { mAttemptingQuit = PR_TRUE; diff --git a/toolkit/components/url-classifier/src/nsUrlClassifierDBService.cpp b/toolkit/components/url-classifier/src/nsUrlClassifierDBService.cpp index 7749abd035ef..46660d3b78fb 100644 --- a/toolkit/components/url-classifier/src/nsUrlClassifierDBService.cpp +++ b/toolkit/components/url-classifier/src/nsUrlClassifierDBService.cpp @@ -3948,7 +3948,7 @@ nsUrlClassifierDBService::Init() // Add an observer for shutdown nsCOMPtr observerService = - do_GetService("@mozilla.org/observer-service;1"); + mozilla::services::GetObserverService(); if (!observerService) return NS_ERROR_FAILURE; diff --git a/toolkit/components/url-classifier/src/nsUrlClassifierHashCompleter.cpp b/toolkit/components/url-classifier/src/nsUrlClassifierHashCompleter.cpp index 4fef5ebd3e50..725ea0396e13 100644 --- a/toolkit/components/url-classifier/src/nsUrlClassifierHashCompleter.cpp +++ b/toolkit/components/url-classifier/src/nsUrlClassifierHashCompleter.cpp @@ -90,7 +90,7 @@ nsUrlClassifierHashCompleterRequest::Begin() } nsCOMPtr observerService = - do_GetService("@mozilla.org/observer-service;1"); + mozilla::services::GetObserverService(); if (observerService) observerService->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, PR_FALSE); @@ -471,7 +471,7 @@ nsUrlClassifierHashCompleterRequest::OnStopRequest(nsIRequest *request, this, status)); nsCOMPtr observerService = - do_GetService("@mozilla.org/observer-service;1"); + mozilla::services::GetObserverService(); if (observerService) observerService->RemoveObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID); @@ -537,7 +537,7 @@ nsUrlClassifierHashCompleter::Init() #endif nsCOMPtr observerService = - do_GetService("@mozilla.org/observer-service;1"); + mozilla::services::GetObserverService(); if (observerService) observerService->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, PR_TRUE); @@ -673,17 +673,14 @@ nsUrlClassifierHashCompleter::RekeyRequested() // Notify the key manager that we need a new key. Until we get a // new key, gethash requests will be unauthenticated (and therefore // uncacheable). - nsresult rv; nsCOMPtr observerService = - do_GetService("@mozilla.org/observer-service;1", &rv); - NS_ENSURE_SUCCESS(rv, rv); + mozilla::services::GetObserverService(); + if (!observerService) + return NS_ERROR_FAILURE; - rv = observerService->NotifyObservers(static_cast(this), - "url-classifier-rekey-requested", - nsnull); - NS_ENSURE_SUCCESS(rv, rv); - - return NS_OK; + return observerService->NotifyObservers(static_cast(this), + "url-classifier-rekey-requested", + nsnull); } void diff --git a/toolkit/components/url-classifier/src/nsUrlClassifierStreamUpdater.cpp b/toolkit/components/url-classifier/src/nsUrlClassifierStreamUpdater.cpp index 16a99ab36c36..48e510fba3d7 100644 --- a/toolkit/components/url-classifier/src/nsUrlClassifierStreamUpdater.cpp +++ b/toolkit/components/url-classifier/src/nsUrlClassifierStreamUpdater.cpp @@ -212,7 +212,7 @@ nsUrlClassifierStreamUpdater::DownloadUpdates( // downloads. quit-application is the same event that the download // manager listens for and uses to cancel pending downloads. nsCOMPtr observerService = - do_GetService("@mozilla.org/observer-service;1"); + mozilla::services::GetObserverService(); if (!observerService) return NS_ERROR_FAILURE; @@ -274,10 +274,11 @@ nsUrlClassifierStreamUpdater::UpdateUrlRequested(const nsACString &aUrl, NS_IMETHODIMP nsUrlClassifierStreamUpdater::RekeyRequested() { - nsresult rv; nsCOMPtr observerService = - do_GetService("@mozilla.org/observer-service;1", &rv); - NS_ENSURE_SUCCESS(rv, rv); + mozilla::services::GetObserverService(); + + if (!observerService) + return NS_ERROR_FAILURE; return observerService->NotifyObservers(static_cast(this), "url-classifier-rekey-requested", diff --git a/toolkit/xre/nsAppRunner.cpp b/toolkit/xre/nsAppRunner.cpp index ab19c3836b02..fac2d199e9ca 100644 --- a/toolkit/xre/nsAppRunner.cpp +++ b/toolkit/xre/nsAppRunner.cpp @@ -3438,8 +3438,8 @@ XRE_main(int argc, char* argv[], const nsXREAppData* aAppData) /* Special-case services that need early access to the command line. */ - nsCOMPtr obsService - (do_GetService("@mozilla.org/observer-service;1")); + nsCOMPtr obsService = + mozilla::services::GetObserverService(); if (obsService) { obsService->NotifyObservers(cmdLine, "command-line-startup", nsnull); } @@ -3524,8 +3524,8 @@ XRE_main(int argc, char* argv[], const nsXREAppData* aAppData) MOZ_SPLASHSCREEN_UPDATE(70); - nsCOMPtr obsService - (do_GetService("@mozilla.org/observer-service;1")); + nsCOMPtr obsService = + mozilla::services::GetObserverService(); if (obsService) obsService->NotifyObservers(nsnull, "final-ui-startup", nsnull); diff --git a/toolkit/xre/nsNativeAppSupportOS2.cpp b/toolkit/xre/nsNativeAppSupportOS2.cpp index adab9b211580..0ec7818a2974 100644 --- a/toolkit/xre/nsNativeAppSupportOS2.cpp +++ b/toolkit/xre/nsNativeAppSupportOS2.cpp @@ -1012,8 +1012,7 @@ NS_IMETHODIMP nsNativeAppSupportOS2::Enable() { mCanHandleRequests = PR_TRUE; - nsCOMPtr obs - (do_GetService("@mozilla.org/observer-service;1")); + nsCOMPtr obs = mozilla::services::GetObserverService(); if (obs) { obs->AddObserver(this, "quit-application", PR_FALSE); } else { diff --git a/toolkit/xre/nsNativeAppSupportUnix.cpp b/toolkit/xre/nsNativeAppSupportUnix.cpp index 753df0074761..3764c202b15f 100644 --- a/toolkit/xre/nsNativeAppSupportUnix.cpp +++ b/toolkit/xre/nsNativeAppSupportUnix.cpp @@ -59,6 +59,7 @@ #include "nsIWidget.h" #include "nsIWritablePropertyBag2.h" #include "nsIPrefService.h" +#include "mozilla/Services.h" #include #include @@ -129,7 +130,7 @@ gboolean save_yourself_cb(GnomeClient *client, gint phase, gpointer user_data) { nsCOMPtr obsServ = - do_GetService("@mozilla.org/observer-service;1"); + mozilla::services::GetObserverService(); nsCOMPtr didSaveSession = do_CreateInstance(NS_SUPPORTS_PRBOOL_CONTRACTID); @@ -297,7 +298,7 @@ static void OssoRequestAccelerometer(osso_context_t *ctx, PRBool aEnabled) static void OssoDisplayCallback(osso_display_state_t state, gpointer data) { - nsCOMPtr os = do_GetService("@mozilla.org/observer-service;1"); + nsCOMPtr os = mozilla::services::GetObserverService(); if (!os) return; @@ -326,16 +327,14 @@ static void OssoHardwareCallback(osso_hw_state_t *state, gpointer data) return; } - if (state->memory_low_ind) { - if (! ourState->memory_low_ind) { - nsCOMPtr os = do_GetService("@mozilla.org/observer-service;1"); - if (os) - os->NotifyObservers(nsnull, "memory-pressure", NS_LITERAL_STRING("low-memory").get()); - } + if (state->memory_low_ind && !ourState->memory_low_ind) { + nsCOMPtr os = mozilla::services::GetObserverService(); + if (os) + os->NotifyObservers(nsnull, "memory-pressure", NS_LITERAL_STRING("low-memory").get()); } if (state->system_inactivity_ind != ourState->system_inactivity_ind) { - nsCOMPtr os = do_GetService("@mozilla.org/observer-service;1"); + nsCOMPtr os = mozilla::services::GetObserverService(); if (!os) return; diff --git a/toolkit/xre/nsNativeAppSupportWin.cpp b/toolkit/xre/nsNativeAppSupportWin.cpp index 707028373288..9ac6bf7850b1 100644 --- a/toolkit/xre/nsNativeAppSupportWin.cpp +++ b/toolkit/xre/nsNativeAppSupportWin.cpp @@ -862,8 +862,7 @@ nsNativeAppSupportWin::Enable() { mCanHandleRequests = PR_TRUE; - nsCOMPtr obs - (do_GetService("@mozilla.org/observer-service;1")); + nsCOMPtr obs = mozilla::services::GetObserverService(); if (obs) { obs->AddObserver(this, "quit-application", PR_FALSE); } else { diff --git a/toolkit/xre/nsXREDirProvider.cpp b/toolkit/xre/nsXREDirProvider.cpp index a60d45eadc98..01e0f98f89dc 100644 --- a/toolkit/xre/nsXREDirProvider.cpp +++ b/toolkit/xre/nsXREDirProvider.cpp @@ -64,6 +64,7 @@ #include "nsArrayEnumerator.h" #include "nsEnumeratorUtils.h" #include "nsReadableUtils.h" +#include "mozilla/Services.h" #include @@ -800,8 +801,8 @@ NS_IMETHODIMP nsXREDirProvider::DoStartup() { if (!mProfileNotified) { - nsCOMPtr obsSvc - (do_GetService("@mozilla.org/observer-service;1")); + nsCOMPtr obsSvc = + mozilla::services::GetObserverService(); if (!obsSvc) return NS_ERROR_FAILURE; mProfileNotified = PR_TRUE; @@ -850,15 +851,15 @@ void nsXREDirProvider::DoShutdown() { if (mProfileNotified) { - nsCOMPtr obssvc - (do_GetService("@mozilla.org/observer-service;1")); - NS_ASSERTION(obssvc, "No observer service?"); - if (obssvc) { + nsCOMPtr obsSvc = + mozilla::services::GetObserverService(); + NS_ASSERTION(obsSvc, "No observer service?"); + if (obsSvc) { nsCOMPtr cs = new ProfileChangeStatusImpl(); static const PRUnichar kShutdownPersist[] = {'s','h','u','t','d','o','w','n','-','p','e','r','s','i','s','t','\0'}; - obssvc->NotifyObservers(cs, "profile-change-net-teardown", kShutdownPersist); - obssvc->NotifyObservers(cs, "profile-change-teardown", kShutdownPersist); + obsSvc->NotifyObservers(cs, "profile-change-net-teardown", kShutdownPersist); + obsSvc->NotifyObservers(cs, "profile-change-teardown", kShutdownPersist); // Phase 2c: Now that things are torn down, force JS GC so that things which depend on // resources which are about to go away in "profile-before-change" are destroyed first. @@ -873,7 +874,7 @@ nsXREDirProvider::DoShutdown() } // Phase 3: Notify observers of a profile change - obssvc->NotifyObservers(cs, "profile-before-change", kShutdownPersist); + obsSvc->NotifyObservers(cs, "profile-before-change", kShutdownPersist); } mProfileNotified = PR_FALSE; } diff --git a/uriloader/exthandler/nsExternalHelperAppService.cpp b/uriloader/exthandler/nsExternalHelperAppService.cpp index 0fbb5699c792..3222031fb54d 100644 --- a/uriloader/exthandler/nsExternalHelperAppService.cpp +++ b/uriloader/exthandler/nsExternalHelperAppService.cpp @@ -580,9 +580,9 @@ nsresult nsExternalHelperAppService::Init() } // Add an observer for profile change - nsresult rv = NS_OK; - nsCOMPtr obs = do_GetService("@mozilla.org/observer-service;1", &rv); - NS_ENSURE_SUCCESS(rv, rv); + nsCOMPtr obs = mozilla::services::GetObserverService(); + if (!obs) + return NS_ERROR_FAILURE; #ifdef PR_LOGGING if (!mLog) { @@ -592,7 +592,7 @@ nsresult nsExternalHelperAppService::Init() } #endif - rv = obs->AddObserver(this, "profile-before-change", PR_TRUE); + nsresult rv = obs->AddObserver(this, "profile-before-change", PR_TRUE); NS_ENSURE_SUCCESS(rv, rv); return obs->AddObserver(this, NS_PRIVATE_BROWSING_SWITCH_TOPIC, PR_TRUE); } diff --git a/uriloader/prefetch/nsOfflineCacheUpdate.cpp b/uriloader/prefetch/nsOfflineCacheUpdate.cpp index e82da57712fe..697391d772da 100644 --- a/uriloader/prefetch/nsOfflineCacheUpdate.cpp +++ b/uriloader/prefetch/nsOfflineCacheUpdate.cpp @@ -2342,8 +2342,6 @@ nsOfflineCacheUpdateService::~nsOfflineCacheUpdateService() nsresult nsOfflineCacheUpdateService::Init() { - nsresult rv; - #if defined(PR_LOGGING) if (!gOfflineCacheUpdateLog) gOfflineCacheUpdateLog = PR_NewLogModule("nsOfflineCacheUpdate"); @@ -2351,12 +2349,13 @@ nsOfflineCacheUpdateService::Init() // Observe xpcom-shutdown event nsCOMPtr observerService = - do_GetService("@mozilla.org/observer-service;1", &rv); - NS_ENSURE_SUCCESS(rv, rv); + mozilla::services::GetObserverService(); + if (!observerService) + return NS_ERROR_FAILURE; - rv = observerService->AddObserver(this, - NS_XPCOM_SHUTDOWN_OBSERVER_ID, - PR_TRUE); + nsresult rv = observerService->AddObserver(this, + NS_XPCOM_SHUTDOWN_OBSERVER_ID, + PR_TRUE); NS_ENSURE_SUCCESS(rv, rv); gOfflineCacheUpdateService = this; @@ -2407,10 +2406,10 @@ nsOfflineCacheUpdateService::Schedule(nsOfflineCacheUpdate *aUpdate) aUpdate->SetOwner(this); - nsresult rv; nsCOMPtr observerService = - do_GetService("@mozilla.org/observer-service;1", &rv); - NS_ENSURE_SUCCESS(rv, rv); + mozilla::services::GetObserverService(); + if (!observerService) + return NS_ERROR_FAILURE; observerService->NotifyObservers(static_cast(aUpdate), "offline-cache-update-added", @@ -2466,10 +2465,10 @@ nsOfflineCacheUpdateService::UpdateFinished(nsOfflineCacheUpdate *aUpdate) mUpdates.RemoveElementAt(0); mUpdateRunning = PR_FALSE; - nsresult rv; nsCOMPtr observerService = - do_GetService("@mozilla.org/observer-service;1", &rv); - NS_ENSURE_SUCCESS(rv, rv); + mozilla::services::GetObserverService(); + if (!observerService) + return NS_ERROR_FAILURE; observerService->NotifyObservers(static_cast(aUpdate), "offline-cache-update-completed", diff --git a/uriloader/prefetch/nsPrefetchService.cpp b/uriloader/prefetch/nsPrefetchService.cpp index f328f34e983e..af9db0d9cf98 100644 --- a/uriloader/prefetch/nsPrefetchService.cpp +++ b/uriloader/prefetch/nsPrefetchService.cpp @@ -441,12 +441,13 @@ nsPrefetchService::Init() } // Observe xpcom-shutdown event - nsCOMPtr observerServ( - do_GetService("@mozilla.org/observer-service;1", &rv)); - if (NS_FAILED(rv)) return rv; + nsCOMPtr observerService = + mozilla::services::GetObserverService(); + if (!observerService) + return NS_ERROR_FAILURE; - rv = observerServ->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, PR_TRUE); - if (NS_FAILED(rv)) return rv; + rv = observerService->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, PR_TRUE); + NS_ENSURE_SUCCESS(rv, rv); if (!mDisabled) AddProgressListener(); @@ -486,11 +487,10 @@ nsPrefetchService::ProcessNextURI() void nsPrefetchService::NotifyLoadRequested(nsPrefetchNode *node) { - nsresult rv; - nsCOMPtr observerService = - do_GetService("@mozilla.org/observer-service;1", &rv); - if (NS_FAILED(rv)) return; + mozilla::services::GetObserverService(); + if (!observerService) + return; observerService->NotifyObservers(static_cast(node), "prefetch-load-requested", nsnull); @@ -499,11 +499,10 @@ nsPrefetchService::NotifyLoadRequested(nsPrefetchNode *node) void nsPrefetchService::NotifyLoadCompleted(nsPrefetchNode *node) { - nsresult rv; - nsCOMPtr observerService = - do_GetService("@mozilla.org/observer-service;1", &rv); - if (NS_FAILED(rv)) return; + mozilla::services::GetObserverService(); + if (!observerService) + return; observerService->NotifyObservers(static_cast(node), "prefetch-load-completed", nsnull); diff --git a/widget/src/gtk2/nsClipboard.cpp b/widget/src/gtk2/nsClipboard.cpp index 98f6f8867e17..72a2ae304f17 100644 --- a/widget/src/gtk2/nsClipboard.cpp +++ b/widget/src/gtk2/nsClipboard.cpp @@ -47,6 +47,7 @@ #include "nsImageToPixbuf.h" #include "nsStringStream.h" #include "nsIObserverService.h" +#include "mozilla/Services.h" #include "imgIContainer.h" @@ -141,10 +142,9 @@ NS_IMPL_ISUPPORTS1(nsClipboard, nsIClipboard) nsresult nsClipboard::Init(void) { - nsresult rv; - nsCOMPtr os - (do_GetService("@mozilla.org/observer-service;1", &rv)); - NS_ENSURE_SUCCESS(rv, rv); + nsCOMPtr os = mozilla::services::GetObserverService(); + if (!os) + return NS_ERROR_FAILURE; os->AddObserver(this, "quit-application", PR_FALSE); diff --git a/widget/src/gtk2/nsDragService.cpp b/widget/src/gtk2/nsDragService.cpp index 76f951599870..0451d1ddfe05 100644 --- a/widget/src/gtk2/nsDragService.cpp +++ b/widget/src/gtk2/nsDragService.cpp @@ -60,6 +60,7 @@ #include #include #include "nsCRT.h" +#include "mozilla/Services.h" #include "gfxASurface.h" #include "gfxXlibSurface.h" @@ -112,7 +113,7 @@ nsDragService::nsDragService() // We have to destroy the hidden widget before the event loop stops // running. nsCOMPtr obsServ = - do_GetService("@mozilla.org/observer-service;1"); + mozilla::services::GetObserverService(); obsServ->AddObserver(this, "quit-application", PR_FALSE); // our hidden source widget diff --git a/widget/src/gtk2/nsGtkIMModule.cpp b/widget/src/gtk2/nsGtkIMModule.cpp index 03990e4ab948..97f707e8af69 100644 --- a/widget/src/gtk2/nsGtkIMModule.cpp +++ b/widget/src/gtk2/nsGtkIMModule.cpp @@ -53,6 +53,7 @@ #ifdef MOZ_PLATFORM_MAEMO #include "nsServiceManagerUtils.h" #include "nsIObserverService.h" +#include "mozilla/Services.h" #endif #ifdef PR_LOGGING @@ -587,7 +588,7 @@ nsGtkIMModule::SetIMEEnabled(nsWindow* aCaller, PRUint32 aState) } nsCOMPtr observerService = - do_GetService("@mozilla.org/observer-service;1"); + mozilla::services::GetObserverService(); if (observerService) { nsAutoString rectBuf; PRInt32 x, y, w, h; diff --git a/widget/src/gtk2/nsNativeThemeGTK.cpp b/widget/src/gtk2/nsNativeThemeGTK.cpp index cc6b80fd62ca..35ef4db49048 100644 --- a/widget/src/gtk2/nsNativeThemeGTK.cpp +++ b/widget/src/gtk2/nsNativeThemeGTK.cpp @@ -61,6 +61,7 @@ #include "nsIDOMHTMLInputElement.h" #include "nsIDOMNSHTMLInputElement.h" #include "nsWidgetAtoms.h" +#include "mozilla/Services.h" #include #include @@ -82,7 +83,7 @@ nsNativeThemeGTK::nsNativeThemeGTK() // We have to call moz_gtk_shutdown before the event loop stops running. nsCOMPtr obsServ = - do_GetService("@mozilla.org/observer-service;1"); + mozilla::services::GetObserverService(); obsServ->AddObserver(this, "xpcom-shutdown", PR_FALSE); memset(mDisabledWidgetTypes, 0, sizeof(mDisabledWidgetTypes)); diff --git a/widget/src/os2/nsClipboard.cpp b/widget/src/os2/nsClipboard.cpp index 4eed57618d4a..0d57a1d0f9de 100644 --- a/widget/src/os2/nsClipboard.cpp +++ b/widget/src/os2/nsClipboard.cpp @@ -48,6 +48,7 @@ #include "nsIServiceManager.h" #include "nsOS2Uni.h" #include "nsClipboard.h" +#include "mozilla/Services.h" inline ULONG RegisterClipboardFormat(PCSZ pcszFormat) { @@ -75,7 +76,7 @@ nsClipboard::nsClipboard() : nsBaseClipboard() // Register for a shutdown notification so that we can flush data // to the OS clipboard. nsCOMPtr observerService = - do_GetService("@mozilla.org/observer-service;1"); + mozilla::services::GetObserverService(); if (observerService) observerService->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, PR_FALSE); } diff --git a/widget/src/os2/nsRwsService.cpp b/widget/src/os2/nsRwsService.cpp index 0b9a0a3956bc..db55696981d5 100644 --- a/widget/src/os2/nsRwsService.cpp +++ b/widget/src/os2/nsRwsService.cpp @@ -45,6 +45,7 @@ #include "nsLiteralString.h" #include "nsReadableUtils.h" #include "nsIStringBundle.h" +#include "mozilla/Services.h" #define INCL_WIN #define INCL_DOS @@ -1224,7 +1225,7 @@ static nsresult nsRwsServiceInit(nsRwsService **aClass) NS_ADDREF(*aClass); // set the class up as a shutdown observer - nsCOMPtr os = do_GetService("@mozilla.org/observer-service;1"); + nsCOMPtr os = mozilla::services::GetObserverService(); if (os) os->AddObserver(*aClass, "quit-application", PR_FALSE); diff --git a/widget/src/windows/nsWindow.cpp b/widget/src/windows/nsWindow.cpp index 302b01508e1e..3de438aeb239 100644 --- a/widget/src/windows/nsWindow.cpp +++ b/widget/src/windows/nsWindow.cpp @@ -154,6 +154,7 @@ #include "nsTHashtable.h" #include "nsHashKeys.h" #include "nsString.h" +#include "mozilla/Services.h" #if defined(WINCE) #include "nsWindowCE.h" @@ -4083,7 +4084,7 @@ PRBool nsWindow::ProcessMessage(UINT msg, WPARAM &wParam, LPARAM &lParam, // Ask if it's ok to quit, and store the answer until we // get WM_ENDSESSION signaling the round is complete. nsCOMPtr obsServ = - do_GetService("@mozilla.org/observer-service;1"); + mozilla::services::GetObserverService(); nsCOMPtr cancelQuit = do_CreateInstance(NS_SUPPORTS_PRBOOL_CONTRACTID); cancelQuit->SetData(PR_FALSE); @@ -4109,7 +4110,7 @@ PRBool nsWindow::ProcessMessage(UINT msg, WPARAM &wParam, LPARAM &lParam, // require having a chance to pump some messages. Unfortunately // Windows won't let us do that. Bug 212316. nsCOMPtr obsServ = - do_GetService("@mozilla.org/observer-service;1"); + mozilla::services::GetObserverService(); NS_NAMED_LITERAL_STRING(context, "shutdown-persist"); obsServ->NotifyObservers(nsnull, "quit-application-granted", nsnull); obsServ->NotifyObservers(nsnull, "quit-application-forced", nsnull); @@ -4998,11 +4999,10 @@ void nsWindow::GlobalMsgWindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lP #ifndef WINCE void nsWindow::PostSleepWakeNotification(const char* aNotification) { - nsCOMPtr observerService = do_GetService("@mozilla.org/observer-service;1"); + nsCOMPtr observerService = + mozilla::services::GetObserverService(); if (observerService) - { observerService->NotifyObservers(nsnull, aNotification, nsnull); - } } #endif diff --git a/widget/src/xpwidgets/nsBaseAppShell.cpp b/widget/src/xpwidgets/nsBaseAppShell.cpp index 96111c35c98b..1320eefb403a 100644 --- a/widget/src/xpwidgets/nsBaseAppShell.cpp +++ b/widget/src/xpwidgets/nsBaseAppShell.cpp @@ -40,6 +40,7 @@ #include "nsThreadUtils.h" #include "nsIObserverService.h" #include "nsServiceManagerUtils.h" +#include "mozilla/Services.h" #ifdef MOZ_IPC #include "base/message_loop.h" @@ -81,7 +82,7 @@ nsBaseAppShell::Init() threadInt->SetObserver(this); nsCOMPtr obsSvc = - do_GetService("@mozilla.org/observer-service;1"); + mozilla::services::GetObserverService(); if (obsSvc) obsSvc->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, PR_FALSE); return NS_OK; diff --git a/widget/src/xpwidgets/nsClipboardPrivacyHandler.cpp b/widget/src/xpwidgets/nsClipboardPrivacyHandler.cpp index 59a1aa957c3d..c983f8b4bacf 100644 --- a/widget/src/xpwidgets/nsClipboardPrivacyHandler.cpp +++ b/widget/src/xpwidgets/nsClipboardPrivacyHandler.cpp @@ -46,6 +46,7 @@ #include "nsLiteralString.h" #include "nsNetCID.h" #include "nsXPCOM.h" +#include "mozilla/Services.h" #if defined(XP_WIN) && !defined(WINCE) #include @@ -58,12 +59,12 @@ NS_IMPL_ISUPPORTS2(nsClipboardPrivacyHandler, nsIObserver, nsISupportsWeakRefere nsresult nsClipboardPrivacyHandler::Init() { - nsresult rv; nsCOMPtr observerService = - do_GetService("@mozilla.org/observer-service;1", &rv); - NS_ENSURE_SUCCESS(rv, rv); - rv = observerService->AddObserver(this, NS_PRIVATE_BROWSING_SWITCH_TOPIC, PR_TRUE); - return rv; + mozilla::services::GetObserverService(); + if (!observerService) + return NS_ERROR_FAILURE; + return observerService->AddObserver(this, NS_PRIVATE_BROWSING_SWITCH_TOPIC, + PR_TRUE); } /** diff --git a/widget/src/xpwidgets/nsIdleService.cpp b/widget/src/xpwidgets/nsIdleService.cpp index c855cf5a4ac5..6aa48efe4a8a 100644 --- a/widget/src/xpwidgets/nsIdleService.cpp +++ b/widget/src/xpwidgets/nsIdleService.cpp @@ -49,6 +49,7 @@ #include "nsDebug.h" #include "nsCOMArray.h" #include "prinrval.h" +#include "mozilla/Services.h" // observer topics used: #define OBSERVER_TOPIC_IDLE "idle" @@ -80,7 +81,7 @@ nsIdleServiceDaily::Observe(nsISupports *, { // Notify anyone who cares. nsCOMPtr observerService = - do_GetService("@mozilla.org/observer-service;1"); + mozilla::services::GetObserverService(); observerService->NotifyObservers(nsnull, OBSERVER_TOPIC_IDLE_DAILY, diff --git a/xpcom/base/nsCycleCollector.cpp b/xpcom/base/nsCycleCollector.cpp index cb613242bf2d..f26356b9991f 100644 --- a/xpcom/base/nsCycleCollector.cpp +++ b/xpcom/base/nsCycleCollector.cpp @@ -144,6 +144,7 @@ #include "nsThreadUtils.h" #include "nsTPtrArray.h" #include "nsTArray.h" +#include "mozilla/Services.h" #include #include @@ -2502,10 +2503,9 @@ nsCycleCollector::Collect(PRUint32 aTryCollections) mCollectionInProgress = PR_TRUE; nsCOMPtr obs = - do_GetService("@mozilla.org/observer-service;1"); - if (obs) { + mozilla::services::GetObserverService(); + if (obs) obs->NotifyObservers(nsnull, "cycle-collector-begin", nsnull); - } mFollowupCollection = PR_FALSE; mCollectedObjects = 0; diff --git a/xpcom/base/nsExceptionService.cpp b/xpcom/base/nsExceptionService.cpp index 3cd37d985a4e..342239916e51 100644 --- a/xpcom/base/nsExceptionService.cpp +++ b/xpcom/base/nsExceptionService.cpp @@ -42,6 +42,8 @@ #include "nsCOMPtr.h" #include "prthread.h" #include "prlock.h" +#include "mozilla/Services.h" + static const PRUintn BAD_TLS_INDEX = (PRUintn) -1; #define CHECK_SERVICE_USE_OK() if (!lock) return NS_ERROR_NOT_INITIALIZED @@ -172,7 +174,8 @@ nsExceptionService::nsExceptionService() NS_ASSERTION(lock, "Error allocating ExceptionService lock"); // observe XPCOM shutdown. - nsCOMPtr observerService = do_GetService("@mozilla.org/observer-service;1"); + nsCOMPtr observerService = + mozilla::services::GetObserverService(); NS_ASSERTION(observerService, "Could not get observer service!"); if (observerService) observerService->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, PR_FALSE); diff --git a/xpcom/base/nsMemoryImpl.cpp b/xpcom/base/nsMemoryImpl.cpp index 670b0af728a2..b8b2fca99116 100644 --- a/xpcom/base/nsMemoryImpl.cpp +++ b/xpcom/base/nsMemoryImpl.cpp @@ -52,6 +52,7 @@ #include "nsAutoLock.h" #include "nsCOMPtr.h" #include "nsString.h" +#include "mozilla/Services.h" #if defined(XP_WIN) #include @@ -206,7 +207,7 @@ nsMemoryImpl::FlushMemory(const PRUnichar* aReason, PRBool aImmediate) nsresult nsMemoryImpl::RunFlushers(const PRUnichar* aReason) { - nsCOMPtr os = do_GetService("@mozilla.org/observer-service;1"); + nsCOMPtr os = mozilla::services::GetObserverService(); if (os) { // Instead of: diff --git a/xpcom/components/nsCategoryManager.cpp b/xpcom/components/nsCategoryManager.cpp index 9b1c059373dd..d23726de6ac6 100644 --- a/xpcom/components/nsCategoryManager.cpp +++ b/xpcom/components/nsCategoryManager.cpp @@ -60,6 +60,7 @@ #include "nsEnumeratorUtils.h" #include "nsIProxyObjectManager.h" #include "nsThreadUtils.h" +#include "mozilla/Services.h" using namespace mozilla; class nsIComponentLoaderManager; @@ -519,8 +520,8 @@ nsCategoryManager::NotifyObservers( const char *aTopic, if (mSuppressNotifications) return; - nsCOMPtr observerService - (do_GetService("@mozilla.org/observer-service;1")); + nsCOMPtr observerService = + mozilla::services::GetObserverService(); if (!observerService) return; diff --git a/xpcom/threads/TimerThread.cpp b/xpcom/threads/TimerThread.cpp index 840b27096a63..3e4365df77e8 100644 --- a/xpcom/threads/TimerThread.cpp +++ b/xpcom/threads/TimerThread.cpp @@ -48,6 +48,7 @@ #include "nsIObserverService.h" #include "nsIServiceManager.h" #include "nsIProxyObjectManager.h" +#include "mozilla/Services.h" NS_IMPL_THREADSAFE_ISUPPORTS2(TimerThread, nsIRunnable, nsIObserver) @@ -111,7 +112,7 @@ nsresult TimerThread::Init() } else { nsCOMPtr observerService = - do_GetService("@mozilla.org/observer-service;1"); + mozilla::services::GetObserverService(); // We must not use the observer service from a background thread! if (observerService && !NS_IsMainThread()) { nsCOMPtr result = nsnull; diff --git a/xpcom/threads/nsProcessCommon.cpp b/xpcom/threads/nsProcessCommon.cpp index 5987b5e42cda..dcb3ce479df2 100644 --- a/xpcom/threads/nsProcessCommon.cpp +++ b/xpcom/threads/nsProcessCommon.cpp @@ -56,6 +56,7 @@ #include "nsAutoLock.h" #include "nsThreadUtils.h" #include "nsIObserverService.h" +#include "mozilla/Services.h" #include @@ -293,7 +294,8 @@ void PR_CALLBACK nsProcess::Monitor(void *arg) void nsProcess::ProcessComplete() { if (mThread) { - nsCOMPtr os = do_GetService("@mozilla.org/observer-service;1"); + nsCOMPtr os = + mozilla::services::GetObserverService(); if (os) os->RemoveObserver(this, "xpcom-shutdown"); PR_JoinThread(mThread); @@ -519,7 +521,8 @@ nsProcess::RunProcess(PRBool blocking, char **my_argv, PRUint32 count, } // It isn't a failure if we just can't watch for shutdown - nsCOMPtr os = do_GetService("@mozilla.org/observer-service;1"); + nsCOMPtr os = + mozilla::services::GetObserverService(); if (os) os->AddObserver(this, "xpcom-shutdown", PR_FALSE); } @@ -567,7 +570,7 @@ nsProcess::Kill() // We must null out mThread if we want IsRunning to return false immediately // after this call. - nsCOMPtr os = do_GetService("@mozilla.org/observer-service;1"); + nsCOMPtr os = mozilla::services::GetObserverService(); if (os) os->RemoveObserver(this, "xpcom-shutdown"); PR_JoinThread(mThread); @@ -591,7 +594,8 @@ nsProcess::Observe(nsISupports* subject, const char* topic, const PRUnichar* dat { // Shutting down, drop all references if (mThread) { - nsCOMPtr os = do_GetService("@mozilla.org/observer-service;1"); + nsCOMPtr os = + mozilla::services::GetObserverService(); if (os) os->RemoveObserver(this, "xpcom-shutdown"); mThread = nsnull; diff --git a/xpinstall/src/nsInstallTrigger.cpp b/xpinstall/src/nsInstallTrigger.cpp index 93b4c2570f47..e58f78810473 100644 --- a/xpinstall/src/nsInstallTrigger.cpp +++ b/xpinstall/src/nsInstallTrigger.cpp @@ -256,7 +256,8 @@ nsInstallTrigger::HandleContent(const char * aContentType, } else { - nsCOMPtr os(do_GetService("@mozilla.org/observer-service;1")); + nsCOMPtr os = + mozilla::services::GetObserverService(); if (os) os->NotifyObservers(installInfo, "xpinstall-install-blocked", diff --git a/xpinstall/src/nsJSInstallTriggerGlobal.cpp b/xpinstall/src/nsJSInstallTriggerGlobal.cpp index be9fd3aa4825..06c29bdacd15 100644 --- a/xpinstall/src/nsJSInstallTriggerGlobal.cpp +++ b/xpinstall/src/nsJSInstallTriggerGlobal.cpp @@ -420,7 +420,8 @@ InstallTriggerGlobalInstall(JSContext *cx, JSObject *obj, uintN argc, jsval *arg nativeThis->UpdateEnabled(checkuri, XPI_WHITELIST, &enabled); if (!enabled) { - nsCOMPtr os(do_GetService("@mozilla.org/observer-service;1")); + nsCOMPtr os = + mozilla::services::GetObserverService(); if (os) os->NotifyObservers(installInfo, "xpinstall-install-blocked", @@ -543,7 +544,8 @@ InstallTriggerGlobalInstallChrome(JSContext *cx, JSObject *obj, uintN argc, jsva &enabled); if (!enabled) { - nsCOMPtr os(do_GetService("@mozilla.org/observer-service;1")); + nsCOMPtr os = + mozilla::services::GetObserverService(); if (os) os->NotifyObservers(installInfo, "xpinstall-install-blocked", @@ -647,7 +649,8 @@ InstallTriggerGlobalStartSoftwareUpdate(JSContext *cx, JSObject *obj, uintN argc nativeThis->UpdateEnabled(checkuri, XPI_WHITELIST, &enabled); if (!enabled) { - nsCOMPtr os(do_GetService("@mozilla.org/observer-service;1")); + nsCOMPtr os = + mozilla::services::GetObserverService(); if (os) os->NotifyObservers(installInfo, "xpinstall-install-blocked", diff --git a/xpinstall/src/nsXPInstallManager.cpp b/xpinstall/src/nsXPInstallManager.cpp index ec8c85b6a39d..988692980915 100644 --- a/xpinstall/src/nsXPInstallManager.cpp +++ b/xpinstall/src/nsXPInstallManager.cpp @@ -527,7 +527,8 @@ nsXPInstallManager::OpenProgressDialog(const PRUnichar **aPackageList, PRUint32 nsCOMPtr recentWindow; wm->GetMostRecentWindow(type.get(), getter_AddRefs(recentWindow)); if (recentWindow) { - nsCOMPtr os(do_GetService("@mozilla.org/observer-service;1")); + nsCOMPtr os = + mozilla::services::GetObserverService(); os->NotifyObservers(params, "xpinstall-download-started", nsnull); recentWindow->Focus(); @@ -574,7 +575,8 @@ NS_IMETHODIMP nsXPInstallManager::Observe( nsISupports *aSubject, mDialogOpen = PR_TRUE; rv = NS_OK; - nsCOMPtr os(do_GetService("@mozilla.org/observer-service;1")); + nsCOMPtr os = + mozilla::services::GetObserverService(); if (os) { os->AddObserver(this, NS_IOSERVICE_GOING_OFFLINE_TOPIC, PR_TRUE); @@ -998,7 +1000,8 @@ void nsXPInstallManager::Shutdown(PRInt32 status) item->mFile->Remove(PR_FALSE); } - nsCOMPtr os(do_GetService("@mozilla.org/observer-service;1")); + nsCOMPtr os = + mozilla::services::GetObserverService(); if (os) { os->RemoveObserver(this, NS_IOSERVICE_GOING_OFFLINE_TOPIC);