From 6ce7e433266f60294537a740bebbded35bf27caa Mon Sep 17 00:00:00 2001 From: "cathleen%netscape.com" Date: Fri, 29 Jun 2001 22:57:09 +0000 Subject: [PATCH] fix bug 85770, auto register components always called at startup. r=ssu sr=alecf a=chofmann git-svn-id: svn://10.0.0.236/branches/MOZILLA_0_9_2_BRANCH@98321 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/modules/libreg/xpcom/nsRegistry.cpp | 2 +- mozilla/xpcom/components/nsRegistry.cpp | 2 +- mozilla/xpfe/bootstrap/nsAppRunner.cpp | 17 +++- mozilla/xpinstall/public/nsISoftwareUpdate.h | 82 +++++++++++++++++++ mozilla/xpinstall/src/nsInstall.cpp | 12 +-- .../xpinstall/src/nsInstallProgressDialog.cpp | 4 +- mozilla/xpinstall/src/nsSoftwareUpdate.h | 4 - 7 files changed, 102 insertions(+), 21 deletions(-) diff --git a/mozilla/modules/libreg/xpcom/nsRegistry.cpp b/mozilla/modules/libreg/xpcom/nsRegistry.cpp index 922aa5b0fa6..885ce2eda43 100644 --- a/mozilla/modules/libreg/xpcom/nsRegistry.cpp +++ b/mozilla/modules/libreg/xpcom/nsRegistry.cpp @@ -342,7 +342,7 @@ static void reginfo2Length( const REGINFO &in, PRUint32 &out ) { | This code generates the implementation of the nsISupports member functions | | for each class implemented in this file. | ------------------------------------------------------------------------------*/ -NS_IMPL_ISUPPORTS1( nsRegistry, nsIRegistry ) +NS_IMPL_THREADSAFE_ISUPPORTS1( nsRegistry, nsIRegistry ) NS_IMPL_ISUPPORTS2( nsRegSubtreeEnumerator, nsIEnumerator, nsIRegistryEnumerator) NS_IMPL_ISUPPORTS1( nsRegistryNode, nsIRegistryNode ) diff --git a/mozilla/xpcom/components/nsRegistry.cpp b/mozilla/xpcom/components/nsRegistry.cpp index 922aa5b0fa6..885ce2eda43 100644 --- a/mozilla/xpcom/components/nsRegistry.cpp +++ b/mozilla/xpcom/components/nsRegistry.cpp @@ -342,7 +342,7 @@ static void reginfo2Length( const REGINFO &in, PRUint32 &out ) { | This code generates the implementation of the nsISupports member functions | | for each class implemented in this file. | ------------------------------------------------------------------------------*/ -NS_IMPL_ISUPPORTS1( nsRegistry, nsIRegistry ) +NS_IMPL_THREADSAFE_ISUPPORTS1( nsRegistry, nsIRegistry ) NS_IMPL_ISUPPORTS2( nsRegSubtreeEnumerator, nsIEnumerator, nsIRegistryEnumerator) NS_IMPL_ISUPPORTS1( nsRegistryNode, nsIRegistryNode ) diff --git a/mozilla/xpfe/bootstrap/nsAppRunner.cpp b/mozilla/xpfe/bootstrap/nsAppRunner.cpp index 48a7378ef25..168b393129a 100644 --- a/mozilla/xpfe/bootstrap/nsAppRunner.cpp +++ b/mozilla/xpfe/bootstrap/nsAppRunner.cpp @@ -66,6 +66,7 @@ #include "nsProcess.h" #include "InstallCleanupDefines.h" +#include "nsISoftwareUpdate.h" // Interfaces Needed #include "nsIXULWindow.h" @@ -1039,8 +1040,20 @@ static nsresult main1(int argc, char* argv[], nsISupports *nativeApp ) NS_ASSERTION(NS_SUCCEEDED(rv), "Initializing AppleEvents failed"); #endif - // XXX: This call will be replaced by a registry initialization... - NS_SetupRegistry_1( PR_TRUE ); + // Ask XPInstall if we need to autoregister anything new. + PRBool needAutoReg = NS_SoftwareUpdateNeedsAutoReg(); + +#ifdef DEBUG + // _Always_ autoreg if we're in a debug build, under the assumption + // that people are busily modifying components and will be angry if + // their changes aren't noticed. + needAutoReg = PR_TRUE; +#endif + + NS_SetupRegistry_1(needAutoReg); + + if (needAutoReg) // XXX ...and autoreg was successful? + NS_SoftwareUpdateDidAutoReg(); // remove the nativeApp as an XPCOM autoreg observer if (obsService) diff --git a/mozilla/xpinstall/public/nsISoftwareUpdate.h b/mozilla/xpinstall/public/nsISoftwareUpdate.h index ed6f5ae5f73..6bdd824e512 100644 --- a/mozilla/xpinstall/public/nsISoftwareUpdate.h +++ b/mozilla/xpinstall/public/nsISoftwareUpdate.h @@ -37,6 +37,9 @@ #include "nsIGenericFactory.h" #include "nsIDOMWindowInternal.h" +#include "nsIRegistry.h" +#include "nsIRegistryUtils.h" + #define NS_IXPINSTALLCOMPONENT_CONTRACTID NS_IAPPSHELLCOMPONENT_CONTRACTID "/xpinstall;1" #define NS_IXPINSTALLCOMPONENT_CLASSNAME "Mozilla XPInstall Component" @@ -108,6 +111,85 @@ protected: nsCOMPtr mInstallVersionFactory; }; +#define XPI_ROOT_KEY "software/mozilla/xpinstall" +#define XPI_AUTOREG_VAL "Autoreg" +#define XPCOM_KEY "software/mozilla/XPCOM" + +/** + * @return PR_TRUE if XPI has requested an autoreg be performed. + */ +inline PRBool +NS_SoftwareUpdateNeedsAutoReg() +{ + nsresult rv; + + // Conservatively assume that we'll need to autoreg. + PRBool needAutoReg = PR_TRUE; + + nsCOMPtr reg = do_GetService(NS_REGISTRY_CONTRACTID, &rv); + if (NS_SUCCEEDED(rv)) { + rv = reg->OpenWellKnownRegistry(nsIRegistry::ApplicationComponentRegistry); + if (NS_SUCCEEDED(rv)) { + nsRegistryKey idKey = 0; + rv = reg->GetSubtree(nsIRegistry::Common, XPI_ROOT_KEY, &idKey); + if (NS_SUCCEEDED(rv)) { + char* autoRegVal = nsnull; + rv = reg->GetStringUTF8(idKey, XPI_AUTOREG_VAL, &autoRegVal); + + // If the string exists and isn't ``yes'', then we can avoid + // autoreg; otherwise, be conservative and autoregister. + if (NS_SUCCEEDED(rv) && (PL_strcmp(autoRegVal, "yes") != 0)) + needAutoReg = PR_FALSE; + + if (autoRegVal) + nsMemory::Free(autoRegVal); + } + } + } + + return needAutoReg; +} + +/** + * Notify XPI that autoreg was performed successfully. + */ +inline void +NS_SoftwareUpdateDidAutoReg() +{ + nsresult rv; + nsCOMPtr reg = do_GetService(NS_REGISTRY_CONTRACTID, &rv); + if (NS_SUCCEEDED(rv)) { + rv = reg->OpenWellKnownRegistry(nsIRegistry::ApplicationComponentRegistry); + if (NS_SUCCEEDED(rv)) { + nsRegistryKey idKey = 0; + rv = reg->AddSubtree(nsIRegistry::Common, XPI_ROOT_KEY, &idKey); + + if (NS_SUCCEEDED(rv)) + reg->SetStringUTF8(idKey, XPI_AUTOREG_VAL, "no"); + } + } +} + +/** + * Request that an autoreg be performed at next startup. (Used + * internally by XPI.) + */ +inline void +NS_SoftwareUpdateRequestAutoReg() +{ + nsresult rv; + nsCOMPtr reg = do_GetService(NS_REGISTRY_CONTRACTID, &rv); + if (NS_SUCCEEDED(rv)) { + rv = reg->OpenWellKnownRegistry(nsIRegistry::ApplicationComponentRegistry); + if (NS_SUCCEEDED(rv)) { + nsRegistryKey idKey = 0; + rv = reg->AddSubtree(nsIRegistry::Common, XPI_ROOT_KEY, &idKey); + + if (NS_SUCCEEDED(rv)) + reg->SetStringUTF8(idKey, XPI_AUTOREG_VAL, "yes"); + } + } +} #endif // nsISoftwareUpdate_h__ diff --git a/mozilla/xpinstall/src/nsInstall.cpp b/mozilla/xpinstall/src/nsInstall.cpp index 40d1a3e3e5c..5d9e9fa6a2c 100644 --- a/mozilla/xpinstall/src/nsInstall.cpp +++ b/mozilla/xpinstall/src/nsInstall.cpp @@ -860,17 +860,7 @@ nsInstall::FinalizeInstall(PRInt32* aReturn) // XXX for now all successful installs will trigger an Autoreg. // We eventually want to do this only when flagged. - HREG reg; - if ( REGERR_OK == NR_RegOpen("", ®) ) - { - RKEY xpiRoot; - REGERR err; - err = NR_RegAddKey(reg,ROOTKEY_COMMON,XPI_ROOT_KEY,&xpiRoot); - if ( err == REGERR_OK ) - NR_RegSetEntryString(reg, xpiRoot, XPI_AUTOREG_VAL, "yes"); - - NR_RegClose(reg); - } + NS_SoftwareUpdateRequestAutoReg(); } else *aReturn = SaveError( result ); diff --git a/mozilla/xpinstall/src/nsInstallProgressDialog.cpp b/mozilla/xpinstall/src/nsInstallProgressDialog.cpp index a0977e1ba13..2b6b0c396f9 100644 --- a/mozilla/xpinstall/src/nsInstallProgressDialog.cpp +++ b/mozilla/xpinstall/src/nsInstallProgressDialog.cpp @@ -56,8 +56,8 @@ nsInstallProgressDialog::~nsInstallProgressDialog() } -NS_IMPL_ADDREF( nsInstallProgressDialog ); -NS_IMPL_RELEASE( nsInstallProgressDialog ); +NS_IMPL_THREADSAFE_ADDREF( nsInstallProgressDialog ); +NS_IMPL_THREADSAFE_RELEASE( nsInstallProgressDialog ); NS_IMETHODIMP nsInstallProgressDialog::QueryInterface(REFNSIID aIID,void** aInstancePtr) diff --git a/mozilla/xpinstall/src/nsSoftwareUpdate.h b/mozilla/xpinstall/src/nsSoftwareUpdate.h index 93887ba304f..89b17ee94c8 100644 --- a/mozilla/xpinstall/src/nsSoftwareUpdate.h +++ b/mozilla/xpinstall/src/nsSoftwareUpdate.h @@ -25,10 +25,6 @@ class nsInstallInfo; #include "nsTopProgressNotifier.h" -#define XPI_ROOT_KEY "software/mozilla/xpinstall" -#define XPI_AUTOREG_VAL "Autoreg" -#define XPCOM_KEY "software/mozilla/XPCOM" - class nsSoftwareUpdate: public nsISoftwareUpdate, public nsPIXPIStubHook, public nsIObserver