зеркало из https://github.com/mozilla/gecko-dev.git
back out my string bundle changes from yesterday to fix blockers
a=nhotta
This commit is contained in:
Родитель
54194a8799
Коммит
aef9cd8fd0
|
@ -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.
|
||||
|
|
|
@ -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,7 +85,7 @@ public:
|
|||
NS_DECL_NSISTRINGBUNDLE
|
||||
NS_DECL_NSISTREAMLOADEROBSERVER
|
||||
|
||||
void FlushStrings();
|
||||
nsCOMPtr<nsIPersistentProperties> mProps;
|
||||
|
||||
protected:
|
||||
//
|
||||
|
@ -95,7 +95,6 @@ protected:
|
|||
nsresult GetStringFromName(const nsAReadableString& aName, nsString& aResult);
|
||||
|
||||
private:
|
||||
nsCOMPtr<nsIPersistentProperties> 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<nsIURI> 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<nsIEventQueueService> 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 : "");
|
||||
}
|
||||
}
|
||||
|
@ -336,18 +340,9 @@ 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<nsIErrorService> 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<nsIStringBundle> 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,
|
||||
|
|
Загрузка…
Ссылка в новой задаче