mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-22 02:09:28 +00:00
Bug 1287945: Return the number of modified/filled preferences and use it for subsequent operations. r=aklotz
This commit is contained in:
parent
3236586a67
commit
f49db94bcc
@ -93,6 +93,26 @@ static const char kTelemetryPref[] = "toolkit.telemetry.enabled";
|
||||
static const char kOldTelemetryPref[] = "toolkit.telemetry.enabledPreRelease";
|
||||
static const char kChannelPref[] = "app.update.channel";
|
||||
|
||||
static const char kPrefFileHeader[] =
|
||||
"# Mozilla User Preferences"
|
||||
NS_LINEBREAK
|
||||
NS_LINEBREAK
|
||||
"/* Do not edit this file."
|
||||
NS_LINEBREAK
|
||||
" *"
|
||||
NS_LINEBREAK
|
||||
" * If you make changes to this file while the application is running,"
|
||||
NS_LINEBREAK
|
||||
" * the changes will be overwritten when the application exits."
|
||||
NS_LINEBREAK
|
||||
" *"
|
||||
NS_LINEBREAK
|
||||
" * To make a manual change to preferences, you can visit the URL about:config"
|
||||
NS_LINEBREAK
|
||||
" */"
|
||||
NS_LINEBREAK
|
||||
NS_LINEBREAK;
|
||||
|
||||
Preferences* Preferences::sPreferences = nullptr;
|
||||
nsIPrefBranch* Preferences::sRootBranch = nullptr;
|
||||
nsIPrefBranch* Preferences::sDefaultRootBranch = nullptr;
|
||||
@ -944,26 +964,6 @@ Preferences::SavePrefFileInternal(nsIFile *aFile)
|
||||
nsresult
|
||||
Preferences::WritePrefFile(nsIFile* aFile)
|
||||
{
|
||||
const char outHeader[] =
|
||||
"# Mozilla User Preferences"
|
||||
NS_LINEBREAK
|
||||
NS_LINEBREAK
|
||||
"/* Do not edit this file."
|
||||
NS_LINEBREAK
|
||||
" *"
|
||||
NS_LINEBREAK
|
||||
" * If you make changes to this file while the application is running,"
|
||||
NS_LINEBREAK
|
||||
" * the changes will be overwritten when the application exits."
|
||||
NS_LINEBREAK
|
||||
" *"
|
||||
NS_LINEBREAK
|
||||
" * To make a manual change to preferences, you can visit the URL about:config"
|
||||
NS_LINEBREAK
|
||||
" */"
|
||||
NS_LINEBREAK
|
||||
NS_LINEBREAK;
|
||||
|
||||
nsCOMPtr<nsIOutputStream> outStreamSink;
|
||||
nsCOMPtr<nsIOutputStream> outStream;
|
||||
uint32_t writeAmount;
|
||||
@ -984,23 +984,23 @@ Preferences::WritePrefFile(nsIFile* aFile)
|
||||
return rv;
|
||||
|
||||
// get the lines that we're supposed to be writing to the file
|
||||
UniquePtr<char*[]> valueArray = pref_savePrefs(gHashTable);
|
||||
uint32_t prefCount;
|
||||
UniquePtr<char*[]> valueArray = pref_savePrefs(gHashTable, &prefCount);
|
||||
|
||||
/* Sort the preferences to make a readable file on disk */
|
||||
NS_QuickSort(valueArray.get(), gHashTable->EntryCount(), sizeof(char *),
|
||||
NS_QuickSort(valueArray.get(), prefCount, sizeof(char *),
|
||||
pref_CompareStrings, nullptr);
|
||||
|
||||
// write out the file header
|
||||
outStream->Write(outHeader, sizeof(outHeader) - 1, &writeAmount);
|
||||
outStream->Write(kPrefFileHeader, sizeof(kPrefFileHeader) - 1, &writeAmount);
|
||||
|
||||
for (uint32_t valueIdx = 0; valueIdx < gHashTable->EntryCount(); valueIdx++) {
|
||||
for (uint32_t valueIdx = 0; valueIdx < prefCount; valueIdx++) {
|
||||
char*& pref = valueArray[valueIdx];
|
||||
if (pref) {
|
||||
outStream->Write(pref, strlen(pref), &writeAmount);
|
||||
outStream->Write(NS_LINEBREAK, NS_LINEBREAK_LEN, &writeAmount);
|
||||
free(pref);
|
||||
pref = nullptr;
|
||||
}
|
||||
MOZ_ASSERT(pref);
|
||||
outStream->Write(pref, strlen(pref), &writeAmount);
|
||||
outStream->Write(NS_LINEBREAK, NS_LINEBREAK_LEN, &writeAmount);
|
||||
free(pref);
|
||||
pref = nullptr;
|
||||
}
|
||||
|
||||
// tell the safe output stream to overwrite the real prefs file
|
||||
|
@ -330,9 +330,16 @@ pref_SetPref(const dom::PrefSetting& aPref)
|
||||
}
|
||||
|
||||
UniquePtr<char*[]>
|
||||
pref_savePrefs(PLDHashTable* aTable)
|
||||
pref_savePrefs(PLDHashTable* aTable, uint32_t* aPrefCount)
|
||||
{
|
||||
// This function allocates the entries in the savedPrefs array it returns.
|
||||
// It is the callers responsibility to go through the array and free
|
||||
// all of them. The aPrefCount entries will be non-null. Any end padding
|
||||
// is an implementation detail and may change.
|
||||
MOZ_ASSERT(aPrefCount);
|
||||
auto savedPrefs = MakeUnique<char*[]>(aTable->EntryCount());
|
||||
|
||||
// This is not necessary, but leaving it in for now
|
||||
memset(savedPrefs.get(), 0, aTable->EntryCount() * sizeof(char*));
|
||||
|
||||
int32_t j = 0;
|
||||
@ -380,6 +387,7 @@ pref_savePrefs(PLDHashTable* aTable)
|
||||
prefValue +
|
||||
NS_LITERAL_CSTRING(");"));
|
||||
}
|
||||
*aPrefCount = j;
|
||||
|
||||
return savedPrefs;
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ class PrefSetting;
|
||||
} // namespace mozilla
|
||||
|
||||
mozilla::UniquePtr<char*[]>
|
||||
pref_savePrefs(PLDHashTable* aTable);
|
||||
pref_savePrefs(PLDHashTable* aTable, uint32_t* aPrefCount);
|
||||
|
||||
nsresult
|
||||
pref_SetPref(const mozilla::dom::PrefSetting& aPref);
|
||||
|
Loading…
x
Reference in New Issue
Block a user