Bug 629697 - Cache the XPConnect services for accesses from Places; r=bsmedberg a=sdwilsh
authorEhsan Akhgari <ehsan@mozilla.com>
Fri, 28 Jan 2011 12:15:37 -0500
changeset 61844 dfe5ab77a706b6d795d406b9a13f56c666e8cc0c
parent 61843 e9fe7402dc536c0ba9386381da934b718bf19795
child 61845 108aec53a28051831834d4f909e1336046c57dcb
push idunknown
push userunknown
push dateunknown
reviewersbsmedberg, sdwilsh
bugs629697
milestone2.0b12pre
Bug 629697 - Cache the XPConnect services for accesses from Places; r=bsmedberg a=sdwilsh
toolkit/components/places/src/History.cpp
toolkit/components/places/src/PlaceInfo.cpp
xpcom/build/ServiceList.h
xpcom/build/Services.cpp
--- a/toolkit/components/places/src/History.cpp
+++ b/toolkit/components/places/src/History.cpp
@@ -201,19 +201,17 @@ GetURIFromJSObject(JSContext* aCtx,
                    JSObject* aObject,
                    const char* aProperty)
 {
   jsval uriVal;
   JSBool rc = JS_GetProperty(aCtx, aObject, aProperty, &uriVal);
   NS_ENSURE_TRUE(rc, nsnull);
 
   if (!JSVAL_IS_PRIMITIVE(uriVal)) {
-    static NS_DEFINE_CID(kXPConnectCID, NS_XPCONNECT_CID);
-    nsCOMPtr<nsIXPConnect> xpc = do_GetService(kXPConnectCID);
-    NS_ENSURE_TRUE(xpc, nsnull);
+    nsCOMPtr<nsIXPConnect> xpc = mozilla::services::GetXPConnect();
 
     nsCOMPtr<nsIXPConnectWrappedNative> wrappedObj;
     nsresult rv = xpc->GetWrappedNativeOfJSObject(aCtx, JSVAL_TO_OBJECT(uriVal),
                                                   getter_AddRefs(wrappedObj));
     NS_ENSURE_SUCCESS(rv, nsnull);
     nsCOMPtr<nsIURI> uri = do_QueryWrappedNative(wrappedObj);
     return uri.forget();
   }
--- a/toolkit/components/places/src/PlaceInfo.cpp
+++ b/toolkit/components/places/src/PlaceInfo.cpp
@@ -35,16 +35,17 @@
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "PlaceInfo.h"
 #include "VisitInfo.h"
 #include "nsIURI.h"
 #include "nsServiceManagerUtils.h"
 #include "nsIXPConnect.h"
+#include "mozilla/Services.h"
 
 namespace mozilla {
 namespace places {
 
 ////////////////////////////////////////////////////////////////////////////////
 //// PlaceInfo
 
 PlaceInfo::PlaceInfo(PRInt64 aId,
@@ -108,26 +109,23 @@ PlaceInfo::GetVisits(JSContext* aContext
   // TODO bug 625913 when we use this in situations that have more than one
   // visit here, we will likely want to make this cache the value.
   JSObject* visits = JS_NewArrayObject(aContext, 0, NULL);
   NS_ENSURE_TRUE(visits, NS_ERROR_OUT_OF_MEMORY);
 
   JSObject* global = JS_GetGlobalForScopeChain(aContext);
   NS_ENSURE_TRUE(global, NS_ERROR_UNEXPECTED);
 
-  static NS_DEFINE_CID(kXPConnectCID, NS_XPCONNECT_CID);
-  nsresult rv;
-  nsCOMPtr<nsIXPConnect> xpc(do_GetService(kXPConnectCID, &rv));
-  NS_ENSURE_SUCCESS(rv, rv);
+  nsCOMPtr<nsIXPConnect> xpc = mozilla::services::GetXPConnect();
 
   for (VisitsArray::size_type idx = 0; idx < mVisits.Length(); idx++) {
     nsCOMPtr<nsIXPConnectJSObjectHolder> wrapper;
-    rv = xpc->WrapNative(aContext, global, mVisits[idx],
-                         NS_GET_IID(mozIVisitInfo),
-                         getter_AddRefs(wrapper));
+    nsresult rv = xpc->WrapNative(aContext, global, mVisits[idx],
+                                  NS_GET_IID(mozIVisitInfo),
+                                  getter_AddRefs(wrapper));
     NS_ENSURE_SUCCESS(rv, rv);
 
     JSObject* jsobj;
     rv = wrapper->GetJSObject(&jsobj);
     NS_ENSURE_SUCCESS(rv, rv);
     jsval wrappedVisit = OBJECT_TO_JSVAL(jsobj);
 
     JSBool rc = JS_SetElement(aContext, visits, idx, &wrappedVisit);
--- a/xpcom/build/ServiceList.h
+++ b/xpcom/build/ServiceList.h
@@ -1,15 +1,16 @@
 MOZ_SERVICE(ChromeRegistryService, nsIChromeRegistry, "@mozilla.org/chrome/chrome-registry;1")
 MOZ_SERVICE(ToolkitChromeRegistryService, nsIToolkitChromeRegistry, "@mozilla.org/chrome/chrome-registry;1")
 MOZ_SERVICE(XULChromeRegistryService, nsIXULChromeRegistry, "@mozilla.org/chrome/chrome-registry;1")
 MOZ_SERVICE(XULOverlayProviderService, nsIXULOverlayProvider, "@mozilla.org/chrome/chrome-registry;1")
 MOZ_SERVICE(IOService, nsIIOService, "@mozilla.org/network/io-service;1")
 MOZ_SERVICE(ObserverService, nsIObserverService, "@mozilla.org/observer-service;1")
 MOZ_SERVICE(StringBundleService, nsIStringBundleService, "@mozilla.org/intl/stringbundle;1")
+MOZ_SERVICE(XPConnect, nsIXPConnect, "@mozilla.org/js/xpc/XPConnect;1")
 
 #ifdef MOZ_USE_NAMESPACE
 namespace mozilla
 {
 #endif
 
 MOZ_SERVICE(HistoryService, IHistory, "@mozilla.org/browser/history;1")
 
--- a/xpcom/build/Services.cpp
+++ b/xpcom/build/Services.cpp
@@ -44,16 +44,17 @@
 #include "nsIObserverService.h"
 #include "nsNetCID.h"
 #include "nsObserverService.h"
 #include "nsXPCOMPrivate.h"
 #include "nsIStringBundle.h"
 #include "nsIToolkitChromeRegistry.h"
 #include "nsIXULOverlayProvider.h"
 #include "IHistory.h"
+#include "nsIXPConnect.h"
 
 using namespace mozilla;
 using namespace mozilla::services;
 
 /*
  * Define a global variable and a getter for every service in ServiceList.
  * eg. gIOService and GetIOService()
  */