Bug 560095 - Use mozilla::services::GetObserverService(). r=biesi,dveditz,gavin,josh,jst,mrbkap,roc,sdwilsh,shaver,sicking,smontagu,surkov
authorMitchell Field <mitchell.field@live.com.au>
Thu, 29 Apr 2010 18:59:13 +0200
changeset 41540 79cbadb26768422fbd77a2a34ad83ec5965f1056
parent 41539 c8e77c61cfed9e8b4df6ddc1ad32b823dc89740a
child 41541 416b9b6ffc77dd23fe719607a04bbe88ab9dbecd
push idunknown
push userunknown
push dateunknown
reviewersbiesi, dveditz, gavin, josh, jst, mrbkap, roc, sdwilsh, shaver, sicking, smontagu, surkov
bugs560095
milestone1.9.3a5pre
Bug 560095 - Use mozilla::services::GetObserverService(). r=biesi,dveditz,gavin,josh,jst,mrbkap,roc,sdwilsh,shaver,sicking,smontagu,surkov
accessible/src/base/nsAccessNode.cpp
accessible/src/base/nsAccessibilityService.cpp
accessible/src/base/nsAccessible.cpp
chrome/src/nsChromeRegistry.cpp
content/base/src/nsCCUncollectableMarker.cpp
content/base/src/nsContentUtils.cpp
content/events/src/nsEventStateManager.cpp
content/html/content/src/nsHTMLDNSPrefetch.cpp
content/html/content/src/nsHTMLFormElement.cpp
content/xbl/src/nsXBLService.cpp
content/xul/document/src/nsXULDocument.cpp
content/xul/document/src/nsXULPrototypeCache.cpp
docshell/base/nsDocShell.cpp
docshell/shistory/src/nsSHistory.cpp
dom/base/nsDOMScriptObjectFactory.cpp
dom/base/nsGlobalWindow.cpp
dom/base/nsJSEnvironment.cpp
dom/src/geolocation/nsGeolocation.cpp
dom/src/offline/nsDOMOfflineResourceList.cpp
dom/src/storage/nsDOMStorage.cpp
embedding/components/find/src/nsWebBrowserFind.cpp
embedding/components/windowwatcher/src/nsWindowWatcher.cpp
gfx/src/thebes/nsThebesDeviceContext.cpp
intl/chardet/src/nsXMLEncodingObserver.cpp
intl/strres/src/nsStringBundle.cpp
layout/base/nsPresShell.cpp
layout/base/nsStyleSheetService.cpp
layout/build/nsLayoutModule.cpp
layout/forms/nsFileControlFrame.cpp
layout/generic/nsObjectFrame.cpp
layout/mathml/nsMathMLChar.cpp
layout/style/nsCSSRuleProcessor.cpp
layout/style/nsLayoutStylesheetCache.cpp
modules/libpr0n/src/imgLoader.cpp
modules/libpref/src/nsPrefBranch.cpp
modules/libpref/src/nsPrefService.cpp
modules/plugin/base/src/nsNPAPIPlugin.cpp
modules/plugin/base/src/nsPluginHost.cpp
netwerk/base/src/nsIOService.cpp
netwerk/base/src/nsIOThreadPool.cpp
netwerk/base/src/nsIncrementalDownload.cpp
netwerk/base/src/nsProtocolProxyService.cpp
netwerk/base/src/nsStreamTransportService.cpp
netwerk/cache/src/nsCacheService.cpp
netwerk/cookie/src/nsCookieService.cpp
netwerk/protocol/ftp/src/nsFtpProtocolHandler.cpp
netwerk/protocol/http/src/nsHttpHandler.cpp
netwerk/system/maemo/nsMaemoNetworkLinkService.cpp
netwerk/system/win32/nsNotifyAddrListener.cpp
netwerk/wifi/src/nsWifiMonitor.cpp
parser/html/nsHtml5Module.cpp
profile/dirserviceprovider/src/nsProfileDirServiceProvider.cpp
storage/src/mozStorageService.cpp
toolkit/components/autocomplete/src/nsAutoCompleteController.cpp
toolkit/components/downloads/src/nsDownloadManager.cpp
toolkit/components/places/src/nsFaviconService.cpp
toolkit/components/satchel/src/nsStorageFormHistory.cpp
toolkit/components/startup/src/nsAppStartup.cpp
toolkit/components/url-classifier/src/nsUrlClassifierDBService.cpp
toolkit/components/url-classifier/src/nsUrlClassifierHashCompleter.cpp
toolkit/components/url-classifier/src/nsUrlClassifierStreamUpdater.cpp
toolkit/xre/nsAppRunner.cpp
toolkit/xre/nsNativeAppSupportOS2.cpp
toolkit/xre/nsNativeAppSupportUnix.cpp
toolkit/xre/nsNativeAppSupportWin.cpp
toolkit/xre/nsXREDirProvider.cpp
uriloader/exthandler/nsExternalHelperAppService.cpp
uriloader/prefetch/nsOfflineCacheUpdate.cpp
uriloader/prefetch/nsPrefetchService.cpp
widget/src/gtk2/nsClipboard.cpp
widget/src/gtk2/nsDragService.cpp
widget/src/gtk2/nsGtkIMModule.cpp
widget/src/gtk2/nsNativeThemeGTK.cpp
widget/src/os2/nsClipboard.cpp
widget/src/os2/nsRwsService.cpp
widget/src/windows/nsWindow.cpp
widget/src/xpwidgets/nsBaseAppShell.cpp
widget/src/xpwidgets/nsClipboardPrivacyHandler.cpp
widget/src/xpwidgets/nsIdleService.cpp
xpcom/base/nsCycleCollector.cpp
xpcom/base/nsExceptionService.cpp
xpcom/base/nsMemoryImpl.cpp
xpcom/components/nsCategoryManager.cpp
xpcom/threads/TimerThread.cpp
xpcom/threads/nsProcessCommon.cpp
xpinstall/src/nsInstallTrigger.cpp
xpinstall/src/nsJSInstallTriggerGlobal.cpp
xpinstall/src/nsXPInstallManager.cpp
--- a/accessible/src/base/nsAccessNode.cpp
+++ b/accessible/src/base/nsAccessNode.cpp
@@ -67,16 +67,17 @@
 #include "nsIPrefBranch.h"
 #include "nsPresContext.h"
 #include "nsIPresShell.h"
 #include "nsIServiceManager.h"
 #include "nsIStringBundle.h"
 #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
  */
 
 nsIStringBundle *nsAccessNode::gStringBundle = 0;
 nsIStringBundle *nsAccessNode::gKeyStringBundle = 0;
 nsIDOMNode *nsAccessNode::gLastFocusedNode = 0;
@@ -276,24 +277,25 @@ void nsAccessNode::InitXPAccessibility()
 
   NotifyA11yInitOrShutdown(PR_TRUE);
 }
 
 // nsAccessNode protected static
 void nsAccessNode::NotifyA11yInitOrShutdown(PRBool aIsInit)
 {
   nsCOMPtr<nsIObserverService> 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()
 {
   // Called by nsAccessibilityService::Shutdown()
   // which happens when xpcom is shutting down
   // at exit of program
 
--- a/accessible/src/base/nsAccessibilityService.cpp
+++ b/accessible/src/base/nsAccessibilityService.cpp
@@ -80,16 +80,17 @@
 #include "nsOuterDocAccessible.h"
 #include "nsRootAccessibleWrap.h"
 #include "nsTextFragment.h"
 #include "nsServiceManagerUtils.h"
 #include "nsUnicharUtils.h"
 #include "nsIWebProgress.h"
 #include "nsNetError.h"
 #include "nsDocShellLoadTypes.h"
+#include "mozilla/Services.h"
 
 #ifdef MOZ_XUL
 #include "nsXULAlertAccessible.h"
 #include "nsXULColorPickerAccessible.h"
 #include "nsXULComboboxAccessible.h"
 #include "nsXULFormControlAccessible.h"
 #include "nsXULListboxAccessibleWrap.h"
 #include "nsXULMenuAccessibleWrap.h"
@@ -114,18 +115,18 @@
 ////////////////////////////////////////////////////////////////////////////////
 
 nsAccessibilityService *nsAccessibilityService::gAccessibilityService = nsnull;
 PRBool nsAccessibilityService::gIsShutdown = PR_TRUE;
 
 nsAccessibilityService::nsAccessibilityService()
 {
   // Add observers.
-  nsCOMPtr<nsIObserverService> observerService = 
-    do_GetService("@mozilla.org/observer-service;1");
+  nsCOMPtr<nsIObserverService> observerService =
+    mozilla::services::GetObserverService();
   if (!observerService)
     return;
 
   observerService->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, PR_FALSE);
   nsCOMPtr<nsIWebProgress> progress(do_GetService(NS_DOCUMENTLOADER_SERVICE_CONTRACTID));
   if (progress) {
     progress->AddProgressListener(static_cast<nsIWebProgressListener*>(this),
                                   nsIWebProgress::NOTIFY_STATE_DOCUMENT);
@@ -150,21 +151,21 @@ NS_IMPL_THREADSAFE_ISUPPORTS5(nsAccessib
 
 NS_IMETHODIMP
 nsAccessibilityService::Observe(nsISupports *aSubject, const char *aTopic,
                          const PRUnichar *aData)
 {
   if (!nsCRT::strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID)) {
 
     // Remove observers.
-    nsCOMPtr<nsIObserverService> observerService = 
-      do_GetService("@mozilla.org/observer-service;1");
-    if (observerService) {
+    nsCOMPtr<nsIObserverService> observerService =
+      mozilla::services::GetObserverService();
+    if (observerService)
       observerService->RemoveObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID);
-    }
+
     nsCOMPtr<nsIWebProgress> progress(do_GetService(NS_DOCUMENTLOADER_SERVICE_CONTRACTID));
     if (progress)
       progress->RemoveProgressListener(static_cast<nsIWebProgressListener*>(this));
 
     // Application is going to be closed, shutdown accessibility and mark
     // accessibility service as shutdown to prevent calls of its methods.
     // Don't null accessibility service static member at this point to be safe
     // if someone will try to operate with it.
--- a/accessible/src/base/nsAccessible.cpp
+++ b/accessible/src/base/nsAccessible.cpp
@@ -1300,17 +1300,17 @@ nsresult
 nsAccessible::HandleAccEvent(nsAccEvent *aEvent)
 {
   NS_ENSURE_ARG_POINTER(aEvent);
   nsCOMPtr<nsIDOMNode> eventNode;
   aEvent->GetDOMNode(getter_AddRefs(eventNode));
   NS_ENSURE_TRUE(nsAccUtils::IsNodeRelevant(eventNode), NS_ERROR_FAILURE);
 
   nsCOMPtr<nsIObserverService> 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);
 }
 
 NS_IMETHODIMP
 nsAccessible::GetRole(PRUint32 *aRole)
 {
--- a/chrome/src/nsChromeRegistry.cpp
+++ b/chrome/src/nsChromeRegistry.cpp
@@ -519,17 +519,18 @@ nsChromeRegistry::Init()
     nsCOMPtr<nsIPrefBranch2> prefs2 (do_QueryInterface(prefs));
     if (prefs2) {
       rv = prefs2->AddObserver(MATCH_OS_LOCALE_PREF, this, PR_TRUE);
       rv = prefs2->AddObserver(SELECTED_LOCALE_PREF, this, PR_TRUE);
       rv = prefs2->AddObserver(SELECTED_SKIN_PREF, this, PR_TRUE);
     }
   }
 
-  nsCOMPtr<nsIObserverService> obsService (do_GetService("@mozilla.org/observer-service;1"));
+  nsCOMPtr<nsIObserverService> obsService =
+    mozilla::services::GetObserverService();
   if (obsService) {
     obsService->AddObserver(this, "command-line-startup", PR_TRUE);
     obsService->AddObserver(this, "profile-initial-state", PR_TRUE);
   }
 
   CheckForNewChrome();
 
   mInitialized = PR_TRUE;
@@ -899,17 +900,17 @@ NS_IMETHODIMP nsChromeRegistry::RefreshS
    
   return NS_OK;
 }
 
 void
 nsChromeRegistry::FlushSkinCaches()
 {
   nsCOMPtr<nsIObserverService> obsSvc =
-    do_GetService("@mozilla.org/observer-service;1");
+    mozilla::services::GetObserverService();
   NS_ASSERTION(obsSvc, "Couldn't get observer service.");
 
   obsSvc->NotifyObservers(static_cast<nsIChromeRegistry*>(this),
                           NS_CHROME_FLUSH_SKINS_TOPIC, nsnull);
 }
 
 static PRBool IsChromeURI(nsIURI* aURI)
 {
@@ -1025,17 +1026,17 @@ nsresult nsChromeRegistry::RefreshWindow
   document->UpdateStyleSheets(oldSheets, newSheets);
   return NS_OK;
 }
 
 void
 nsChromeRegistry::FlushAllCaches()
 {
   nsCOMPtr<nsIObserverService> obsSvc =
-    do_GetService("@mozilla.org/observer-service;1");
+    mozilla::services::GetObserverService();
   NS_ASSERTION(obsSvc, "Couldn't get observer service.");
 
   obsSvc->NotifyObservers((nsIChromeRegistry*) this,
                           NS_CHROME_FLUSH_TOPIC, nsnull);
 }  
 
 // xxxbsmedberg Move me to nsIWindowMediator
 NS_IMETHODIMP
--- a/content/base/src/nsCCUncollectableMarker.cpp
+++ b/content/base/src/nsCCUncollectableMarker.cpp
@@ -45,16 +45,17 @@
 #include "nsIDocument.h"
 #include "nsIWindowMediator.h"
 #include "nsPIDOMWindow.h"
 #include "nsIWebNavigation.h"
 #include "nsISHistory.h"
 #include "nsISHEntry.h"
 #include "nsISHContainer.h"
 #include "nsIWindowWatcher.h"
+#include "mozilla/Services.h"
 
 static PRBool sInited = 0;
 PRUint32 nsCCUncollectableMarker::sGeneration = 0;
 
 NS_IMPL_ISUPPORTS1(nsCCUncollectableMarker, nsIObserver)
 
 /* static */
 nsresult
@@ -62,20 +63,22 @@ nsCCUncollectableMarker::Init()
 {
   if (sInited) {
     return NS_OK;
   }
   
   nsCOMPtr<nsIObserver> marker = new nsCCUncollectableMarker;
   NS_ENSURE_TRUE(marker, NS_ERROR_OUT_OF_MEMORY);
 
+  nsCOMPtr<nsIObserverService> obs =
+    mozilla::services::GetObserverService();
+  if (!obs)
+    return NS_ERROR_FAILURE;
+
   nsresult rv;
-  nsCOMPtr<nsIObserverService> obs =
-    do_GetService("@mozilla.org/observer-service;1", &rv);
-  NS_ENSURE_SUCCESS(rv, rv);
 
   // This makes the observer service hold an owning reference to the marker
   rv = obs->AddObserver(marker, "xpcom-shutdown", PR_FALSE);
   NS_ENSURE_SUCCESS(rv, rv);
 
   rv = obs->AddObserver(marker, "cycle-collector-begin", PR_FALSE);
   NS_ENSURE_SUCCESS(rv, rv);
 
@@ -181,22 +184,21 @@ MarkWindowList(nsISimpleEnumerator* aWin
     }
   }
 }
 
 nsresult
 nsCCUncollectableMarker::Observe(nsISupports* aSubject, const char* aTopic,
                                  const PRUnichar* aData)
 {
-  nsresult rv;
-
   if (!strcmp(aTopic, "xpcom-shutdown")) {
     nsCOMPtr<nsIObserverService> 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");
     obs->RemoveObserver(this, "cycle-collector-begin");
     
     sGeneration = 0;
     
     return NS_OK;
@@ -204,16 +206,18 @@ nsCCUncollectableMarker::Observe(nsISupp
 
   NS_ASSERTION(!strcmp(aTopic, "cycle-collector-begin"), "wrong topic");
 
   // Increase generation to effectivly unmark all current objects
   if (!++sGeneration) {
     ++sGeneration;
   }
 
+  nsresult rv;
+
   // Iterate all toplevel windows
   nsCOMPtr<nsISimpleEnumerator> windowList;
   nsCOMPtr<nsIWindowMediator> med =
     do_GetService(NS_WINDOWMEDIATOR_CONTRACTID);
   if (med) {
     rv = med->GetEnumerator(nsnull, getter_AddRefs(windowList));
     NS_ENSURE_SUCCESS(rv, rv);
 
--- a/content/base/src/nsContentUtils.cpp
+++ b/content/base/src/nsContentUtils.cpp
@@ -3489,30 +3489,30 @@ nsContentUtils::GetReferencedElement(nsI
   return ref.get();
 }
 
 /* static */
 void
 nsContentUtils::RegisterShutdownObserver(nsIObserver* aObserver)
 {
   nsCOMPtr<nsIObserverService> observerService =
-    do_GetService("@mozilla.org/observer-service;1");
+    mozilla::services::GetObserverService();
   if (observerService) {
     observerService->AddObserver(aObserver, 
                                  NS_XPCOM_SHUTDOWN_OBSERVER_ID, 
                                  PR_FALSE);
   }
 }
 
 /* static */
 void
 nsContentUtils::UnregisterShutdownObserver(nsIObserver* aObserver)
 {
   nsCOMPtr<nsIObserverService> observerService =
-    do_GetService("@mozilla.org/observer-service;1");
+    mozilla::services::GetObserverService();
   if (observerService) {
     observerService->RemoveObserver(aObserver, NS_XPCOM_SHUTDOWN_OBSERVER_ID);
   }
 }
 
 /* static */
 PRBool
 nsContentUtils::HasNonEmptyAttr(nsIContent* aContent, PRInt32 aNameSpaceID,
--- a/content/events/src/nsEventStateManager.cpp
+++ b/content/events/src/nsEventStateManager.cpp
@@ -148,16 +148,17 @@
 #include "nsIDragSession.h"
 #include "nsDOMDataTransfer.h"
 #include "nsContentAreaDragDrop.h"
 #ifdef MOZ_XUL
 #include "nsTreeBodyFrame.h"
 #endif
 #include "nsIController.h"
 #include "nsICommandParams.h"
+#include "mozilla/Services.h"
 
 #ifdef XP_MACOSX
 #import <ApplicationServices/ApplicationServices.h>
 #endif
 
 //#define DEBUG_DOCSHELL_FOCUS
 
 #define NS_USER_INTERACTION_INTERVAL 5000 // ms
@@ -267,20 +268,20 @@ private:
 
 NS_IMPL_ISUPPORTS1(nsUITimerCallback, nsITimerCallback)
 
 // If aTimer is nsnull, this method always sends "user-interaction-inactive"
 // notification.
 NS_IMETHODIMP
 nsUITimerCallback::Notify(nsITimer* aTimer)
 {
-  nsresult rv;
   nsCOMPtr<nsIObserverService> 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);
   } else {
     obs->NotifyObservers(nsnull, "user-interaction-active", nsnull);
   }
   mPreviousCount = gMouseOrKeyboardEventCounter;
   return NS_OK;
@@ -784,20 +785,20 @@ nsEventStateManager::nsEventStateManager
     }
   }
   ++sESMInstanceCount;
 }
 
 NS_IMETHODIMP
 nsEventStateManager::Init()
 {
-  nsresult rv;
   nsCOMPtr<nsIObserverService> 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);
 
   nsIPrefBranch2* prefBranch = nsContentUtils::GetPrefBranch();
 
   if (prefBranch) {
     if (sESMInstanceCount == 1) {
       sLeftClickOnly =
@@ -827,17 +828,17 @@ nsEventStateManager::Init()
     prefBranch->AddObserver("mousewheel.withshiftkey.action", this, PR_TRUE);
     prefBranch->AddObserver("mousewheel.withshiftkey.numlines", this, PR_TRUE);
     prefBranch->AddObserver("mousewheel.withshiftkey.sysnumlines", this, PR_TRUE);
 #endif
 
     prefBranch->AddObserver("dom.popup_allowed_events", this, PR_TRUE);
   }
 
-  return rv;
+  return NS_OK;
 }
 
 nsEventStateManager::~nsEventStateManager()
 {
 #if CLICK_HOLD_CONTEXT_MENUS
   KillClickHoldTimer();
 #endif
 
@@ -856,21 +857,19 @@ nsEventStateManager::~nsEventStateManage
 
   if (!m_haveShutdown) {
     Shutdown();
 
     // Don't remove from Observer service in Shutdown because Shutdown also
     // gets called from xpcom shutdown observer.  And we don't want to remove
     // from the service in that case.
 
-    nsresult rv;
-
     nsCOMPtr<nsIObserverService> 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);
     }
   }
 
 }
 
 nsresult
 nsEventStateManager::Shutdown()
@@ -1042,17 +1041,17 @@ nsEventStateManager::PreHandleEvent(nsPr
       ((aEvent->eventStructType == NS_MOUSE_EVENT  &&
         IsMouseEventReal(aEvent) &&
         aEvent->message != NS_MOUSE_ENTER &&
         aEvent->message != NS_MOUSE_EXIT) ||
        aEvent->eventStructType == NS_MOUSE_SCROLL_EVENT ||
        aEvent->eventStructType == NS_KEY_EVENT)) {
     if (gMouseOrKeyboardEventCounter == 0) {
       nsCOMPtr<nsIObserverService> obs =
-        do_GetService("@mozilla.org/observer-service;1");
+        mozilla::services::GetObserverService();
       if (obs) {
         obs->NotifyObservers(nsnull, "user-interaction-active", nsnull);
       }
     }
     ++gMouseOrKeyboardEventCounter;
   }
 
   *aStatus = nsEventStatus_eIgnore;
--- a/content/html/content/src/nsHTMLDNSPrefetch.cpp
+++ b/content/html/content/src/nsHTMLDNSPrefetch.cpp
@@ -290,20 +290,19 @@ nsHTMLDNSPrefetch::nsDeferrals::Activate
 {
   // Register as an observer for the document loader  
   nsCOMPtr<nsIWebProgress> progress = 
     do_GetService(NS_DOCUMENTLOADER_SERVICE_CONTRACTID);
   if (progress)
     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<nsIObserverService> 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);
 }
 
 // nsITimer related method
 
 void 
 nsHTMLDNSPrefetch::nsDeferrals::Tick(nsITimer *aTimer, void *aClosure)
 {
--- a/content/html/content/src/nsHTMLFormElement.cpp
+++ b/content/html/content/src/nsHTMLFormElement.cpp
@@ -901,26 +901,26 @@ nsHTMLFormElement::NotifySubmitObservers
   if (!gFirstFormSubmitted) {
     gFirstFormSubmitted = PR_TRUE;
     NS_CreateServicesFromCategory(NS_FIRST_FORMSUBMIT_CATEGORY,
                                   nsnull,
                                   NS_FIRST_FORMSUBMIT_CATEGORY);
   }
 
   // Notify observers that the form is being submitted.
-  nsresult rv = NS_OK;
   nsCOMPtr<nsIObserverService> service =
-    do_GetService("@mozilla.org/observer-service;1", &rv);
-  NS_ENSURE_SUCCESS(rv, rv);
+    mozilla::services::GetObserverService();
+  if (!service)
+    return NS_ERROR_FAILURE;
 
   nsCOMPtr<nsISimpleEnumerator> 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) {
     nsCOMPtr<nsISupports> inst;
     *aCancelSubmit = PR_FALSE;
 
     // XXXbz what do the submit observers actually want?  The window
     // of the document this is shown in?  Or something else?
--- a/content/xbl/src/nsXBLService.cpp
+++ b/content/xbl/src/nsXBLService.cpp
@@ -1316,15 +1316,15 @@ NS_NewXBLService(nsIXBLService** aResult
   nsXBLService* result = new nsXBLService;
   if (! result)
     return NS_ERROR_OUT_OF_MEMORY;
 
   NS_ADDREF(*aResult = result);
 
   // Register the first (and only) nsXBLService as a memory pressure observer
   // so it can flush the LRU list in low-memory situations.
-  nsCOMPtr<nsIObserverService> os = do_GetService("@mozilla.org/observer-service;1");
+  nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
   if (os)
     os->AddObserver(result, "memory-pressure", PR_TRUE);
 
   return NS_OK;
 }
 
--- a/content/xul/document/src/nsXULDocument.cpp
+++ b/content/xul/document/src/nsXULDocument.cpp
@@ -637,18 +637,18 @@ nsXULDocument::OnPrototypeLoadDone(PRBoo
 // called when an error occurs parsing a document
 PRBool
 nsXULDocument::OnDocumentParserError()
 {
   // don't report errors that are from overlays
   if (mCurrentPrototype && mMasterPrototype != mCurrentPrototype) {
     nsCOMPtr<nsIURI> uri = mCurrentPrototype->GetURI();
     if (IsChromeURI(uri)) {
-      nsCOMPtr<nsIObserverService> os(
-        do_GetService("@mozilla.org/observer-service;1"));
+      nsCOMPtr<nsIObserverService> os =
+        mozilla::services::GetObserverService();
       if (os)
         os->NotifyObservers(uri, "xul-overlay-parsererror",
                             EmptyString().get());
     }
 
     return PR_FALSE;
   }
 
--- a/content/xul/document/src/nsXULPrototypeCache.cpp
+++ b/content/xul/document/src/nsXULPrototypeCache.cpp
@@ -135,17 +135,18 @@ NS_NewXULPrototypeCache(nsISupports* aOu
     gDisableXULCache =
         nsContentUtils::GetBoolPref(kDisableXULCachePref, gDisableXULCache);
     nsContentUtils::RegisterPrefCallback(kDisableXULCachePref,
                                          DisableXULCacheChangedCallback,
                                          nsnull);
 
     nsresult rv = result->QueryInterface(aIID, aResult);
 
-    nsCOMPtr<nsIObserverService> obsSvc(do_GetService("@mozilla.org/observer-service;1"));
+    nsCOMPtr<nsIObserverService> obsSvc =
+        mozilla::services::GetObserverService();
     if (obsSvc && NS_SUCCEEDED(rv)) {
         nsXULPrototypeCache *p = result;
         obsSvc->AddObserver(p, "chrome-flush-skin-caches", PR_FALSE);
         obsSvc->AddObserver(p, "chrome-flush-caches", PR_FALSE);
     }
 
     return rv;
 }
--- a/docshell/base/nsDocShell.cpp
+++ b/docshell/base/nsDocShell.cpp
@@ -10118,17 +10118,17 @@ nsDocShell::AddToGlobalHistory(nsIURI * 
         return rv;
 
     rv = mGlobalHistory->AddURI(aURI, aRedirect, !IsFrame(), aReferrer);
     if (NS_FAILED(rv))
         return rv;
 
     if (!visited) {
         nsCOMPtr<nsIObserverService> obsService =
-            do_GetService("@mozilla.org/observer-service;1");
+            mozilla::services::GetObserverService();
         if (obsService) {
             obsService->NotifyObservers(aURI, NS_LINK_VISITED_EVENT_TOPIC, nsnull);
         }
     }
 
     return NS_OK;
 
 }
--- a/docshell/shistory/src/nsSHistory.cpp
+++ b/docshell/shistory/src/nsSHistory.cpp
@@ -55,16 +55,17 @@
 #include "nsIServiceManager.h"
 #include "nsIPrefService.h"
 #include "nsIURI.h"
 #include "nsIContentViewer.h"
 #include "nsIPrefBranch2.h"
 #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"
 #include <math.h>  // for log()
 
 #define PREF_SHISTORY_SIZE "browser.sessionhistory.max_entries"
 #define PREF_SHISTORY_MAX_TOTAL_VIEWERS "browser.sessionhistory.max_total_viewers"
 
@@ -248,17 +249,17 @@ nsSHistory::Startup()
       nsSHistoryObserver* obs = new nsSHistoryObserver();
       if (!obs) {
         return NS_ERROR_OUT_OF_MEMORY;
       }
       branch->AddObserver(PREF_SHISTORY_MAX_TOTAL_VIEWERS,
                           obs, PR_FALSE);
 
       nsCOMPtr<nsIObserverService> 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.
         obsSvc->AddObserver(obs,
                             NS_CACHESERVICE_EMPTYCACHE_TOPIC_ID, PR_FALSE);
 
         // Same for memory-pressure notifications
         obsSvc->AddObserver(obs, "memory-pressure", PR_FALSE);
--- a/dom/base/nsDOMScriptObjectFactory.cpp
+++ b/dom/base/nsDOMScriptObjectFactory.cpp
@@ -70,18 +70,17 @@
 static NS_DEFINE_CID(kDOMScriptObjectFactoryCID, NS_DOM_SCRIPT_OBJECT_FACTORY_CID);
 
 nsIExceptionProvider* gExceptionProvider = nsnull;
 
 nsDOMScriptObjectFactory::nsDOMScriptObjectFactory() :
   mLoadedAllLanguages(PR_FALSE)
 {
   nsCOMPtr<nsIObserverService> observerService =
-    do_GetService("@mozilla.org/observer-service;1");
-
+    mozilla::services::GetObserverService();
   if (observerService) {
     observerService->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, PR_FALSE);
   }
 
   nsCOMPtr<nsIExceptionProvider> provider(new nsDOMExceptionProvider());
   if (provider) {
     nsCOMPtr<nsIExceptionService> xs =
       do_GetService(NS_EXCEPTIONSERVICE_CONTRACTID);
--- a/dom/base/nsGlobalWindow.cpp
+++ b/dom/base/nsGlobalWindow.cpp
@@ -675,18 +675,17 @@ nsGlobalWindow::nsGlobalWindow(nsGlobalW
   if (aOuterWindow) {
     // |this| is an inner window, add this inner window to the outer
     // window list of inners.
     PR_INSERT_AFTER(this, aOuterWindow);
 
     mObserver = new nsGlobalWindowObserver(this);
     if (mObserver) {
       NS_ADDREF(mObserver);
-      nsCOMPtr<nsIObserverService> os =
-        do_GetService("@mozilla.org/observer-service;1");
+      nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
       if (os) {
         // Watch for online/offline status changes so we can fire events. Use
         // a strong reference.
         os->AddObserver(mObserver, NS_IOSERVICE_OFFLINE_STATUS_TOPIC,
                         PR_FALSE);
 
         // Watch for dom-storage-changed so we can fire storage
         // events. Use a strong reference.
@@ -768,18 +767,17 @@ nsGlobalWindow::~nsGlobalWindow()
 
 #ifdef PR_LOGGING
   if (gDOMLeakPRLog)
     PR_LOG(gDOMLeakPRLog, PR_LOG_DEBUG,
            ("DOMWINDOW %p destroyed", this));
 #endif
 
   if (mObserver) {
-    nsCOMPtr<nsIObserverService> os =
-      do_GetService("@mozilla.org/observer-service;1");
+    nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
     if (os) {
       os->RemoveObserver(mObserver, NS_IOSERVICE_OFFLINE_STATUS_TOPIC);
       os->RemoveObserver(mObserver, "dom-storage2-changed");
       os->RemoveObserver(mObserver, "dom-storage-changed");
     }
 
     // Drop its reference to this dying window, in case for some bogus reason
     // the object stays around.
@@ -2109,17 +2107,17 @@ nsGlobalWindow::SetNewDocument(nsIDocume
                                   GetScriptContextInternal(st_id);
     if (this_ctx) {
       this_ctx->GC();
       this_ctx->DidInitializeContext();
     }
   }
 
   nsCOMPtr<nsIObserverService> observerService =
-    do_GetService("@mozilla.org/observer-service;1");
+    mozilla::services::GetObserverService();
   if (observerService) {
     nsAutoString origin;
     nsIPrincipal* principal = aDocument->NodePrincipal();
     nsContentUtils::GetUTFOrigin(principal, origin);
     observerService->
       NotifyObservers(static_cast<nsIDOMWindow*>(this),
                       nsContentUtils::IsSystemPrincipal(principal) ?
                         "chrome-document-global-created" :
--- a/dom/base/nsJSEnvironment.cpp
+++ b/dom/base/nsJSEnvironment.cpp
@@ -272,18 +272,17 @@ nsUserActivityObserver::Observe(nsISuppo
     higherProbability = (mUserActivityCounter > NS_CC_SOFT_LIMIT_INACTIVE);
   } else if (!strcmp(aTopic, "user-interaction-active")) {
 #ifdef DEBUG_smaug
     printf("user-interaction-active\n");
 #endif
     sUserIsActive = PR_TRUE;
     higherProbability = (mUserActivityCounter > NS_CC_SOFT_LIMIT_ACTIVE);
   } else if (!strcmp(aTopic, "xpcom-shutdown")) {
-    nsCOMPtr<nsIObserverService> obs =
-      do_GetService("@mozilla.org/observer-service;1");
+    nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
     if (obs) {
       obs->RemoveObserver(this, "user-interaction-active");
       obs->RemoveObserver(this, "user-interaction-inactive");
       obs->RemoveObserver(this, "xpcom-shutdown");
     }
     return NS_OK;
   }
   nsJSContext::MaybeCC(higherProbability);
@@ -4015,32 +4014,32 @@ nsJSRuntime::Init()
                                             nsnull);
 
   nsContentUtils::RegisterPrefCallback("javascript.options.mem.gc_frequency",
                                        SetMemoryGCFrequencyPrefChangedCallback,
                                        nsnull);
   SetMemoryGCFrequencyPrefChangedCallback("javascript.options.mem.gc_frequency",
                                           nsnull);
 
-  nsCOMPtr<nsIObserverService> obs =
-    do_GetService("@mozilla.org/observer-service;1", &rv);
-  NS_ENSURE_SUCCESS(rv, rv);
+  nsCOMPtr<nsIObserverService> 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);
   obs->AddObserver(activityObserver, "user-interaction-active", PR_FALSE);
   obs->AddObserver(activityObserver, "xpcom-shutdown", PR_FALSE);
 
   nsIObserver* ccMemPressureObserver = new nsCCMemoryPressureObserver();
   NS_ENSURE_TRUE(ccMemPressureObserver, NS_ERROR_OUT_OF_MEMORY);
   obs->AddObserver(ccMemPressureObserver, "memory-pressure", PR_FALSE);
 
   sIsInitialized = PR_TRUE;
 
-  return rv;
+  return NS_OK;
 }
 
 //static
 nsScriptNameSpaceManager*
 nsJSRuntime::GetNameSpaceManager()
 {
   if (sDidShutdown)
     return nsnull;
--- a/dom/src/geolocation/nsGeolocation.cpp
+++ b/dom/src/geolocation/nsGeolocation.cpp
@@ -45,16 +45,17 @@
 #include "nsServiceManagerUtils.h"
 #include "nsContentUtils.h"
 #include "nsIURI.h"
 #include "nsIPermissionManager.h"
 #include "nsIObserverService.h"
 #include "nsIPrefService.h"
 #include "nsIPrefBranch2.h"
 #include "nsIJSContextStack.h"
+#include "mozilla/Services.h"
 
 #include <math.h>
 
 #ifdef WINCE_WINDOWS_MOBILE
 #include "WinMobileLocationProvider.h"
 #endif
 
 #ifdef MOZ_MAEMO_LIBLOCATION
@@ -378,17 +379,17 @@ nsresult nsGeolocationService::Init()
     mProviders.AppendObject(provider);
 
   // look up any providers that were registered via the category manager
   nsCOMPtr<nsICategoryManager> catMan(do_GetService("@mozilla.org/categorymanager;1"));
   if (!catMan)
     return NS_ERROR_FAILURE;
 
   // geolocation service can be enabled -> now register observer
-  nsCOMPtr<nsIObserverService> obs = do_GetService("@mozilla.org/observer-service;1");
+  nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
   if (!obs)
     return NS_ERROR_FAILURE;
 
   obs->AddObserver(this, "quit-application", false);
 
   nsCOMPtr<nsISimpleEnumerator> geoproviders;
   catMan->EnumerateCategory("geolocation-provider", getter_AddRefs(geoproviders));
   if (geoproviders) {
@@ -434,17 +435,17 @@ nsGeolocationService::~nsGeolocationServ
 
 NS_IMETHODIMP
 nsGeolocationService::Observe(nsISupports* aSubject,
                               const char* aTopic,
                               const PRUnichar* aData)
 {
   if (!strcmp("quit-application", aTopic))
   {
-    nsCOMPtr<nsIObserverService> obs = do_GetService("@mozilla.org/observer-service;1");
+    nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
     if (obs) {
       obs->RemoveObserver(this, "quit-application");
     }
 
     for (PRUint32 i = 0; i< mGeolocators.Length(); i++)
       mGeolocators[i]->Shutdown();
 
     StopDevice();
--- a/dom/src/offline/nsDOMOfflineResourceList.cpp
+++ b/dom/src/offline/nsDOMOfflineResourceList.cpp
@@ -188,23 +188,24 @@ nsDOMOfflineResourceList::Init()
     rv = cacheUpdateService->GetUpdate(i, getter_AddRefs(cacheUpdate));
     NS_ENSURE_SUCCESS(rv, rv);
 
     UpdateAdded(cacheUpdate);
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
   // watch for new offline cache updates
-  nsCOMPtr<nsIObserverService> observerServ =
-    do_GetService("@mozilla.org/observer-service;1", &rv);
-  NS_ENSURE_SUCCESS(rv, rv);
+  nsCOMPtr<nsIObserverService> 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;
 
   return NS_OK;
 }
 
 void
--- a/dom/src/storage/nsDOMStorage.cpp
+++ b/dom/src/storage/nsDOMStorage.cpp
@@ -250,28 +250,29 @@ nsDOMStorageManager::Initialize()
   if (!gStorageManager->mStorages.Init()) {
     delete gStorageManager;
     gStorageManager = nsnull;
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
   NS_ADDREF(gStorageManager);
 
-  nsCOMPtr<nsIObserverService> 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<nsIObserverService> os = mozilla::services::GetObserverService();
+  if (!os)
+    return NS_OK;
 
-    nsCOMPtr<nsIPrivateBrowsingService> 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<nsIPrivateBrowsingService> pbs =
+    do_GetService(NS_PRIVATE_BROWSING_SERVICE_CONTRACTID);
+  if (pbs)
+    pbs->GetPrivateBrowsingEnabled(&gStorageManager->mInPrivateBrowsing);
 
   return NS_OK;
 }
 
 //static
 nsDOMStorageManager*
 nsDOMStorageManager::GetInstance()
 {
@@ -1268,18 +1269,17 @@ nsDOMStorage::SetDBValue(const nsAString
     if (stack && NS_SUCCEEDED(stack->Peek(&cx)) && cx) {
       nsCOMPtr<nsIScriptContext> scriptContext;
       scriptContext = GetScriptContextFromJSContext(cx);
       if (scriptContext) {
         window = do_QueryInterface(scriptContext->GetGlobalObject());
       }
     }
 
-    nsCOMPtr<nsIObserverService> os =
-      do_GetService("@mozilla.org/observer-service;1");
+    nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
     os->NotifyObservers(window, "dom-storage-warn-quota-exceeded",
                         NS_ConvertUTF8toUTF16(mDomain).get());
   }
 
 #endif
 
   return NS_OK;
 }
@@ -1418,20 +1418,19 @@ nsDOMStorage::StorageType()
   return mStorageType;
 }
 
 void
 nsDOMStorage::BroadcastChangeNotification(const nsSubstring &aKey,
                                           const nsSubstring &aOldValue,
                                           const nsSubstring &aNewValue)
 {
-  nsresult rv;
   nsCOMPtr<nsIObserverService> observerService =
-    do_GetService("@mozilla.org/observer-service;1", &rv);
-  if (NS_FAILED(rv)) {
+    mozilla::services::GetObserverService();
+  if (!observerService) {
     return;
   }
 
   // Fire off a notification that a storage object changed. If the
   // storage object is a session storage object, we don't pass a
   // domain, but if it's a global storage object we do.
   observerService->NotifyObservers((nsIDOMStorageObsolete *)this,
                                    "dom-storage-changed",
@@ -1611,18 +1610,18 @@ nsDOMStorage2::BroadcastChangeNotificati
                                aNewValue,
                                mDocumentURI,
                                static_cast<nsIDOMStorage*>(this));
   if (NS_FAILED(rv)) {
     return;
   }
 
   nsCOMPtr<nsIObserverService> observerService =
-    do_GetService("@mozilla.org/observer-service;1", &rv);
-  if (NS_FAILED(rv)) {
+    mozilla::services::GetObserverService();
+  if (!observerService) {
     return;
   }
 
   nsCOMPtr<nsIObserverService> observerServiceProxy;
   rv = NS_GetProxyForObject(NS_PROXY_TO_MAIN_THREAD,
                             NS_GET_IID(nsIObserverService),
                             observerService,
                             NS_PROXY_ASYNC | NS_PROXY_ALWAYS,
--- a/embedding/components/find/src/nsWebBrowserFind.cpp
+++ b/embedding/components/find/src/nsWebBrowserFind.cpp
@@ -70,16 +70,17 @@
 #include "nsContentCID.h"
 #include "nsIServiceManager.h"
 #include "nsIObserverService.h"
 #include "nsISupportsPrimitives.h"
 #include "nsITimelineService.h"
 #include "nsFind.h"
 #include "nsDOMError.h"
 #include "nsFocusManager.h"
+#include "mozilla/Services.h"
 
 #if DEBUG
 #include "nsIWebNavigation.h"
 #include "nsXPIDLString.h"
 #endif
 
 #if defined(XP_MACOSX) && !defined(__LP64__)
 #include "nsAutoPtr.h"
@@ -125,17 +126,17 @@ NS_IMETHODIMP nsWebBrowserFind::FindNext
     
     // first, if there's a "cmd_findagain" observer around, check to see if it
     // wants to perform the find again command . If it performs the find again
     // it will return true, in which case we exit ::FindNext() early.
     // Otherwise, nsWebBrowserFind needs to perform the find again command itself
     // this is used by nsTypeAheadFind, which controls find again when it was
     // the last executed find in the current window.
     nsCOMPtr<nsIObserverService> observerSvc =
-      do_GetService("@mozilla.org/observer-service;1");
+      mozilla::services::GetObserverService();
     if (observerSvc) {
         nsCOMPtr<nsISupportsInterfacePointer> windowSupportsData = 
           do_CreateInstance(NS_SUPPORTS_INTERFACE_POINTER_CONTRACTID, &rv);
         NS_ENSURE_SUCCESS(rv, rv);
         nsCOMPtr<nsISupports> searchWindowSupports =
           do_QueryInterface(rootFrame);
         windowSupportsData->SetData(searchWindowSupports);
         NS_NAMED_LITERAL_STRING(dnStr, "down");
--- a/embedding/components/windowwatcher/src/nsWindowWatcher.cpp
+++ b/embedding/components/windowwatcher/src/nsWindowWatcher.cpp
@@ -834,20 +834,19 @@ nsWindowWatcher::OpenWindowJSInternal(ns
       }
     }
   }
 
   if (isNewToplevelWindow) {
     // Notify observers that the window is open and ready.
     // The window has not yet started to load a document.
     nsCOMPtr<nsIObserverService> 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
   // that we have to do this _before_ starting any URI loads, thanks to the
   // sync nature of javascript: loads.  Since this is the only place where we
   // set said opener principal, we need to do it for all URIs, including
   // chrome ones.  So to deal with the mess that is bug 79775, just press on in
   // a reasonable way even if GetSubjectPrincipal fails.  In that case, just
@@ -1011,45 +1010,47 @@ nsWindowWatcher::OpenWindowJSInternal(ns
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsWindowWatcher::RegisterNotification(nsIObserver *aObserver)
 {
   // just a convenience method; it delegates to nsIObserverService
-  nsresult rv;
 
   if (!aObserver)
     return NS_ERROR_INVALID_ARG;
   
-  nsCOMPtr<nsIObserverService> 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<nsIObserverService> 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;
 }
 
 NS_IMETHODIMP
 nsWindowWatcher::UnregisterNotification(nsIObserver *aObserver)
 {
   // just a convenience method; it delegates to nsIObserverService
-  nsresult rv;
 
   if (!aObserver)
     return NS_ERROR_INVALID_ARG;
   
-  nsCOMPtr<nsIObserverService> os(do_GetService("@mozilla.org/observer-service;1", &rv));
-  if (os) {
-    os->RemoveObserver(aObserver, "domwindowopened");
-    os->RemoveObserver(aObserver, "domwindowclosed");
-  }
-  return rv;
+  nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
+  if (!os)
+    return NS_ERROR_FAILURE;
+
+  os->RemoveObserver(aObserver, "domwindowopened");
+  os->RemoveObserver(aObserver, "domwindowclosed");
+
+  return NS_OK;
 }
 
 NS_IMETHODIMP
 nsWindowWatcher::GetWindowEnumerator(nsISimpleEnumerator** _retval)
 {
   if (!_retval)
     return NS_ERROR_INVALID_ARG;
 
@@ -1138,18 +1139,16 @@ nsWindowWatcher::SetActiveWindow(nsIDOMW
   if (fm)
     return fm->SetActiveWindow(aActiveWindow);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsWindowWatcher::AddWindow(nsIDOMWindow *aWindow, nsIWebBrowserChrome *aChrome)
 {
-  nsresult rv;
-
   if (!aWindow)
     return NS_ERROR_INVALID_ARG;
 
 #ifdef DEBUG
   {
     nsCOMPtr<nsPIDOMWindow> win(do_QueryInterface(aWindow));
 
     NS_ASSERTION(win->IsOuterWindow(),
@@ -1183,23 +1182,22 @@ nsWindowWatcher::AddWindow(nsIDOMWindow 
     if (mOldestWindow)
       info->InsertAfter(mOldestWindow->mOlder);
     else
       mOldestWindow = info;
   } // leave the mListLock
 
   // a window being added to us signifies a newly opened window.
   // send notifications.
-  nsCOMPtr<nsIObserverService> os(do_GetService("@mozilla.org/observer-service;1", &rv));
-  if (os) {
-    nsCOMPtr<nsISupports> domwin(do_QueryInterface(aWindow));
-    rv = os->NotifyObservers(domwin, "domwindowopened", 0);
-  }
+  nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
+  if (!os)
+    return NS_ERROR_FAILURE;
 
-  return rv;
+  nsCOMPtr<nsISupports> domwin(do_QueryInterface(aWindow));
+  return os->NotifyObservers(domwin, "domwindowopened", 0);
 }
 
 NS_IMETHODIMP
 nsWindowWatcher::RemoveWindow(nsIDOMWindow *aWindow)
 {
   // find the corresponding nsWatcherWindowEntry, remove it
 
   if (!aWindow)
@@ -1252,42 +1250,41 @@ nsWindowWatcher::FindWindowEntry(nsIDOMW
   return 0;
 #endif
 }
 
 nsresult nsWindowWatcher::RemoveWindow(nsWatcherWindowEntry *inInfo)
 {
   PRUint32  ctr,
             count = mEnumeratorList.Length();
-  nsresult rv;
 
   {
     // notify the enumerators
     nsAutoLock lock(mListLock);
     for (ctr = 0; ctr < count; ++ctr) 
       mEnumeratorList[ctr]->WindowRemoved(inInfo);
 
     // remove the element from the list
     if (inInfo == mOldestWindow)
       mOldestWindow = inInfo->mYounger == mOldestWindow ? 0 : inInfo->mYounger;
     inInfo->Unlink();
   }
 
   // a window being removed from us signifies a newly closed window.
   // send notifications.
-  nsCOMPtr<nsIObserverService> os(do_GetService("@mozilla.org/observer-service;1", &rv));
+  nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
   if (os) {
 #ifdef USEWEAKREFS
     nsCOMPtr<nsISupports> 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<nsISupports> domwin(do_QueryInterface(inInfo->mWindow));
-    rv = os->NotifyObservers(domwin, "domwindowclosed", 0);
+    os->NotifyObservers(domwin, "domwindowclosed", 0);
 #endif
   }
 
   delete inInfo;
   return NS_OK;
 }
 
 NS_IMETHODIMP
--- a/gfx/src/thebes/nsThebesDeviceContext.cpp
+++ b/gfx/src/thebes/nsThebesDeviceContext.cpp
@@ -42,16 +42,17 @@
 #include "nsIFontMetrics.h"
 #include "nsHashtable.h"
 #include "nsILanguageAtomService.h"
 #include "nsUnicharUtils.h"
 
 #include "nsIServiceManager.h"
 #include "nsIPrefService.h"
 #include "nsCRT.h"
+#include "mozilla/Services.h"
 
 #include "nsThebesDeviceContext.h"
 #include "nsThebesRenderingContext.h"
 #include "gfxUserFontSet.h"
 #include "gfxPlatform.h"
 
 #include "nsIWidget.h"
 #include "nsIView.h"
@@ -302,17 +303,17 @@ nsThebesDeviceContext::nsThebesDeviceCon
 static PRBool DeleteValue(nsHashKey* aKey, void* aValue, void* closure)
 {
     delete ((nsString*)aValue);
     return PR_TRUE;
 }
 
 nsThebesDeviceContext::~nsThebesDeviceContext()
 {
-    nsCOMPtr<nsIObserverService> obs(do_GetService("@mozilla.org/observer-service;1"));
+    nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
     if (obs)
         obs->RemoveObserver(this, "memory-pressure");
 
     if (nsnull != mFontCache) {
         delete mFontCache;
         mFontCache = nsnull;
     }
 
@@ -704,17 +705,17 @@ nsThebesDeviceContext::Init(nsIWidget *a
 
 #ifdef NS_DEBUG
     NS_ASSERTION(!mInitialized, "device context is initialized twice!");
     mInitialized = PR_TRUE;
 #endif
 
     // register as a memory-pressure observer to free font resources
     // in low-memory situations.
-    nsCOMPtr<nsIObserverService> obs(do_GetService("@mozilla.org/observer-service;1"));
+    nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
     if (obs)
         obs->AddObserver(this, "memory-pressure", PR_TRUE);
 
     mScreenManager = do_GetService("@mozilla.org/gfx/screenmanager;1");
 
     return NS_OK;
 }
 
--- a/intl/chardet/src/nsXMLEncodingObserver.cpp
+++ b/intl/chardet/src/nsXMLEncodingObserver.cpp
@@ -46,16 +46,17 @@
 #include "nsIParser.h"
 #include "pratom.h"
 #include "nsCharDetDll.h"
 #include "nsIServiceManager.h"
 #include "nsObserverBase.h"
 #include "nsWeakReference.h"
 #include "nsReadableUtils.h"
 #include "nsUnicharUtils.h"
+#include "mozilla/Services.h"
 
 static NS_DEFINE_CID(kCharsetAliasCID, NS_CHARSETALIAS_CID);
 
 static const eHTMLTags gTags[] = 
 { eHTMLTag_instruction,
   eHTMLTag_unknown
 };
 
@@ -198,36 +199,37 @@ NS_IMETHODIMP nsXMLEncodingObserver::Obs
 //-------------------------------------------------------------------------
 NS_IMETHODIMP nsXMLEncodingObserver::Start() 
 {
     nsresult res = NS_OK;
 
     if (bXMLEncodingObserverStarted) 
       return res;
 
-    nsCOMPtr<nsIObserverService> anObserverService = do_GetService("@mozilla.org/observer-service;1", &res);
+    nsCOMPtr<nsIObserverService> 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;
 }
 //-------------------------------------------------------------------------
 NS_IMETHODIMP nsXMLEncodingObserver::End() 
 {
     nsresult res = NS_OK;
     
     if (!bXMLEncodingObserverStarted)
       return res;
 
-    nsCOMPtr<nsIObserverService> anObserverService = do_GetService("@mozilla.org/observer-service;1", &res);
-    if (NS_SUCCEEDED(res)) {
-      res = anObserverService->RemoveObserver(this, "xmlparser");
+    nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
+    if (!obs)
+      return NS_ERROR_FAILURE;
 
-      bXMLEncodingObserverStarted = PR_FALSE;
-    }
+    res = obs->RemoveObserver(this, "xmlparser");
+
+    bXMLEncodingObserverStarted = PR_FALSE;
 
     return res;
 }
 
--- a/intl/strres/src/nsStringBundle.cpp
+++ b/intl/strres/src/nsStringBundle.cpp
@@ -577,17 +577,17 @@ nsStringBundleService::~nsStringBundleSe
 {
   flushBundleCache();
   PL_FinishArenaPool(&mCacheEntryPool);
 }
 
 nsresult
 nsStringBundleService::Init()
 {
-  nsCOMPtr<nsIObserverService> os = do_GetService("@mozilla.org/observer-service;1");
+  nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
   if (os) {
     os->AddObserver(this, "memory-pressure", PR_TRUE);
     os->AddObserver(this, "profile-do-change", PR_TRUE);
     os->AddObserver(this, "chrome-flush-caches", PR_TRUE);
     os->AddObserver(this, "xpcom-category-entry-added", PR_TRUE);
   }
 
   // instantiate the override service, if there is any.
--- a/layout/base/nsPresShell.cpp
+++ b/layout/base/nsPresShell.cpp
@@ -1642,18 +1642,17 @@ PresShell::Init(nsIDocument* aDocument,
   
   if (gMaxRCProcessingTime == -1) {
     gMaxRCProcessingTime =
       nsContentUtils::GetIntPref("layout.reflow.timeslice",
                                  NS_MAX_REFLOW_TIME);
   }
 
   {
-    nsCOMPtr<nsIObserverService> os =
-      do_GetService("@mozilla.org/observer-service;1", &result);
+    nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
     if (os) {
       os->AddObserver(this, "agent-sheet-added", PR_FALSE);
       os->AddObserver(this, "user-sheet-added", PR_FALSE);
       os->AddObserver(this, "agent-sheet-removed", PR_FALSE);
       os->AddObserver(this, "user-sheet-removed", PR_FALSE);
 #ifdef MOZ_XUL
       os->AddObserver(this, "chrome-flush-skin-caches", PR_FALSE);
 #endif
@@ -1718,18 +1717,17 @@ PresShell::Destroy()
 
   if (mPresContext) {
     // We need to notify the destroying the nsPresContext to ESM for
     // suppressing to use from ESM.
     mPresContext->EventStateManager()->NotifyDestroyPresContext(mPresContext);
   }
 
   {
-    nsCOMPtr<nsIObserverService> os =
-      do_GetService("@mozilla.org/observer-service;1");
+    nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
     if (os) {
       os->RemoveObserver(this, "agent-sheet-added");
       os->RemoveObserver(this, "user-sheet-added");
       os->RemoveObserver(this, "agent-sheet-removed");
       os->RemoveObserver(this, "user-sheet-removed");
 #ifdef MOZ_XUL
       os->RemoveObserver(this, "chrome-flush-skin-caches");
 #endif
--- a/layout/base/nsStyleSheetService.cpp
+++ b/layout/base/nsStyleSheetService.cpp
@@ -146,17 +146,17 @@ NS_IMETHODIMP
 nsStyleSheetService::LoadAndRegisterSheet(nsIURI *aSheetURI,
                                           PRUint32 aSheetType)
 {
   nsresult rv = LoadAndRegisterSheetInternal(aSheetURI, aSheetType);
   if (NS_SUCCEEDED(rv)) {
     const char* message = (aSheetType == AGENT_SHEET) ?
       "agent-sheet-added" : "user-sheet-added";
     nsCOMPtr<nsIObserverService> 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]
       const nsCOMArray<nsIStyleSheet> & sheets = mSheets[aSheetType];
       serv->NotifyObservers(sheets[sheets.Count() - 1], message, nsnull);
     }
   }
   return rv;
@@ -207,15 +207,14 @@ nsStyleSheetService::UnregisterSheet(nsI
   PRInt32 foundIndex = FindSheetByURI(mSheets[aSheetType], sheetURI);
   NS_ENSURE_TRUE(foundIndex >= 0, NS_ERROR_INVALID_ARG);
   nsCOMPtr<nsIStyleSheet> sheet = mSheets[aSheetType][foundIndex];
   mSheets[aSheetType].RemoveObjectAt(foundIndex);
   
   const char* message = (aSheetType == AGENT_SHEET) ?
       "agent-sheet-removed" : "user-sheet-removed";
   nsCOMPtr<nsIObserverService> serv =
-    do_GetService("@mozilla.org/observer-service;1");
-  if (serv) {
+    mozilla::services::GetObserverService();
+  if (serv)
     serv->NotifyObservers(sheet, message, nsnull);
-  }
-  
+
   return NS_OK;
 }
--- a/layout/build/nsLayoutModule.cpp
+++ b/layout/build/nsLayoutModule.cpp
@@ -90,16 +90,17 @@
 #include "nsBox.h"
 #include "nsIFrameTraversal.h"
 #include "nsLayoutCID.h"
 #include "nsILanguageAtomService.h"
 #include "nsStyleSheetService.h"
 #include "nsXULPopupManager.h"
 #include "nsFocusManager.h"
 #include "nsIContentUtils.h"
+#include "mozilla/Services.h"
 
 #include "nsIEventListenerService.h"
 // Transformiix stuff
 #include "nsXPathEvaluator.h"
 #include "txMozillaXSLTProcessor.h"
 #include "txNodeSetAdaptor.h"
 #include "nsXPath1Scheme.h"
 
@@ -350,17 +351,17 @@ Initialize(nsIModule* aSelf)
   nsresult rv = nsLayoutStatics::Initialize();
   if (NS_FAILED(rv)) {
     Shutdown();
     return rv;
   }
 
   // Add our shutdown observer.
   nsCOMPtr<nsIObserverService> observerService =
-    do_GetService("@mozilla.org/observer-service;1");
+    mozilla::services::GetObserverService();
 
   if (observerService) {
     LayoutShutdownObserver* observer = new LayoutShutdownObserver();
 
     if (!observer) {
       Shutdown();
 
       return NS_ERROR_OUT_OF_MEMORY;
--- a/layout/forms/nsFileControlFrame.cpp
+++ b/layout/forms/nsFileControlFrame.cpp
@@ -85,16 +85,17 @@
 #include "nsIPrivateBrowsingService.h"
 #include "nsNetCID.h"
 #include "nsIObserver.h"
 #include "nsIObserverService.h"
 #include "nsWeakReference.h"
 #include "nsIVariant.h"
 #include "nsIContentPrefService.h"
 #include "nsIContentURIGrouper.h"
+#include "mozilla/Services.h"
 
 #define SYNC_TEXT 0x1
 #define SYNC_BUTTON 0x2
 #define SYNC_BOTH 0x3
 
 #define CPS_PREF_NAME NS_LITERAL_STRING("browser.upload.lastDir")
 
 class UploadLastDir : public nsIObserver, public nsSupportsWeakReference {
@@ -488,17 +489,17 @@ nsFileControlFrame::MouseListener::Mouse
   return NS_OK;
 }
 
 void nsFileControlFrame::InitUploadLastDir() {
   gUploadLastDir = new UploadLastDir();
   NS_IF_ADDREF(gUploadLastDir);
 
   nsCOMPtr<nsIObserverService> 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);
   }
 }
 
 void nsFileControlFrame::DestroyUploadLastDir() {
   if (gUploadLastDir)
@@ -838,22 +839,20 @@ nsFileControlFrame::BuildDisplayList(nsD
   return DisplaySelectionOverlay(aBuilder, aLists);
 }
 
 #ifdef ACCESSIBILITY
 NS_IMETHODIMP nsFileControlFrame::GetAccessible(nsIAccessible** aAccessible)
 {
   // Accessible object exists just to hold onto its children, for later shutdown
   nsCOMPtr<nsIAccessibilityService> accService = do_GetService("@mozilla.org/accessibilityService;1");
+  if (!accService)
+    return NS_ERROR_FAILURE;
 
-  if (accService) {
-    return accService->CreateHTMLGenericAccessible(static_cast<nsIFrame*>(this), aAccessible);
-  }
-
-  return NS_ERROR_FAILURE;
+  return accService->CreateHTMLGenericAccessible(static_cast<nsIFrame*>(this), aAccessible);
 }
 #endif
 
 ////////////////////////////////////////////////////////////
 // Mouse listener implementation
 
 NS_IMPL_ISUPPORTS2(nsFileControlFrame::MouseListener,
                    nsIDOMMouseListener,
--- a/layout/generic/nsObjectFrame.cpp
+++ b/layout/generic/nsObjectFrame.cpp
@@ -1258,17 +1258,18 @@ nsObjectFrame::SetAbsoluteScreenPosition
   return mInstanceOwner->SetAbsoluteScreenPosition(element, position, clip);
 #else
   return NS_ERROR_NOT_IMPLEMENTED;
 #endif
 }
 
 nsresult
 nsObjectFrame::PluginEventNotifier::Run() {
-  nsCOMPtr<nsIObserverService> obsSvc = do_GetService("@mozilla.org/observer-service;1");
+  nsCOMPtr<nsIObserverService> obsSvc =
+    mozilla::services::GetObserverService();
   obsSvc->NotifyObservers(nsnull, "plugin-changed-event", mEventType.get());
   return NS_OK;
 }
 
 void
 nsObjectFrame::NotifyPluginReflowObservers()
 {
   nsContentUtils::AddScriptRunner(new PluginEventNotifier(NS_LITERAL_STRING("reflow")));
--- a/layout/mathml/nsMathMLChar.cpp
+++ b/layout/mathml/nsMathMLChar.cpp
@@ -574,38 +574,38 @@ nsGlyphTableList::Observe(nsISupports*  
   Finalize();
   return NS_OK;
 }
 
 // Add an observer to XPCOM shutdown so that we can free our data at shutdown
 nsresult
 nsGlyphTableList::Initialize()
 {
-  nsresult rv;
-  nsCOMPtr<nsIObserverService> obs = 
-           do_GetService("@mozilla.org/observer-service;1", &rv);
-  NS_ENSURE_SUCCESS(rv, rv);
+  nsCOMPtr<nsIObserverService> 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;
 }
 
 // Remove our observer and free the memory that were allocated for us
 nsresult
 nsGlyphTableList::Finalize()
 {
   // Remove our observer from the observer service
   nsresult rv = NS_OK;
-  nsCOMPtr<nsIObserverService> obs = 
-           do_GetService("@mozilla.org/observer-service;1", &rv);
-  if (NS_SUCCEEDED(rv)) {
+  nsCOMPtr<nsIObserverService> 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;
 }
 
 nsGlyphTable*
 nsGlyphTableList::AddGlyphTable(const nsString& aPrimaryFontName)
 {
--- a/layout/style/nsCSSRuleProcessor.cpp
+++ b/layout/style/nsCSSRuleProcessor.cpp
@@ -85,16 +85,17 @@
 #include "nsIMediaList.h"
 #include "nsCSSRules.h"
 #include "nsIPrincipal.h"
 #include "nsStyleSet.h"
 #include "prlog.h"
 #include "nsIObserverService.h"
 #include "nsIPrivateBrowsingService.h"
 #include "nsNetCID.h"
+#include "mozilla/Services.h"
 
 #define VISITED_PSEUDO_PREF "layout.css.visited_links_enabled"
 
 static PRBool gSupportVisitedPseudo = PR_TRUE;
 
 static NS_DEFINE_CID(kLookAndFeelCID, NS_LOOKANDFEEL_CID);
 static nsTArray< nsCOMPtr<nsIAtom> >* sSystemMetrics = 0;
 
@@ -798,25 +799,25 @@ nsPrivateBrowsingObserver::nsPrivateBrow
 {
 }
 
 void
 nsPrivateBrowsingObserver::Init()
 {
   nsCOMPtr<nsIPrivateBrowsingService> pbService =
     do_GetService(NS_PRIVATE_BROWSING_SERVICE_CONTRACTID);
-  if (pbService) {
-    pbService->GetPrivateBrowsingEnabled(&mInPrivateBrowsing);
+  if (!pbService)
+    return;
+
+  pbService->GetPrivateBrowsingEnabled(&mInPrivateBrowsing);
 
-    nsCOMPtr<nsIObserverService> observerService =
-      do_GetService("@mozilla.org/observer-service;1");
-    if (observerService) {
-      observerService->AddObserver(this, NS_PRIVATE_BROWSING_SWITCH_TOPIC, PR_TRUE);
-    }
-  }
+  nsCOMPtr<nsIObserverService> observerService =
+    mozilla::services::GetObserverService();
+  if (observerService)
+    observerService->AddObserver(this, NS_PRIVATE_BROWSING_SWITCH_TOPIC, PR_TRUE);
 }
 
 nsresult
 nsPrivateBrowsingObserver::Observe(nsISupports *aSubject,
                                    const char *aTopic,
                                    const PRUnichar *aData)
 {
   if (!strcmp(aTopic, NS_PRIVATE_BROWSING_SWITCH_TOPIC)) {
--- a/layout/style/nsLayoutStylesheetCache.cpp
+++ b/layout/style/nsLayoutStylesheetCache.cpp
@@ -159,17 +159,17 @@ nsLayoutStylesheetCache::Shutdown()
 {
   NS_IF_RELEASE(gCSSLoader);
   NS_IF_RELEASE(gStyleCache);
 }
 
 nsLayoutStylesheetCache::nsLayoutStylesheetCache()
 {
   nsCOMPtr<nsIObserverService> obsSvc =
-    do_GetService("@mozilla.org/observer-service;1");
+    mozilla::services::GetObserverService();
   NS_ASSERTION(obsSvc, "No global observer service?");
 
   if (obsSvc) {
     obsSvc->AddObserver(this, "profile-before-change", PR_FALSE);
     obsSvc->AddObserver(this, "profile-do-change", PR_FALSE);
     obsSvc->AddObserver(this, "chrome-flush-skin-caches", PR_FALSE);
     obsSvc->AddObserver(this, "chrome-flush-caches", PR_FALSE);
   }
--- a/modules/libpr0n/src/imgLoader.cpp
+++ b/modules/libpr0n/src/imgLoader.cpp
@@ -660,19 +660,19 @@ imgCacheQueue & imgLoader::GetCacheQueue
     return sChromeCacheQueue;
   else
     return sCacheQueue;
 }
 
 nsresult imgLoader::InitCache()
 {
   nsresult rv;
-  nsCOMPtr<nsIObserverService> os = do_GetService("@mozilla.org/observer-service;1", &rv);
-  if (NS_FAILED(rv))
-    return rv;
+  nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
+  if (!os)
+    return NS_ERROR_FAILURE;
   
   gCacheObserver = new imgCacheObserver();
   if (!gCacheObserver) 
     return NS_ERROR_OUT_OF_MEMORY;
   NS_ADDREF(gCacheObserver);
 
   os->AddObserver(gCacheObserver, "memory-pressure", PR_FALSE);
   os->AddObserver(gCacheObserver, "chrome-flush-skin-caches", PR_FALSE);
--- a/modules/libpref/src/nsPrefBranch.cpp
+++ b/modules/libpref/src/nsPrefBranch.cpp
@@ -49,16 +49,17 @@
 #include "nsIStringBundle.h"
 #include "prefapi.h"
 #include "prmem.h"
 #include "pldhash.h"
 #include "nsPrefsCID.h"
 
 #include "plstr.h"
 #include "nsCRT.h"
+#include "mozilla/Services.h"
 
 #include "prefapi_private_data.h"
 
 // Definitions
 struct EnumerateData {
   const char  *parent;
   nsVoidArray *pref_list;
 };
@@ -84,18 +85,18 @@ static nsresult
 
 nsPrefBranch::nsPrefBranch(const char *aPrefRoot, PRBool aDefaultBranch)
   : mObservers(nsnull)
 {
   mPrefRoot = aPrefRoot;
   mPrefRootLength = mPrefRoot.Length();
   mIsDefault = aDefaultBranch;
 
-  nsCOMPtr<nsIObserverService> observerService = 
-           do_GetService("@mozilla.org/observer-service;1");
+  nsCOMPtr<nsIObserverService> 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
     observerService->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, PR_TRUE);
     --mRefCnt;
   }
 }
 
--- a/modules/libpref/src/nsPrefService.cpp
+++ b/modules/libpref/src/nsPrefService.cpp
@@ -134,24 +134,25 @@ nsresult nsPrefService::Init()
    */
 
   rv = mRootBranch->GetCharPref("general.config.filename", getter_Copies(lockFileName));
   if (NS_SUCCEEDED(rv))
     NS_CreateServicesFromCategory("pref-config-startup",
                                   static_cast<nsISupports *>(static_cast<void *>(this)),
                                   "pref-config-startup");    
 
-  nsCOMPtr<nsIObserverService> 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<nsIObserverService> 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);
 }
 
 NS_IMETHODIMP nsPrefService::Observe(nsISupports *aSubject, const char *aTopic, const PRUnichar *someData)
 {
   nsresult rv = NS_OK;
 
@@ -242,22 +243,20 @@ NS_IMETHODIMP nsPrefService::GetDefaultB
 
   rv = CallQueryInterface(prefBranch, _retval);
   return rv;
 }
 
 
 nsresult nsPrefService::NotifyServiceObservers(const char *aTopic)
 {
-  nsresult rv;
   nsCOMPtr<nsIObserverService> 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);
   
   return NS_OK;
 }
 
 nsresult nsPrefService::UseDefaultPrefFile()
@@ -699,18 +698,17 @@ static nsresult pref_InitInitialObjects(
   }
 
   rv = pref_LoadPrefsInDirList(NS_APP_PREFS_DEFAULTS_DIR_LIST);
   NS_ENSURE_SUCCESS(rv, rv);
 
   NS_CreateServicesFromCategory(NS_PREFSERVICE_APPDEFAULTS_TOPIC_ID,
                                 nsnull, NS_PREFSERVICE_APPDEFAULTS_TOPIC_ID);
 
-  nsCOMPtr<nsIObserverService> observerService = 
-    do_GetService("@mozilla.org/observer-service;1", &rv);
-  
-  if (NS_FAILED(rv) || !observerService)
-    return rv;
+  nsCOMPtr<nsIObserverService> observerService =
+    mozilla::services::GetObserverService();
+  if (!observerService)
+    return NS_ERROR_FAILURE;
 
   observerService->NotifyObservers(nsnull, NS_PREFSERVICE_APPDEFAULTS_TOPIC_ID, nsnull);
 
   return pref_LoadPrefsInDirList(NS_EXT_PREFS_DEFAULTS_DIR_LIST);
 }
--- a/modules/plugin/base/src/nsNPAPIPlugin.cpp
+++ b/modules/plugin/base/src/nsNPAPIPlugin.cpp
@@ -190,17 +190,17 @@ static NS_DEFINE_IID(kMemoryCID, NS_MEMO
 // This function sends a notification using the observer service to any object
 // registered to listen to the "experimental-notify-plugin-call" subject.
 // Each "experimental-notify-plugin-call" notification carries with it the run
 // time value in milliseconds that the call took to execute.
 void NS_NotifyPluginCall(PRIntervalTime startTime) 
 {
   PRIntervalTime endTime = PR_IntervalNow() - startTime;
   nsCOMPtr<nsIObserverService> notifyUIService =
-    do_GetService("@mozilla.org/observer-service;1");
+    mozilla::services::GetObserverService();
   if (!notifyUIService)
     return;
 
   float runTimeInSeconds = float(endTime) / PR_TicksPerSecond();
   nsAutoString runTimeString;
   runTimeString.AppendFloat(runTimeInSeconds);
   const PRUnichar* runTime = runTimeString.get();
   notifyUIService->NotifyObservers(nsnull, "experimental-notify-plugin-call",
--- a/modules/plugin/base/src/nsPluginHost.cpp
+++ b/modules/plugin/base/src/nsPluginHost.cpp
@@ -1528,17 +1528,18 @@ nsPluginHost::nsPluginHost()
       mPluginsDisabled = tmp;
     }
 
 #ifdef WINCE
     mDefaultPluginDisabled = PR_TRUE;
 #endif
   }
 
-  nsCOMPtr<nsIObserverService> obsService = do_GetService("@mozilla.org/observer-service;1");
+  nsCOMPtr<nsIObserverService> 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);
   }
 
 #ifdef PLUGIN_LOGGING
   nsPluginLogging::gNPNLog = PR_NewLogModule(NPN_LOG_NAME);
   nsPluginLogging::gNPPLog = PR_NewLogModule(NPP_LOG_NAME);
@@ -3550,18 +3551,18 @@ NS_IMETHODIMP nsPluginHost::LoadPlugins(
 
   PRBool pluginschanged;
   nsresult rv = FindPlugins(PR_TRUE, &pluginschanged);
   if (NS_FAILED(rv))
     return rv;
 
   // only if plugins have changed will we notify plugin-change observers
   if (pluginschanged) {
-    nsCOMPtr<nsIObserverService>
-      obsService(do_GetService("@mozilla.org/observer-service;1"));
+    nsCOMPtr<nsIObserverService> obsService =
+      mozilla::services::GetObserverService();
     if (obsService)
       obsService->NotifyObservers(nsnull, "plugins-list-updated", nsnull);
   }
 
   return NS_OK;
 }
 
 #include "nsITimelineService.h"
@@ -5063,17 +5064,17 @@ nsPluginHost::PluginCrashed(nsNPAPIPlugi
     NS_WARNING("nsPluginTag not found in nsPluginHost::PluginCrashed");
     return;
   }
 
   // Notify the app's observer that a plugin crashed so it can submit
   // a crashreport.
   PRBool submittedCrashReport = PR_FALSE;
   nsCOMPtr<nsIObserverService> obsService =
-    do_GetService("@mozilla.org/observer-service;1");
+    mozilla::services::GetObserverService();
   nsCOMPtr<nsIWritablePropertyBag2> propbag =
     do_CreateInstance("@mozilla.org/hash-property-bag;1");
   if (obsService && propbag) {
     propbag->SetPropertyAsAString(NS_LITERAL_STRING("pluginDumpID"),
                                   pluginDumpID);
     propbag->SetPropertyAsAString(NS_LITERAL_STRING("browserDumpID"),
                                   browserDumpID);
     propbag->SetPropertyAsBool(NS_LITERAL_STRING("submittedCrashReport"),
--- a/netwerk/base/src/nsIOService.cpp
+++ b/netwerk/base/src/nsIOService.cpp
@@ -224,17 +224,17 @@ nsIOService::Init()
         prefBranch->AddObserver(PORT_PREF_PREFIX, this, PR_TRUE);
         prefBranch->AddObserver(AUTODIAL_PREF, this, PR_TRUE);
         prefBranch->AddObserver(MANAGE_OFFLINE_STATUS_PREF, this, PR_TRUE);
         PrefsChanged(prefBranch);
     }
     
     // Register for profile change notifications
     nsCOMPtr<nsIObserverService> 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);
         observerService->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, PR_TRUE);
         observerService->AddObserver(this, NS_NETWORK_LINK_TOPIC, PR_TRUE);
     }
     else
         NS_WARNING("failed to get observer service");
@@ -660,17 +660,17 @@ nsIOService::SetOffline(PRBool offline)
     // down the service.
     mSetOfflineValue = offline;
     if (mSettingOffline) {
         return NS_OK;
     }
     mSettingOffline = PR_TRUE;
 
     nsCOMPtr<nsIObserverService> observerService =
-        do_GetService("@mozilla.org/observer-service;1");
+        mozilla::services::GetObserverService();
 
     while (mSetOfflineValue != mOffline) {
         offline = mSetOfflineValue;
 
         nsresult rv;
         if (offline && !mOffline) {
             NS_NAMED_LITERAL_STRING(offlineString, NS_IOSERVICE_OFFLINE);
             mOffline = PR_TRUE; // indicate we're trying to shutdown
--- a/netwerk/base/src/nsIOThreadPool.cpp
+++ b/netwerk/base/src/nsIOThreadPool.cpp
@@ -121,17 +121,17 @@ nsIOThreadPool::Init()
 
     mExitThreadCV = PR_NewCondVar(mLock);
     if (!mExitThreadCV)
         return NS_ERROR_OUT_OF_MEMORY;
 
     PR_INIT_CLIST(&mEventQ);
 
     // We want to shutdown the i/o thread pool at xpcom-shutdown-threads time.
-    nsCOMPtr<nsIObserverService> os = do_GetService("@mozilla.org/observer-service;1");
+    nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
     if (os)
         os->AddObserver(this, "xpcom-shutdown-threads", PR_FALSE);
     return NS_OK;
 }
 
 nsIOThreadPool::~nsIOThreadPool()
 {
     LOG(("Destroying nsIOThreadPool @%p\n", this));
--- a/netwerk/base/src/nsIncrementalDownload.cpp
+++ b/netwerk/base/src/nsIncrementalDownload.cpp
@@ -499,18 +499,17 @@ nsIncrementalDownload::Start(nsIRequestO
 {
   NS_ENSURE_ARG(observer);
   NS_ENSURE_FALSE(mIsPending, NS_ERROR_IN_PROGRESS);
 
   // Observe system shutdown so we can be sure to release any reference held
   // 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<nsIObserverService> obs =
-      do_GetService("@mozilla.org/observer-service;1");
+  nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
   if (obs)
     obs->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, PR_TRUE);
 
   nsresult rv = ReadCurrentSize();
   if (NS_FAILED(rv))
     return rv;
 
   rv = StartTimer(0);
--- a/netwerk/base/src/nsProtocolProxyService.cpp
+++ b/netwerk/base/src/nsProtocolProxyService.cpp
@@ -333,18 +333,17 @@ nsProtocolProxyService::Init()
         // monitor proxy prefs
         prefBranch->AddObserver(PROXY_PREF_BRANCH, this, PR_FALSE);
 
         // read all prefs
         PrefsChanged(prefBranch, nsnull);
     }
 
     // register for shutdown notification so we can clean ourselves up properly.
-    nsCOMPtr<nsIObserverService> obs =
-            do_GetService("@mozilla.org/observer-service;1");
+    nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
     if (obs)
         obs->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, PR_FALSE);
 
     return NS_OK;
 }
 
 NS_IMETHODIMP
 nsProtocolProxyService::Observe(nsISupports     *aSubject,
--- a/netwerk/base/src/nsStreamTransportService.cpp
+++ b/netwerk/base/src/nsStreamTransportService.cpp
@@ -48,16 +48,17 @@
 #include "nsIServiceManager.h"
 #include "nsIAsyncInputStream.h"
 #include "nsIAsyncOutputStream.h"
 #include "nsISeekableStream.h"
 #include "nsIPipe.h"
 #include "nsITransport.h"
 #include "nsIRunnable.h"
 #include "nsIObserverService.h"
+#include "mozilla/Services.h"
 
 //-----------------------------------------------------------------------------
 // nsInputStreamTransport
 //
 // Implements nsIInputStream as a wrapper around the real input stream.  This
 // allows the transport to support seeking, range-limiting, progress reporting,
 // and close-when-done semantics while utilizing NS_AsyncCopy.
 //-----------------------------------------------------------------------------
@@ -476,17 +477,17 @@ nsStreamTransportService::Init()
     NS_ENSURE_STATE(mPool);
 
     // Configure the pool
     mPool->SetThreadLimit(4);
     mPool->SetIdleThreadLimit(1);
     mPool->SetIdleThreadTimeout(PR_SecondsToInterval(60));
 
     nsCOMPtr<nsIObserverService> obsSvc =
-            do_GetService("@mozilla.org/observer-service;1");
+        mozilla::services::GetObserverService();
     if (obsSvc)
         obsSvc->AddObserver(this, "xpcom-shutdown-threads", PR_FALSE);
     return NS_OK;
 }
 
 NS_IMPL_THREADSAFE_ISUPPORTS3(nsStreamTransportService,
                               nsIStreamTransportService,
                               nsIEventTarget,
--- a/netwerk/cache/src/nsCacheService.cpp
+++ b/netwerk/cache/src/nsCacheService.cpp
@@ -66,16 +66,17 @@
 #include "nsAppDirectoryServiceDefs.h"
 #include "nsThreadUtils.h"
 #include "nsProxyRelease.h"
 #include "nsVoidArray.h"
 #include "nsDeleteDir.h"
 #include "nsIPrivateBrowsingService.h"
 #include "nsNetCID.h"
 #include <math.h>  // for log()
+#include "mozilla/Services.h"
 
 
 /******************************************************************************
  * nsCacheProfilePrefObserver
  *****************************************************************************/
 #ifdef XP_MAC
 #pragma mark nsCacheProfilePrefObserver
 #endif
@@ -169,23 +170,23 @@ private:
 };
 
 NS_IMPL_ISUPPORTS1(nsCacheProfilePrefObserver, nsIObserver)
 
 
 nsresult
 nsCacheProfilePrefObserver::Install()
 {
-    nsresult rv, rv2 = NS_OK;
+    // install profile-change observer
+    nsCOMPtr<nsIObserverService> observerService =
+        mozilla::services::GetObserverService();
+    if (!observerService)
+        return NS_ERROR_FAILURE;
     
-    // install profile-change observer
-    nsCOMPtr<nsIObserverService> observerService = do_GetService("@mozilla.org/observer-service;1", &rv);
-    NS_ENSURE_SUCCESS(rv, rv);
-    NS_ENSURE_ARG(observerService);
-    
+    nsresult rv, rv2 = NS_OK;
     for (unsigned int i=0; i<NS_ARRAY_LENGTH(observerList); i++) {
         rv = observerService->AddObserver(this, observerList[i], PR_FALSE);
         if (NS_FAILED(rv)) 
             rv2 = rv;
     }
     
     // install preferences observer
     nsCOMPtr<nsIPrefBranch2> branch = do_GetService(NS_PREFSERVICE_CONTRACTID);
@@ -205,51 +206,48 @@ nsCacheProfilePrefObserver::Install()
 
     // Determine if we have a profile already
     //     Install() is called *after* the profile-after-change notification
     //     when there is only a single profile, or it is specified on the
     //     commandline at startup.
     //     In that case, we detect the presence of a profile by the existence
     //     of the NS_APP_USER_PROFILE_50_DIR directory.
 
-    nsCOMPtr<nsIFile>  directory;
+    nsCOMPtr<nsIFile> 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);
 
     return rv2;
 }
 
 
 void
 nsCacheProfilePrefObserver::Remove()
 {
     // remove Observer Service observers
     nsCOMPtr<nsIObserverService> obs =
-            do_GetService("@mozilla.org/observer-service;1");
+        mozilla::services::GetObserverService();
     if (obs) {
         for (unsigned int i=0; i<NS_ARRAY_LENGTH(observerList); i++) {
             obs->RemoveObserver(this, observerList[i]);
         }
     }
 
     // remove Pref Service observers
     nsCOMPtr<nsIPrefBranch2> prefs =
-           do_GetService(NS_PREFSERVICE_CONTRACTID);
-    if (prefs) {
-        for (unsigned int i=0; i<NS_ARRAY_LENGTH(prefList); i++) {
-            // remove cache pref observers
-            prefs->RemoveObserver(prefList[i], this);
-        }
-    }
+        do_GetService(NS_PREFSERVICE_CONTRACTID);
+    if (!prefs)
+        return;
+    for (unsigned int i=0; i<NS_ARRAY_LENGTH(prefList); i++)
+        prefs->RemoveObserver(prefList[i], this); // remove cache pref observers
 }
 
 
 NS_IMETHODIMP
 nsCacheProfilePrefObserver::Observe(nsISupports *     subject,
                                     const char *      topic,
                                     const PRUnichar * data_unicode)
 {
@@ -789,17 +787,17 @@ nsCacheService::EvictEntriesForSession(n
 
 nsresult
 nsCacheService::EvictEntriesForClient(const char *          clientID,
                                       nsCacheStoragePolicy  storagePolicy)
 {
     if (this == nsnull) return NS_ERROR_NOT_AVAILABLE; // XXX eh?
 
     nsCOMPtr<nsIObserverService> 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
         // notification happens before or after the actual eviction.
 
         nsCOMPtr<nsIObserverService> obsProxy;
         NS_GetProxyForObject(NS_PROXY_TO_MAIN_THREAD,
                              NS_GET_IID(nsIObserverService), obsSvc,
--- a/netwerk/cookie/src/nsCookieService.cpp
+++ b/netwerk/cookie/src/nsCookieService.cpp
@@ -540,17 +540,17 @@ nsCookieService::Init()
   }
 
   // failure here is non-fatal (we can run fine without
   // persistent storage - e.g. if there's no profile)
   rv = InitDB();
   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);
     mObserverService->AddObserver(this, NS_PRIVATE_BROWSING_SWITCH_TOPIC, PR_TRUE);
 
     nsCOMPtr<nsIPrivateBrowsingService> pbs =
       do_GetService(NS_PRIVATE_BROWSING_SERVICE_CONTRACTID);
     if (pbs) {
--- a/netwerk/protocol/ftp/src/nsFtpProtocolHandler.cpp
+++ b/netwerk/protocol/ftp/src/nsFtpProtocolHandler.cpp
@@ -118,32 +118,31 @@ NS_IMPL_THREADSAFE_ISUPPORTS4(nsFtpProto
                               nsIProtocolHandler,
                               nsIProxiedProtocolHandler,
                               nsIObserver,
                               nsISupportsWeakReference)
 
 nsresult
 nsFtpProtocolHandler::Init()
 {
-    nsresult rv;
-
     if (mIdleTimeout == -1) {
+        nsresult rv;
         nsCOMPtr<nsIPrefBranch2> branch = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv);
         if (NS_FAILED(rv)) return rv;
 
         rv = branch->GetIntPref(IDLE_TIMEOUT_PREF, &mIdleTimeout);
         if (NS_FAILED(rv))
             mIdleTimeout = 5*60; // 5 minute default
 
         rv = branch->AddObserver(IDLE_TIMEOUT_PREF, this, PR_TRUE);
         if (NS_FAILED(rv)) return rv;
     }
 
     nsCOMPtr<nsIObserverService> observerService =
-        do_GetService("@mozilla.org/observer-service;1");
+        mozilla::services::GetObserverService();
     if (observerService) {
         observerService->AddObserver(this,
                                      "network:offline-about-to-go-offline",
                                      PR_TRUE);
 
         observerService->AddObserver(this,
                                      "net:clear-active-logins",
                                      PR_TRUE);
--- a/netwerk/protocol/http/src/nsHttpHandler.cpp
+++ b/netwerk/protocol/http/src/nsHttpHandler.cpp
@@ -286,17 +286,17 @@ nsHttpHandler::Init()
         mProductSub.SetLength(8);
 
     // Startup the http category
     // Bring alive the objects in the http-protocol-startup category
     NS_CreateServicesFromCategory(NS_HTTP_STARTUP_CATEGORY,
                                   static_cast<nsISupports*>(static_cast<void*>(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);
         mObserverService->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, PR_TRUE);
         mObserverService->AddObserver(this, "net:clear-active-logins", PR_TRUE);
         mObserverService->AddObserver(this, "xpcom-shutdown-threads", PR_TRUE);
     }
  
--- a/netwerk/system/maemo/nsMaemoNetworkLinkService.cpp
+++ b/netwerk/system/maemo/nsMaemoNetworkLinkService.cpp
@@ -24,16 +24,17 @@
  * ***** END LICENSE BLOCK ***** */
 
 #include "nsMaemoNetworkLinkService.h"
 #include "nsCOMPtr.h"
 #include "nsIObserverService.h"
 #include "nsServiceManagerUtils.h"
 #include "nsString.h"
 #include "nsMaemoNetworkManager.h"
+#include "mozilla/Services.h"
 
 NS_IMPL_ISUPPORTS2(nsMaemoNetworkLinkService,
                    nsINetworkLinkService,
                    nsIObserver)
 
 nsMaemoNetworkLinkService::nsMaemoNetworkLinkService()
 {
 }
@@ -65,23 +66,22 @@ nsMaemoNetworkLinkService::Observe(nsISu
     Shutdown();
 
   return NS_OK;
 }
 
 nsresult
 nsMaemoNetworkLinkService::Init(void)
 {
-  nsresult rv;
+  nsCOMPtr<nsIObserverService> observerService =
+    mozilla::services::GetObserverService();
+  if (!observerService)
+    return NS_ERROR_FAILURE;
 
-  nsCOMPtr<nsIObserverService> observerService =
-    do_GetService("@mozilla.org/observer-service;1", &rv);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  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())
     return NS_ERROR_FAILURE;
 
   return NS_OK;
 }
 
--- a/netwerk/system/win32/nsNotifyAddrListener.cpp
+++ b/netwerk/system/win32/nsNotifyAddrListener.cpp
@@ -48,16 +48,17 @@
 #include "prmem.h"
 #include "plstr.h"
 #include "nsThreadUtils.h"
 #include "nsIObserverService.h"
 #include "nsServiceManagerUtils.h"
 #include "nsNotifyAddrListener.h"
 #include "nsString.h"
 #include "nsAutoPtr.h"
+#include "mozilla/Services.h"
 
 #include <iptypes.h>
 #include <iphlpapi.h>
 
 typedef DWORD (WINAPI *GetAdaptersAddressesFunc)(ULONG, DWORD, PVOID,
                                                  PIP_ADAPTER_ADDRESSES,
                                                  PULONG);
 typedef DWORD (WINAPI *GetAdaptersInfoFunc)(PIP_ADAPTER_INFO, PULONG);
@@ -224,40 +225,40 @@ nsNotifyAddrListener::Init(void)
     //
     // CheckLinkStatus();
 
     // only start a thread on Windows 2000 or later
     if (mOSVerInfo.dwPlatformId != VER_PLATFORM_WIN32_NT ||
         mOSVerInfo.dwMajorVersion < 5)
         return NS_OK;
 
-    nsresult rv;
     nsCOMPtr<nsIObserverService> 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);
     NS_ENSURE_TRUE(mShutdownEvent, NS_ERROR_OUT_OF_MEMORY);
 
     rv = NS_NewThread(getter_AddRefs(mThread), this);
     NS_ENSURE_SUCCESS(rv, rv);
 
     return NS_OK;
 }
 
 nsresult
 nsNotifyAddrListener::Shutdown(void)
 {
     // remove xpcom shutdown observer
     nsCOMPtr<nsIObserverService> observerService =
-        do_GetService("@mozilla.org/observer-service;1");
+        mozilla::services::GetObserverService();
     if (observerService)
         observerService->RemoveObserver(this, "xpcom-shutdown-threads");
 
     if (!mShutdownEvent)
         return NS_OK;
 
     SetEvent(mShutdownEvent);
 
@@ -289,17 +290,17 @@ nsNotifyAddrListener::SendEventToUI(cons
         NS_WARNING("Failed to dispatch ChangeEvent");
     return rv;
 }
 
 NS_IMETHODIMP
 nsNotifyAddrListener::ChangeEvent::Run()
 {
     nsCOMPtr<nsIObserverService> observerService =
-        do_GetService("@mozilla.org/observer-service;1");
+        mozilla::services::GetObserverService();
     if (observerService)
         observerService->NotifyObservers(
                 mService, NS_NETWORK_LINK_TOPIC,
                 NS_ConvertASCIItoUTF16(mEventID).get());
     return NS_OK;
 }
 
 DWORD
--- a/netwerk/wifi/src/nsWifiMonitor.cpp
+++ b/netwerk/wifi/src/nsWifiMonitor.cpp
@@ -47,16 +47,17 @@
 #include "nsAutoLock.h"
 #include "nsIObserver.h"
 #include "nsIObserverService.h"
 #include "nsWifiMonitor.h"
 
 #include "nsIProxyObjectManager.h"
 #include "nsServiceManagerUtils.h"
 #include "nsComponentManagerUtils.h"
+#include "mozilla/Services.h"
 
 #if defined(PR_LOGGING)
 PRLogModuleInfo *gWifiMonitorLog;
 #endif
 
 NS_IMPL_THREADSAFE_ISUPPORTS3(nsWifiMonitor,
                               nsIRunnable,
                               nsIObserver,
@@ -66,17 +67,17 @@ nsWifiMonitor::nsWifiMonitor()
 : mKeepGoing(PR_TRUE)
 {
 #if defined(PR_LOGGING)
   gWifiMonitorLog = PR_NewLogModule("WifiMonitor");
 #endif
 
   mMonitor = nsAutoMonitor::NewMonitor("nsWifiMonitor");
 
-  nsCOMPtr<nsIObserverService> obsSvc = do_GetService("@mozilla.org/observer-service;1");
+  nsCOMPtr<nsIObserverService> obsSvc = mozilla::services::GetObserverService();
   if (obsSvc)
     obsSvc->AddObserver(this, "xpcom-shutdown", PR_FALSE);
 
   LOG(("@@@@@ wifimonitor created\n"));
 }
 
 nsWifiMonitor::~nsWifiMonitor()
 {
--- a/parser/html/nsHtml5Module.cpp
+++ b/parser/html/nsHtml5Module.cpp
@@ -43,16 +43,17 @@
 #include "nsHtml5Portability.h"
 #include "nsHtml5StackNode.h"
 #include "nsHtml5Tokenizer.h"
 #include "nsHtml5TreeBuilder.h"
 #include "nsHtml5UTF16Buffer.h"
 #include "nsHtml5Module.h"
 #include "nsIObserverService.h"
 #include "nsIServiceManager.h"
+#include "mozilla/Services.h"
 
 // static
 PRBool nsHtml5Module::sEnabled = PR_FALSE;
 PRBool nsHtml5Module::sOffMainThread = PR_TRUE;
 nsIThread* nsHtml5Module::sStreamParserThread = nsnull;
 nsIThread* nsHtml5Module::sMainThread = nsnull;
 
 // static
@@ -142,17 +143,17 @@ NS_IMPL_ISUPPORTS1(nsHtml5ParserThreadTe
 // static 
 nsIThread*
 nsHtml5Module::GetStreamParserThread()
 {
   if (sOffMainThread) {
     if (!sStreamParserThread) {
       NS_NewThread(&sStreamParserThread);
       NS_ASSERTION(sStreamParserThread, "Thread creation failed!");
-      nsCOMPtr<nsIObserverService> os = do_GetService("@mozilla.org/observer-service;1");
+      nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
       NS_ASSERTION(os, "do_GetService failed");
       os->AddObserver(new nsHtml5ParserThreadTerminator(sStreamParserThread), 
                       "xpcom-shutdown-threads",
                       PR_FALSE);
     }
     return sStreamParserThread;
   }
   if (!sMainThread) {
--- a/profile/dirserviceprovider/src/nsProfileDirServiceProvider.cpp
+++ b/profile/dirserviceprovider/src/nsProfileDirServiceProvider.cpp
@@ -40,16 +40,17 @@
 #include "nsProfileStringTypes.h"
 #include "nsProfileLock.h"
 #include "nsILocalFile.h"
 #include "nsDirectoryServiceDefs.h"
 #include "nsAppDirectoryServiceDefs.h"
 #include "nsISupportsUtils.h"
 #include "nsISimpleEnumerator.h"
 #include "nsIObserverService.h"
+#include "mozilla/Services.h"
 
 // File Name Defines
 
 #define PREFS_FILE_50_NAME           NS_LITERAL_CSTRING("prefs.js")
 #define USER_CHROME_DIR_50_NAME      NS_LITERAL_CSTRING("chrome")
 #define LOCAL_STORE_FILE_50_NAME     NS_LITERAL_CSTRING("localstore.rdf")
 #define HISTORY_FILE_50_NAME         NS_LITERAL_CSTRING("history.dat")
 #define PANELS_FILE_50_NAME          NS_LITERAL_CSTRING("panels.rdf")
@@ -122,17 +123,17 @@ nsProfileDirServiceProvider::SetProfileD
     dirToLock = do_QueryInterface(mProfileDir);
   rv = mProfileDirLock->Lock(dirToLock, nsnull);
   if (NS_FAILED(rv))
     return rv;
 #endif
 
   if (mNotifyObservers) {
     nsCOMPtr<nsIObserverService> observerService =
-             do_GetService("@mozilla.org/observer-service;1");
+      mozilla::services::GetObserverService();
     if (!observerService)
       return NS_ERROR_FAILURE;
 
     NS_NAMED_LITERAL_STRING(context, "startup");
     // Notify observers that the profile has changed - Here they respond to new profile
     observerService->NotifyObservers(nsnull, "profile-do-change", context.get());
     // Now observers can respond to something another observer did on "profile-do-change"
     observerService->NotifyObservers(nsnull, "profile-after-change", context.get());
@@ -153,17 +154,17 @@ nsProfileDirServiceProvider::Register()
 
 nsresult
 nsProfileDirServiceProvider::Shutdown()
 {
   if (!mNotifyObservers)
     return NS_OK;
 
   nsCOMPtr<nsIObserverService> observerService =
-           do_GetService("@mozilla.org/observer-service;1");
+    mozilla::services::GetObserverService();
   if (!observerService)
     return NS_ERROR_FAILURE;
 
   NS_NAMED_LITERAL_STRING(context, "shutdown-persist");
   observerService->NotifyObservers(nsnull, "profile-before-change", context.get());
   return NS_OK;
 }
 
--- a/storage/src/mozStorageService.cpp
+++ b/storage/src/mozStorageService.cpp
@@ -46,16 +46,17 @@
 #include "nsAutoPtr.h"
 #include "nsCollationCID.h"
 #include "nsEmbedCID.h"
 #include "mozStoragePrivateHelpers.h"
 #include "nsILocale.h"
 #include "nsILocaleService.h"
 #include "nsIXPConnect.h"
 #include "nsIObserverService.h"
+#include "mozilla/Services.h"
 
 #include "sqlite3.h"
 
 #include "nsIPromptService.h"
 
 namespace mozilla {
 namespace storage {
 
@@ -165,17 +166,17 @@ Service::initialize()
   // only ever called from Service::GetSingleton, which will only
   // call this function once, and will not return until this function returns.
   // (It does not matter where this is called relative to sqlite3_initialize.)
   rc = ::sqlite3_enable_shared_cache(1);
   if (rc != SQLITE_OK)
     return convertResultCode(rc);
 
   nsCOMPtr<nsIObserverService> 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);
   NS_ENSURE_SUCCESS(rv, rv);
 
   // We cache XPConnect for our language helpers.
   (void)CallGetService(nsIXPConnect::GetCID(), &sXPConnect);
   return NS_OK;
--- a/toolkit/components/autocomplete/src/nsAutoCompleteController.cpp
+++ b/toolkit/components/autocomplete/src/nsAutoCompleteController.cpp
@@ -48,16 +48,17 @@
 #include "nsIServiceManager.h"
 #include "nsIAtomService.h"
 #include "nsReadableUtils.h"
 #include "nsUnicharUtils.h"
 #include "nsITreeColumns.h"
 #include "nsIGenericFactory.h"
 #include "nsIObserverService.h"
 #include "nsIDOMKeyEvent.h"
+#include "mozilla/Services.h"
 
 static const char *kAutoCompleteSearchCID = "@mozilla.org/autocomplete/search;1?name=";
 
 NS_IMPL_CYCLE_COLLECTION_CLASS(nsAutoCompleteController)
 NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsAutoCompleteController)
   tmp->SetInput(nsnull);
 NS_IMPL_CYCLE_COLLECTION_UNLINK_END
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsAutoCompleteController)
@@ -1128,17 +1129,17 @@ nsAutoCompleteController::EnterMatch(PRB
             break;
           }
         }
       }
     }
   }
 
   nsCOMPtr<nsIObserverService> obsSvc =
-    do_GetService("@mozilla.org/observer-service;1");
+    mozilla::services::GetObserverService();
   NS_ENSURE_STATE(obsSvc);
   obsSvc->NotifyObservers(input, "autocomplete-will-enter-text", nsnull);
 
   if (!value.IsEmpty()) {
     input->SetTextValue(value);
     input->SelectTextRange(value.Length(), value.Length());
     mSearchString = value;
   }
@@ -1164,17 +1165,17 @@ nsAutoCompleteController::RevertTextValu
   nsAutoString oldValue(mSearchString);
   nsCOMPtr<nsIAutoCompleteInput> input(mInput);
 
   PRBool cancel = PR_FALSE;
   input->OnTextReverted(&cancel);
 
   if (!cancel) {
     nsCOMPtr<nsIObserverService> obsSvc =
-      do_GetService("@mozilla.org/observer-service;1");
+      mozilla::services::GetObserverService();
     NS_ENSURE_STATE(obsSvc);
     obsSvc->NotifyObservers(input, "autocomplete-will-revert-text", nsnull);
 
     input->SetTextValue(oldValue);
 
     obsSvc->NotifyObservers(input, "autocomplete-did-revert-text", nsnull);
   }
 
--- a/toolkit/components/downloads/src/nsDownloadManager.cpp
+++ b/toolkit/components/downloads/src/nsDownloadManager.cpp
@@ -837,19 +837,21 @@ nsDownloadManager::Init()
     if (NS_SUCCEEDED(NS_GetSpecialDirectory(NS_APP_DOWNLOADS_50_FILE,
           getter_AddRefs(oldDownloadsFile))) &&
         NS_SUCCEEDED(oldDownloadsFile->Exists(&fileExists)) &&
         fileExists) {
       (void)oldDownloadsFile->Remove(PR_FALSE);
     }
   }
 
+  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<nsIStringBundleService> bundleService =
     do_GetService(NS_STRINGBUNDLE_CONTRACTID, &rv);
   NS_ENSURE_SUCCESS(rv, rv);
 
   rv = InitDB();
   NS_ENSURE_SUCCESS(rv, rv);
 
--- a/toolkit/components/places/src/nsFaviconService.cpp
+++ b/toolkit/components/places/src/nsFaviconService.cpp
@@ -1055,17 +1055,17 @@ ExpireFaviconsStatementCallbackNotifier:
 {
   *mFaviconsExpirationRunning = false;
 
   // We should dispatch only if expiration has been successful.
   if (aReason != mozIStorageStatementCallback::REASON_FINISHED)
     return NS_OK;
 
   nsCOMPtr<nsIObserverService> observerService =
-    do_GetService("@mozilla.org/observer-service;1");
+    mozilla::services::GetObserverService();
   if (observerService) {
     (void)observerService->NotifyObservers(nsnull,
                                            NS_PLACES_FAVICONS_EXPIRED_TOPIC_ID,
                                            nsnull);
   }
 
   return NS_OK;
 }
--- a/toolkit/components/satchel/src/nsStorageFormHistory.cpp
+++ b/toolkit/components/satchel/src/nsStorageFormHistory.cpp
@@ -67,16 +67,17 @@
 #include "nsIPrefBranch2.h"
 #include "nsCOMArray.h"
 #include "mozStorageHelper.h"
 #include "mozStorageCID.h"
 #include "nsTArray.h"
 #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")
 #define DB_CORRUPT_FILENAME NS_LITERAL_STRING("formhistory.sqlite.corrupt")
 
 #define PR_HOURS ((PRInt64)60 * 60 * 1000000)
 
 // Limit the length of names and values stored in form history
@@ -136,17 +137,17 @@ nsFormHistory::Init()
     /* If the DB is corrupt, nuke it and try again with a new DB. */
     rv = dbCleanup();
     NS_ENSURE_SUCCESS(rv, rv);
     rv = OpenDatabase(&doImport);
     doImport = PR_FALSE;
   }
   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);
     mObserverService->AddObserver(this, "formhistory-expire-now", PR_TRUE);
   }
 
   return NS_OK;
 }
--- a/toolkit/components/startup/src/nsAppStartup.cpp
+++ b/toolkit/components/startup/src/nsAppStartup.cpp
@@ -63,16 +63,17 @@
 #include "nsAutoPtr.h"
 #include "nsStringGlue.h"
 
 #include "prprf.h"
 #include "nsCRT.h"
 #include "nsIInterfaceRequestorUtils.h"
 #include "nsWidgetsCID.h"
 #include "nsAppShellCID.h"
+#include "mozilla/Services.h"
 
 static NS_DEFINE_CID(kAppShellCID, NS_APPSHELL_CID);
 
 class nsAppExitEvent : public nsRunnable {
 private:
   nsRefPtr<nsAppStartup> mService;
 
 public:
@@ -106,19 +107,20 @@ nsresult
 nsAppStartup::Init()
 {
   nsresult rv;
 
   // Create widget application shell
   mAppShell = do_GetService(kAppShellCID, &rv);
   NS_ENSURE_SUCCESS(rv, rv);
 
-  nsCOMPtr<nsIObserverService> os
-    (do_GetService("@mozilla.org/observer-service;1", &rv));
-  NS_ENSURE_SUCCESS(rv, rv);
+  nsCOMPtr<nsIObserverService> 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);
   os->AddObserver(this, "xul-window-registered", PR_TRUE);
   os->AddObserver(this, "xul-window-destroyed", PR_TRUE);
 
   return NS_OK;
 }
@@ -251,17 +253,17 @@ nsAppStartup::Quit(PRUint32 aMode)
         }
       }
     }
 
     mShuttingDown = PR_TRUE;
     if (!mRestart)
       mRestart = (aMode & eRestart) != 0;
 
-    obsService = do_GetService("@mozilla.org/observer-service;1");
+    obsService = mozilla::services::GetObserverService();
 
     if (!mAttemptingQuit) {
       mAttemptingQuit = PR_TRUE;
 #ifdef XP_MACOSX
       // now even the Mac wants to quit when the last window is closed
       ExitLastWindowClosingSurvivalArea();
 #endif
       if (obsService)
--- a/toolkit/components/url-classifier/src/nsUrlClassifierDBService.cpp
+++ b/toolkit/components/url-classifier/src/nsUrlClassifierDBService.cpp
@@ -3943,17 +3943,17 @@ nsUrlClassifierDBService::Init()
                             NS_PROXY_ASYNC,
                             getter_AddRefs(mWorkerProxy));
   NS_ENSURE_SUCCESS(rv, rv);
 
   mCompleters.Init();
 
   // Add an observer for shutdown
   nsCOMPtr<nsIObserverService> observerService =
-      do_GetService("@mozilla.org/observer-service;1");
+      mozilla::services::GetObserverService();
   if (!observerService)
     return NS_ERROR_FAILURE;
 
   observerService->AddObserver(this, "profile-before-change", PR_FALSE);
   observerService->AddObserver(this, "xpcom-shutdown-threads", PR_FALSE);
 
   return NS_OK;
 }
--- a/toolkit/components/url-classifier/src/nsUrlClassifierHashCompleter.cpp
+++ b/toolkit/components/url-classifier/src/nsUrlClassifierHashCompleter.cpp
@@ -85,17 +85,17 @@ nsUrlClassifierHashCompleterRequest::Beg
 
   if (PR_IntervalNow() < mCompleter->GetNextRequestTime()) {
     NS_WARNING("Gethash server backed off, failing gethash request.");
     NotifyFailure(NS_ERROR_ABORT);
     return NS_ERROR_ABORT;
   }
 
   nsCOMPtr<nsIObserverService> observerService =
-    do_GetService("@mozilla.org/observer-service;1");
+    mozilla::services::GetObserverService();
   if (observerService)
     observerService->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, PR_FALSE);
 
   nsresult rv = OpenChannel();
   if (NS_FAILED(rv)) {
     NotifyFailure(rv);
     return rv;
   }
@@ -466,17 +466,17 @@ NS_IMETHODIMP
 nsUrlClassifierHashCompleterRequest::OnStopRequest(nsIRequest *request,
                                                    nsISupports *context,
                                                    nsresult status)
 {
   LOG(("nsUrlClassifierHashCompleter::OnStopRequest [%p, status=%d]",
        this, status));
 
   nsCOMPtr<nsIObserverService> observerService =
-    do_GetService("@mozilla.org/observer-service;1");
+    mozilla::services::GetObserverService();
   if (observerService)
     observerService->RemoveObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID);
 
   if (mShuttingDown)
     return NS_ERROR_ABORT;
 
   if (NS_SUCCEEDED(status)) {
     nsCOMPtr<nsIHttpChannel> channel = do_QueryInterface(request);
@@ -532,17 +532,17 @@ nsresult
 nsUrlClassifierHashCompleter::Init()
 {
 #if defined(PR_LOGGING)
   if (!gUrlClassifierHashCompleterLog)
     gUrlClassifierHashCompleterLog = PR_NewLogModule("UrlClassifierHashCompleter");
 #endif
 
   nsCOMPtr<nsIObserverService> observerService =
-    do_GetService("@mozilla.org/observer-service;1");
+    mozilla::services::GetObserverService();
   if (observerService)
     observerService->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, PR_TRUE);
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsUrlClassifierHashCompleter::Complete(const nsACString &partialHash,
@@ -668,27 +668,24 @@ nsresult
 nsUrlClassifierHashCompleter::RekeyRequested()
 {
   // Our keys are no longer valid.
   SetKeys(EmptyCString(), EmptyCString());
 
   // 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<nsIObserverService> 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<nsIUrlClassifierHashCompleter*>(this),
-                                        "url-classifier-rekey-requested",
-                                        nsnull);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  return NS_OK;
+  return observerService->NotifyObservers(static_cast<nsIUrlClassifierHashCompleter*>(this),
+                                          "url-classifier-rekey-requested",
+                                          nsnull);
 }
 
 void
 nsUrlClassifierHashCompleter::NoteServerResponse(PRBool success)
 {
   LOG(("nsUrlClassifierHashCompleter::NoteServerResponse [%p, %d]",
        this, success));
 
--- a/toolkit/components/url-classifier/src/nsUrlClassifierStreamUpdater.cpp
+++ b/toolkit/components/url-classifier/src/nsUrlClassifierStreamUpdater.cpp
@@ -207,17 +207,17 @@ nsUrlClassifierStreamUpdater::DownloadUp
 
   nsresult rv;
 
   if (!mInitialized) {
     // Add an observer for shutdown so we can cancel any pending list
     // downloads.  quit-application is the same event that the download
     // manager listens for and uses to cancel pending downloads.
     nsCOMPtr<nsIObserverService> observerService =
-        do_GetService("@mozilla.org/observer-service;1");
+      mozilla::services::GetObserverService();
     if (!observerService)
       return NS_ERROR_FAILURE;
 
     observerService->AddObserver(this, gQuitApplicationMessage, PR_FALSE);
 
     mDBService = do_GetService(NS_URLCLASSIFIERDBSERVICE_CONTRACTID, &rv);
     NS_ENSURE_SUCCESS(rv, rv);
 
@@ -269,20 +269,21 @@ nsUrlClassifierStreamUpdater::UpdateUrlR
   update->mServerMAC = aServerMAC;
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsUrlClassifierStreamUpdater::RekeyRequested()
 {
-  nsresult rv;
   nsCOMPtr<nsIObserverService> 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<nsIUrlClassifierStreamUpdater*>(this),
                                           "url-classifier-rekey-requested",
                                           nsnull);
 }
 
 nsresult
 nsUrlClassifierStreamUpdater::FetchNext()
--- a/toolkit/xre/nsAppRunner.cpp
+++ b/toolkit/xre/nsAppRunner.cpp
@@ -3433,18 +3433,18 @@ XRE_main(int argc, char* argv[], const n
           NS_ENSURE_TRUE(cmdLine, 1);
 
           rv = cmdLine->Init(gArgc, gArgv,
                              workingDir, nsICommandLine::STATE_INITIAL_LAUNCH);
           NS_ENSURE_SUCCESS(rv, 1);
 
           /* Special-case services that need early access to the command
              line. */
-          nsCOMPtr<nsIObserverService> obsService
-            (do_GetService("@mozilla.org/observer-service;1"));
+          nsCOMPtr<nsIObserverService> obsService =
+            mozilla::services::GetObserverService();
           if (obsService) {
             obsService->NotifyObservers(cmdLine, "command-line-startup", nsnull);
           }
 
           NS_TIME_FUNCTION_MARK("Next: CreateHiddenWindow");
 
           NS_TIMELINE_ENTER("appStartup->CreateHiddenWindow");
           rv = appStartup->CreateHiddenWindow();
@@ -3519,18 +3519,18 @@ XRE_main(int argc, char* argv[], const n
 #endif
 #ifdef MOZ_WIDGET_COCOA
             // Prepare Cocoa's form of Apple Event handling.
             SetupMacApplicationDelegate();
 #endif
 
             MOZ_SPLASHSCREEN_UPDATE(70);
 
-            nsCOMPtr<nsIObserverService> obsService
-              (do_GetService("@mozilla.org/observer-service;1"));
+            nsCOMPtr<nsIObserverService> obsService =
+              mozilla::services::GetObserverService();
             if (obsService)
               obsService->NotifyObservers(nsnull, "final-ui-startup", nsnull);
 
             appStartup->GetShuttingDown(&shuttingDown);
           }
 
           if (!shuttingDown) {
             rv = cmdLine->Run();
--- a/toolkit/xre/nsNativeAppSupportOS2.cpp
+++ b/toolkit/xre/nsNativeAppSupportOS2.cpp
@@ -1007,18 +1007,17 @@ nsNativeAppSupportOS2::Quit() {
 
     return NS_OK;
 }
 
 NS_IMETHODIMP
 nsNativeAppSupportOS2::Enable()
 {
     mCanHandleRequests = PR_TRUE;
-    nsCOMPtr<nsIObserverService> obs
-        (do_GetService("@mozilla.org/observer-service;1"));
+    nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
     if (obs) {
         obs->AddObserver(this, "quit-application", PR_FALSE);
     } else {
         NS_ERROR("No observer service?");
     }
 
     return NS_OK;
 }
--- a/toolkit/xre/nsNativeAppSupportUnix.cpp
+++ b/toolkit/xre/nsNativeAppSupportUnix.cpp
@@ -54,16 +54,17 @@
 #include "nsIWindowMediator.h"
 #include "nsIDOMWindowInternal.h"
 #include "nsPIDOMWindow.h"
 #include "nsIDocShell.h"
 #include "nsIBaseWindow.h"
 #include "nsIWidget.h"
 #include "nsIWritablePropertyBag2.h"
 #include "nsIPrefService.h"
+#include "mozilla/Services.h"
 
 #include <stdlib.h>
 #include <glib.h>
 #include <glib-object.h>
 #include <gtk/gtk.h>
 
 #ifdef MOZ_X11
 #include <gdk/gdkx.h>
@@ -124,17 +125,17 @@ typedef void (*_gnome_client_set_restart
 static _gnome_client_set_restart_command_fn gnome_client_set_restart_command;
 
 gboolean save_yourself_cb(GnomeClient *client, gint phase,
                           GnomeSaveStyle style, gboolean shutdown,
                           GnomeInteractStyle interact, gboolean fast,
                           gpointer user_data)
 {
   nsCOMPtr<nsIObserverService> obsServ =
-    do_GetService("@mozilla.org/observer-service;1");
+    mozilla::services::GetObserverService();
 
   nsCOMPtr<nsISupportsPRBool> didSaveSession =
     do_CreateInstance(NS_SUPPORTS_PRBOOL_CONTRACTID);
 
   if (!obsServ || !didSaveSession)
     return TRUE; // OOM
 
   // Notify observers to save the session state
@@ -292,17 +293,17 @@ static void OssoRequestAccelerometer(oss
   if (rv == OSSO_OK && aEnabled) {    
       OssoSetWindowOrientation(strcmp(ret.value.s, "portrait") == 0);
       osso_rpc_free_val(&ret);
   }
 }
 
 static void OssoDisplayCallback(osso_display_state_t state, gpointer data)
 {
-  nsCOMPtr<nsIObserverService> os = do_GetService("@mozilla.org/observer-service;1");
+  nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
   if (!os)
       return;
 
   osso_context_t* context = (osso_context_t*) data;
 
   if (state == OSSO_DISPLAY_ON) {
       os->NotifyObservers(nsnull, "system-display-on", nsnull);
       OssoRequestAccelerometer(context, PR_TRUE);
@@ -321,26 +322,24 @@ static void OssoHardwareCallback(osso_hw
 
   if (state->shutdown_ind) {
     nsCOMPtr<nsIAppStartup> appService = do_GetService("@mozilla.org/toolkit/app-startup;1");
     if (appService)
       appService->Quit(nsIAppStartup::eForceQuit);
     return;
   }
 
-  if (state->memory_low_ind) {
-      if (! ourState->memory_low_ind) {
-      nsCOMPtr<nsIObserverService> 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<nsIObserverService> 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<nsIObserverService> os = do_GetService("@mozilla.org/observer-service;1");
+      nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
       if (!os)
         return;
  
       if (state->system_inactivity_ind)
           os->NotifyObservers(nsnull, "system-idle", nsnull);
       else
           os->NotifyObservers(nsnull, "system-active", nsnull);
   }
--- a/toolkit/xre/nsNativeAppSupportWin.cpp
+++ b/toolkit/xre/nsNativeAppSupportWin.cpp
@@ -857,18 +857,17 @@ nsNativeAppSupportWin::Quit() {
     return NS_OK;
 }
 
 NS_IMETHODIMP
 nsNativeAppSupportWin::Enable()
 {
     mCanHandleRequests = PR_TRUE;
 
-    nsCOMPtr<nsIObserverService> obs
-        (do_GetService("@mozilla.org/observer-service;1"));
+    nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
     if (obs) {
         obs->AddObserver(this, "quit-application", PR_FALSE);
     } else {
         NS_ERROR("No observer service?");
     }
 
     return NS_OK;
 }
--- a/toolkit/xre/nsXREDirProvider.cpp
+++ b/toolkit/xre/nsXREDirProvider.cpp
@@ -59,16 +59,17 @@
 #include "nsCategoryManagerUtils.h"
 
 #include "nsINIParser.h"
 #include "nsDependentString.h"
 #include "nsCOMArray.h"
 #include "nsArrayEnumerator.h"
 #include "nsEnumeratorUtils.h"
 #include "nsReadableUtils.h"
+#include "mozilla/Services.h"
 
 #include <stdlib.h>
 
 #ifdef XP_WIN
 #include <windows.h>
 #include <shlobj.h>
 // This is not defined by VC6.
 #ifndef CSIDL_LOCAL_APPDATA
@@ -795,18 +796,18 @@ nsXREDirProvider::GetDirectory(nsIFile* 
 
   return mProfileDir->Clone(aResult);
 }
 
 NS_IMETHODIMP
 nsXREDirProvider::DoStartup()
 {
   if (!mProfileNotified) {
-    nsCOMPtr<nsIObserverService> obsSvc
-      (do_GetService("@mozilla.org/observer-service;1"));
+    nsCOMPtr<nsIObserverService> obsSvc =
+      mozilla::services::GetObserverService();
     if (!obsSvc) return NS_ERROR_FAILURE;
 
     mProfileNotified = PR_TRUE;
 
     static const PRUnichar kStartup[] = {'s','t','a','r','t','u','p','\0'};
     obsSvc->NotifyObservers(nsnull, "profile-do-change", kStartup);
     obsSvc->NotifyObservers(nsnull, "profile-after-change", kStartup);
 
@@ -845,40 +846,40 @@ ProfileChangeStatusImpl::ChangeFailed()
   NS_ERROR("Profile change cancellation.");
   return NS_ERROR_FAILURE;
 }
 
 void
 nsXREDirProvider::DoShutdown()
 {
   if (mProfileNotified) {
-    nsCOMPtr<nsIObserverService> obssvc
-      (do_GetService("@mozilla.org/observer-service;1"));
-    NS_ASSERTION(obssvc, "No observer service?");
-    if (obssvc) {
+    nsCOMPtr<nsIObserverService> obsSvc =
+      mozilla::services::GetObserverService();
+    NS_ASSERTION(obsSvc, "No observer service?");
+    if (obsSvc) {
       nsCOMPtr<nsIProfileChangeStatus> 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.
       nsCOMPtr<nsIThreadJSContextStack> stack
         (do_GetService("@mozilla.org/js/xpc/ContextStack;1"));
       if (stack)
       {
         JSContext *cx = nsnull;
         stack->GetSafeJSContext(&cx);
         if (cx)
           ::JS_GC(cx);
       }
 
       // 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;
   }
 }
 
 #ifdef XP_WIN
 static nsresult
 GetShellFolderPath(int folder, nsAString& _retval)
--- a/uriloader/exthandler/nsExternalHelperAppService.cpp
+++ b/uriloader/exthandler/nsExternalHelperAppService.cpp
@@ -575,29 +575,29 @@ nsresult nsExternalHelperAppService::Ini
 {
   nsCOMPtr<nsIPrivateBrowsingService> pbs =
     do_GetService(NS_PRIVATE_BROWSING_SERVICE_CONTRACTID);
   if (pbs) {
     pbs->GetPrivateBrowsingEnabled(&mInPrivateBrowsing);
   }
 
   // Add an observer for profile change
-  nsresult rv = NS_OK;
-  nsCOMPtr<nsIObserverService> obs = do_GetService("@mozilla.org/observer-service;1", &rv);
-  NS_ENSURE_SUCCESS(rv, rv);
+  nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
+  if (!obs)
+    return NS_ERROR_FAILURE;
 
 #ifdef PR_LOGGING
   if (!mLog) {
     mLog = PR_NewLogModule("HelperAppService");
     if (!mLog)
       return NS_ERROR_OUT_OF_MEMORY;
   }
 #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);
 }
 
 nsExternalHelperAppService::~nsExternalHelperAppService()
 {
   gExtProtSvc = nsnull;
 }
--- a/uriloader/prefetch/nsOfflineCacheUpdate.cpp
+++ b/uriloader/prefetch/nsOfflineCacheUpdate.cpp
@@ -2337,31 +2337,30 @@ nsOfflineCacheUpdateService::nsOfflineCa
 nsOfflineCacheUpdateService::~nsOfflineCacheUpdateService()
 {
     gOfflineCacheUpdateService = nsnull;
 }
 
 nsresult
 nsOfflineCacheUpdateService::Init()
 {
-    nsresult rv;
-
 #if defined(PR_LOGGING)
     if (!gOfflineCacheUpdateLog)
         gOfflineCacheUpdateLog = PR_NewLogModule("nsOfflineCacheUpdate");
 #endif
 
     // Observe xpcom-shutdown event
     nsCOMPtr<nsIObserverService> observerService =
-        do_GetService("@mozilla.org/observer-service;1", &rv);
-    NS_ENSURE_SUCCESS(rv, rv);
-
-    rv = observerService->AddObserver(this,
-                                      NS_XPCOM_SHUTDOWN_OBSERVER_ID,
-                                      PR_TRUE);
+      mozilla::services::GetObserverService();
+    if (!observerService)
+      return NS_ERROR_FAILURE;
+
+    nsresult rv = observerService->AddObserver(this,
+                                               NS_XPCOM_SHUTDOWN_OBSERVER_ID,
+                                               PR_TRUE);
     NS_ENSURE_SUCCESS(rv, rv);
 
     gOfflineCacheUpdateService = this;
 
     return NS_OK;
 }
 
 /* static */
@@ -2402,20 +2401,20 @@ nsOfflineCacheUpdateService::EnsureServi
 nsresult
 nsOfflineCacheUpdateService::Schedule(nsOfflineCacheUpdate *aUpdate)
 {
     LOG(("nsOfflineCacheUpdateService::Schedule [%p, update=%p]",
          this, aUpdate));
 
     aUpdate->SetOwner(this);
 
-    nsresult rv;
     nsCOMPtr<nsIObserverService> 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<nsIOfflineCacheUpdate*>(aUpdate),
                                      "offline-cache-update-added",
                                      nsnull);
 
     mUpdates.AppendElement(aUpdate);
 
     ProcessNextUpdate();
@@ -2461,20 +2460,20 @@ nsOfflineCacheUpdateService::UpdateFinis
     NS_ASSERTION(mUpdates.Length() > 0 &&
                  mUpdates[0] == aUpdate, "Unknown update completed");
 
     // keep this item alive until we're done notifying observers
     nsRefPtr<nsOfflineCacheUpdate> update = mUpdates[0];
     mUpdates.RemoveElementAt(0);
     mUpdateRunning = PR_FALSE;
 
-    nsresult rv;
     nsCOMPtr<nsIObserverService> 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<nsIOfflineCacheUpdate*>(aUpdate),
                                      "offline-cache-update-completed",
                                      nsnull);
 
     ProcessNextUpdate();
 
     return NS_OK;
--- a/uriloader/prefetch/nsPrefetchService.cpp
+++ b/uriloader/prefetch/nsPrefetchService.cpp
@@ -436,22 +436,23 @@ nsPrefetchService::Init()
       rv = prefs->GetBoolPref(PREFETCH_PREF, &enabled);
       if (NS_SUCCEEDED(rv) && enabled)
         mDisabled = PR_FALSE;
 
       prefs->AddObserver(PREFETCH_PREF, this, PR_TRUE);
     }
 
     // Observe xpcom-shutdown event
-    nsCOMPtr<nsIObserverService> observerServ(
-            do_GetService("@mozilla.org/observer-service;1", &rv));
-    if (NS_FAILED(rv)) return rv;
+    nsCOMPtr<nsIObserverService> 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();
 
     return NS_OK;
 }
 
 void
@@ -481,34 +482,32 @@ nsPrefetchService::ProcessNextURI()
         rv = mCurrentNode->OpenChannel();
     }
     while (NS_FAILED(rv));
 }
 
 void
 nsPrefetchService::NotifyLoadRequested(nsPrefetchNode *node)
 {
-    nsresult rv;
-
     nsCOMPtr<nsIObserverService> observerService =
-        do_GetService("@mozilla.org/observer-service;1", &rv);
-    if (NS_FAILED(rv)) return;
+      mozilla::services::GetObserverService();
+    if (!observerService)
+      return;
 
     observerService->NotifyObservers(static_cast<nsIDOMLoadStatus*>(node),
                                      "prefetch-load-requested", nsnull);
 }
 
 void
 nsPrefetchService::NotifyLoadCompleted(nsPrefetchNode *node)
 {
-    nsresult rv;
-
     nsCOMPtr<nsIObserverService> observerService =
-        do_GetService("@mozilla.org/observer-service;1", &rv);
-    if (NS_FAILED(rv)) return;
+      mozilla::services::GetObserverService();
+    if (!observerService)
+      return;
 
     observerService->NotifyObservers(static_cast<nsIDOMLoadStatus*>(node),
                                      "prefetch-load-completed", nsnull);
 }
 
 //-----------------------------------------------------------------------------
 // nsPrefetchService <private>
 //-----------------------------------------------------------------------------
--- a/widget/src/gtk2/nsClipboard.cpp
+++ b/widget/src/gtk2/nsClipboard.cpp
@@ -42,16 +42,17 @@
 #include "nsReadableUtils.h"
 #include "nsXPIDLString.h"
 #include "nsPrimitiveHelpers.h"
 #include "nsICharsetConverterManager.h"
 #include "nsIServiceManager.h"
 #include "nsImageToPixbuf.h"
 #include "nsStringStream.h"
 #include "nsIObserverService.h"
+#include "mozilla/Services.h"
 
 #include "imgIContainer.h"
 
 #include <gtk/gtk.h>
 
 // For manipulation of the X event queue
 #include <X11/Xlib.h>
 #include <gdk/gdkx.h>
@@ -136,20 +137,19 @@ nsClipboard::~nsClipboard()
     }
 }
 
 NS_IMPL_ISUPPORTS1(nsClipboard, nsIClipboard)
 
 nsresult
 nsClipboard::Init(void)
 {
-    nsresult rv;
-    nsCOMPtr<nsIObserverService> os
-      (do_GetService("@mozilla.org/observer-service;1", &rv));
-    NS_ENSURE_SUCCESS(rv, rv);
+    nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
+    if (!os)
+      return NS_ERROR_FAILURE;
 
     os->AddObserver(this, "quit-application", PR_FALSE);
 
     return NS_OK;
 }
 
 NS_IMETHODIMP
 nsClipboard::Observe(nsISupports *aSubject, const char *aTopic, const PRUnichar *aData)
--- a/widget/src/gtk2/nsDragService.cpp
+++ b/widget/src/gtk2/nsDragService.cpp
@@ -55,16 +55,17 @@
 #include "prlog.h"
 #include "nsTArray.h"
 #include "nsPrimitiveHelpers.h"
 #include "prtime.h"
 #include "prthread.h"
 #include <gtk/gtk.h>
 #include <gdk/gdkx.h>
 #include "nsCRT.h"
+#include "mozilla/Services.h"
 
 #include "gfxASurface.h"
 #include "gfxXlibSurface.h"
 #include "gfxContext.h"
 #include "nsImageToPixbuf.h"
 #include "nsPresContext.h"
 #include "nsIDocument.h"
 #include "nsISelection.h"
@@ -107,17 +108,17 @@ invisibleSourceDragDataGet(GtkWidget    
                            guint32           aTime,
                            gpointer          aData);
 
 nsDragService::nsDragService()
 {
     // We have to destroy the hidden widget before the event loop stops
     // running.
     nsCOMPtr<nsIObserverService> obsServ =
-        do_GetService("@mozilla.org/observer-service;1");
+        mozilla::services::GetObserverService();
     obsServ->AddObserver(this, "quit-application", PR_FALSE);
 
     // our hidden source widget
     mHiddenWidget = gtk_invisible_new();
     // make sure that the widget is realized so that
     // we can use it as a drag source.
     gtk_widget_realize(mHiddenWidget);
     // hook up our internal signals so that we can get some feedback
--- a/widget/src/gtk2/nsGtkIMModule.cpp
+++ b/widget/src/gtk2/nsGtkIMModule.cpp
@@ -48,16 +48,17 @@
 #include "prlog.h"
 
 #include "nsGtkIMModule.h"
 #include "nsWindow.h"
 
 #ifdef MOZ_PLATFORM_MAEMO
 #include "nsServiceManagerUtils.h"
 #include "nsIObserverService.h"
+#include "mozilla/Services.h"
 #endif
 
 #ifdef PR_LOGGING
 PRLogModuleInfo* gGtkIMLog = nsnull;
 
 static const char*
 GetRangeTypeName(PRUint32 aRangeType)
 {
@@ -582,17 +583,17 @@ nsGtkIMModule::SetIMEEnabled(nsWindow* a
             hildon_gtk_im_context_show(im);
         } else {
             gIsVirtualKeyboardOpened = PR_FALSE;
             hildon_gtk_im_context_hide(im);
         }
     }
 
     nsCOMPtr<nsIObserverService> observerService =
-        do_GetService("@mozilla.org/observer-service;1");
+        mozilla::services::GetObserverService();
     if (observerService) {
         nsAutoString rectBuf;
         PRInt32 x, y, w, h;
         gdk_window_get_position(aCaller->GetGdkWindow(), &x, &y);
         gdk_window_get_size(aCaller->GetGdkWindow(), &w, &h);
         rectBuf.Assign(NS_LITERAL_STRING("{\"left\": "));
         rectBuf.AppendInt(x);
         rectBuf.Append(NS_LITERAL_STRING(" \"top\": "));
--- a/widget/src/gtk2/nsNativeThemeGTK.cpp
+++ b/widget/src/gtk2/nsNativeThemeGTK.cpp
@@ -56,16 +56,17 @@
 #include "nsIDeviceContext.h"
 #include "nsGfxCIID.h"
 #include "nsTransform2D.h"
 #include "nsIMenuFrame.h"
 #include "prlink.h"
 #include "nsIDOMHTMLInputElement.h"
 #include "nsIDOMNSHTMLInputElement.h"
 #include "nsWidgetAtoms.h"
+#include "mozilla/Services.h"
 
 #include <gdk/gdkprivate.h>
 #include <gtk/gtk.h>
 
 #include "gfxContext.h"
 #include "gfxPlatformGtk.h"
 #include "gfxGdkNativeRenderer.h"
 
@@ -77,17 +78,17 @@ nsNativeThemeGTK::nsNativeThemeGTK()
 {
   if (moz_gtk_init() != MOZ_GTK_SUCCESS) {
     memset(mDisabledWidgetTypes, 0xff, sizeof(mDisabledWidgetTypes));
     return;
   }
 
   // We have to call moz_gtk_shutdown before the event loop stops running.
   nsCOMPtr<nsIObserverService> obsServ =
-    do_GetService("@mozilla.org/observer-service;1");
+    mozilla::services::GetObserverService();
   obsServ->AddObserver(this, "xpcom-shutdown", PR_FALSE);
 
   memset(mDisabledWidgetTypes, 0, sizeof(mDisabledWidgetTypes));
   memset(mSafeWidgetStates, 0, sizeof(mSafeWidgetStates));
 }
 
 nsNativeThemeGTK::~nsNativeThemeGTK() {
 }
--- a/widget/src/os2/nsClipboard.cpp
+++ b/widget/src/os2/nsClipboard.cpp
@@ -43,16 +43,17 @@
 #include "nsCOMPtr.h"
 #include "nsPrimitiveHelpers.h"
 #include "nsXPIDLString.h"
 #include "prmem.h"
 #include "nsIObserverService.h"
 #include "nsIServiceManager.h"
 #include "nsOS2Uni.h"
 #include "nsClipboard.h"
+#include "mozilla/Services.h"
 
 inline ULONG RegisterClipboardFormat(PCSZ pcszFormat)
 {
   ATOM atom = WinFindAtom(WinQuerySystemAtomTable(), pcszFormat);
   if (!atom) {
     atom = WinAddAtom(WinQuerySystemAtomTable(), pcszFormat); 
   }
   return atom;
@@ -70,17 +71,17 @@ nsClipboard::nsClipboard() : nsBaseClipb
   RegisterClipboardFormat(kFileMime);
   RegisterClipboardFormat(kURLMime);
   RegisterClipboardFormat(kNativeImageMime);
   RegisterClipboardFormat(kNativeHTMLMime);
 
   // Register for a shutdown notification so that we can flush data
   // to the OS clipboard.
   nsCOMPtr<nsIObserverService> observerService =
-    do_GetService("@mozilla.org/observer-service;1");
+    mozilla::services::GetObserverService();
   if (observerService)
     observerService->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, PR_FALSE);
 }
 
 nsClipboard::~nsClipboard()
 {}
 
 NS_IMPL_ISUPPORTS_INHERITED1(nsClipboard, nsBaseClipboard, nsIObserver)
--- a/widget/src/os2/nsRwsService.cpp
+++ b/widget/src/os2/nsRwsService.cpp
@@ -40,16 +40,17 @@
 #include "nsIFile.h"
 #include "nsIGenericFactory.h"
 #include "nsIObserver.h"
 #include "nsIObserverService.h"
 #include "nsDirectoryServiceDefs.h"
 #include "nsLiteralString.h"
 #include "nsReadableUtils.h"
 #include "nsIStringBundle.h"
+#include "mozilla/Services.h"
 
 #define INCL_WIN
 #define INCL_DOS
 #include <os2.h>
 
 // nsRwsService must be included _after_ os2.h
 #include "nsRwsService.h"
 #include "rwserr.h"
@@ -1219,17 +1220,17 @@ static nsresult nsRwsServiceInit(nsRwsSe
   NS_NEWXPCOM(sRwsInstance, nsRwsService);
   if (sRwsInstance == 0)
     return NS_ERROR_OUT_OF_MEMORY;
 
   *aClass = sRwsInstance;
   NS_ADDREF(*aClass);
 
   // set the class up as a shutdown observer
-  nsCOMPtr<nsIObserverService> os = do_GetService("@mozilla.org/observer-service;1");
+  nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
   if (os)
     os->AddObserver(*aClass, "quit-application", PR_FALSE);
 
   return NS_OK;
 }
 
 //------------------------------------------------------------------------
 
--- a/widget/src/windows/nsWindow.cpp
+++ b/widget/src/windows/nsWindow.cpp
@@ -149,16 +149,17 @@
 #include "nsUnicharUtils.h"
 #include "nsCRT.h"
 #include "nsAppDirectoryServiceDefs.h"
 #include "nsXPIDLString.h"
 #include "nsWidgetsCID.h"
 #include "nsTHashtable.h"
 #include "nsHashKeys.h"
 #include "nsString.h"
+#include "mozilla/Services.h"
 
 #if defined(WINCE)
 #include "nsWindowCE.h"
 #endif
 
 #if defined(WINCE_WINDOWS_MOBILE)
 #define KILL_PRIORITY_ID 2444
 #endif
@@ -4078,17 +4079,17 @@ PRBool nsWindow::ProcessMessage(UINT msg
     // WM_QUERYENDSESSION must be handled by all windows.
     // Otherwise Windows thinks the window can just be killed at will.
     case WM_QUERYENDSESSION:
       if (sCanQuit == TRI_UNKNOWN)
       {
         // Ask if it's ok to quit, and store the answer until we
         // get WM_ENDSESSION signaling the round is complete.
         nsCOMPtr<nsIObserverService> obsServ =
-          do_GetService("@mozilla.org/observer-service;1");
+          mozilla::services::GetObserverService();
         nsCOMPtr<nsISupportsPRBool> cancelQuit =
           do_CreateInstance(NS_SUPPORTS_PRBOOL_CONTRACTID);
         cancelQuit->SetData(PR_FALSE);
         obsServ->NotifyObservers(cancelQuit, "quit-application-requested", nsnull);
 
         PRBool abortQuit;
         cancelQuit->GetData(&abortQuit);
         sCanQuit = abortQuit ? TRI_FALSE : TRI_TRUE;
@@ -4104,17 +4105,17 @@ PRBool nsWindow::ProcessMessage(UINT msg
     case MOZ_WM_APP_QUIT:
       if (msg == MOZ_WM_APP_QUIT || (wParam == TRUE && sCanQuit == TRI_TRUE))
       {
         // Let's fake a shutdown sequence without actually closing windows etc.
         // to avoid Windows killing us in the middle. A proper shutdown would
         // require having a chance to pump some messages. Unfortunately
         // Windows won't let us do that. Bug 212316.
         nsCOMPtr<nsIObserverService> 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);
         obsServ->NotifyObservers(nsnull, "quit-application", nsnull);
         obsServ->NotifyObservers(nsnull, "profile-change-net-teardown", context.get());
         obsServ->NotifyObservers(nsnull, "profile-change-teardown", context.get());
         obsServ->NotifyObservers(nsnull, "profile-before-change", context.get());
         // Then a controlled but very quick exit.
@@ -4993,21 +4994,20 @@ void nsWindow::GlobalMsgWindowProc(HWND 
  * Special processing for certain event types and 
  * synthesized events.
  *
  **************************************************************/
 
 #ifndef WINCE
 void nsWindow::PostSleepWakeNotification(const char* aNotification)
 {
-  nsCOMPtr<nsIObserverService> observerService = do_GetService("@mozilla.org/observer-service;1");
+  nsCOMPtr<nsIObserverService> observerService =
+    mozilla::services::GetObserverService();
   if (observerService)
-  {
     observerService->NotifyObservers(nsnull, aNotification, nsnull);
-  }
 }
 #endif
 
 LRESULT nsWindow::ProcessCharMessage(const MSG &aMsg, PRBool *aEventDispatched)
 {
   NS_PRECONDITION(aMsg.message == WM_CHAR || aMsg.message == WM_SYSCHAR,
                   "message is not keydown event");
   PR_LOG(gWindowsLog, PR_LOG_ALWAYS,
--- a/widget/src/xpwidgets/nsBaseAppShell.cpp
+++ b/widget/src/xpwidgets/nsBaseAppShell.cpp
@@ -35,16 +35,17 @@
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "nsBaseAppShell.h"
 #include "nsThreadUtils.h"
 #include "nsIObserverService.h"
 #include "nsServiceManagerUtils.h"
+#include "mozilla/Services.h"
 
 #ifdef MOZ_IPC
 #include "base/message_loop.h"
 #endif
 
 // When processing the next thread event, the appshell may process native
 // events (if not in performance mode), which can result in suppressing the
 // next thread event for at most this many ticks:
@@ -76,17 +77,17 @@ nsBaseAppShell::Init()
 
   nsCOMPtr<nsIThreadInternal> threadInt =
       do_QueryInterface(NS_GetCurrentThread());
   NS_ENSURE_STATE(threadInt);
 
   threadInt->SetObserver(this);
 
   nsCOMPtr<nsIObserverService> 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;
 }
 
 void
 nsBaseAppShell::NativeEventCallback()
 {
--- a/widget/src/xpwidgets/nsClipboardPrivacyHandler.cpp
+++ b/widget/src/xpwidgets/nsClipboardPrivacyHandler.cpp
@@ -41,34 +41,35 @@
 #include "nsISupportsPrimitives.h"
 #include "nsIObserverService.h"
 #include "nsIClipboard.h"
 #include "nsComponentManagerUtils.h"
 #include "nsServiceManagerUtils.h"
 #include "nsLiteralString.h"
 #include "nsNetCID.h"
 #include "nsXPCOM.h"
+#include "mozilla/Services.h"
 
 #if defined(XP_WIN) && !defined(WINCE)
 #include <ole2.h>
 #endif
 
 #define NS_MOZ_DATA_FROM_PRIVATEBROWSING "application/x-moz-private-browsing"
 
 NS_IMPL_ISUPPORTS2(nsClipboardPrivacyHandler, nsIObserver, nsISupportsWeakReference)
 
 nsresult
 nsClipboardPrivacyHandler::Init()
 {
-  nsresult rv;
   nsCOMPtr<nsIObserverService> 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);
 }
 
 /**
   * Prepare the transferable object to be inserted into the clipboard
   *
   */
 nsresult
 nsClipboardPrivacyHandler::PrepareDataForClipboard(nsITransferable * aTransferable)
--- a/widget/src/xpwidgets/nsIdleService.cpp
+++ b/widget/src/xpwidgets/nsIdleService.cpp
@@ -44,16 +44,17 @@
 #include "nsString.h"
 #include "nsIObserverService.h"
 #include "nsIPrefBranch.h"
 #include "nsIPrefService.h"
 #include "nsIServiceManager.h"
 #include "nsDebug.h"
 #include "nsCOMArray.h"
 #include "prinrval.h"
+#include "mozilla/Services.h"
 
 // observer topics used:
 #define OBSERVER_TOPIC_IDLE "idle"
 #define OBSERVER_TOPIC_BACK "back"
 #define OBSERVER_TOPIC_IDLE_DAILY "idle-daily"
 // interval in seconds between internal idle time requests.
 #define MIN_IDLE_POLL_INTERVAL 5
 #define MAX_IDLE_POLL_INTERVAL 300 /* 5 min */
@@ -75,17 +76,17 @@ NS_IMPL_ISUPPORTS1(nsIdleServiceDaily, n
 
 NS_IMETHODIMP
 nsIdleServiceDaily::Observe(nsISupports *,
                             const char *,
                             const PRUnichar *)
 {
   // Notify anyone who cares.
   nsCOMPtr<nsIObserverService> observerService =
-    do_GetService("@mozilla.org/observer-service;1");
+    mozilla::services::GetObserverService();
 
   observerService->NotifyObservers(nsnull,
                                    OBSERVER_TOPIC_IDLE_DAILY,
                                    nsnull);
   // Remove from idle timeout.
   mIdleService->RemoveIdleObserver(this, MAX_IDLE_POLL_INTERVAL*1000);
 
   // Start timer for next search in 1 day.
--- a/xpcom/base/nsCycleCollector.cpp
+++ b/xpcom/base/nsCycleCollector.cpp
@@ -139,16 +139,17 @@
 #include "nsPrintfCString.h"
 #include "nsTArray.h"
 #include "nsIObserverService.h"
 #include "nsIConsoleService.h"
 #include "nsServiceManagerUtils.h"
 #include "nsThreadUtils.h"
 #include "nsTPtrArray.h"
 #include "nsTArray.h"
+#include "mozilla/Services.h"
 
 #include <stdio.h>
 #include <string.h>
 #ifdef WIN32
 #include <io.h>
 #include <process.h>
 #endif
 
@@ -2497,20 +2498,19 @@ nsCycleCollector::Collect(PRUint32 aTryC
 #ifdef COLLECT_TIME_DEBUG
     printf("cc: Starting nsCycleCollector::Collect(%d)\n", aTryCollections);
     PRTime start = PR_Now();
 #endif
 
     mCollectionInProgress = PR_TRUE;
 
     nsCOMPtr<nsIObserverService> 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;
     nsAutoTPtrArray<PtrInfo, 4000> whiteNodes;
     mWhiteNodes = &whiteNodes;
 
     PRUint32 totalCollections = 0;
     while (aTryCollections > totalCollections) {
--- a/xpcom/base/nsExceptionService.cpp
+++ b/xpcom/base/nsExceptionService.cpp
@@ -37,16 +37,18 @@
  * ***** END LICENSE BLOCK ***** */
 
 #include "nsISupports.h"
 #include "nsExceptionService.h"
 #include "nsIServiceManager.h"
 #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
 #define CHECK_MANAGER_USE_OK() if (!mService || !nsExceptionService::lock) return NS_ERROR_NOT_INITIALIZED
 
 // A key for our registered module providers hashtable
 class nsProviderKey : public nsHashKey {
 protected:
@@ -167,17 +169,18 @@ nsExceptionService::nsExceptionService()
     PRStatus status;
     status = PR_NewThreadPrivateIndex( &tlsIndex, ThreadDestruct );
     NS_ASSERTION(status==0, "ScriptErrorService could not allocate TLS storage.");
   }
   lock = PR_NewLock();
   NS_ASSERTION(lock, "Error allocating ExceptionService lock");
 
   // observe XPCOM shutdown.
-  nsCOMPtr<nsIObserverService> observerService = do_GetService("@mozilla.org/observer-service;1");
+  nsCOMPtr<nsIObserverService> observerService =
+    mozilla::services::GetObserverService();
   NS_ASSERTION(observerService, "Could not get observer service!");
   if (observerService)
     observerService->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, PR_FALSE);
 }
 
 nsExceptionService::~nsExceptionService()
 {
   Shutdown();
--- a/xpcom/base/nsMemoryImpl.cpp
+++ b/xpcom/base/nsMemoryImpl.cpp
@@ -47,16 +47,17 @@
 #include "prmem.h"
 #include "prcvar.h"
 #include "pratom.h"
 
 #include "nsAlgorithm.h"
 #include "nsAutoLock.h"
 #include "nsCOMPtr.h"
 #include "nsString.h"
+#include "mozilla/Services.h"
 
 #if defined(XP_WIN)
 #include <windows.h>
 #endif
 
 #if defined(MOZ_PLATFORM_MAEMO) && defined(__arm__)
 #include <fcntl.h>
 #include <unistd.h>
@@ -201,17 +202,17 @@ nsMemoryImpl::FlushMemory(const PRUnicha
 
     sLastFlushTime = now;
     return rv;
 }
 
 nsresult
 nsMemoryImpl::RunFlushers(const PRUnichar* aReason)
 {
-    nsCOMPtr<nsIObserverService> os = do_GetService("@mozilla.org/observer-service;1");
+    nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
     if (os) {
 
         // Instead of:
         //  os->NotifyObservers(this, "memory-pressure", aReason);
         // we are going to do this manually to see who/what is
         // deallocating.
 
         nsCOMPtr<nsISimpleEnumerator> e;
--- a/xpcom/components/nsCategoryManager.cpp
+++ b/xpcom/components/nsCategoryManager.cpp
@@ -55,16 +55,17 @@
 #include "nsIObserver.h"
 #include "nsIObserverService.h"
 #include "nsReadableUtils.h"
 #include "nsCRT.h"
 #include "nsQuickSort.h"
 #include "nsEnumeratorUtils.h"
 #include "nsIProxyObjectManager.h"
 #include "nsThreadUtils.h"
+#include "mozilla/Services.h"
 
 using namespace mozilla;
 class nsIComponentLoaderManager;
 
 /*
   CategoryDatabase
   contains 0 or more 1-1 mappings of string to Category
   each Category contains 0 or more 1-1 mappings of string keys to string values
@@ -514,18 +515,18 @@ nsCategoryManager::get_category(const ch
 void
 nsCategoryManager::NotifyObservers( const char *aTopic,
                                     const char *aCategoryName,
                                     const char *aEntryName )
 {
   if (mSuppressNotifications)
     return;
 
-  nsCOMPtr<nsIObserverService> observerService
-    (do_GetService("@mozilla.org/observer-service;1"));
+  nsCOMPtr<nsIObserverService> observerService =
+    mozilla::services::GetObserverService();
   if (!observerService)
     return;
 
   nsCOMPtr<nsIObserverService> obsProxy;
   NS_GetProxyForObject(NS_PROXY_TO_MAIN_THREAD,
                        NS_GET_IID(nsIObserverService),
                        observerService,
                        NS_PROXY_ASYNC,
--- a/xpcom/threads/TimerThread.cpp
+++ b/xpcom/threads/TimerThread.cpp
@@ -43,16 +43,17 @@
 
 #include "nsAutoLock.h"
 #include "nsThreadUtils.h"
 #include "pratom.h"
 
 #include "nsIObserverService.h"
 #include "nsIServiceManager.h"
 #include "nsIProxyObjectManager.h"
+#include "mozilla/Services.h"
 
 NS_IMPL_THREADSAFE_ISUPPORTS2(TimerThread, nsIRunnable, nsIObserver)
 
 TimerThread::TimerThread() :
   mInitInProgress(0),
   mInitialized(PR_FALSE),
   mLock(nsnull),
   mCondVar(nsnull),
@@ -106,17 +107,17 @@ nsresult TimerThread::Init()
   if (PR_AtomicSet(&mInitInProgress, 1) == 0) {
     // We hold on to mThread to keep the thread alive.
     nsresult rv = NS_NewThread(getter_AddRefs(mThread), this);
     if (NS_FAILED(rv)) {
       mThread = nsnull;
     }
     else {
       nsCOMPtr<nsIObserverService> 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<nsIObserverService> result = nsnull;
         NS_GetProxyForObject(NS_PROXY_TO_MAIN_THREAD,
                              NS_GET_IID(nsIObserverService),
                              observerService, NS_PROXY_ASYNC,
                              getter_AddRefs(result));
         observerService.swap(result);
--- a/xpcom/threads/nsProcessCommon.cpp
+++ b/xpcom/threads/nsProcessCommon.cpp
@@ -51,16 +51,17 @@
 #include "nsProcess.h"
 #include "prtypes.h"
 #include "prio.h"
 #include "prenv.h"
 #include "nsCRT.h"
 #include "nsAutoLock.h"
 #include "nsThreadUtils.h"
 #include "nsIObserverService.h"
+#include "mozilla/Services.h"
 
 #include <stdlib.h>
 
 #if defined(PROCESSMODEL_WINAPI)
 #include "prmem.h"
 #include "nsString.h"
 #include "nsLiteralString.h"
 #include "nsReadableUtils.h"
@@ -288,17 +289,18 @@ void PR_CALLBACK nsProcess::Monitor(void
             NS_NewRunnableMethod(process, &nsProcess::ProcessComplete);
         NS_DispatchToMainThread(event);
     }
 }
 
 void nsProcess::ProcessComplete()
 {
     if (mThread) {
-        nsCOMPtr<nsIObserverService> os = do_GetService("@mozilla.org/observer-service;1");
+        nsCOMPtr<nsIObserverService> os =
+            mozilla::services::GetObserverService();
         if (os)
             os->RemoveObserver(this, "xpcom-shutdown");
         PR_JoinThread(mThread);
         mThread = nsnull;
     }
 
     const char* topic;
     if (mExitValue < 0)
@@ -514,17 +516,18 @@ nsProcess::RunProcess(PRBool blocking, c
                                   PR_PRIORITY_NORMAL, PR_LOCAL_THREAD,
                                   PR_JOINABLE_THREAD, 0);
         if (!mThread) {
             NS_RELEASE_THIS();
             return NS_ERROR_FAILURE;
         }
 
         // It isn't a failure if we just can't watch for shutdown
-        nsCOMPtr<nsIObserverService> os = do_GetService("@mozilla.org/observer-service;1");
+        nsCOMPtr<nsIObserverService> os =
+          mozilla::services::GetObserverService();
         if (os)
             os->AddObserver(this, "xpcom-shutdown", PR_FALSE);
     }
 
     return NS_OK;
 }
 
 NS_IMETHODIMP nsProcess::GetIsRunning(PRBool *aIsRunning)
@@ -562,17 +565,17 @@ nsProcess::Kill()
 #else
         if (!mProcess || (PR_KillProcess(mProcess) != PR_SUCCESS))
             return NS_ERROR_FAILURE;
 #endif
     }
 
     // We must null out mThread if we want IsRunning to return false immediately
     // after this call.
-    nsCOMPtr<nsIObserverService> os = do_GetService("@mozilla.org/observer-service;1");
+    nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
     if (os)
         os->RemoveObserver(this, "xpcom-shutdown");
     PR_JoinThread(mThread);
     mThread = nsnull;
 
     return NS_OK;
 }
 
@@ -586,17 +589,18 @@ nsProcess::GetExitValue(PRInt32 *aExitVa
     return NS_OK;
 }
 
 NS_IMETHODIMP
 nsProcess::Observe(nsISupports* subject, const char* topic, const PRUnichar* data)
 {
     // Shutting down, drop all references
     if (mThread) {
-        nsCOMPtr<nsIObserverService> os = do_GetService("@mozilla.org/observer-service;1");
+        nsCOMPtr<nsIObserverService> os =
+          mozilla::services::GetObserverService();
         if (os)
             os->RemoveObserver(this, "xpcom-shutdown");
         mThread = nsnull;
     }
 
     mObserver = nsnull;
     mWeakObserver = nsnull;
 
--- a/xpinstall/src/nsInstallTrigger.cpp
+++ b/xpinstall/src/nsInstallTrigger.cpp
@@ -251,17 +251,18 @@ nsInstallTrigger::HandleContent(const ch
             // From here trigger is owned by installInfo until passed on to nsXPInstallManager
             trigger.forget();
             if (AllowInstall(checkuri))
             {
                 return StartInstall(installInfo, nsnull);
             }
             else
             {
-                nsCOMPtr<nsIObserverService> os(do_GetService("@mozilla.org/observer-service;1"));
+                nsCOMPtr<nsIObserverService> os =
+                  mozilla::services::GetObserverService();
                 if (os)
                     os->NotifyObservers(installInfo,
                                         "xpinstall-install-blocked",
                                         nsnull);
                 return NS_ERROR_ABORT;
             }
         }
     }
--- a/xpinstall/src/nsJSInstallTriggerGlobal.cpp
+++ b/xpinstall/src/nsJSInstallTriggerGlobal.cpp
@@ -415,17 +415,18 @@ InstallTriggerGlobalInstall(JSContext *c
                 new nsXPIInstallInfo(win, checkuri, trigger, 0);
             if (installInfo)
             {
                 // installInfo now owns triggers
                 PRBool enabled = PR_FALSE;
                 nativeThis->UpdateEnabled(checkuri, XPI_WHITELIST, &enabled);
                 if (!enabled)
                 {
-                    nsCOMPtr<nsIObserverService> os(do_GetService("@mozilla.org/observer-service;1"));
+                    nsCOMPtr<nsIObserverService> os =
+                      mozilla::services::GetObserverService();
                     if (os)
                         os->NotifyObservers(installInfo,
                                             "xpinstall-install-blocked",
                                             nsnull);
                 }
                 else
                 {
                     // save callback function if any (ignore bad args for now)
@@ -538,17 +539,18 @@ InstallTriggerGlobalInstallChrome(JSCont
                 {
                     // installInfo owns trigger now
                     trigger.forget();
                     PRBool enabled = PR_FALSE;
                     nativeThis->UpdateEnabled(checkuri, XPI_WHITELIST,
                                               &enabled);
                     if (!enabled)
                     {
-                        nsCOMPtr<nsIObserverService> os(do_GetService("@mozilla.org/observer-service;1"));
+                        nsCOMPtr<nsIObserverService> os =
+                          mozilla::services::GetObserverService();
                         if (os)
                             os->NotifyObservers(installInfo,
                                                 "xpinstall-install-blocked",
                                                 nsnull);
                     }
                     else
                     {
                         PRBool nativeRet = PR_FALSE;
@@ -642,17 +644,18 @@ InstallTriggerGlobalStartSoftwareUpdate(
             if (installInfo)
             {
                 // From here trigger is owned by installInfo until passed on to nsXPInstallManager
                 trigger.forget();
                 PRBool enabled = PR_FALSE;
                 nativeThis->UpdateEnabled(checkuri, XPI_WHITELIST, &enabled);
                 if (!enabled)
                 {
-                    nsCOMPtr<nsIObserverService> os(do_GetService("@mozilla.org/observer-service;1"));
+                    nsCOMPtr<nsIObserverService> os =
+                      mozilla::services::GetObserverService();
                     if (os)
                         os->NotifyObservers(installInfo,
                                             "xpinstall-install-blocked",
                                             nsnull);
                 }
                 else
                 {
                     nativeThis->StartInstall(installInfo, &nativeRet);
--- a/xpinstall/src/nsXPInstallManager.cpp
+++ b/xpinstall/src/nsXPInstallManager.cpp
@@ -522,17 +522,18 @@ nsXPInstallManager::OpenProgressDialog(c
     nsAutoString type;
     type.AssignWithConversion(statusDialogType);
     if (NS_SUCCEEDED(rv) && !type.IsEmpty()) {
         nsCOMPtr<nsIWindowMediator> wm = do_GetService(NS_WINDOWMEDIATOR_CONTRACTID);
 
         nsCOMPtr<nsIDOMWindowInternal> recentWindow;
         wm->GetMostRecentWindow(type.get(), getter_AddRefs(recentWindow));
         if (recentWindow) {
-            nsCOMPtr<nsIObserverService> os(do_GetService("@mozilla.org/observer-service;1"));
+            nsCOMPtr<nsIObserverService> os =
+              mozilla::services::GetObserverService();
             os->NotifyObservers(params, "xpinstall-download-started", nsnull);
 
             recentWindow->Focus();
             return NS_OK;
         }
     }
 
     nsCOMPtr<nsIDOMWindow> newWindow;
@@ -569,17 +570,18 @@ NS_IMETHODIMP nsXPInstallManager::Observ
         {
             // -- The dialog has been opened
             if (mDialogOpen)
                 return NS_OK; // We've already been opened, nothing more to do
 
             mDialogOpen = PR_TRUE;
             rv = NS_OK;
 
-            nsCOMPtr<nsIObserverService> os(do_GetService("@mozilla.org/observer-service;1"));
+            nsCOMPtr<nsIObserverService> os =
+              mozilla::services::GetObserverService();
             if (os)
             {
                 os->AddObserver(this, NS_IOSERVICE_GOING_OFFLINE_TOPIC, PR_TRUE);
                 os->AddObserver(this, "quit-application", PR_TRUE);
             }
 
             mDlg = do_QueryInterface(aSubject);
 
@@ -993,17 +995,18 @@ void nsXPInstallManager::Shutdown(PRInt3
         // Clean up downloaded files (regular install only, not chrome installs)
         for (PRUint32 i = 0; i < mTriggers->Size(); i++ )
         {
             item = static_cast<nsXPITriggerItem*>(mTriggers->Get(i));
             if ( item && item->mFile && !item->IsFileURL() )
                 item->mFile->Remove(PR_FALSE);
         }
 
-        nsCOMPtr<nsIObserverService> os(do_GetService("@mozilla.org/observer-service;1"));
+        nsCOMPtr<nsIObserverService> os =
+          mozilla::services::GetObserverService();
         if (os)
         {
             os->RemoveObserver(this, NS_IOSERVICE_GOING_OFFLINE_TOPIC);
             os->RemoveObserver(this, "quit-application");
         }
 
         if (mTriggers)
         {