Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes
nsStringBundleService Class Reference

#include <nsStringBundleService.h>

Inheritance diagram for nsStringBundleService:
Inheritance graph
Collaboration diagram for nsStringBundleService:
Collaboration graph

List of all members.

Public Member Functions

 nsStringBundleService ()
virtual ~nsStringBundleService ()
nsresult Init ()
nsIStringBundle createBundle (in string aURLSpec)
nsIStringBundle createExtensibleBundle (in string aRegistryKey)
wstring formatStatusMessage (in nsresult aStatus, in wstring aStatusArg)
 Formats a message string from a status code and status arguments.
void flushBundles ()
 flushes the string bundle cache - useful when the locale changes or when we need to get some extra memory back
void observe (in nsISupports aSubject, in string aTopic, in wstring aData)
 Observe will be called when there is a notification for the topic |aTopic|.

Private Member Functions

nsresult getStringBundle (const char *aUrl, nsIStringBundle **aResult)
nsresult FormatWithBundle (nsIStringBundle *bundle, nsresult aStatus, PRUint32 argCount, PRUnichar **argArray, PRUnichar **result)
void flushBundleCache ()
bundleCacheEntry_tinsertIntoCache (nsIStringBundle *aBundle, nsCStringKey *aHashKey)

Static Private Member Functions

static void recycleEntry (bundleCacheEntry_t *)

Private Attributes

nsHashtable mBundleMap
PRCList mBundleCache
PLArenaPool mCacheEntryPool
nsCOMPtr< nsIErrorServicemErrorService
nsCOMPtr< nsIStringBundleOverridemOverrideStrings

Detailed Description

Definition at line 55 of file nsStringBundleService.h.

Constructor & Destructor Documentation

Definition at line 540 of file nsStringBundle.cpp.

#ifdef DEBUG_tao_
  printf("\n++ nsStringBundleService::nsStringBundleService ++\n");

  PL_InitArenaPool(&mCacheEntryPool, "srEntries",

  mErrorService = do_GetService(kErrorServiceCID);
  NS_ASSERTION(mErrorService, "Couldn't get error service");


Here is the call graph for this function:

Member Function Documentation

Definition at line 599 of file nsStringBundle.cpp.

  // release all bundles in the cache
  PRCList *current = PR_LIST_HEAD(&mBundleCache);
  while (current != &mBundleCache) {
    bundleCacheEntry_t *cacheEntry = (bundleCacheEntry_t*)current;

    PRCList *oldItem = current;
    current = PR_NEXT_LINK(current);
    // will be freed in PL_FreeArenaPool

Here is the call graph for this function:

flushes the string bundle cache - useful when the locale changes or when we need to get some extra memory back

at some point, we might want to make this flush all the bundles, because any bundles that are floating around when the locale changes will suddenly contain bad data

wstring nsIStringBundleService::formatStatusMessage ( in nsresult  aStatus,
in wstring  aStatusArg 
) [inherited]

Formats a message string from a status code and status arguments.

aStatus- The status code. This is mapped into a string ID and and used in the string lookup process (see nsIErrorService).
aStatusArg- The status message argument(s). Multiple arguments can be separated by newline ('
') characters.
the formatted message
nsresult nsStringBundleService::FormatWithBundle ( nsIStringBundle bundle,
nsresult  aStatus,
PRUint32  argCount,
PRUnichar **  argArray,
PRUnichar **  result 
) [private]

Definition at line 757 of file nsStringBundle.cpp.

  nsresult rv;
  nsXPIDLCString key;

  // then find a key into the string bundle for that particular error:
  rv = mErrorService->GetErrorStringBundleKey(aStatus, getter_Copies(key));

  // first try looking up the error message with the string key:
  if (NS_SUCCEEDED(rv)) {
    rv = bundle->FormatStringFromName(NS_ConvertASCIItoUCS2(key).get(),
                                      (const PRUnichar**)argArray, 
                                      argCount, result);

  // if the string key fails, try looking up the error message with the int key:
  if (NS_FAILED(rv)) {
    PRUint16 code = NS_ERROR_GET_CODE(aStatus);
    rv = bundle->FormatStringFromID(code, (const PRUnichar**)argArray, argCount, result);

  // If the int key fails, try looking up the default error message. E.g. print:
  //   An unknown error has occurred (0x804B0003).
  if (NS_FAILED(rv)) {
    nsAutoString statusStr; statusStr.AppendInt(aStatus, 16);
    const PRUnichar* otherArgArray[1];
    otherArgArray[0] = statusStr.get();
    rv = bundle->FormatStringFromID(code, otherArgArray, 1, result);

  return rv;

Here is the call graph for this function:

nsresult nsStringBundleService::getStringBundle ( const char *  aUrl,
nsIStringBundle **  aResult 
) [private]

Definition at line 626 of file nsStringBundle.cpp.

  nsCStringKey completeKey(aURLSpec);

  bundleCacheEntry_t* cacheEntry =
  if (cacheEntry) {
    // cache hit!
    // remove it from the list, it will later be reinserted
    // at the head of the list
  } else {

    // hasn't been cached, so insert it into the hash table
    nsStringBundle* bundle = new nsStringBundle(aURLSpec, mOverrideStrings);
    if (!bundle) return NS_ERROR_OUT_OF_MEMORY;
    cacheEntry = insertIntoCache(bundle, &completeKey);
    NS_RELEASE(bundle);         // cache should now be holding a ref
                                // in the cacheEntry

  // at this point the cacheEntry should exist in the hashtable,
  // but is not in the LRU cache.
  // put the cache entry at the front of the list
  PR_INSERT_LINK((PRCList *)cacheEntry, &mBundleCache);

  // finally, return the value
  *aResult = cacheEntry->mBundle;

  return NS_OK;

Here is the call graph for this function:

Definition at line 569 of file nsStringBundle.cpp.

  nsCOMPtr<nsIObserverService> os = do_GetService(";1");
  if (os) {
    os->AddObserver(this, "memory-pressure", PR_TRUE);
    os->AddObserver(this, "profile-do-change", PR_TRUE);
    os->AddObserver(this, "chrome-flush-caches", PR_TRUE);

  // instantiate the override service, if there is any.
  // at some point we probably want to make this a category, and
  // support multiple overrides
  return NS_OK;

Here is the call graph for this function:

bundleCacheEntry_t * nsStringBundleService::insertIntoCache ( nsIStringBundle aBundle,
nsCStringKey *  aHashKey 
) [private]

Definition at line 666 of file nsStringBundle.cpp.

  bundleCacheEntry_t *cacheEntry;
  if (mBundleMap.Count() < MAX_CACHED_BUNDLES) {
    // cache not full - create a new entry
    void *cacheEntryArena;
    PL_ARENA_ALLOCATE(cacheEntryArena, &mCacheEntryPool, sizeof(bundleCacheEntry_t));
    cacheEntry = (bundleCacheEntry_t*)cacheEntryArena;
  } else {
    // cache is full
    // take the last entry in the list, and recycle it.
    cacheEntry = (bundleCacheEntry_t*)PR_LIST_TAIL(&mBundleCache);
    // remove it from the hash table and linked list
                 "Element will not be removed!");
#ifdef DEBUG_alecf
                               "Booting %s to make room for %s\n",

    // free up excess memory
  // at this point we have a new cacheEntry that doesn't exist
  // in the hashtable, so set up the cacheEntry
  cacheEntry->mBundle = aBundle;

  cacheEntry->mHashKey = (nsCStringKey*)aHashKey->Clone();
  // insert the entry into the cache and map, make it the MRU
  mBundleMap.Put(cacheEntry->mHashKey, cacheEntry);

  return cacheEntry;

Here is the call graph for this function:

Here is the caller graph for this function:

void nsIObserver::observe ( in nsISupports  aSubject,
in string  aTopic,
in wstring  aData 
) [inherited]

Observe will be called when there is a notification for the topic |aTopic|.

This assumes that the object implementing this interface has been registered with an observer service such as the nsIObserverService.

If you expect multiple topics/subjects, the impl is responsible for filtering.

You should not modify, add, remove, or enumerate notifications in the implemention of observe.

aSubject: Notification specific interface pointer.
aTopic: The notification topic or subject.
aData: Notification specific wide string. subject event.

Definition at line 713 of file nsStringBundle.cpp.

  delete aEntry->mHashKey;

Here is the caller graph for this function:

Member Data Documentation

Definition at line 83 of file nsStringBundleService.h.

nsHashtable nsStringBundleService::mBundleMap [private]

Definition at line 82 of file nsStringBundleService.h.

Definition at line 84 of file nsStringBundleService.h.

Definition at line 86 of file nsStringBundleService.h.

Definition at line 87 of file nsStringBundleService.h.

The documentation for this class was generated from the following files: