Bug 568691, followup to RegisterFactory implementation: make the nsFactoryEntry hold a CIDEntry with the proper CID, because code elsewhere expects that to be present (ContractIDToCID and the pending-CID checks).
authorBenjamin Smedberg <benjamin@smedbergs.us>
Fri, 25 Jun 2010 10:44:35 -0400
changeset 47048 52c230d5f1379797fe99145dfeb1c48d105f1ceb
parent 47047 1407279e548c331d155ac130eef322859656173f
child 47049 47b1ed20995a626c15948d81f466e9dc406e7ce5
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)
bugs568691
milestone1.9.3a6pre
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 568691, followup to RegisterFactory implementation: make the nsFactoryEntry hold a CIDEntry with the proper CID, because code elsewhere expects that to be present (ContractIDToCID and the pending-CID checks).
xpcom/components/nsComponentManager.cpp
xpcom/components/nsComponentManager.h
--- a/xpcom/components/nsComponentManager.cpp
+++ b/xpcom/components/nsComponentManager.cpp
@@ -1497,17 +1497,17 @@ nsComponentManagerImpl::RegisterFactory(
         nsFactoryEntry* oldf = mFactories.Get(aClass);
         if (!oldf)
             return NS_ERROR_FACTORY_NOT_REGISTERED;
 
         mContractIDs.Put(nsDependentCString(aContractID), oldf);
         return NS_OK;
     }
 
-    nsAutoPtr<nsFactoryEntry> f(new nsFactoryEntry(aFactory));
+    nsAutoPtr<nsFactoryEntry> f(new nsFactoryEntry(aClass, aFactory));
 
     nsAutoMonitor mon(mMon);
     nsFactoryEntry* oldf = mFactories.Get(aClass);
     if (oldf)
         return NS_ERROR_FACTORY_EXISTS;
 
     if (aContractID)
         mContractIDs.Put(nsDependentCString(aContractID), f);
@@ -1680,23 +1680,37 @@ nsComponentManagerImpl::ContractIDToCID(
 
 nsFactoryEntry::nsFactoryEntry(const mozilla::Module::CIDEntry* entry,
                                nsComponentManagerImpl::KnownModule* module)
     : mCIDEntry(entry)
     , mModule(module)
 {
 }
 
-nsFactoryEntry::nsFactoryEntry(nsIFactory* factory)
+nsFactoryEntry::nsFactoryEntry(const nsCID& aCID, nsIFactory* factory)
     : mCIDEntry(NULL)
     , mModule(NULL)
     , mFactory(factory)
 {
+    mozilla::Module::CIDEntry* e = new mozilla::Module::CIDEntry();
+    nsCID* cid = new nsCID;
+    *cid = aCID;
+    e->cid = cid;
+    mCIDEntry = e;
 }        
 
+nsFactoryEntry::~nsFactoryEntry()
+{
+    // If this was a RegisterFactory entry, we own the CIDEntry/CID
+    if (!mModule) {
+        delete mCIDEntry->cid;
+        delete mCIDEntry;
+    }
+}
+
 already_AddRefed<nsIFactory>
 nsFactoryEntry::GetFactory()
 {
     if (!mFactory) {
         // RegisterFactory then UnregisterFactory can leave an entry in mContractIDs
         // pointing to an unusable nsFactoryEntry.
         if (!mModule)
             return NULL;
--- a/xpcom/components/nsComponentManager.h
+++ b/xpcom/components/nsComponentManager.h
@@ -294,17 +294,19 @@ private:
 #define NS_ERROR_IS_DIR NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_XPCOM, 24)
 
 struct nsFactoryEntry
 {
     nsFactoryEntry(const mozilla::Module::CIDEntry* entry,
                    nsComponentManagerImpl::KnownModule* module);
 
     // nsIComponentRegistrar.registerFactory support
-    nsFactoryEntry(nsIFactory* factory);
+    nsFactoryEntry(const nsCID& aClass, nsIFactory* factory);
+
+    ~nsFactoryEntry();
 
     already_AddRefed<nsIFactory> GetFactory();
 
     const mozilla::Module::CIDEntry* mCIDEntry;
     nsComponentManagerImpl::KnownModule* mModule;
 
     nsCOMPtr<nsIFactory>   mFactory;
     nsCOMPtr<nsISupports>  mServiceObject;