Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Functions | Variables
prefapi.cpp File Reference
#include "prefapi.h"
#include "prefapi_private_data.h"
#include "prefread.h"
#include "nsReadableUtils.h"
#include "nsCRT.h"
#include "plarena.h"
#include "plstr.h"
#include "pldhash.h"
#include "plbase64.h"
#include "prlog.h"
#include "prmem.h"
#include "prprf.h"
#include "nsQuickSort.h"
#include "nsString.h"
#include "nsPrintfCString.h"
#include "prlink.h"

Go to the source code of this file.

Classes

struct  CallbackNode

Defines

#define PL_ARENA_CONST_ALIGN_MASK   3
#define BOGUS_DEFAULT_INT_PREF_VALUE   (-5632)
#define BOGUS_DEFAULT_BOOL_PREF_VALUE   (-2)
#define PR_ALIGN_OF_WORD   PR_ALIGN_OF_POINTER
#define PREFNAME_ARENA_SIZE   8192
#define WORD_ALIGN_MASK   (PR_ALIGN_OF_WORD - 1)
#define PREF_IS_LOCKED(pref)   ((pref)->flags & PREF_LOCKED)
#define PREF_HAS_USER_VALUE(pref)   ((pref)->flags & PREF_USERSET)
#define PREF_TYPE(pref)   (PrefType)((pref)->flags & PREF_VALUETYPE_MASK)

Functions

 clearPrefEntry (PLDHashTable *table, PLDHashEntryHdr *entry)
 matchPrefEntry (PLDHashTable *, const PLDHashEntryHdr *entry, const void *key)
static char * ArenaStrDup (const char *str, PLArenaPool *aArena)
static PRBool pref_ValueChanged (PrefValue oldValue, PrefValue newValue, PrefType type)
static nsresult pref_DoCallback (const char *changed_pref)
static nsresult pref_HashPref (const char *key, PrefValue value, PrefType type, PRBool defaultPref)
static PrefHashEntrypref_HashTableLookup (const void *key)
nsresult PREF_Init ()
void PREF_Cleanup ()
void PREF_CleanupPrefs ()
static void str_escape (const char *original, nsAFlatCString &aResult)
nsresult PREF_SetCharPref (const char *pref_name, const char *value, PRBool set_default)
nsresult PREF_SetIntPref (const char *pref_name, PRInt32 value, PRBool set_default)
nsresult PREF_SetBoolPref (const char *pref_name, PRBool value, PRBool set_default)
PLDHashOperator pref_savePref (PLDHashTable *table, PLDHashEntryHdr *heh, PRUint32 i, void *arg)
int PR_CALLBACK pref_CompareStrings (const void *v1, const void *v2, void *unused)
PRBool PREF_HasUserPref (const char *pref_name)
nsresult PREF_GetCharPref (const char *pref_name, char *return_buffer, int *length, PRBool get_default)
nsresult PREF_CopyCharPref (const char *pref_name, char **return_buffer, PRBool get_default)
nsresult PREF_GetIntPref (const char *pref_name, PRInt32 *return_int, PRBool get_default)
nsresult PREF_GetBoolPref (const char *pref_name, PRBool *return_value, PRBool get_default)
 pref_DeleteItem (PLDHashTable *table, PLDHashEntryHdr *heh, PRUint32 i, void *arg)
nsresult PREF_DeleteBranch (const char *branch_name)
nsresult PREF_ClearUserPref (const char *pref_name)
 pref_ClearUserPref (PLDHashTable *table, PLDHashEntryHdr *he, PRUint32, void *arg)
nsresult PREF_ClearAllUserPrefs ()
nsresult PREF_LockPref (const char *key, PRBool lockit)
static void pref_SetValue (PrefValue *oldValue, PrefValue newValue, PrefType type)
PrefType PREF_GetPrefType (const char *pref_name)
PRBool PREF_PrefIsLocked (const char *pref_name)
void PREF_RegisterCallback (const char *pref_node, PrefChangedFunc callback, void *instance_data)
struct CallbackNodepref_RemoveCallbackNode (struct CallbackNode *node, struct CallbackNode *prev_node)
nsresult PREF_UnregisterCallback (const char *pref_node, PrefChangedFunc callback, void *instance_data)
void PREF_ReaderCallback (void *closure, const char *pref, PrefValue value, PrefType type, PRBool isDefault)

Variables

PLDHashTable gHashTable = { nsnull }
static PLArenaPool gPrefNameArena
PRBool gDirty = PR_FALSE
static struct CallbackNodegCallbacks = NULL
static PRBool gCallbacksEnabled = PR_TRUE
static PRBool gIsAnyPrefLocked = PR_FALSE
static PRBool gCallbacksInProgress = PR_FALSE
static PRBool gShouldCleanupDeadNodes = PR_FALSE
static PLDHashTableOps pref_HashTableOps

Class Documentation

struct CallbackNode

Definition at line 179 of file prefapi.cpp.

Collaboration diagram for CallbackNode:
Class Members
void * data
char * domain
PrefChangedFunc func
struct CallbackNode * next

Define Documentation

Definition at line 86 of file prefapi.cpp.

Definition at line 85 of file prefapi.cpp.

Definition at line 44 of file prefapi.cpp.

Definition at line 145 of file prefapi.cpp.

#define PREF_HAS_USER_VALUE (   pref)    ((pref)->flags & PREF_USERSET)

Definition at line 173 of file prefapi.cpp.

#define PREF_IS_LOCKED (   pref)    ((pref)->flags & PREF_LOCKED)

Definition at line 172 of file prefapi.cpp.

#define PREF_TYPE (   pref)    (PrefType)((pref)->flags & PREF_VALUETYPE_MASK)

Definition at line 174 of file prefapi.cpp.

Definition at line 149 of file prefapi.cpp.

Definition at line 151 of file prefapi.cpp.


Function Documentation

static char* ArenaStrDup ( const char *  str,
PLArenaPool aArena 
) [static]

Definition at line 160 of file prefapi.cpp.

{
    void* mem;
    PRUint32 len = strlen(str);
    PL_ARENA_ALLOCATE(mem, aArena, len+1);
    if (mem)
        memcpy(mem, str, len+1);
    return NS_STATIC_CAST(char*, mem);
}

Here is the call graph for this function:

Here is the caller graph for this function:

clearPrefEntry ( PLDHashTable table,
PLDHashEntryHdr entry 
)

Definition at line 89 of file prefapi.cpp.

{
    PrefHashEntry *pref = NS_STATIC_CAST(PrefHashEntry *, entry);
    if (pref->flags & PREF_STRING)
    {
        PR_FREEIF(pref->defaultPref.stringVal);
        PR_FREEIF(pref->userPref.stringVal);
    }
    // don't need to free this as it's allocated in memory owned by
    // gPrefNameArena
    pref->key = nsnull;
    memset(entry, 0, table->entrySize);
}

Here is the call graph for this function:

matchPrefEntry ( PLDHashTable ,
const PLDHashEntryHdr entry,
const void key 
)

Definition at line 104 of file prefapi.cpp.

{
    const PrefHashEntry *prefEntry =
        NS_STATIC_CAST(const PrefHashEntry*,entry);

    if (prefEntry->key == key) return PR_TRUE;

    if (!prefEntry->key || !key) return PR_FALSE;

    const char *otherKey = NS_REINTERPRET_CAST(const char*, key);
    return (strcmp(prefEntry->key, otherKey) == 0);
}

Definition at line 213 of file prefapi.cpp.

{
    NS_ASSERTION(!gCallbacksInProgress,
        "PREF_Cleanup was called while gCallbacksInProgress is PR_TRUE!");
    struct CallbackNode* node = gCallbacks;
    struct CallbackNode* next_node;

    while (node)
    {
        next_node = node->next;
        PR_Free(node->domain);
        PR_Free(node);
        node = next_node;
    }
    gCallbacks = NULL;

    PREF_CleanupPrefs();
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 233 of file prefapi.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 603 of file prefapi.cpp.

Here is the call graph for this function:

nsresult PREF_ClearUserPref ( const char *  pref_name)

Definition at line 562 of file prefapi.cpp.

{
    if (!gHashTable.ops)
        return NS_ERROR_NOT_INITIALIZED;

    nsresult rv = NS_ERROR_UNEXPECTED;
    PrefHashEntry* pref = pref_HashTableLookup(pref_name);
    if (pref && PREF_HAS_USER_VALUE(pref))
    {
        pref->flags &= ~PREF_USERSET;
        if (gCallbacksEnabled)
            pref_DoCallback(pref_name);
        gDirty = PR_TRUE;
        rv = NS_OK;
    }
    return rv;
}

Here is the call graph for this function:

pref_ClearUserPref ( PLDHashTable table,
PLDHashEntryHdr he,
PRUint32  ,
void arg 
)

Definition at line 581 of file prefapi.cpp.

{
    PrefHashEntry *pref = NS_STATIC_CAST(PrefHashEntry*,  he);

    if (PREF_HAS_USER_VALUE(pref))
    {
        // Note that we're not unhashing the pref. A pref which has both
        // a user value and a default value needs to remain. Currently,
        // there isn't a way to determine that a pref has a default value,
        // other than comparing its value to BOGUS_DEFAULT_XXX_PREF_VALUE.
        // This needs to be fixed. If we could positively identify a pref
        // as not having a set default value here, we could unhash it.

        pref->flags &= ~PREF_USERSET;
        if (gCallbacksEnabled)
            pref_DoCallback(pref->key);
    }
    return PL_DHASH_NEXT;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int PR_CALLBACK pref_CompareStrings ( const void v1,
const void v2,
void unused 
)

Definition at line 379 of file prefapi.cpp.

{
    char *s1 = *(char**) v1;
    char *s2 = *(char**) v2;

    if (!s1)
    {
        if (!s2)
            return 0;
        else
            return -1;
    }
    else if (!s2)
        return 1;
    else
        return strcmp(s1, s2);
}

Here is the caller graph for this function:

nsresult PREF_CopyCharPref ( const char *  pref_name,
char **  return_buffer,
PRBool  get_default 
)

Definition at line 444 of file prefapi.cpp.

{
    if (!gHashTable.ops)
        return NS_ERROR_NOT_INITIALIZED;

    nsresult rv = NS_ERROR_UNEXPECTED;
    char* stringVal;
    PrefHashEntry* pref = pref_HashTableLookup(pref_name);

    if (pref && (pref->flags & PREF_STRING))
    {
        if (get_default || PREF_IS_LOCKED(pref) || !PREF_HAS_USER_VALUE(pref))
            stringVal = pref->defaultPref.stringVal;
        else
            stringVal = pref->userPref.stringVal;

        if (stringVal) {
            *return_buffer = PL_strdup(stringVal);
            rv = NS_OK;
        }
    }
    return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult PREF_DeleteBranch ( const char *  branch_name)

Definition at line 537 of file prefapi.cpp.

{
    int len = (int)PL_strlen(branch_name);

    if (!gHashTable.ops)
        return NS_ERROR_NOT_INITIALIZED;

    /* The following check insures that if the branch name already has a "."
     * at the end, we don't end up with a "..". This fixes an incompatibility
     * between nsIPref, which needs the period added, and nsIPrefBranch which
     * does not. When nsIPref goes away this function should be fixed to
     * never add the period at all.
     */
    nsCAutoString branch_dot(branch_name);
    if ((len > 1) && branch_name[len - 1] != '.')
        branch_dot += '.';

    PL_DHashTableEnumerate(&gHashTable, pref_DeleteItem,
                           (void*) branch_dot.get());
    gDirty = PR_TRUE;
    return NS_OK;
}

Here is the call graph for this function:

pref_DeleteItem ( PLDHashTable table,
PLDHashEntryHdr heh,
PRUint32  i,
void arg 
)

Definition at line 521 of file prefapi.cpp.

{
    PrefHashEntry* he = NS_STATIC_CAST(PrefHashEntry*,heh);
    const char *to_delete = (const char *) arg;
    int len = PL_strlen(to_delete);

    /* note if we're deleting "ldap" then we want to delete "ldap.xxx"
        and "ldap" (if such a leaf node exists) but not "ldap_1.xxx" */
    if (to_delete && (PL_strncmp(he->key, to_delete, (PRUint32) len) == 0 ||
        (len-1 == (int)PL_strlen(he->key) && PL_strncmp(he->key, to_delete, (PRUint32)(len-1)) == 0)))
        return PL_DHASH_REMOVE;

    return PL_DHASH_NEXT;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static nsresult pref_DoCallback ( const char *  changed_pref) [static]

Definition at line 894 of file prefapi.cpp.

{
    nsresult rv = NS_OK;
    struct CallbackNode* node;

    PRBool reentered = gCallbacksInProgress;
    gCallbacksInProgress = PR_TRUE;
    // Nodes must not be deleted while gCallbacksInProgress is PR_TRUE.
    // Nodes that need to be deleted are marked for deletion by nulling
    // out the |func| pointer. We release them at the end of this function
    // if we haven't reentered.

    for (node = gCallbacks; node != NULL; node = node->next)
    {
        if ( node->func &&
             PL_strncmp(changed_pref,
                        node->domain,
                        PL_strlen(node->domain)) == 0 )
        {
            nsresult rv2 = (*node->func) (changed_pref, node->data);
            if (NS_FAILED(rv2))
                rv = rv2;
        }
    }

    gCallbacksInProgress = reentered;

    if (gShouldCleanupDeadNodes && !gCallbacksInProgress)
    {
        struct CallbackNode* prev_node = NULL;
        node = gCallbacks;

        while (node != NULL)
        {
            if (!node->func)
            {
                node = pref_RemoveCallbackNode(node, prev_node);
            }
            else
            {
                prev_node = node;
                node = node->next;
            }
        }
        gShouldCleanupDeadNodes = PR_FALSE;
    }

    return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult PREF_GetBoolPref ( const char *  pref_name,
PRBool return_value,
PRBool  get_default 
)

Definition at line 492 of file prefapi.cpp.

{
    if (!gHashTable.ops)
        return NS_ERROR_NOT_INITIALIZED;

    nsresult rv = NS_ERROR_UNEXPECTED;
    PrefHashEntry* pref = pref_HashTableLookup(pref_name);
    //NS_ASSERTION(pref, pref_name);
    if (pref && (pref->flags & PREF_BOOL))
    {
        if (get_default || PREF_IS_LOCKED(pref) || !PREF_HAS_USER_VALUE(pref))
        {
            PRBool tempBool = pref->defaultPref.boolVal;
            /* check to see if we even had a default */
            if (tempBool != ((PRBool) BOGUS_DEFAULT_BOOL_PREF_VALUE)) {
                *return_value = tempBool;
                rv = NS_OK;
            }
        }
        else {
            *return_value = pref->userPref.boolVal;
            rv = NS_OK;
        }
    }
    return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult PREF_GetCharPref ( const char *  pref_name,
char *  return_buffer,
int length,
PRBool  get_default 
)

Definition at line 410 of file prefapi.cpp.

{
    if (!gHashTable.ops)
        return NS_ERROR_NOT_INITIALIZED;

    nsresult rv = NS_ERROR_UNEXPECTED;
    char* stringVal;

    PrefHashEntry* pref = pref_HashTableLookup(pref_name);

    if (pref)
    {
        if (get_default || PREF_IS_LOCKED(pref) || !PREF_HAS_USER_VALUE(pref))
            stringVal = pref->defaultPref.stringVal;
        else
            stringVal = pref->userPref.stringVal;

        if (stringVal)
        {
            if (*length <= 0)
                *length = PL_strlen(stringVal) + 1;
            else
            {
                PL_strncpy(return_buffer, stringVal, PR_MIN((size_t)*length - 1, PL_strlen(stringVal) + 1));
                return_buffer[*length - 1] = '\0';
            }
            rv = NS_OK;
        }
    }

    return rv;
}

Here is the call graph for this function:

nsresult PREF_GetIntPref ( const char *  pref_name,
PRInt32 return_int,
PRBool  get_default 
)

Definition at line 468 of file prefapi.cpp.

{
    if (!gHashTable.ops)
        return NS_ERROR_NOT_INITIALIZED;

    nsresult rv = NS_ERROR_UNEXPECTED;
    PrefHashEntry* pref = pref_HashTableLookup(pref_name);
    if (pref && (pref->flags & PREF_INT))
    {
        if (get_default || PREF_IS_LOCKED(pref) || !PREF_HAS_USER_VALUE(pref))
        {
            PRInt32 tempInt = pref->defaultPref.intVal;
            /* check to see if we even had a default */
            if (tempInt == ((PRInt32) BOGUS_DEFAULT_INT_PREF_VALUE))
                return NS_ERROR_UNEXPECTED;
            *return_int = tempInt;
        }
        else
            *return_int = pref->userPref.intVal;
        rv = NS_OK;
    }
    return rv;
}

Here is the call graph for this function:

PrefType PREF_GetPrefType ( const char *  pref_name)

Definition at line 778 of file prefapi.cpp.

{
    if (gHashTable.ops)
    {
        PrefHashEntry* pref = pref_HashTableLookup(pref_name);
        if (pref)
        {
            if (pref->flags & PREF_STRING)
                return PREF_STRING;
            else if (pref->flags & PREF_INT)
                return PREF_INT;
            else if (pref->flags & PREF_BOOL)
                return PREF_BOOL;
        }
    }
    return PREF_INVALID;
}

Here is the call graph for this function:

nsresult pref_HashPref ( const char *  key,
PrefValue  value,
PrefType  type,
PRBool  defaultPref 
) [static]

Definition at line 689 of file prefapi.cpp.

{
    if (!gHashTable.ops)
        return NS_ERROR_OUT_OF_MEMORY;

    PrefHashEntry* pref = NS_STATIC_CAST(PrefHashEntry*, PL_DHashTableOperate(&gHashTable, key, PL_DHASH_ADD));

    if (!pref)
        return NS_ERROR_OUT_OF_MEMORY;

    // new entry, better intialize
    if (!pref->key) {

        // initialize the pref entry
        pref->flags = type;
        pref->key = ArenaStrDup(key, &gPrefNameArena);
        pref->defaultPref.intVal = 0;
        pref->userPref.intVal = 0;

        /* ugly hack -- define it to a default that no pref will ever
           default to this should really get fixed right by some out
           of band data
        */
        if (pref->flags & PREF_BOOL)
            pref->defaultPref.boolVal = (PRBool) BOGUS_DEFAULT_BOOL_PREF_VALUE;
        if (pref->flags & PREF_INT)
            pref->defaultPref.intVal = (PRInt32) BOGUS_DEFAULT_INT_PREF_VALUE;
    }
    else if ((((PrefType)(pref->flags)) & PREF_VALUETYPE_MASK) !=
                 (type & PREF_VALUETYPE_MASK))
    {
        NS_WARNING(nsPrintfCString(192, "Trying to set pref %s to with the wrong type!", key).get());
        return NS_ERROR_UNEXPECTED;
    }

    PRBool valueChanged = PR_FALSE;
    if (set_default)
    {
        if (!PREF_IS_LOCKED(pref))
        {       /* ?? change of semantics? */
            if (pref_ValueChanged(pref->defaultPref, value, type))
            {
                pref_SetValue(&pref->defaultPref, value, type);
                if (!PREF_HAS_USER_VALUE(pref))
                    valueChanged = PR_TRUE;
            }
        }
    }
    else
    {
        /* If new value is same as the default value, then un-set the user value.
           Otherwise, set the user value only if it has changed */
        if ( !pref_ValueChanged(pref->defaultPref, value, type) )
        {
            if (PREF_HAS_USER_VALUE(pref))
            {
                pref->flags &= ~PREF_USERSET;
                if (!PREF_IS_LOCKED(pref))
                    valueChanged = PR_TRUE;
            }
        }
        else if ( !PREF_HAS_USER_VALUE(pref) ||
                   pref_ValueChanged(pref->userPref, value, type) )
        {
            pref_SetValue(&pref->userPref, value, type);
            pref->flags |= PREF_USERSET;
            if (!PREF_IS_LOCKED(pref))
                valueChanged = PR_TRUE;
        }
    }

    nsresult rv = NS_OK;
    if (valueChanged) {
        gDirty = PR_TRUE;

        if (gCallbacksEnabled) {
            nsresult rv2 = pref_DoCallback(key);
            if (NS_FAILED(rv2))
                rv = rv2;
        }
#ifdef MOZ_PROFILESHARING
        if (gSharedPrefHandler)
            gSharedPrefHandler->OnPrefChanged(set_default, pref, value);
#endif
    }
    return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PrefHashEntry * pref_HashTableLookup ( const void key) [inline, static]

Definition at line 678 of file prefapi.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool PREF_HasUserPref ( const char *  pref_name)

Definition at line 398 of file prefapi.cpp.

{
    if (!gHashTable.ops)
        return PR_FALSE;

    PrefHashEntry *pref = pref_HashTableLookup(pref_name);
    if (!pref) return PR_FALSE;

    /* convert PREF_HAS_USER_VALUE to bool */
    return (PREF_HAS_USER_VALUE(pref) != 0);

}

Here is the call graph for this function:

Definition at line 197 of file prefapi.cpp.

{
    if (!gHashTable.ops) {
        if (!PL_DHashTableInit(&gHashTable, &pref_HashTableOps, nsnull,
                               sizeof(PrefHashEntry), 1024)) {
            gHashTable.ops = nsnull;
            return NS_ERROR_OUT_OF_MEMORY;
        }

        PL_INIT_ARENA_POOL(&gPrefNameArena, "PrefNameArena",
                           PREFNAME_ARENA_SIZE);
    }
    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult PREF_LockPref ( const char *  key,
PRBool  lockit 
)

Definition at line 614 of file prefapi.cpp.

{
    if (!gHashTable.ops)
        return NS_ERROR_NOT_INITIALIZED;

    PrefHashEntry* pref = pref_HashTableLookup(key);
    if (!pref)
        return NS_ERROR_UNEXPECTED;

    if (lockit) {
        if (!PREF_IS_LOCKED(pref))
        {
            pref->flags |= PREF_LOCKED;
            gIsAnyPrefLocked = PR_TRUE;
            if (gCallbacksEnabled)
                pref_DoCallback(key);
        }
    }
    else
    {
        if (PREF_IS_LOCKED(pref))
        {
            pref->flags &= ~PREF_LOCKED;
            if (gCallbacksEnabled)
                pref_DoCallback(key);
        }
    }
    return NS_OK;
}

Here is the call graph for this function:

PRBool PREF_PrefIsLocked ( const char *  pref_name)

Definition at line 799 of file prefapi.cpp.

{
    PRBool result = PR_FALSE;
    if (gIsAnyPrefLocked) {
        PrefHashEntry* pref = pref_HashTableLookup(pref_name);
        if (pref && PREF_IS_LOCKED(pref))
            result = PR_TRUE;
    }

    return result;
}

Here is the call graph for this function:

void PREF_ReaderCallback ( void closure,
const char *  pref,
PrefValue  value,
PrefType  type,
PRBool  isDefault 
)

Definition at line 944 of file prefapi.cpp.

{
    pref_HashPref(pref, value, type, isDefault);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void PREF_RegisterCallback ( const char *  pref_node,
PrefChangedFunc  callback,
void instance_data 
)

Definition at line 813 of file prefapi.cpp.

{
    NS_PRECONDITION(pref_node, "pref_node must not be nsnull");
    NS_PRECONDITION(callback, "callback must not be nsnull");

    struct CallbackNode* node = (struct CallbackNode*) malloc(sizeof(struct CallbackNode));
    if (node)
    {
        node->domain = PL_strdup(pref_node);
        node->func = callback;
        node->data = instance_data;
        node->next = gCallbacks;
        gCallbacks = node;
    }
    return;
}

Here is the caller graph for this function:

struct CallbackNode* pref_RemoveCallbackNode ( struct CallbackNode node,
struct CallbackNode prev_node 
) [read]

Definition at line 835 of file prefapi.cpp.

{
    NS_PRECONDITION(!prev_node || prev_node->next == node, "invalid params");
    NS_PRECONDITION(prev_node || gCallbacks == node, "invalid params");

    NS_ASSERTION(!gCallbacksInProgress,
        "modifying the callback list while gCallbacksInProgress is PR_TRUE");

    struct CallbackNode* next_node = node->next;
    if (prev_node)
        prev_node->next = next_node;
    else
        gCallbacks = next_node;
    PR_Free(node->domain);
    PR_Free(node);
    return next_node;
}

Here is the caller graph for this function:

PLDHashOperator pref_savePref ( PLDHashTable table,
PLDHashEntryHdr heh,
PRUint32  i,
void arg 
)

Definition at line 321 of file prefapi.cpp.

{
    pref_saveArgs *argData = NS_STATIC_CAST(pref_saveArgs *, arg);
    PrefHashEntry *pref = NS_STATIC_CAST(PrefHashEntry *, heh);

    PR_ASSERT(pref);
    if (!pref)
        return PL_DHASH_NEXT;

    nsCAutoString prefValue;

    // where we're getting our pref from
    PrefValue* sourcePref;

    if (PREF_HAS_USER_VALUE(pref) &&
        pref_ValueChanged(pref->defaultPref,
                          pref->userPref,
                          (PrefType) PREF_TYPE(pref)))
        sourcePref = &pref->userPref;
    else if (PREF_IS_LOCKED(pref))
        sourcePref = &pref->defaultPref;
    else
        // do not save default prefs that haven't changed
        return PL_DHASH_NEXT;

#if MOZ_PROFILESHARING
  if ((argData->saveTypes == SAVE_SHARED &&
      !gSharedPrefHandler->IsPrefShared(pref->key)) ||
      (argData->saveTypes == SAVE_NONSHARED &&
      gSharedPrefHandler->IsPrefShared(pref->key)))
    return PL_DHASH_NEXT;
#endif

    // strings are in quotes!
    if (pref->flags & PREF_STRING) {
        prefValue = '\"';
        str_escape(sourcePref->stringVal, prefValue);
        prefValue += '\"';
    }

    else if (pref->flags & PREF_INT)
        prefValue.AppendInt(sourcePref->intVal);

    else if (pref->flags & PREF_BOOL)
        prefValue = (sourcePref->boolVal) ? "true" : "false";

    nsCAutoString prefName;
    str_escape(pref->key, prefName);

    argData->prefArray[i] = ToNewCString(NS_LITERAL_CSTRING("user_pref(\"") +
                                prefName +
                                NS_LITERAL_CSTRING("\", ") +
                                prefValue +
                                NS_LITERAL_CSTRING(");"));
    return PL_DHASH_NEXT;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult PREF_SetBoolPref ( const char *  pref_name,
PRBool  value,
PRBool  set_default 
)

Definition at line 311 of file prefapi.cpp.

{
    PrefValue pref;
    pref.boolVal = value ? PR_TRUE : PR_FALSE;

    return pref_HashPref(pref_name, pref, PREF_BOOL, set_default);
}

Here is the call graph for this function:

nsresult PREF_SetCharPref ( const char *  pref_name,
const char *  value,
PRBool  set_default 
)

Definition at line 293 of file prefapi.cpp.

{
    PrefValue pref;
    pref.stringVal = (char*) value;

    return pref_HashPref(pref_name, pref, PREF_STRING, set_default);
}

Here is the call graph for this function:

nsresult PREF_SetIntPref ( const char *  pref_name,
PRInt32  value,
PRBool  set_default 
)

Definition at line 302 of file prefapi.cpp.

{
    PrefValue pref;
    pref.intVal = value;

    return pref_HashPref(pref_name, pref, PREF_INT, set_default);
}

Here is the call graph for this function:

static void pref_SetValue ( PrefValue oldValue,
PrefValue  newValue,
PrefType  type 
) [static]

Definition at line 662 of file prefapi.cpp.

{
    switch (type & PREF_VALUETYPE_MASK)
    {
        case PREF_STRING:
            PR_ASSERT(newValue.stringVal);
            PR_FREEIF(oldValue->stringVal);
            oldValue->stringVal = newValue.stringVal ? PL_strdup(newValue.stringVal) : NULL;
            break;

        default:
            *oldValue = newValue;
    }
    gDirty = PR_TRUE;
}

Here is the caller graph for this function:

nsresult PREF_UnregisterCallback ( const char *  pref_node,
PrefChangedFunc  callback,
void instance_data 
)

Definition at line 856 of file prefapi.cpp.

{
    nsresult rv = NS_ERROR_FAILURE;
    struct CallbackNode* node = gCallbacks;
    struct CallbackNode* prev_node = NULL;

    while (node != NULL)
    {
        if ( strcmp(node->domain, pref_node) == 0 &&
             node->func == callback &&
             node->data == instance_data)
        {
            if (gCallbacksInProgress)
            {
                // postpone the node removal until after
                // gCallbacks enumeration is finished.
                node->func = nsnull;
                gShouldCleanupDeadNodes = PR_TRUE;
                prev_node = node;
                node = node->next;
            }
            else
            {
                node = pref_RemoveCallbackNode(node, prev_node);
            }
            rv = NS_OK;
        }
        else
        {
            prev_node = node;
            node = node->next;
        }
    }
    return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PRBool pref_ValueChanged ( PrefValue  oldValue,
PrefValue  newValue,
PrefType  type 
) [static]

Definition at line 647 of file prefapi.cpp.

{
    PRBool changed = PR_TRUE;
    if (type & PREF_STRING)
    {
        if (oldValue.stringVal && newValue.stringVal)
            changed = (strcmp(oldValue.stringVal, newValue.stringVal) != 0);
    }
    else if (type & PREF_INT)
        changed = oldValue.intVal != newValue.intVal;
    else if (type & PREF_BOOL)
        changed = oldValue.boolVal != newValue.boolVal;
    return changed;
}

Here is the caller graph for this function:

static void str_escape ( const char *  original,
nsAFlatCString aResult 
) [static]

Definition at line 243 of file prefapi.cpp.

{
    /* JavaScript does not allow quotes, slashes, or line terminators inside
     * strings so we must escape them. ECMAScript defines four line
     * terminators, but we're only worrying about \r and \n here.  We currently
     * feed our pref script to the JS interpreter as Latin-1 so  we won't
     * encounter \u2028 (line separator) or \u2029 (paragraph separator).
     *
     * WARNING: There are hints that we may be moving to storing prefs
     * as utf8. If we ever feed them to the JS compiler as UTF8 then
     * we'll have to worry about the multibyte sequences that would be
     * interpreted as \u2028 and \u2029
     */
    const char *p;

    if (original == NULL)
        return;

    /* Paranoid worst case all slashes will free quickly */
    for  (p=original; *p; ++p)
    {
        switch (*p)
        {
            case '\n':
                aResult.Append("\\n");
                break;

            case '\r':
                aResult.Append("\\r");
                break;

            case '\\':
                aResult.Append("\\\\");
                break;

            case '\"':
                aResult.Append("\\\"");
                break;

            default:
                aResult.Append(*p);
                break;
        }
    }
}

Here is the caller graph for this function:


Variable Documentation

struct CallbackNode* gCallbacks = NULL [static]

Definition at line 122 of file prefapi.cpp.

Definition at line 123 of file prefapi.cpp.

Definition at line 126 of file prefapi.cpp.

Definition at line 120 of file prefapi.cpp.

Definition at line 118 of file prefapi.cpp.

Definition at line 124 of file prefapi.cpp.

Definition at line 119 of file prefapi.cpp.

Definition at line 127 of file prefapi.cpp.