Bug 405241 - "Don't register nsDownloadHistory if it's not needed" [p=comrade693+bmo@gmail.com (Shawn Wilsher [sdwilsh]) r=biesi sr=bzbarsky a1.9=damons]
authorreed@reedloden.com
Fri, 30 Nov 2007 23:18:43 -0800
changeset 8507 7526fd0d10291e2b6e9bff279942039857bed513
parent 8506 f169c1029ca99c61fa49a868f2efb3abd65fc326
child 8508 8bbbb89664c566f02faf6532dc0348d800ee882b
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbiesi, bzbarsky
bugs405241
milestone1.9b2pre
Bug 405241 - "Don't register nsDownloadHistory if it's not needed" [p=comrade693+bmo@gmail.com (Shawn Wilsher [sdwilsh]) r=biesi sr=bzbarsky a1.9=damons]
docshell/base/nsDownloadHistory.cpp
docshell/base/nsDownloadHistory.h
docshell/build/nsDocShellModule.cpp
--- a/docshell/base/nsDownloadHistory.cpp
+++ b/docshell/base/nsDownloadHistory.cpp
@@ -39,22 +39,53 @@
 
 #include "nsDownloadHistory.h"
 #include "nsCOMPtr.h"
 #include "nsServiceManagerUtils.h"
 #include "nsIGlobalHistory.h"
 #include "nsIGlobalHistory2.h"
 #include "nsIObserverService.h"
 #include "nsIURI.h"
+#include "nsIComponentRegistrar.h"
+#include "nsDocShellCID.h"
 
 ////////////////////////////////////////////////////////////////////////////////
 //// nsDownloadHistory
 
 NS_IMPL_ISUPPORTS1(nsDownloadHistory, nsIDownloadHistory)
 
+nsresult
+nsDownloadHistory::RegisterSelf(nsIComponentManager *aCompMgr,
+                                nsIFile *aPath,
+                                const char *aLoaderStr,
+                                const char *aType,
+                                const nsModuleComponentInfo *aInfo)
+{
+  nsCOMPtr<nsIComponentRegistrar> compReg(do_QueryInterface(aCompMgr));
+  if (!compReg)
+    return NS_ERROR_UNEXPECTED;
+  
+  PRBool registered;
+  nsresult rv = compReg->IsContractIDRegistered(NS_DOWNLOADHISTORY_CONTRACTID,
+                                                &registered);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  // If someone has already registered the contractID, we don't want to register
+  // it ourself.  We do want to register though in case someone wants to access
+  // this implementation (by CID).
+  if (registered) {
+    return compReg->RegisterFactoryLocation(GetCID(), "nsDownloadHistory",
+                                            nsnull, aPath, aLoaderStr, aType);
+  }
+
+  return compReg->RegisterFactoryLocation(GetCID(), "nsDownloadHistory",
+                                          NS_DOWNLOADHISTORY_CONTRACTID,
+                                          aPath, aLoaderStr, aType);
+}
+
 ////////////////////////////////////////////////////////////////////////////////
 //// nsIDownloadHistory
 
 NS_IMETHODIMP
 nsDownloadHistory::AddDownload(nsIURI *aSource,
                                nsIURI *aReferrer,
                                PRTime aStartTime)
 {
--- a/docshell/base/nsDownloadHistory.h
+++ b/docshell/base/nsDownloadHistory.h
@@ -36,20 +36,29 @@
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #ifndef __nsDownloadHistory_h__
 #define __nsDownloadHistory_h__
 
 #include "nsIDownloadHistory.h"
+#include "nsIGenericFactory.h"
 
 #define NS_DOWNLOADHISTORY_CID \
   {0x2ee83680, 0x2af0, 0x4bcb, {0xbf, 0xa0, 0xc9, 0x70, 0x5f, 0x65, 0x54, 0xf1}}
 
 class nsDownloadHistory : public nsIDownloadHistory
 {
 public:
   NS_DECL_ISUPPORTS
   NS_DECL_NSIDOWNLOADHISTORY
+
+  static NS_METHOD RegisterSelf(nsIComponentManager *aCompMgr,
+                                nsIFile *aPath,
+                                const char *aLoaderStr,
+                                const char *aType,
+                                const nsModuleComponentInfo *aInfo);
+
+  NS_DEFINE_STATIC_CID_ACCESSOR(NS_DOWNLOADHISTORY_CID)
 };
 
 #endif // __nsDownloadHistory_h__
--- a/docshell/build/nsDocShellModule.cpp
+++ b/docshell/build/nsDocShellModule.cpp
@@ -245,15 +245,16 @@ static const nsModuleComponentInfo gDocS
       nsnull, nsGlobalHistoryAdapter::Create,
       nsGlobalHistoryAdapter::RegisterSelf },
     { "nsGlobalHistory2Adapter", NS_GLOBALHISTORY2ADAPTER_CID,
       nsnull, nsGlobalHistory2Adapter::Create,
       nsGlobalHistory2Adapter::RegisterSelf },
     
     // download history
     { "nsDownloadHistory", NS_DOWNLOADHISTORY_CID,
-      NS_DOWNLOADHISTORY_CONTRACTID, nsDownloadHistoryConstructor }
+      nsnull, nsDownloadHistoryConstructor,
+      nsDownloadHistory::RegisterSelf }
 };
 
 // "docshell provider" to illustrate that this thing really *should*
 // be dispensing docshells rather than webshells.
 NS_IMPL_NSGETMODULE_WITH_CTOR_DTOR(docshell_provider, gDocShellModuleInfo,
                                    Initialize, Shutdown)