fix for bug 160377 - only write prefs when they are dirty.

sr=dveditz, r=timeless
This commit is contained in:
alecf%netscape.com 2003-01-20 19:08:54 +00:00
Родитель 0e49101844
Коммит c13ffc7c9a
3 изменённых файлов: 26 добавлений и 9 удалений

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

@ -219,6 +219,13 @@ NS_IMETHODIMP nsPrefService::ResetUserPrefs()
NS_IMETHODIMP nsPrefService::SavePrefFile(nsIFile *aFile)
{
if (nsnull == aFile) {
// the gDirty flag tells us if we should write to mCurrentFile
// we only check this flag when the caller wants to write to the default
if (!gDirty) {
NS_WARNING("not writing prefs because they haven't changed");
return NS_OK;
}
// It's possible that we never got a prefs file.
return mCurrentFile ? WritePrefFile(mCurrentFile) : NS_OK;
} else {
@ -407,6 +414,8 @@ nsresult nsPrefService::WritePrefFile(nsIFile* aFile)
rv = NS_OK;
}
}
if (NS_SUCCEEDED(rv))
gDirty = PR_FALSE;
return rv;
}

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

@ -63,6 +63,7 @@
#include "prprf.h"
#include "nsQuickSort.h"
#include "nsString.h"
#include "nsPrintfCString.h"
#include "prlink.h"
#ifdef XP_OS2
@ -126,6 +127,7 @@ global_resolve(JSContext *cx, JSObject *obj, jsval id)
JSContext * gMochaContext = NULL;
PRBool gErrorOpeningUserPrefs = PR_FALSE;
PLDHashTable gHashTable = { nsnull };
PRBool gDirty = PR_FALSE;
static JSRuntime * gMochaTaskState = NULL;
static JSObject * gMochaPrefObject = NULL;
@ -840,7 +842,7 @@ PREF_DeleteBranch(const char *branch_name)
PL_DHashTableEnumerate(&gHashTable, pref_DeleteItem,
(void*) branch_dot.get());
gDirty = PR_TRUE;
return PREF_NOERROR;
}
@ -861,6 +863,7 @@ PREF_ClearUserPref(const char *pref_name)
if (gCallbacksEnabled)
pref_DoCallback(pref_name);
success = PREF_OK;
gDirty = PR_TRUE;
}
return success;
}
@ -894,7 +897,8 @@ PREF_ClearAllUserPrefs()
return PREF_NOT_INITIALIZED;
PL_DHashTableEnumerate(&gHashTable, pref_ClearUserPref, nsnull);
gDirty = PR_TRUE;
return PREF_OK;
}
@ -962,6 +966,7 @@ static void pref_SetValue(PrefValue* oldValue, PrefValue newValue, PrefType type
default:
*oldValue = newValue;
}
gDirty = PR_TRUE;
}
static inline PrefHashEntry* pref_HashTableLookup(const void *key)
@ -1009,8 +1014,7 @@ PrefResult pref_HashPref(const char *key, PrefValue value, PrefType type, PrefAc
else if ((((PrefType)(pref->flags)) & PREF_VALUETYPE_MASK) !=
(type & PREF_VALUETYPE_MASK))
{
/*PR_ASSERT(0);*/ /* this shouldn't happen */
/* NS_ASSERTION(0, "Trying to set pref to with the wrong type!"); */
NS_WARNING(nsPrintfCString("Trying to set pref %s to with the wrong type!", key).get());
return PREF_TYPE_CHANGE_ERR;
}
@ -1068,11 +1072,14 @@ PrefResult pref_HashPref(const char *key, PrefValue value, PrefType type, PrefAc
break;
}
if (result == PREF_VALUECHANGED && gCallbacksEnabled)
{
PrefResult result2 = pref_DoCallback(key);
if (result2 < 0)
result = result2;
if (result == PREF_VALUECHANGED) {
gDirty = PR_TRUE;
if (gCallbacksEnabled) {
PrefResult result2 = pref_DoCallback(key);
if (result2 < 0)
result = result2;
}
}
return result;
}

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

@ -40,6 +40,7 @@
extern JSContext * gMochaContext;
extern PRBool gErrorOpeningUserPrefs;
extern PLDHashTable gHashTable;
extern PRBool gDirty;
PLDHashOperator PR_CALLBACK pref_savePref(PLDHashTable*, PLDHashEntryHdr *, PRUint32, void *arg);
int PR_CALLBACK pref_CompareStrings(const void *v1, const void *v2, void* unused);