From aef9cd8fd09b3af29342b5a719381aee3105be84 Mon Sep 17 00:00:00 2001 From: "alecf%netscape.com" Date: Tue, 3 Jul 2001 17:34:47 +0000 Subject: [PATCH] back out my string bundle changes from yesterday to fix blockers a=nhotta --- intl/strres/public/nsIStringBundle.idl | 5 +- intl/strres/src/nsStringBundle.cpp | 116 ++++++++----------------- 2 files changed, 40 insertions(+), 81 deletions(-) diff --git a/intl/strres/public/nsIStringBundle.idl b/intl/strres/public/nsIStringBundle.idl index 42371401eb58..7f5faeaef769 100644 --- a/intl/strres/public/nsIStringBundle.idl +++ b/intl/strres/public/nsIStringBundle.idl @@ -78,8 +78,9 @@ interface nsIStringBundle : nsISupports [scriptable, uuid(D85A17C0-AA7C-11d2-9B8C-00805F8A16D9)] interface nsIStringBundleService : nsISupports { - nsIStringBundle createBundle(in string aURLSpec); - nsIStringBundle createExtensibleBundle(in string aRegistryKey); + nsIStringBundle createBundle([const] in string aURLSpec); + nsIStringBundle createAsyncBundle([const] in string aURLSpec); + nsIStringBundle createExtensibleBundle([const] in string aRegistryKey); /** * Formats a message string from a status code and status arguments. diff --git a/intl/strres/src/nsStringBundle.cpp b/intl/strres/src/nsStringBundle.cpp index a05578601372..20666fae5345 100644 --- a/intl/strres/src/nsStringBundle.cpp +++ b/intl/strres/src/nsStringBundle.cpp @@ -47,7 +47,6 @@ #include "nsIModule.h" #include "nsIRegistry.h" #include "nsISupportsArray.h" -#include "nsVoidArray.h" #include "nsHashtable.h" #include "nsAutoLock.h" #include "nsTextFormatter.h" @@ -69,8 +68,9 @@ static NS_DEFINE_CID(kErrorServiceCID, NS_ERRORSERVICE_CID); // XXX investigate need for proper locking in this module //static PRInt32 gLockCount = 0; +NS_DEFINE_IID(kStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID); + class nsStringBundle : public nsIStringBundle, - public nsSupportsWeakReference, public nsIStreamLoaderObserver { public: @@ -85,8 +85,8 @@ public: NS_DECL_NSISTRINGBUNDLE NS_DECL_NSISTREAMLOADEROBSERVER - void FlushStrings(); - + nsCOMPtr mProps; + protected: // // functional decomposition of the funitions repeatively called @@ -95,7 +95,6 @@ protected: nsresult GetStringFromName(const nsAReadableString& aName, nsString& aResult); private: - nsCOMPtr mProps; nsCString mPropertiesURL; PRBool mAttemptedLoad; PRBool mLoaded; @@ -114,6 +113,12 @@ nsStringBundle::InitSyncStream(const char* aURLSpec) nsresult rv = NS_OK; + // plan A: don't fallback; use aURLSpec: xxx.pro -> xxx.pro + +#ifdef DEBUG_tao_ + printf("\n** nsStringBundle::InitSyncStream: %s\n", aURLSpec?s:"null"); +#endif + nsCOMPtr uri; rv = NS_NewURI(getter_AddRefs(uri), aURLSpec); if (NS_FAILED(rv)) return rv; @@ -167,9 +172,8 @@ nsStringBundle::LoadProperties() mAttemptedLoad = PR_TRUE; // - // use eventloop to load the string bundle + // use eventloop instead // - // create an event queue for this thread. nsresult rv; nsCOMPtr service = do_GetService(NS_EVENTQUEUESERVICE_CONTRACTID, &rv); @@ -188,17 +192,17 @@ nsStringBundle::LoadProperties() rv = NS_NewStreamLoader(getter_AddRefs(loader), uri, this /*the load observer*/); - NS_ASSERTION(NS_SUCCEEDED(rv), "nsStringBundle::Init: NS_NewStreamLoader failed..."); + NS_ASSERTION(NS_SUCCEEDED(rv), "\n-->nsStringBundle::Init: NS_NewStreamLoader failed...\n"); // process events until we're finished. PLEvent *event; while (!mLoaded) { rv = currentThreadQ->WaitForEvent(&event); - NS_ASSERTION(NS_SUCCEEDED(rv), "nsStringBundle::Init: currentThreadQ->WaitForEvent failed."); + NS_ASSERTION(NS_SUCCEEDED(rv), "\n-->nsStringBundle::Init: currentThreadQ->WaitForEvent failed...\n"); if (NS_FAILED(rv)) return rv; rv = currentThreadQ->HandleEvent(event); - NS_ASSERTION(NS_SUCCEEDED(rv), "nsStringBundle::Init: currentThreadQ->HandleEvent failed..."); + NS_ASSERTION(NS_SUCCEEDED(rv), "\n-->nsStringBundle::Init: currentThreadQ->HandleEvent failed...\n"); if (NS_FAILED(rv)) return rv; } @@ -229,7 +233,7 @@ nsStringBundle::OnStreamComplete(nsIStreamLoader* aLoader, channel->GetURI(getter_AddRefs(uri)); if (uri) { uri->GetSpec(getter_Copies(uriSpec)); - printf("-->nsStringBundle::OnStreamComplete: Failed to load %s\n", + printf("\n -->nsStringBundle::OnStreamComplete: Failed to load %s\n", uriSpec ? (const char *) uriSpec : ""); } } @@ -335,19 +339,10 @@ nsStringBundle::FormatStringFromName(const PRUnichar *aName, return FormatString(formatStr.get(), aParams, aLength, aResult); } + -void -nsStringBundle::FlushStrings() -{ - mProps = nsnull; - mLoaded = mAttemptedLoad = PR_FALSE; -} - - -NS_IMPL_THREADSAFE_ISUPPORTS3(nsStringBundle, - nsIStringBundle, - nsISupportsWeakReference, - nsIStreamLoaderObserver) +NS_IMPL_THREADSAFE_ISUPPORTS2(nsStringBundle, + nsIStringBundle, nsIStreamLoaderObserver) /* void GetStringFromID (in long aID, out wstring aResult); */ NS_IMETHODIMP @@ -734,18 +729,14 @@ private: PRUnichar* *result); void flushBundleCache(); - void flushNotificationList(); bundleCacheEntry_t *insertIntoCache(nsIStringBundle *aBundle, nsCStringKey *aHashKey); - void insertIntoNotificationList(nsStringBundle* aBundle); - static void recycleEntry(bundleCacheEntry_t*); nsHashtable mBundleMap; PRCList mBundleCache; - nsVoidArray mBundleList; PLArenaPool mCacheEntryPool; nsCOMPtr mErrorService; @@ -756,6 +747,9 @@ private: nsStringBundleService::nsStringBundleService() : mBundleMap(MAX_CACHED_BUNDLES, PR_TRUE) { +#ifdef DEBUG_tao_ + printf("\n++ nsStringBundleService::nsStringBundleService ++\n"); +#endif NS_INIT_REFCNT(); PR_INIT_CLIST(&mBundleCache); @@ -820,47 +814,10 @@ nsStringBundleService::flushBundleCache() PL_FreeArenaPool(&mCacheEntryPool); } -void -nsStringBundleService::flushNotificationList() -{ - nsWeakPtr weakBundle; - nsCOMPtr bundle; - - PRUint32 count; - count = mBundleList.Count(); - - // count backwards through the list, since we might be removing - // elements - printf("flushNotificationList()\n"); - PRInt32 i; - for (i=count; i>0; --i) { - weakBundle = (nsIWeakReference*)mBundleList.ElementAt(i-1); - printf("\tFlushing element %d: %p (%p)", i-1, - mBundleList.ElementAt(i-1), weakBundle.get()); - if (!weakBundle) { - mBundleList.RemoveElementAt(i-1); - continue; - } - - bundle = do_QueryReferent(weakBundle); - - // remove weak references whose target has gone away - if (!bundle) - mBundleList.RemoveElementAt(i-1); - else { - // we own this list, so we know exactly what is stored there - nsStringBundle* bundleImpl = (nsStringBundle*)bundle.get(); - bundleImpl->FlushStrings(); - } - } - -} - NS_IMETHODIMP nsStringBundleService::FlushBundles() { flushBundleCache(); - flushNotificationList(); return NS_OK; } @@ -899,8 +856,6 @@ nsStringBundleService::getStringBundle(const char *aURLSpec, return NS_ERROR_FAILURE; } - insertIntoNotificationList(bundle); - cacheEntry = insertIntoCache(bundle, &completeKey); NS_RELEASE(bundle); // cache should now be holding a ref // in the cacheEntry @@ -960,18 +915,6 @@ nsStringBundleService::insertIntoCache(nsIStringBundle* aBundle, return cacheEntry; } -void -nsStringBundleService::insertIntoNotificationList(nsStringBundle *aBundle) -{ - nsIStringBundle* bundle = NS_STATIC_CAST(nsIStringBundle*, aBundle); - nsWeakPtr weakBundle = do_GetWeakReference(bundle); - - printf("inserting %p into notification list\n", weakBundle.get()); - if (weakBundle) - mBundleList.AppendElement((void*)weakBundle.get()); -} - - void nsStringBundleService::recycleEntry(bundleCacheEntry_t *aEntry) { @@ -983,9 +926,24 @@ NS_IMETHODIMP nsStringBundleService::CreateBundle(const char* aURLSpec, nsIStringBundle** aResult) { +#ifdef DEBUG_tao_ + printf("\n++ nsStringBundleService::CreateBundle ++\n"); + { + nsAutoString aURLStr(aURLSpec); + char *s = aURLStr.ToNewCString(); + printf("\n** nsStringBundleService::CreateBundle: %s\n", s?s:"null"); + delete s; + } +#endif + return getStringBundle(aURLSpec, mAsync?PR_TRUE:PR_FALSE, aResult); } - + +NS_IMETHODIMP +nsStringBundleService::CreateAsyncBundle(const char* aURLSpec, nsIStringBundle** aResult) +{ + return getStringBundle(aURLSpec, PR_TRUE, aResult); +} NS_IMETHODIMP nsStringBundleService::CreateExtensibleBundle(const char* aRegistryKey,