Bug 671190 - Stop using BOGUS_DEFAULT_*_PREF_VALUE in prefapi.cpp and cleanup PRBool abuse, r=bsmedberg

This commit is contained in:
Michael Wu 2011-08-22 19:15:52 -07:00
Родитель 1b86c0083f
Коммит c8c410e891
7 изменённых файлов: 25 добавлений и 40 удалений

Просмотреть файл

@ -285,7 +285,7 @@ NS_IMETHODIMP nsSystemPrefService::GetBoolPref(const char *aPrefName, PRBool *_r
}
/* void setBoolPref (in string aPrefName, in long aValue); */
NS_IMETHODIMP nsSystemPrefService::SetBoolPref(const char *aPrefName, PRInt32 aValue)
NS_IMETHODIMP nsSystemPrefService::SetBoolPref(const char *aPrefName, PRBool aValue)
{
return NS_ERROR_NOT_IMPLEMENTED;
}

Просмотреть файл

@ -55,7 +55,7 @@
* @see nsIPrefService
*/
[scriptable, uuid(e0b6e170-691b-11e0-ae3e-0800200c9a66)]
[scriptable, uuid(e162bfa0-01bd-4e9f-9843-8fb2efcd6d1f)]
interface nsIPrefBranch : nsISupports
{
@ -107,7 +107,7 @@ interface nsIPrefBranch : nsISupports
*
* @see getBoolPref
*/
void setBoolPref(in string aPrefName, in long aValue);
void setBoolPref(in string aPrefName, in boolean aValue);
/**
* Called to get the state of an individual string preference.

Просмотреть файл

@ -47,7 +47,7 @@ interface nsIObserver;
*
* @see nsIPrefBranch
*/
[scriptable, uuid(784de8e2-e72f-441a-ae74-9d5fdfe13be3)]
[scriptable, uuid(d9bb54df-daac-4ce6-a70c-95d87b770cd8)]
interface nsIPrefBranch2 : nsIPrefBranch
{
/**

Просмотреть файл

@ -44,7 +44,7 @@
* @status NON-FROZEN interface WHICH WILL PROBABLY GO AWAY.
*/
[scriptable, uuid(d1d412d9-15d6-4a6a-9533-b949dc175ff5)]
[scriptable, uuid(355bd1e9-248a-438b-809d-e0db1b287882)]
interface nsIPrefBranchInternal : nsIPrefBranch2
{
};

Просмотреть файл

@ -164,7 +164,7 @@ NS_IMETHODIMP nsPrefBranch::GetBoolPref(const char *aPrefName, PRBool *_retval)
return PREF_GetBoolPref(pref, _retval, mIsDefault);
}
NS_IMETHODIMP nsPrefBranch::SetBoolPref(const char *aPrefName, PRInt32 aValue)
NS_IMETHODIMP nsPrefBranch::SetBoolPref(const char *aPrefName, PRBool aValue)
{
if (GetContentChild()) {
NS_ERROR("cannot set pref from content process");

Просмотреть файл

@ -68,9 +68,6 @@
#include <os2.h>
#endif
#define BOGUS_DEFAULT_INT_PREF_VALUE (-5632)
#define BOGUS_DEFAULT_BOOL_PREF_VALUE (-2)
static void
clearPrefEntry(PLDHashTable *table, PLDHashEntryHdr *entry)
{
@ -298,7 +295,7 @@ nsresult
PREF_SetBoolPref(const char *pref_name, PRBool value, PRBool set_default)
{
PrefValue pref;
pref.boolVal = value ? PR_TRUE : PR_FALSE;
pref.boolVal = value;
return pref_HashPref(pref_name, pref, PREF_BOOL, set_default);
}
@ -339,9 +336,10 @@ pref_savePref(PLDHashTable *table, PLDHashEntryHdr *heh, PRUint32 i, void *arg)
PrefValue* sourcePref;
if (PREF_HAS_USER_VALUE(pref) &&
pref_ValueChanged(pref->defaultPref,
pref->userPref,
(PrefType) PREF_TYPE(pref))) {
(pref_ValueChanged(pref->defaultPref,
pref->userPref,
(PrefType) PREF_TYPE(pref)) ||
!(pref->flags & PREF_HAS_DEFAULT))) {
sourcePref = &pref->userPref;
} else {
if (argData->saveTypes == SAVE_ALL_AND_DEFAULTS) {
@ -523,7 +521,7 @@ nsresult PREF_GetIntPref(const char *pref_name,PRInt32 * return_int, PRBool get_
{
PRInt32 tempInt = pref->defaultPref.intVal;
/* check to see if we even had a default */
if (tempInt == ((PRInt32) BOGUS_DEFAULT_INT_PREF_VALUE))
if (!(pref->flags & PREF_HAS_DEFAULT))
return NS_ERROR_UNEXPECTED;
*return_int = tempInt;
}
@ -548,7 +546,7 @@ nsresult PREF_GetBoolPref(const char *pref_name, PRBool * return_value, PRBool g
{
PRBool tempBool = pref->defaultPref.boolVal;
/* check to see if we even had a default */
if (tempBool != ((PRBool) BOGUS_DEFAULT_BOOL_PREF_VALUE)) {
if (pref->flags & PREF_HAS_DEFAULT) {
*return_value = tempBool;
rv = NS_OK;
}
@ -614,11 +612,7 @@ PREF_ClearUserPref(const char *pref_name)
{
pref->flags &= ~PREF_USERSET;
if ((pref->flags & PREF_INT &&
pref->defaultPref.intVal == ((PRInt32) BOGUS_DEFAULT_INT_PREF_VALUE)) ||
(pref->flags & PREF_BOOL &&
pref->defaultPref.boolVal == ((PRBool) BOGUS_DEFAULT_BOOL_PREF_VALUE)) ||
(pref->flags & PREF_STRING && !pref->defaultPref.stringVal)) {
if (!(pref->flags & PREF_HAS_DEFAULT)) {
PL_DHashTableOperate(&gHashTable, pref_name, PL_DHASH_REMOVE);
}
@ -640,11 +634,7 @@ pref_ClearUserPref(PLDHashTable *table, PLDHashEntryHdr *he, PRUint32,
{
pref->flags &= ~PREF_USERSET;
if ((pref->flags & PREF_INT &&
pref->defaultPref.intVal == ((PRInt32) BOGUS_DEFAULT_INT_PREF_VALUE)) ||
(pref->flags & PREF_BOOL &&
pref->defaultPref.boolVal == ((PRBool) BOGUS_DEFAULT_BOOL_PREF_VALUE)) ||
(pref->flags & PREF_STRING && !pref->defaultPref.stringVal)) {
if (!(pref->flags & PREF_HAS_DEFAULT)) {
nextOp = PL_DHASH_REMOVE;
}
@ -757,15 +747,6 @@ nsresult pref_HashPref(const char *key, PrefValue value, PrefType type, PRBool s
pref->key = ArenaStrDup(key, &gPrefNameArena);
memset(&pref->defaultPref, 0, sizeof(pref->defaultPref));
memset(&pref->userPref, 0, sizeof(pref->userPref));
/* 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))
@ -779,9 +760,11 @@ nsresult pref_HashPref(const char *key, PrefValue value, PrefType type, PRBool s
{
if (!PREF_IS_LOCKED(pref))
{ /* ?? change of semantics? */
if (pref_ValueChanged(pref->defaultPref, value, type))
if (pref_ValueChanged(pref->defaultPref, value, type) ||
!(pref->flags & PREF_HAS_DEFAULT))
{
pref_SetValue(&pref->defaultPref, value, type);
pref->flags |= PREF_HAS_DEFAULT;
if (!PREF_HAS_USER_VALUE(pref))
valueChanged = PR_TRUE;
}
@ -791,7 +774,8 @@ nsresult pref_HashPref(const char *key, PrefValue value, PrefType type, PRBool s
{
/* 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_ValueChanged(pref->defaultPref, value, type) &&
pref->flags & PREF_HAS_DEFAULT)
{
if (PREF_HAS_USER_VALUE(pref))
{

Просмотреть файл

@ -58,7 +58,7 @@ struct PrefHashEntry : PLDHashEntryHdr
const char *key;
PrefValue defaultPref;
PrefValue userPref;
PRUint8 flags;
PRUint16 flags;
};
/*
@ -84,9 +84,10 @@ void PREF_CleanupPrefs();
typedef enum { PREF_INVALID = 0,
PREF_LOCKED = 1, PREF_USERSET = 2, PREF_CONFIG = 4, PREF_REMOTE = 8,
PREF_LILOCAL = 16, PREF_STRING = 32, PREF_INT = 64, PREF_BOOL = 128,
PREF_VALUETYPE_MASK = (PREF_STRING | PREF_INT | PREF_BOOL)
} PrefType;
PREF_LILOCAL = 16, PREF_STRING = 32, PREF_INT = 64, PREF_BOOL = 128,
PREF_HAS_DEFAULT = 256,
PREF_VALUETYPE_MASK = (PREF_STRING | PREF_INT | PREF_BOOL)
} PrefType;
/*
// <font color=blue>