--- a/modules/libpref/Preferences.cpp
+++ b/modules/libpref/Preferences.cpp
@@ -1,142 +1,147 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-#include "mozilla/MemoryReporting.h"
-#include "mozilla/dom/PContent.h"
-
+#include "GeckoProfiler.h"
#include "mozilla/ArrayUtils.h"
#include "mozilla/Attributes.h"
+#include "mozilla/dom/PContent.h"
#include "mozilla/HashFunctions.h"
+#include "mozilla/MemoryReporting.h"
+#include "mozilla/Omnijar.h"
+#include "mozilla/Preferences.h"
#include "mozilla/ResultExtensions.h"
#include "mozilla/ScopeExit.h"
#include "mozilla/ServoStyleSet.h"
#include "mozilla/SyncRunnable.h"
#include "mozilla/Telemetry.h"
+#include "mozilla/UniquePtrExtensions.h"
#include "mozilla/URLPreloader.h"
-#include "mozilla/UniquePtrExtensions.h"
-
-#include "nsXULAppAPI.h"
-
-#include "mozilla/Preferences.h"
#include "nsAppDirectoryServiceDefs.h"
+#include "nsAutoPtr.h"
+#include "nsCategoryManagerUtils.h"
+#include "nsCOMArray.h"
+#include "nsCRT.h"
#include "nsDataHashtable.h"
#include "nsDirectoryServiceDefs.h"
#include "nsICategoryManager.h"
-#include "nsCategoryManagerUtils.h"
-#include "nsNetUtil.h"
#include "nsIFile.h"
#include "nsIInputStream.h"
+#include "nsIMemoryReporter.h"
#include "nsIObserverService.h"
#include "nsIOutputStream.h"
#include "nsISafeOutputStream.h"
#include "nsISimpleEnumerator.h"
#include "nsIStringEnumerator.h"
#include "nsIZipReader.h"
+#include "nsNetUtil.h"
#include "nsPrefBranch.h"
+#include "nsPrintfCString.h"
+#include "nsQuickSort.h"
+#include "nsRefPtrHashtable.h"
#include "nsString.h"
-#include "nsCRT.h"
-#include "nsCOMArray.h"
+#include "nsTArray.h"
+#include "nsThreadUtils.h"
#include "nsXPCOMCID.h"
-#include "nsAutoPtr.h"
-#include "nsPrintfCString.h"
-
-#include "nsQuickSort.h"
+#include "nsXULAppAPI.h"
+#include "nsZipArchive.h"
#include "PLDHashTable.h"
-
#include "prefapi.h"
+#include "prefapi_private_data.h"
#include "prefread.h"
-#include "prefapi_private_data.h"
-
-#include "mozilla/Omnijar.h"
-#include "nsZipArchive.h"
-
-#include "nsTArray.h"
-#include "nsRefPtrHashtable.h"
-#include "nsIMemoryReporter.h"
-#include "nsThreadUtils.h"
-#include "GeckoProfiler.h"
using namespace mozilla;
#ifdef DEBUG
+
#define ENSURE_MAIN_PROCESS(message, pref) \
do { \
if (MOZ_UNLIKELY(!XRE_IsParentProcess())) { \
nsPrintfCString msg("ENSURE_MAIN_PROCESS failed. %s %s", message, pref); \
NS_WARNING(msg.get()); \
return NS_ERROR_NOT_AVAILABLE; \
} \
- } while (0);
+ } while (0)
+
class WatchinPrefRAII
{
public:
WatchinPrefRAII() { pref_SetWatchingPref(true); }
~WatchinPrefRAII() { pref_SetWatchingPref(false); }
};
+
#define WATCHING_PREF_RAII() WatchinPrefRAII watchingPrefRAII
-#else
+
+#else // DEBUG
+
#define ENSURE_MAIN_PROCESS(message, pref) \
if (MOZ_UNLIKELY(!XRE_IsParentProcess())) { \
return NS_ERROR_NOT_AVAILABLE; \
}
+
#define WATCHING_PREF_RAII()
-#endif
+
+#endif // DEBUG
class PrefCallback;
namespace mozilla {
-// Definitions
#define INITIAL_PREF_FILES 10
+
static NS_DEFINE_CID(kZipReaderCID, NS_ZIPREADER_CID);
void
Preferences::DirtyCallback()
{
if (!XRE_IsParentProcess()) {
// TODO: this should really assert because you can't set prefs in a
// content process. But so much code currently does this that we just
// ignore it for now.
return;
}
+
if (!gHashTable || !sPreferences) {
return;
}
+
if (sPreferences->mProfileShutdown) {
NS_WARNING("Setting user pref after profile shutdown.");
return;
}
+
if (!sPreferences->mDirty) {
sPreferences->mDirty = true;
if (sPreferences->mCurrentFile && sPreferences->AllowOffMainThreadSave() &&
!sPreferences->mSavePending) {
sPreferences->mSavePending = true;
static const int PREF_DELAY_MS = 500;
NS_DelayedDispatchToCurrentThread(
mozilla::NewRunnableMethod("Preferences::SavePrefFileAsynchronous",
sPreferences,
&Preferences::SavePrefFileAsynchronous),
PREF_DELAY_MS);
}
}
}
-// Prototypes
static nsresult
openPrefFile(nsIFile* aFile);
+
static Result<Ok, const char*>
pref_InitInitialObjects();
+
static nsresult
-pref_LoadPrefsInDirList(const char* listId);
+pref_LoadPrefsInDirList(const char* aListId);
+
static nsresult
ReadExtensionPrefs(nsIFile* aFile);
static const char kTelemetryPref[] = "toolkit.telemetry.enabled";
static const char kOldTelemetryPref[] = "toolkit.telemetry.enabledPreRelease";
static const char kChannelPref[] = "app.update.channel";
// clang-format off
@@ -149,29 +154,30 @@ static const char kPrefFileHeader[] =
" *"
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"
+ " * To make a manual change to preferences, you can visit the URL "
+ "about:config"
NS_LINEBREAK
" */"
NS_LINEBREAK
NS_LINEBREAK;
// clang-format on
Preferences* Preferences::sPreferences = nullptr;
nsIPrefBranch* Preferences::sRootBranch = nullptr;
nsIPrefBranch* Preferences::sDefaultRootBranch = nullptr;
bool Preferences::sShutdown = false;
-// This globally enables or disables OMT pref writing, both sync and async
+// This globally enables or disables OMT pref writing, both sync and async.
static int32_t sAllowOMTPrefWrite = -1;
class ValueObserverHashKey : public PLDHashEntryHdr
{
public:
typedef ValueObserverHashKey* KeyType;
typedef const ValueObserverHashKey* KeyTypePointer;
@@ -254,43 +260,44 @@ NS_IMPL_ISUPPORTS(ValueObserver, nsIObse
NS_IMETHODIMP
ValueObserver::Observe(nsISupports* aSubject,
const char* aTopic,
const char16_t* aData)
{
NS_ASSERTION(!nsCRT::strcmp(aTopic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID),
"invalid topic");
+
NS_ConvertUTF16toUTF8 data(aData);
if (mMatchKind == Preferences::ExactMatch &&
!mPrefName.EqualsASCII(data.get())) {
return NS_OK;
}
+
for (uint32_t i = 0; i < mClosures.Length(); i++) {
mCallback(data.get(), mClosures.ElementAt(i));
}
return NS_OK;
}
// Write the preference data to a file.
-//
class PreferencesWriter final
{
public:
PreferencesWriter() {}
static nsresult Write(nsIFile* aFile, PrefSaveData& aPrefs)
{
nsCOMPtr<nsIOutputStream> outStreamSink;
nsCOMPtr<nsIOutputStream> outStream;
uint32_t writeAmount;
nsresult rv;
- // execute a "safe" save by saving through a tempfile
+ // Execute a "safe" save by saving through a tempfile.
rv = NS_NewSafeLocalFileOutputStream(
getter_AddRefs(outStreamSink), aFile, -1, 0600);
if (NS_FAILED(rv)) {
return rv;
}
rv = NS_NewBufferedOutputStream(
getter_AddRefs(outStream), outStreamSink, 4096);
@@ -300,92 +307,94 @@ public:
struct CharComparator
{
bool LessThan(const mozilla::UniqueFreePtr<char>& a,
const mozilla::UniqueFreePtr<char>& b) const
{
return strcmp(a.get(), b.get()) < 0;
}
+
bool Equals(const mozilla::UniqueFreePtr<char>& a,
const mozilla::UniqueFreePtr<char>& b) const
{
return strcmp(a.get(), b.get()) == 0;
}
};
- /* Sort the preferences to make a readable file on disk */
+ // Sort the preferences to make a readable file on disk.
aPrefs.Sort(CharComparator());
- // write out the file header
+ // Write out the file header.
outStream->Write(
kPrefFileHeader, sizeof(kPrefFileHeader) - 1, &writeAmount);
for (auto& prefptr : aPrefs) {
char* pref = prefptr.get();
MOZ_ASSERT(pref);
outStream->Write(pref, strlen(pref), &writeAmount);
outStream->Write(NS_LINEBREAK, NS_LINEBREAK_LEN, &writeAmount);
}
- // tell the safe output stream to overwrite the real prefs file
- // (it'll abort if there were any errors during writing)
+ // Tell the safe output stream to overwrite the real prefs file.
+ // (It'll abort if there were any errors during writing.)
nsCOMPtr<nsISafeOutputStream> safeStream = do_QueryInterface(outStream);
NS_ASSERTION(safeStream, "expected a safe output stream!");
if (safeStream) {
rv = safeStream->Finish();
}
#ifdef DEBUG
if (NS_FAILED(rv)) {
NS_WARNING("failed to save prefs file! possible data loss");
}
#endif
+
return rv;
}
static void Flush()
{
- // This can be further optimized; instead of waiting for
- // all of the writer thread to be available, we just have
- // to wait for all the pending writes to be done.
+ // This can be further optimized; instead of waiting for all of the writer
+ // thread to be available, we just have to wait for all the pending writes
+ // to be done.
if (!sPendingWriteData.compareExchange(nullptr, nullptr)) {
nsresult rv = NS_OK;
nsCOMPtr<nsIEventTarget> target =
do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID, &rv);
if (NS_SUCCEEDED(rv)) {
target->Dispatch(NS_NewRunnableFunction("Preferences_dummy", [] {}),
nsIEventTarget::DISPATCH_SYNC);
}
}
}
// This is the data that all of the runnables (see below) will attempt
// to write. It will always have the most up to date version, or be
// null, if the up to date information has already been written out.
static Atomic<PrefSaveData*> sPendingWriteData;
};
+
Atomic<PrefSaveData*> PreferencesWriter::sPendingWriteData(nullptr);
class PWRunnable : public Runnable
{
public:
explicit PWRunnable(nsIFile* aFile)
: Runnable("PWRunnable")
, mFile(aFile)
{
}
NS_IMETHOD Run() override
{
+ // If we get a nullptr on the exchange, it means that somebody
+ // else has already processed the request, and we can just return.
mozilla::UniquePtr<PrefSaveData> prefs(
PreferencesWriter::sPendingWriteData.exchange(nullptr));
- // If we get a nullptr on the exchange, it means that somebody
- // else has already processed the request, and we can just return.
-
nsresult rv = NS_OK;
if (prefs) {
rv = PreferencesWriter::Write(mFile, *prefs);
// Make a copy of these so we can have them in runnable lambda.
// nsIFile is only there so that we would never release the
// ref counted pointer off main thread.
nsresult rvCopy = rv;
@@ -404,22 +413,22 @@ public:
}
protected:
nsCOMPtr<nsIFile> mFile;
};
struct CacheData
{
- void* cacheLocation;
+ void* mCacheLocation;
union {
- bool defaultValueBool;
- int32_t defaultValueInt;
- uint32_t defaultValueUint;
- float defaultValueFloat;
+ bool mDefaultValueBool;
+ int32_t mDefaultValueInt;
+ uint32_t mDefaultValueUint;
+ float mDefaultValueFloat;
};
};
// gCacheDataDesc holds information about prefs startup. It's being used for
// diagnosing prefs startup problems in bug 1276488.
static const char* gCacheDataDesc = "untouched";
static nsTArray<nsAutoPtr<CacheData>>* gCacheData = nullptr;
static nsRefPtrHashtable<ValueObserverHashKey, ValueObserver>* gObserverTable =
@@ -427,17 +436,17 @@ static nsRefPtrHashtable<ValueObserverHa
#ifdef DEBUG
static bool
HaveExistingCacheFor(void* aPtr)
{
MOZ_ASSERT(NS_IsMainThread());
if (gCacheData) {
for (size_t i = 0, count = gCacheData->Length(); i < count; ++i) {
- if ((*gCacheData)[i]->cacheLocation == aPtr) {
+ if ((*gCacheData)[i]->mCacheLocation == aPtr) {
return true;
}
}
}
return false;
}
static void
@@ -472,42 +481,48 @@ ReportToConsole(const char* aMessage, in
/* static */ int64_t
Preferences::SizeOfIncludingThisAndOtherStuff(
mozilla::MallocSizeOf aMallocSizeOf)
{
NS_ENSURE_TRUE(InitStaticMembers(), 0);
size_t n = aMallocSizeOf(sPreferences);
if (gHashTable) {
- // pref keys are allocated in a private arena, which we count elsewhere.
- // pref stringvals are allocated out of the same private arena.
+ // Pref keys are allocated in a private arena, which we count elsewhere.
+ // Pref stringvals are allocated out of the same private arena.
n += gHashTable->ShallowSizeOfIncludingThis(aMallocSizeOf);
}
+
if (gCacheData) {
n += gCacheData->ShallowSizeOfIncludingThis(aMallocSizeOf);
for (uint32_t i = 0, count = gCacheData->Length(); i < count; ++i) {
n += aMallocSizeOf((*gCacheData)[i]);
}
}
+
if (gObserverTable) {
n += gObserverTable->ShallowSizeOfIncludingThis(aMallocSizeOf);
for (auto iter = gObserverTable->Iter(); !iter.Done(); iter.Next()) {
n += iter.Key()->mPrefName.SizeOfExcludingThisIfUnshared(aMallocSizeOf);
n += iter.Data()->mClosures.ShallowSizeOfExcludingThis(aMallocSizeOf);
}
}
+
if (sRootBranch) {
n += reinterpret_cast<nsPrefBranch*>(sRootBranch)
->SizeOfIncludingThis(aMallocSizeOf);
}
+
if (sDefaultRootBranch) {
n += reinterpret_cast<nsPrefBranch*>(sDefaultRootBranch)
->SizeOfIncludingThis(aMallocSizeOf);
}
+
n += pref_SizeOfPrivateData(aMallocSizeOf);
+
return n;
}
class PreferenceServiceReporter final : public nsIMemoryReporter
{
~PreferenceServiceReporter() {}
public:
@@ -620,32 +635,34 @@ PreferenceServiceReporter::CollectReport
numWeakDead,
"The number of weak referents held by the preference service that are "
"dead.");
return NS_OK;
}
namespace {
+
class AddPreferencesMemoryReporterRunnable : public Runnable
{
public:
AddPreferencesMemoryReporterRunnable()
: Runnable("AddPreferencesMemoryReporterRunnable")
{
}
+
NS_IMETHOD Run() override
{
return RegisterStrongMemoryReporter(new PreferenceServiceReporter());
}
};
+
} // namespace
-// static
-Preferences*
+/* static */ Preferences*
Preferences::GetInstanceForService()
{
if (sPreferences) {
NS_ADDREF(sPreferences);
return sPreferences;
}
if (sShutdown) {
@@ -681,59 +698,56 @@ Preferences::GetInstanceForService()
RefPtr<AddPreferencesMemoryReporterRunnable> runnable =
new AddPreferencesMemoryReporterRunnable();
NS_DispatchToMainThread(runnable);
NS_ADDREF(sPreferences);
return sPreferences;
}
-// static
-bool
+/* static */ bool
Preferences::IsServiceAvailable()
{
return !!sPreferences;
}
-// static
-bool
+/* static */ bool
Preferences::InitStaticMembers()
{
MOZ_ASSERT(NS_IsMainThread() || mozilla::ServoStyleSet::IsInServoTraversal());
if (!sShutdown && !sPreferences) {
MOZ_ASSERT(NS_IsMainThread());
nsCOMPtr<nsIPrefService> prefService =
do_GetService(NS_PREFSERVICE_CONTRACTID);
}
return sPreferences != nullptr;
}
-// static
-void
+/* static */ void
Preferences::Shutdown()
{
if (!sShutdown) {
sShutdown = true; // Don't create the singleton instance after here.
- // Don't set sPreferences to nullptr here. The instance may be grabbed by
- // other modules. The utility methods of Preferences should be available
+ // Don't set sPreferences to nullptr here. The instance may be grabbed by
+ // other modules. The utility methods of Preferences should be available
// until the singleton instance actually released.
if (sPreferences) {
sPreferences->Release();
}
}
}
//-----------------------------------------------------------------------------
-/*
- * Constructor/Destructor
- */
+//
+// Constructor/Destructor
+//
Preferences::Preferences() {}
Preferences::~Preferences()
{
NS_ASSERTION(sPreferences == this, "Isn't this the singleton instance?");
delete gObserverTable;
@@ -745,39 +759,38 @@ Preferences::~Preferences()
NS_RELEASE(sRootBranch);
NS_RELEASE(sDefaultRootBranch);
sPreferences = nullptr;
PREF_Cleanup();
}
-/*
- * nsISupports Implementation
- */
+//
+// nsISupports Implementation
+//
NS_IMPL_ADDREF(Preferences)
NS_IMPL_RELEASE(Preferences)
NS_INTERFACE_MAP_BEGIN(Preferences)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIPrefService)
NS_INTERFACE_MAP_ENTRY(nsIPrefService)
NS_INTERFACE_MAP_ENTRY(nsIObserver)
NS_INTERFACE_MAP_ENTRY(nsIPrefBranch)
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
NS_INTERFACE_MAP_END
-/*
- * nsIPrefService Implementation
- */
+//
+// nsIPrefService Implementation
+//
InfallibleTArray<Preferences::PrefSetting>* gInitPrefs;
-/*static*/
-void
+/* static */ void
Preferences::SetInitPreferences(nsTArray<PrefSetting>* aPrefs)
{
gInitPrefs = new InfallibleTArray<PrefSetting>(mozilla::Move(*aPrefs));
}
Result<Ok, const char*>
Preferences::Init()
{
@@ -792,31 +805,31 @@ Preferences::Init()
Preferences::SetPreference(gInitPrefs->ElementAt(i));
}
delete gInitPrefs;
gInitPrefs = nullptr;
return Ok();
}
nsCString lockFileName;
- /*
- * The following is a small hack which will allow us to only load the library
- * which supports the netscape.cfg file if the preference is defined. We
- * test for the existence of the pref, set in the all.js (mozilla) or
- * all-ns.js (netscape 6), and if it exists we startup the pref config
- * category which will do the rest.
- */
+
+ // The following is a small hack which will allow us to only load the library
+ // which supports the netscape.cfg file if the preference is defined. We
+ // test for the existence of the pref, set in the all.js (mozilla) or
+ // all-ns.js (netscape 6), and if it exists we startup the pref config
+ // category which will do the rest.
nsresult rv = PREF_CopyCharPref(
"general.config.filename", getter_Copies(lockFileName), false);
- if (NS_SUCCEEDED(rv))
+ if (NS_SUCCEEDED(rv)) {
NS_CreateServicesFromCategory(
"pref-config-startup",
static_cast<nsISupports*>(static_cast<void*>(this)),
"pref-config-startup");
+ }
nsCOMPtr<nsIObserverService> observerService =
mozilla::services::GetObserverService();
if (!observerService) {
return Err("GetObserverService() failed (1)");
}
observerService->AddObserver(this, "profile-before-change-telemetry", true);
@@ -827,35 +840,35 @@ Preferences::Init()
if (NS_FAILED(rv)) {
return Err("AddObserver(\"profile-before-change\") failed");
}
return Ok();
}
-// static
-void
+/* static */ void
Preferences::InitializeUserPrefs()
{
MOZ_ASSERT(!sPreferences->mCurrentFile, "Should only initialize prefs once");
- // prefs which are set before we initialize the profile are silently discarded.
- // This is stupid, but there are various tests which depend on this behavior.
+ // Prefs which are set before we initialize the profile are silently
+ // discarded. This is stupid, but there are various tests which depend on
+ // this behavior.
sPreferences->ResetUserPrefs();
nsCOMPtr<nsIFile> prefsFile = sPreferences->ReadSavedPrefs();
sPreferences->ReadUserOverridePrefs();
sPreferences->mDirty = false;
- // Don't set mCurrentFile until we're done so that dirty flags work properly
+ // Don't set mCurrentFile until we're done so that dirty flags work properly.
sPreferences->mCurrentFile = prefsFile.forget();
- // Migrate the old prerelease telemetry pref
+ // Migrate the old prerelease telemetry pref.
if (!Preferences::GetBool(kOldTelemetryPref, true)) {
Preferences::SetBool(kTelemetryPref, false);
Preferences::ClearUser(kOldTelemetryPref);
}
sPreferences->NotifyServiceObservers(NS_PREFSERVICE_READ_TOPIC_ID);
}
@@ -872,34 +885,39 @@ Preferences::Observe(nsISupports* aSubje
if (!nsCRT::strcmp(aTopic, "profile-before-change")) {
// Normally prefs aren't written after this point, and so we kick off
// an asynchronous pref save so that I/O can be done in parallel with
// other shutdown.
if (AllowOffMainThreadSave()) {
SavePrefFile(nullptr);
}
+
} else if (!nsCRT::strcmp(aTopic, "profile-before-change-telemetry")) {
// It's possible that a profile-before-change observer after ours
// set a pref. A blocking save here re-saves if necessary and also waits
// for any pending saves to complete.
SavePrefFileBlocking();
MOZ_ASSERT(!mDirty, "Preferences should not be dirty");
mProfileShutdown = true;
+
} else if (!strcmp(aTopic, "load-extension-defaults")) {
pref_LoadPrefsInDirList(NS_EXT_PREFS_DEFAULTS_DIR_LIST);
+
} else if (!nsCRT::strcmp(aTopic, "reload-default-prefs")) {
// Reload the default prefs from file.
Unused << pref_InitInitialObjects();
+
} else if (!nsCRT::strcmp(aTopic, "suspend_process_notification")) {
// Our process is being suspended. The OS may wake our process later,
// or it may kill the process. In case our process is going to be killed
// from the suspended state, we save preferences before suspending.
rv = SavePrefFileBlocking();
}
+
return rv;
}
NS_IMETHODIMP
Preferences::ReadUserPrefsFromFile(nsIFile* aFile)
{
if (MOZ_UNLIKELY(!XRE_IsParentProcess())) {
NS_ERROR("must load prefs from parent process");
@@ -940,56 +958,57 @@ Preferences::ResetUserPrefs()
PREF_ClearAllUserPrefs();
return NS_OK;
}
bool
Preferences::AllowOffMainThreadSave()
{
- // Put in a preference that allows us to disable
- // off main thread preference file save.
+ // Put in a preference that allows us to disable off main thread preference
+ // file save.
if (sAllowOMTPrefWrite < 0) {
bool value = false;
Preferences::GetBool("preferences.allow.omt-write", &value);
sAllowOMTPrefWrite = value ? 1 : 0;
}
+
return !!sAllowOMTPrefWrite;
}
nsresult
Preferences::SavePrefFileBlocking()
{
if (mDirty) {
return SavePrefFileInternal(nullptr, SaveMethod::Blocking);
}
- // If we weren't dirty to start, SavePrefFileInternal will early exit
- // so there is no guarantee that we don't have oustanding async
- // saves in the pipe. Since the contract of SavePrefFileOnMainThread
- // is that the file on disk matches the preferences, we have to make
- // sure those requests are completed.
+ // If we weren't dirty to start, SavePrefFileInternal will early exit so
+ // there is no guarantee that we don't have oustanding async saves in the
+ // pipe. Since the contract of SavePrefFileOnMainThread is that the file on
+ // disk matches the preferences, we have to make sure those requests are
+ // completed.
if (AllowOffMainThreadSave()) {
PreferencesWriter::Flush();
}
+
return NS_OK;
}
nsresult
Preferences::SavePrefFileAsynchronous()
{
return SavePrefFileInternal(nullptr, SaveMethod::Asynchronous);
}
NS_IMETHODIMP
Preferences::SavePrefFile(nsIFile* aFile)
{
- // This is the method accessible from service API. Make it off
- // main thread.
+ // This is the method accessible from service API. Make it off main thread.
return SavePrefFileInternal(aFile, SaveMethod::Asynchronous);
}
static nsresult
ReadExtensionPrefs(nsIFile* aFile)
{
nsresult rv;
nsCOMPtr<nsIZipReader> reader = do_CreateInstance(kZipReaderCID, &rv);
@@ -1027,31 +1046,33 @@ ReadExtensionPrefs(nsIFile* aFile)
NS_WARNING("Pref stream read failed");
break;
}
PREF_ParseBuf(&ps, buffer, read);
}
PREF_FinalizeParseState(&ps);
}
+
return rv;
}
void
Preferences::SetPreference(const PrefSetting& aPref)
{
pref_SetPref(aPref);
}
void
Preferences::GetPreference(PrefSetting* aPref)
{
PrefHashEntry* entry = pref_HashTableLookup(aPref->name().get());
- if (!entry)
+ if (!entry) {
return;
+ }
if (pref_EntryHasAdvisablySizedValues(entry)) {
pref_GetPrefFromEntry(entry, aPref);
}
}
void
Preferences::GetPreferences(InfallibleTArray<PrefSetting>* aPrefs)
@@ -1079,68 +1100,69 @@ Preferences::SetInitPhase(pref_initPhase
pref_initPhase
Preferences::InitPhase()
{
return pref_GetInitPhase();
}
#endif
NS_IMETHODIMP
-Preferences::GetBranch(const char* aPrefRoot, nsIPrefBranch** _retval)
+Preferences::GetBranch(const char* aPrefRoot, nsIPrefBranch** aRetVal)
{
- nsresult rv;
-
if ((nullptr != aPrefRoot) && (*aPrefRoot != '\0')) {
- // TODO: - cache this stuff and allow consumers to share branches (hold weak references I think)
+ // TODO: Cache this stuff and allow consumers to share branches (hold weak
+ // references, I think).
RefPtr<nsPrefBranch> prefBranch = new nsPrefBranch(aPrefRoot, false);
- prefBranch.forget(_retval);
- rv = NS_OK;
+ prefBranch.forget(aRetVal);
} else {
- // special case caching the default root
+ // Special case: caching the default root.
nsCOMPtr<nsIPrefBranch> root(sRootBranch);
- root.forget(_retval);
- rv = NS_OK;
- }
- return rv;
-}
-
-NS_IMETHODIMP
-Preferences::GetDefaultBranch(const char* aPrefRoot, nsIPrefBranch** _retval)
-{
- if (!aPrefRoot || !aPrefRoot[0]) {
- nsCOMPtr<nsIPrefBranch> root(sDefaultRootBranch);
- root.forget(_retval);
- return NS_OK;
+ root.forget(aRetVal);
}
- // TODO: - cache this stuff and allow consumers to share branches (hold weak references I think)
- RefPtr<nsPrefBranch> prefBranch = new nsPrefBranch(aPrefRoot, true);
- if (!prefBranch)
- return NS_ERROR_OUT_OF_MEMORY;
-
- prefBranch.forget(_retval);
return NS_OK;
}
NS_IMETHODIMP
-Preferences::GetDirty(bool* _retval)
+Preferences::GetDefaultBranch(const char* aPrefRoot, nsIPrefBranch** aRetVal)
{
- *_retval = mDirty;
+ if (!aPrefRoot || !aPrefRoot[0]) {
+ nsCOMPtr<nsIPrefBranch> root(sDefaultRootBranch);
+ root.forget(aRetVal);
+ return NS_OK;
+ }
+
+ // TODO: Cache this stuff and allow consumers to share branches (hold weak
+ // references, I think).
+ RefPtr<nsPrefBranch> prefBranch = new nsPrefBranch(aPrefRoot, true);
+ if (!prefBranch) {
+ return NS_ERROR_OUT_OF_MEMORY;
+ }
+
+ prefBranch.forget(aRetVal);
+ return NS_OK;
+}
+
+NS_IMETHODIMP
+Preferences::GetDirty(bool* aRetVal)
+{
+ *aRetVal = mDirty;
return NS_OK;
}
nsresult
Preferences::NotifyServiceObservers(const char* aTopic)
{
nsCOMPtr<nsIObserverService> observerService =
mozilla::services::GetObserverService();
- if (!observerService)
+ if (!observerService) {
return NS_ERROR_FAILURE;
+ }
- nsISupports* subject = (nsISupports*)((nsIPrefService*)this);
+ auto subject = static_cast<nsIPrefService*>(this);
observerService->NotifyObservers(subject, aTopic, nullptr);
return NS_OK;
}
already_AddRefed<nsIFile>
Preferences::ReadSavedPrefs()
{
@@ -1148,17 +1170,17 @@ Preferences::ReadSavedPrefs()
nsresult rv =
NS_GetSpecialDirectory(NS_APP_PREFS_50_FILE, getter_AddRefs(file));
if (NS_WARN_IF(NS_FAILED(rv))) {
return nullptr;
}
rv = openPrefFile(file);
if (rv == NS_ERROR_FILE_NOT_FOUND) {
- // this is a normal case for new users
+ // This is a normal case for new users.
Telemetry::ScalarSet(
Telemetry::ScalarID::PREFERENCES_CREATED_NEW_USER_PREFS_FILE, true);
rv = NS_OK;
} else if (NS_FAILED(rv)) {
// Save a backup copy of the current (invalid) prefs file, since all prefs
// from the error line to the end of the file will be lost (bug 361102).
// TODO we should notify the user about it (bug 523725).
Telemetry::ScalarSet(
@@ -1177,94 +1199,100 @@ Preferences::ReadUserOverridePrefs()
NS_GetSpecialDirectory(NS_APP_PREFS_50_DIR, getter_AddRefs(aFile));
if (NS_WARN_IF(NS_FAILED(rv))) {
return;
}
aFile->AppendNative(NS_LITERAL_CSTRING("user.js"));
rv = openPrefFile(aFile);
if (rv != NS_ERROR_FILE_NOT_FOUND) {
- // If the file exists and was at least partially read, record that
- // in telemetry as it may be a sign of pref injection.
+ // If the file exists and was at least partially read, record that in
+ // telemetry as it may be a sign of pref injection.
Telemetry::ScalarSet(Telemetry::ScalarID::PREFERENCES_READ_USER_JS, true);
}
}
nsresult
Preferences::MakeBackupPrefFile(nsIFile* aFile)
{
// Example: this copies "prefs.js" to "Invalidprefs.js" in the same directory.
// "Invalidprefs.js" is removed if it exists, prior to making the copy.
nsAutoString newFilename;
nsresult rv = aFile->GetLeafName(newFilename);
NS_ENSURE_SUCCESS(rv, rv);
+
newFilename.InsertLiteral(u"Invalid", 0);
nsCOMPtr<nsIFile> newFile;
rv = aFile->GetParent(getter_AddRefs(newFile));
NS_ENSURE_SUCCESS(rv, rv);
+
rv = newFile->Append(newFilename);
NS_ENSURE_SUCCESS(rv, rv);
+
bool exists = false;
newFile->Exists(&exists);
if (exists) {
rv = newFile->Remove(false);
NS_ENSURE_SUCCESS(rv, rv);
}
+
rv = aFile->CopyTo(nullptr, newFilename);
NS_ENSURE_SUCCESS(rv, rv);
+
return rv;
}
nsresult
Preferences::SavePrefFileInternal(nsIFile* aFile, SaveMethod aSaveMethod)
{
if (MOZ_UNLIKELY(!XRE_IsParentProcess())) {
NS_ERROR("must save pref file from parent process");
return NS_ERROR_NOT_AVAILABLE;
}
- // We allow different behavior here when aFile argument is not null,
- // but it happens to be the same as the current file. It is not
- // clear that we should, but it does give us a "force" save on the
- // unmodified pref file (see the original bug 160377 when we added this.)
+ // We allow different behavior here when aFile argument is not null, but it
+ // happens to be the same as the current file. It is not clear that we
+ // should, but it does give us a "force" save on the unmodified pref file
+ // (see the original bug 160377 when we added this.)
if (nullptr == aFile) {
mSavePending = false;
- // Off main thread writing only if allowed
+ // Off main thread writing only if allowed.
if (!AllowOffMainThreadSave()) {
aSaveMethod = SaveMethod::Blocking;
}
- // the mDirty flag tells us if we should write to mCurrentFile
- // we only check this flag when the caller wants to write to the default
+ // The mDirty flag tells us if we should write to mCurrentFile. We only
+ // check this flag when the caller wants to write to the default.
if (!mDirty) {
return NS_OK;
}
- // check for profile shutdown after mDirty because the runnables from
- // DirtyCallback can still be pending
+ // Check for profile shutdown after mDirty because the runnables from
+ // DirtyCallback can still be pending.
if (mProfileShutdown) {
NS_WARNING("Cannot save pref file after profile shutdown.");
return NS_ERROR_ILLEGAL_DURING_SHUTDOWN;
}
// It's possible that we never got a prefs file.
nsresult rv = NS_OK;
if (mCurrentFile) {
rv = WritePrefFile(mCurrentFile, aSaveMethod);
}
- // If we succeeded writing to mCurrentFile, reset the dirty flag
+ // If we succeeded writing to mCurrentFile, reset the dirty flag.
if (NS_SUCCEEDED(rv)) {
mDirty = false;
}
return rv;
+
} else {
- // We only allow off main thread writes on mCurrentFile
+ // We only allow off main thread writes on mCurrentFile.
return WritePrefFile(aFile, SaveMethod::Blocking);
}
}
nsresult
Preferences::WritePrefFile(nsIFile* aFile, SaveMethod aSaveMethod)
{
if (!gHashTable) {
@@ -1281,42 +1309,42 @@ Preferences::WritePrefFile(nsIFile* aFil
// Put the newly constructed preference data into sPendingWriteData
// for the next request to pick up
prefs.reset(PreferencesWriter::sPendingWriteData.exchange(prefs.release()));
if (prefs) {
// There was a previous request that hasn't been processed,
// and this is the data it had.
return rv;
- } else {
- // There were no previous requests, dispatch one since
- // sPendingWriteData has the up to date information.
- nsCOMPtr<nsIEventTarget> target =
- do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID, &rv);
- if (NS_SUCCEEDED(rv)) {
- bool async = aSaveMethod == SaveMethod::Asynchronous;
- if (async) {
- rv = target->Dispatch(new PWRunnable(aFile),
- nsIEventTarget::DISPATCH_NORMAL);
- } else {
- // Note that we don't get the nsresult return value here
- SyncRunnable::DispatchToThread(target, new PWRunnable(aFile), true);
- }
- return rv;
- }
}
- // If we can't get the thread for writing, for whatever reason, do the
- // main thread write after making some noise:
+ // There were no previous requests. Dispatch one since sPendingWriteData has
+ // the up to date information.
+ nsCOMPtr<nsIEventTarget> target =
+ do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID, &rv);
+ if (NS_SUCCEEDED(rv)) {
+ bool async = aSaveMethod == SaveMethod::Asynchronous;
+ if (async) {
+ rv = target->Dispatch(new PWRunnable(aFile),
+ nsIEventTarget::DISPATCH_NORMAL);
+ } else {
+ // Note that we don't get the nsresult return value here.
+ SyncRunnable::DispatchToThread(target, new PWRunnable(aFile), true);
+ }
+ return rv;
+ }
+
+ // If we can't get the thread for writing, for whatever reason, do the main
+ // thread write after making some noise.
MOZ_ASSERT(false, "failed to get the target thread for OMT pref write");
}
- // This will do a main thread write. It is safe to do it this way
- // as AllowOffMainThreadSave() returns a consistent value for the
- // lifetime of the parent process.
+ // This will do a main thread write. It is safe to do it this way because
+ // AllowOffMainThreadSave() returns a consistent value for the lifetime of
+ // the parent process.
PrefSaveData prefsData = pref_savePrefs(gHashTable);
return PreferencesWriter::Write(aFile, prefsData);
}
static nsresult
openPrefFile(nsIFile* aFile)
{
PrefParseState ps;
@@ -1327,89 +1355,89 @@ openPrefFile(nsIFile* aFile)
MOZ_TRY_VAR(data, URLPreloader::ReadFile(aFile));
if (!PREF_ParseBuf(&ps, data.get(), data.Length())) {
return NS_ERROR_FILE_CORRUPTED;
}
return NS_OK;
}
-/*
- * some stuff that gets called from Pref_Init()
- */
+//
+// Some stuff that gets called from Pref_Init()
+//
static int
-pref_CompareFileNames(nsIFile* aFile1, nsIFile* aFile2, void* /*unused*/)
+pref_CompareFileNames(nsIFile* aFile1, nsIFile* aFile2, void* /* unused */)
{
nsAutoCString filename1, filename2;
aFile1->GetNativeLeafName(filename1);
aFile2->GetNativeLeafName(filename2);
return Compare(filename2, filename1);
}
-/**
- * Load default pref files from a directory. The files in the
- * directory are sorted reverse-alphabetically; a set of "special file
- * names" may be specified which are loaded after all the others.
- */
+// Load default pref files from a directory. The files in the directory are
+// sorted reverse-alphabetically; a set of "special file names" may be
+// specified which are loaded after all the others.
static nsresult
pref_LoadPrefsInDir(nsIFile* aDir,
char const* const* aSpecialFiles,
uint32_t aSpecialFilesCount)
{
nsresult rv, rv2;
bool hasMoreElements;
nsCOMPtr<nsISimpleEnumerator> dirIterator;
- // this may fail in some normal cases, such as embedders who do not use a GRE
+ // This may fail in some normal cases, such as embedders who do not use a
+ // GRE.
rv = aDir->GetDirectoryEntries(getter_AddRefs(dirIterator));
if (NS_FAILED(rv)) {
- // If the directory doesn't exist, then we have no reason to complain. We
+ // If the directory doesn't exist, then we have no reason to complain. We
// loaded everything (and nothing) successfully.
if (rv == NS_ERROR_FILE_NOT_FOUND ||
- rv == NS_ERROR_FILE_TARGET_DOES_NOT_EXIST)
+ rv == NS_ERROR_FILE_TARGET_DOES_NOT_EXIST) {
rv = NS_OK;
+ }
return rv;
}
rv = dirIterator->HasMoreElements(&hasMoreElements);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMArray<nsIFile> prefFiles(INITIAL_PREF_FILES);
nsCOMArray<nsIFile> specialFiles(aSpecialFilesCount);
nsCOMPtr<nsIFile> prefFile;
while (hasMoreElements && NS_SUCCEEDED(rv)) {
- nsAutoCString leafName;
-
nsCOMPtr<nsISupports> supports;
rv = dirIterator->GetNext(getter_AddRefs(supports));
prefFile = do_QueryInterface(supports);
if (NS_FAILED(rv)) {
break;
}
+ nsAutoCString leafName;
prefFile->GetNativeLeafName(leafName);
NS_ASSERTION(
!leafName.IsEmpty(),
"Failure in default prefs: directory enumerator returned empty file?");
- // Skip non-js files
+ // Skip non-js files.
if (StringEndsWith(leafName,
NS_LITERAL_CSTRING(".js"),
nsCaseInsensitiveCStringComparator())) {
bool shouldParse = true;
- // separate out special files
+
+ // Separate out special files.
for (uint32_t i = 0; i < aSpecialFilesCount; ++i) {
if (leafName.Equals(nsDependentCString(aSpecialFiles[i]))) {
shouldParse = false;
- // special files should be process in order; we put them into
- // the array by index; this can make the array sparse
+ // Special files should be processed in order. We put them into the
+ // array by index, which can make the array sparse.
specialFiles.ReplaceObjectAt(prefFile, i);
}
}
if (shouldParse) {
prefFiles.AppendObject(prefFile);
}
}
@@ -1434,166 +1462,177 @@ pref_LoadPrefsInDir(nsIFile* aDir,
if (NS_FAILED(rv2)) {
NS_ERROR("Default pref file not parsed successfully.");
rv = rv2;
}
}
arrayCount = specialFiles.Count();
for (i = 0; i < arrayCount; ++i) {
- // this may be a sparse array; test before parsing
+ // This may be a sparse array; test before parsing.
nsIFile* file = specialFiles[i];
if (file) {
rv2 = openPrefFile(file);
if (NS_FAILED(rv2)) {
NS_ERROR("Special default pref file not parsed successfully.");
rv = rv2;
}
}
}
return rv;
}
static nsresult
-pref_LoadPrefsInDirList(const char* listId)
+pref_LoadPrefsInDirList(const char* aListId)
{
nsresult rv;
nsCOMPtr<nsIProperties> dirSvc(
do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID, &rv));
- if (NS_FAILED(rv))
+ if (NS_FAILED(rv)) {
return rv;
+ }
nsCOMPtr<nsISimpleEnumerator> list;
- dirSvc->Get(listId, NS_GET_IID(nsISimpleEnumerator), getter_AddRefs(list));
- if (!list)
+ dirSvc->Get(aListId, NS_GET_IID(nsISimpleEnumerator), getter_AddRefs(list));
+ if (!list) {
return NS_OK;
+ }
bool hasMore;
while (NS_SUCCEEDED(list->HasMoreElements(&hasMore)) && hasMore) {
nsCOMPtr<nsISupports> elem;
list->GetNext(getter_AddRefs(elem));
- if (!elem)
+ if (!elem) {
continue;
+ }
nsCOMPtr<nsIFile> path = do_QueryInterface(elem);
- if (!path)
+ if (!path) {
continue;
+ }
nsAutoCString leaf;
path->GetNativeLeafName(leaf);
// Do we care if a file provided by this process fails to load?
- if (Substring(leaf, leaf.Length() - 4).EqualsLiteral(".xpi"))
+ if (Substring(leaf, leaf.Length() - 4).EqualsLiteral(".xpi")) {
ReadExtensionPrefs(path);
- else
+ } else {
pref_LoadPrefsInDir(path, nullptr, 0);
+ }
}
+
return NS_OK;
}
static nsresult
-pref_ReadPrefFromJar(nsZipArchive* jarReader, const char* name)
+pref_ReadPrefFromJar(nsZipArchive* aJarReader, const char* aName)
{
nsCString manifest;
MOZ_TRY_VAR(manifest,
- URLPreloader::ReadZip(jarReader, nsDependentCString(name)));
+ URLPreloader::ReadZip(aJarReader, nsDependentCString(aName)));
PrefParseState ps;
PREF_InitParseState(&ps, PREF_ReaderCallback, ReportToConsole, nullptr);
PREF_ParseBuf(&ps, manifest.get(), manifest.Length());
PREF_FinalizeParseState(&ps);
return NS_OK;
}
-//----------------------------------------------------------------------------------------
-// Initialize default preference JavaScript buffers from
-// appropriate TEXT resources
-//----------------------------------------------------------------------------------------
+// Initialize default preference JavaScript buffers from appropriate TEXT
+// resources.
static Result<Ok, const char*>
pref_InitInitialObjects()
{
- nsresult rv;
-
- // In omni.jar case, we load the following prefs:
+ // In the omni.jar case, we load the following prefs:
// - jar:$gre/omni.jar!/greprefs.js
// - jar:$gre/omni.jar!/defaults/pref/*.js
- // In non omni.jar case, we load:
+ //
+ // In the non-omni.jar case, we load:
// - $gre/greprefs.js
//
// In both cases, we also load:
// - $gre/defaults/pref/*.js
+ //
// This is kept for bug 591866 (channel-prefs.js should not be in omni.jar)
- // on $app == $gre case ; we load all files instead of channel-prefs.js only
- // to have the same behaviour as $app != $gre, where this is required as
- // a supported location for GRE preferences.
+ // in the `$app == $gre` case; we load all files instead of channel-prefs.js
+ // only to have the same behaviour as `$app != $gre`, where this is required
+ // as a supported location for GRE preferences.
//
- // When $app != $gre, we additionally load, in omni.jar case:
+ // When `$app != $gre`, we additionally load, in the omni.jar case:
// - jar:$app/omni.jar!/defaults/preferences/*.js
// - $app/defaults/preferences/*.js
- // and in non omni.jar case:
+ //
+ // and in the non-omni.jar case:
// - $app/defaults/preferences/*.js
- // When $app == $gre, we additionally load, in omni.jar case:
+ //
+ // When `$app == $gre`, we additionally load, in the omni.jar case:
// - jar:$gre/omni.jar!/defaults/preferences/*.js
- // Thus, in omni.jar case, we always load app-specific default preferences
- // from omni.jar, whether or not $app == $gre.
+ //
+ // Thus, in the omni.jar case, we always load app-specific default
+ // preferences from omni.jar, whether or not `$app == $gre`.
+ nsresult rv;
nsZipFind* findPtr;
nsAutoPtr<nsZipFind> find;
nsTArray<nsCString> prefEntries;
const char* entryName;
uint16_t entryNameLen;
RefPtr<nsZipArchive> jarReader =
mozilla::Omnijar::GetReader(mozilla::Omnijar::GRE);
if (jarReader) {
- // Load jar:$gre/omni.jar!/greprefs.js
+ // Load jar:$gre/omni.jar!/greprefs.js.
rv = pref_ReadPrefFromJar(jarReader, "greprefs.js");
NS_ENSURE_SUCCESS(rv, Err("pref_ReadPrefFromJar() failed"));
- // Load jar:$gre/omni.jar!/defaults/pref/*.js
+ // Load jar:$gre/omni.jar!/defaults/pref/*.js.
rv = jarReader->FindInit("defaults/pref/*.js$", &findPtr);
NS_ENSURE_SUCCESS(rv, Err("jarReader->FindInit() failed"));
find = findPtr;
while (NS_SUCCEEDED(find->FindNext(&entryName, &entryNameLen))) {
prefEntries.AppendElement(Substring(entryName, entryNameLen));
}
prefEntries.Sort();
for (uint32_t i = prefEntries.Length(); i--;) {
rv = pref_ReadPrefFromJar(jarReader, prefEntries[i].get());
- if (NS_FAILED(rv))
+ if (NS_FAILED(rv)) {
NS_WARNING("Error parsing preferences.");
+ }
}
+
} else {
- // Load $gre/greprefs.js
+ // Load $gre/greprefs.js.
nsCOMPtr<nsIFile> greprefsFile;
rv = NS_GetSpecialDirectory(NS_GRE_DIR, getter_AddRefs(greprefsFile));
NS_ENSURE_SUCCESS(rv, Err("NS_GetSpecialDirectory(NS_GRE_DIR) failed"));
rv = greprefsFile->AppendNative(NS_LITERAL_CSTRING("greprefs.js"));
NS_ENSURE_SUCCESS(rv, Err("greprefsFile->AppendNative() failed"));
rv = openPrefFile(greprefsFile);
- if (NS_FAILED(rv))
+ if (NS_FAILED(rv)) {
NS_WARNING("Error parsing GRE default preferences. Is this an old-style "
"embedding app?");
+ }
}
- // Load $gre/defaults/pref/*.js
+ // Load $gre/defaults/pref/*.js.
nsCOMPtr<nsIFile> defaultPrefDir;
-
rv = NS_GetSpecialDirectory(NS_APP_PREF_DEFAULTS_50_DIR,
getter_AddRefs(defaultPrefDir));
NS_ENSURE_SUCCESS(
rv, Err("NS_GetSpecialDirectory(NS_APP_PREF_DEFAULTS_50_DIR) failed"));
- /* these pref file names should not be used: we process them after all other application pref files for backwards compatibility */
+ // These pref file names should not be used: we process them after all other
+ // application pref files for backwards compatibility.
static const char* specialFiles[] = {
#if defined(XP_MACOSX)
"macprefs.js"
#elif defined(XP_WIN)
"winpref.js"
#elif defined(XP_UNIX)
"unix.js"
#if defined(_AIX)
@@ -1602,52 +1641,56 @@ pref_InitInitialObjects()
#endif
#elif defined(XP_BEOS)
"beos.js"
#endif
};
rv = pref_LoadPrefsInDir(
defaultPrefDir, specialFiles, ArrayLength(specialFiles));
- if (NS_FAILED(rv))
+ if (NS_FAILED(rv)) {
NS_WARNING("Error parsing application default preferences.");
+ }
// Load jar:$app/omni.jar!/defaults/preferences/*.js
// or jar:$gre/omni.jar!/defaults/preferences/*.js.
RefPtr<nsZipArchive> appJarReader =
mozilla::Omnijar::GetReader(mozilla::Omnijar::APP);
- // GetReader(mozilla::Omnijar::APP) returns null when $app == $gre, in which
- // case we look for app-specific default preferences in $gre.
- if (!appJarReader)
+
+ // GetReader(mozilla::Omnijar::APP) returns null when `$app == $gre`, in
+ // which case we look for app-specific default preferences in $gre.
+ if (!appJarReader) {
appJarReader = mozilla::Omnijar::GetReader(mozilla::Omnijar::GRE);
+ }
+
if (appJarReader) {
rv = appJarReader->FindInit("defaults/preferences/*.js$", &findPtr);
NS_ENSURE_SUCCESS(rv, Err("appJarReader->FindInit() failed"));
find = findPtr;
prefEntries.Clear();
while (NS_SUCCEEDED(find->FindNext(&entryName, &entryNameLen))) {
prefEntries.AppendElement(Substring(entryName, entryNameLen));
}
prefEntries.Sort();
for (uint32_t i = prefEntries.Length(); i--;) {
rv = pref_ReadPrefFromJar(appJarReader, prefEntries[i].get());
- if (NS_FAILED(rv))
+ if (NS_FAILED(rv)) {
NS_WARNING("Error parsing preferences.");
+ }
}
}
rv = pref_LoadPrefsInDirList(NS_APP_PREFS_DEFAULTS_DIR_LIST);
NS_ENSURE_SUCCESS(
rv, Err("pref_LoadPrefsInDirList(NS_APP_PREFS_DEFAULTS_DIR_LIST) failed"));
- // Set up the correct default for toolkit.telemetry.enabled.
- // If this build has MOZ_TELEMETRY_ON_BY_DEFAULT *or* we're on the beta
- // channel, telemetry is on by default, otherwise not. This is necessary
- // so that beta users who are testing final release builds don't flipflop
- // defaults.
+ // Set up the correct default for toolkit.telemetry.enabled. If this build
+ // has MOZ_TELEMETRY_ON_BY_DEFAULT *or* we're on the beta channel, telemetry
+ // is on by default, otherwise not. This is necessary so that beta users who
+ // are testing final release builds don't flipflop defaults.
if (Preferences::GetDefaultType(kTelemetryPref) ==
nsIPrefBranch::PREF_INVALID) {
bool prerelease = false;
#ifdef MOZ_TELEMETRY_ON_BY_DEFAULT
prerelease = true;
#else
nsAutoCString prefValue;
Preferences::GetDefaultCString(kChannelPref, prefValue);
@@ -1671,271 +1714,243 @@ pref_InitInitialObjects()
rv = pref_LoadPrefsInDirList(NS_EXT_PREFS_DEFAULTS_DIR_LIST);
NS_ENSURE_SUCCESS(
rv, Err("pref_LoadPrefsInDirList(NS_EXT_PREFS_DEFAULTS_DIR_LIST) failed"));
return Ok();
}
-/******************************************************************************
- *
- * static utilities
- *
- ******************************************************************************/
+//----------------------------------------------------------------------------
+// Static utilities
+//----------------------------------------------------------------------------
-// static
-nsresult
+/* static */ nsresult
Preferences::GetBool(const char* aPref, bool* aResult)
{
NS_PRECONDITION(aResult, "aResult must not be NULL");
NS_ENSURE_TRUE(InitStaticMembers(), NS_ERROR_NOT_AVAILABLE);
return PREF_GetBoolPref(aPref, aResult, false);
}
-// static
-nsresult
+/* static */ nsresult
Preferences::GetInt(const char* aPref, int32_t* aResult)
{
NS_PRECONDITION(aResult, "aResult must not be NULL");
NS_ENSURE_TRUE(InitStaticMembers(), NS_ERROR_NOT_AVAILABLE);
return PREF_GetIntPref(aPref, aResult, false);
}
-// static
-nsresult
+/* static */ nsresult
Preferences::GetFloat(const char* aPref, float* aResult)
{
NS_PRECONDITION(aResult, "aResult must not be NULL");
NS_ENSURE_TRUE(InitStaticMembers(), NS_ERROR_NOT_AVAILABLE);
nsAutoCString result;
nsresult rv = PREF_CopyCharPref(aPref, getter_Copies(result), false);
if (NS_SUCCEEDED(rv)) {
*aResult = result.ToFloat(&rv);
}
-
return rv;
}
-// static
-nsresult
+/* static */ nsresult
Preferences::GetCString(const char* aPref, nsACString& aResult)
{
NS_ENSURE_TRUE(InitStaticMembers(), NS_ERROR_NOT_AVAILABLE);
char* result;
nsresult rv = PREF_CopyCharPref(aPref, &result, false);
if (NS_SUCCEEDED(rv)) {
aResult.Adopt(result);
}
return rv;
}
-// static
-nsresult
+/* static */ nsresult
Preferences::GetString(const char* aPref, nsAString& aResult)
{
NS_ENSURE_TRUE(InitStaticMembers(), NS_ERROR_NOT_AVAILABLE);
nsAutoCString result;
nsresult rv = PREF_CopyCharPref(aPref, getter_Copies(result), false);
if (NS_SUCCEEDED(rv)) {
CopyUTF8toUTF16(result, aResult);
}
return rv;
}
-// static
-nsresult
+/* static */ nsresult
Preferences::GetLocalizedCString(const char* aPref, nsACString& aResult)
{
nsAutoString result;
nsresult rv = GetLocalizedString(aPref, result);
if (NS_SUCCEEDED(rv)) {
CopyUTF16toUTF8(result, aResult);
}
return rv;
}
-// static
-nsresult
+/* static */ nsresult
Preferences::GetLocalizedString(const char* aPref, nsAString& aResult)
{
NS_ENSURE_TRUE(InitStaticMembers(), NS_ERROR_NOT_AVAILABLE);
nsCOMPtr<nsIPrefLocalizedString> prefLocalString;
nsresult rv = sRootBranch->GetComplexValue(
aPref, NS_GET_IID(nsIPrefLocalizedString), getter_AddRefs(prefLocalString));
if (NS_SUCCEEDED(rv)) {
NS_ASSERTION(prefLocalString, "Succeeded but the result is NULL");
prefLocalString->GetData(getter_Copies(aResult));
}
return rv;
}
-// static
-nsresult
+/* static */ nsresult
Preferences::GetComplex(const char* aPref, const nsIID& aType, void** aResult)
{
NS_ENSURE_TRUE(InitStaticMembers(), NS_ERROR_NOT_AVAILABLE);
return sRootBranch->GetComplexValue(aPref, aType, aResult);
}
-// static
-nsresult
+/* static */ nsresult
Preferences::SetCString(const char* aPref, const char* aValue)
{
ENSURE_MAIN_PROCESS("Cannot SetCString from content process:", aPref);
NS_ENSURE_TRUE(InitStaticMembers(), NS_ERROR_NOT_AVAILABLE);
return PREF_SetCharPref(aPref, aValue, false);
}
-// static
-nsresult
+/* static */ nsresult
Preferences::SetCString(const char* aPref, const nsACString& aValue)
{
ENSURE_MAIN_PROCESS("Cannot SetCString from content process:", aPref);
NS_ENSURE_TRUE(InitStaticMembers(), NS_ERROR_NOT_AVAILABLE);
return PREF_SetCharPref(aPref, PromiseFlatCString(aValue).get(), false);
}
-// static
-nsresult
+/* static */ nsresult
Preferences::SetString(const char* aPref, const char16ptr_t aValue)
{
ENSURE_MAIN_PROCESS("Cannot SetString from content process:", aPref);
NS_ENSURE_TRUE(InitStaticMembers(), NS_ERROR_NOT_AVAILABLE);
return PREF_SetCharPref(aPref, NS_ConvertUTF16toUTF8(aValue).get(), false);
}
-// static
-nsresult
+/* static */ nsresult
Preferences::SetString(const char* aPref, const nsAString& aValue)
{
ENSURE_MAIN_PROCESS("Cannot SetString from content process:", aPref);
NS_ENSURE_TRUE(InitStaticMembers(), NS_ERROR_NOT_AVAILABLE);
return PREF_SetCharPref(aPref, NS_ConvertUTF16toUTF8(aValue).get(), false);
}
-// static
-nsresult
+/* static */ nsresult
Preferences::SetBool(const char* aPref, bool aValue)
{
ENSURE_MAIN_PROCESS("Cannot SetBool from content process:", aPref);
NS_ENSURE_TRUE(InitStaticMembers(), NS_ERROR_NOT_AVAILABLE);
return PREF_SetBoolPref(aPref, aValue, false);
}
-// static
-nsresult
+/* static */ nsresult
Preferences::SetInt(const char* aPref, int32_t aValue)
{
ENSURE_MAIN_PROCESS("Cannot SetInt from content process:", aPref);
NS_ENSURE_TRUE(InitStaticMembers(), NS_ERROR_NOT_AVAILABLE);
return PREF_SetIntPref(aPref, aValue, false);
}
-// static
-nsresult
+/* static */ nsresult
Preferences::SetFloat(const char* aPref, float aValue)
{
return SetCString(aPref, nsPrintfCString("%f", aValue).get());
}
-// static
-nsresult
+/* static */ nsresult
Preferences::SetComplex(const char* aPref,
const nsIID& aType,
nsISupports* aValue)
{
NS_ENSURE_TRUE(InitStaticMembers(), NS_ERROR_NOT_AVAILABLE);
return sRootBranch->SetComplexValue(aPref, aType, aValue);
}
-// static
-nsresult
+/* static */ nsresult
Preferences::ClearUser(const char* aPref)
{
ENSURE_MAIN_PROCESS("Cannot ClearUser from content process:", aPref);
NS_ENSURE_TRUE(InitStaticMembers(), NS_ERROR_NOT_AVAILABLE);
return PREF_ClearUserPref(aPref);
}
-// static
-bool
+/* static */ bool
Preferences::HasUserValue(const char* aPref)
{
NS_ENSURE_TRUE(InitStaticMembers(), false);
return PREF_HasUserPref(aPref);
}
-// static
-int32_t
+/* static */ int32_t
Preferences::GetType(const char* aPref)
{
NS_ENSURE_TRUE(InitStaticMembers(), nsIPrefBranch::PREF_INVALID);
int32_t result;
return NS_SUCCEEDED(sRootBranch->GetPrefType(aPref, &result))
? result
: nsIPrefBranch::PREF_INVALID;
}
-// static
-nsresult
+/* static */ nsresult
Preferences::AddStrongObserver(nsIObserver* aObserver, const char* aPref)
{
MOZ_ASSERT(aObserver);
NS_ENSURE_TRUE(InitStaticMembers(), NS_ERROR_NOT_AVAILABLE);
return sRootBranch->AddObserver(aPref, aObserver, false);
}
-// static
-nsresult
+/* static */ nsresult
Preferences::AddWeakObserver(nsIObserver* aObserver, const char* aPref)
{
MOZ_ASSERT(aObserver);
NS_ENSURE_TRUE(InitStaticMembers(), NS_ERROR_NOT_AVAILABLE);
return sRootBranch->AddObserver(aPref, aObserver, true);
}
-// static
-nsresult
+/* static */ nsresult
Preferences::RemoveObserver(nsIObserver* aObserver, const char* aPref)
{
MOZ_ASSERT(aObserver);
if (!sPreferences && sShutdown) {
return NS_OK; // Observers have been released automatically.
}
NS_ENSURE_TRUE(sPreferences, NS_ERROR_NOT_AVAILABLE);
return sRootBranch->RemoveObserver(aPref, aObserver);
}
-// static
-nsresult
+/* static */ nsresult
Preferences::AddStrongObservers(nsIObserver* aObserver, const char** aPrefs)
{
MOZ_ASSERT(aObserver);
for (uint32_t i = 0; aPrefs[i]; i++) {
nsresult rv = AddStrongObserver(aObserver, aPrefs[i]);
NS_ENSURE_SUCCESS(rv, rv);
}
return NS_OK;
}
-// static
-nsresult
+/* static */ nsresult
Preferences::AddWeakObservers(nsIObserver* aObserver, const char** aPrefs)
{
MOZ_ASSERT(aObserver);
for (uint32_t i = 0; aPrefs[i]; i++) {
nsresult rv = AddWeakObserver(aObserver, aPrefs[i]);
NS_ENSURE_SUCCESS(rv, rv);
}
return NS_OK;
}
-// static
-nsresult
+/* static */ nsresult
Preferences::RemoveObservers(nsIObserver* aObserver, const char** aPrefs)
{
MOZ_ASSERT(aObserver);
if (!sPreferences && sShutdown) {
return NS_OK; // Observers have been released automatically.
}
NS_ENSURE_TRUE(sPreferences, NS_ERROR_NOT_AVAILABLE);
@@ -1972,18 +1987,17 @@ RegisterPriorityCallback(PrefChangedFunc
observer = new ValueObserver(aPref, aCallback, Preferences::ExactMatch);
observer->AppendClosure(aClosure);
PREF_RegisterPriorityCallback(
aPref, NotifyObserver, static_cast<nsIObserver*>(observer));
gObserverTable->Put(observer, observer);
}
-// static
-nsresult
+/* static */ nsresult
Preferences::RegisterCallback(PrefChangedFunc aCallback,
const char* aPref,
void* aClosure,
MatchKind aMatchKind)
{
MOZ_ASSERT(aCallback);
NS_ENSURE_TRUE(InitStaticMembers(), NS_ERROR_NOT_AVAILABLE);
@@ -1994,38 +2008,37 @@ Preferences::RegisterCallback(PrefChange
observer->AppendClosure(aClosure);
return NS_OK;
}
observer = new ValueObserver(aPref, aCallback, aMatchKind);
observer->AppendClosure(aClosure);
nsresult rv = AddStrongObserver(observer, aPref);
NS_ENSURE_SUCCESS(rv, rv);
+
gObserverTable->Put(observer, observer);
return NS_OK;
}
-// static
-nsresult
+/* static */ nsresult
Preferences::RegisterCallbackAndCall(PrefChangedFunc aCallback,
const char* aPref,
void* aClosure,
MatchKind aMatchKind)
{
MOZ_ASSERT(aCallback);
WATCHING_PREF_RAII();
nsresult rv = RegisterCallback(aCallback, aPref, aClosure, aMatchKind);
if (NS_SUCCEEDED(rv)) {
(*aCallback)(aPref, aClosure);
}
return rv;
}
-// static
-nsresult
+/* static */ nsresult
Preferences::UnregisterCallback(PrefChangedFunc aCallback,
const char* aPref,
void* aClosure,
MatchKind aMatchKind)
{
MOZ_ASSERT(aCallback);
if (!sPreferences && sShutdown) {
return NS_OK; // Observers have been released automatically.
@@ -2042,258 +2055,245 @@ Preferences::UnregisterCallback(PrefChan
observer->RemoveClosure(aClosure);
if (observer->HasNoClosures()) {
// Delete the callback since its list of closures is empty.
gObserverTable->Remove(observer);
}
return NS_OK;
}
-// We insert cache observers using RegisterPriorityCallback to ensure they
-// are called prior to ordinary pref observers. Doing this ensures that
-// ordinary observers will never get stale values from cache variables.
+// We insert cache observers using RegisterPriorityCallback to ensure they are
+// called prior to ordinary pref observers. Doing this ensures that ordinary
+// observers will never get stale values from cache variables.
static void
BoolVarChanged(const char* aPref, void* aClosure)
{
CacheData* cache = static_cast<CacheData*>(aClosure);
- *((bool*)cache->cacheLocation) =
- Preferences::GetBool(aPref, cache->defaultValueBool);
+ *static_cast<bool*>(cache->mCacheLocation) =
+ Preferences::GetBool(aPref, cache->mDefaultValueBool);
}
static void
CacheDataAppendElement(CacheData* aData)
{
if (!gCacheData) {
MOZ_CRASH_UNSAFE_PRINTF("!gCacheData: %s", gCacheDataDesc);
}
gCacheData->AppendElement(aData);
}
-// static
-nsresult
+/* static */ nsresult
Preferences::AddBoolVarCache(bool* aCache, const char* aPref, bool aDefault)
{
WATCHING_PREF_RAII();
NS_ASSERTION(aCache, "aCache must not be NULL");
#ifdef DEBUG
AssertNotAlreadyCached("bool", aPref, aCache);
#endif
*aCache = GetBool(aPref, aDefault);
CacheData* data = new CacheData();
- data->cacheLocation = aCache;
- data->defaultValueBool = aDefault;
+ data->mCacheLocation = aCache;
+ data->mDefaultValueBool = aDefault;
CacheDataAppendElement(data);
RegisterPriorityCallback(BoolVarChanged, aPref, data);
return NS_OK;
}
static void
IntVarChanged(const char* aPref, void* aClosure)
{
CacheData* cache = static_cast<CacheData*>(aClosure);
- *((int32_t*)cache->cacheLocation) =
- Preferences::GetInt(aPref, cache->defaultValueInt);
+ *static_cast<int32_t*>(cache->mCacheLocation) =
+ Preferences::GetInt(aPref, cache->mDefaultValueInt);
}
-// static
-nsresult
+/* static */ nsresult
Preferences::AddIntVarCache(int32_t* aCache,
const char* aPref,
int32_t aDefault)
{
WATCHING_PREF_RAII();
NS_ASSERTION(aCache, "aCache must not be NULL");
#ifdef DEBUG
AssertNotAlreadyCached("int", aPref, aCache);
#endif
*aCache = Preferences::GetInt(aPref, aDefault);
CacheData* data = new CacheData();
- data->cacheLocation = aCache;
- data->defaultValueInt = aDefault;
+ data->mCacheLocation = aCache;
+ data->mDefaultValueInt = aDefault;
CacheDataAppendElement(data);
RegisterPriorityCallback(IntVarChanged, aPref, data);
return NS_OK;
}
static void
UintVarChanged(const char* aPref, void* aClosure)
{
CacheData* cache = static_cast<CacheData*>(aClosure);
- *((uint32_t*)cache->cacheLocation) =
- Preferences::GetUint(aPref, cache->defaultValueUint);
+ *static_cast<uint32_t*>(cache->mCacheLocation) =
+ Preferences::GetUint(aPref, cache->mDefaultValueUint);
}
-// static
-nsresult
+/* static */ nsresult
Preferences::AddUintVarCache(uint32_t* aCache,
const char* aPref,
uint32_t aDefault)
{
WATCHING_PREF_RAII();
NS_ASSERTION(aCache, "aCache must not be NULL");
#ifdef DEBUG
AssertNotAlreadyCached("uint", aPref, aCache);
#endif
*aCache = Preferences::GetUint(aPref, aDefault);
CacheData* data = new CacheData();
- data->cacheLocation = aCache;
- data->defaultValueUint = aDefault;
+ data->mCacheLocation = aCache;
+ data->mDefaultValueUint = aDefault;
CacheDataAppendElement(data);
RegisterPriorityCallback(UintVarChanged, aPref, data);
return NS_OK;
}
template<MemoryOrdering Order>
static void
AtomicUintVarChanged(const char* aPref, void* aClosure)
{
CacheData* cache = static_cast<CacheData*>(aClosure);
- *((Atomic<uint32_t, Order>*)cache->cacheLocation) =
- Preferences::GetUint(aPref, cache->defaultValueUint);
+ *static_cast<Atomic<uint32_t, Order>*>(cache->mCacheLocation) =
+ Preferences::GetUint(aPref, cache->mDefaultValueUint);
}
template<MemoryOrdering Order>
-// static
-nsresult
+/* static */ nsresult
Preferences::AddAtomicUintVarCache(Atomic<uint32_t, Order>* aCache,
const char* aPref,
uint32_t aDefault)
{
WATCHING_PREF_RAII();
NS_ASSERTION(aCache, "aCache must not be NULL");
#ifdef DEBUG
AssertNotAlreadyCached("uint", aPref, aCache);
#endif
*aCache = Preferences::GetUint(aPref, aDefault);
CacheData* data = new CacheData();
- data->cacheLocation = aCache;
- data->defaultValueUint = aDefault;
+ data->mCacheLocation = aCache;
+ data->mDefaultValueUint = aDefault;
CacheDataAppendElement(data);
RegisterPriorityCallback(AtomicUintVarChanged<Order>, aPref, data);
return NS_OK;
}
-// Since the definition of this template function is not in a header file,
-// we need to explicitly specify the instantiations that are required.
-// Currently only the order=Relaxed variant is needed.
+// Since the definition of this template function is not in a header file, we
+// need to explicitly specify the instantiations that are required. Currently
+// only the order=Relaxed variant is needed.
template nsresult
Preferences::AddAtomicUintVarCache(Atomic<uint32_t, Relaxed>*,
const char*,
uint32_t);
static void
FloatVarChanged(const char* aPref, void* aClosure)
{
CacheData* cache = static_cast<CacheData*>(aClosure);
- *((float*)cache->cacheLocation) =
- Preferences::GetFloat(aPref, cache->defaultValueFloat);
+ *static_cast<float*>(cache->mCacheLocation) =
+ Preferences::GetFloat(aPref, cache->mDefaultValueFloat);
}
-// static
-nsresult
+/* static */ nsresult
Preferences::AddFloatVarCache(float* aCache, const char* aPref, float aDefault)
{
WATCHING_PREF_RAII();
NS_ASSERTION(aCache, "aCache must not be NULL");
#ifdef DEBUG
AssertNotAlreadyCached("float", aPref, aCache);
#endif
*aCache = Preferences::GetFloat(aPref, aDefault);
CacheData* data = new CacheData();
- data->cacheLocation = aCache;
- data->defaultValueFloat = aDefault;
+ data->mCacheLocation = aCache;
+ data->mDefaultValueFloat = aDefault;
CacheDataAppendElement(data);
RegisterPriorityCallback(FloatVarChanged, aPref, data);
return NS_OK;
}
-// static
-nsresult
+/* static */ nsresult
Preferences::GetDefaultBool(const char* aPref, bool* aResult)
{
NS_PRECONDITION(aResult, "aResult must not be NULL");
NS_ENSURE_TRUE(InitStaticMembers(), NS_ERROR_NOT_AVAILABLE);
return PREF_GetBoolPref(aPref, aResult, true);
}
-// static
-nsresult
+/* static */ nsresult
Preferences::GetDefaultInt(const char* aPref, int32_t* aResult)
{
NS_PRECONDITION(aResult, "aResult must not be NULL");
NS_ENSURE_TRUE(InitStaticMembers(), NS_ERROR_NOT_AVAILABLE);
return PREF_GetIntPref(aPref, aResult, true);
}
-// static
-nsresult
+/* static */ nsresult
Preferences::GetDefaultCString(const char* aPref, nsACString& aResult)
{
NS_ENSURE_TRUE(InitStaticMembers(), NS_ERROR_NOT_AVAILABLE);
char* result;
nsresult rv = PREF_CopyCharPref(aPref, &result, true);
if (NS_SUCCEEDED(rv)) {
aResult.Adopt(result);
}
return rv;
}
-// static
-nsresult
+/* static */ nsresult
Preferences::GetDefaultString(const char* aPref, nsAString& aResult)
{
NS_ENSURE_TRUE(InitStaticMembers(), NS_ERROR_NOT_AVAILABLE);
nsAutoCString result;
nsresult rv = PREF_CopyCharPref(aPref, getter_Copies(result), true);
if (NS_SUCCEEDED(rv)) {
CopyUTF8toUTF16(result, aResult);
}
return rv;
}
-// static
-nsresult
+/* static */ nsresult
Preferences::GetDefaultLocalizedCString(const char* aPref, nsACString& aResult)
{
nsAutoString result;
nsresult rv = GetDefaultLocalizedString(aPref, result);
if (NS_SUCCEEDED(rv)) {
CopyUTF16toUTF8(result, aResult);
}
return rv;
}
-// static
-nsresult
+/* static */ nsresult
Preferences::GetDefaultLocalizedString(const char* aPref, nsAString& aResult)
{
NS_ENSURE_TRUE(InitStaticMembers(), NS_ERROR_NOT_AVAILABLE);
nsCOMPtr<nsIPrefLocalizedString> prefLocalString;
nsresult rv = sDefaultRootBranch->GetComplexValue(
aPref, NS_GET_IID(nsIPrefLocalizedString), getter_AddRefs(prefLocalString));
if (NS_SUCCEEDED(rv)) {
NS_ASSERTION(prefLocalString, "Succeeded but the result is NULL");
prefLocalString->GetData(getter_Copies(aResult));
}
return rv;
}
-// static
-nsresult
+/* static */ nsresult
Preferences::GetDefaultComplex(const char* aPref,
const nsIID& aType,
void** aResult)
{
NS_ENSURE_TRUE(InitStaticMembers(), NS_ERROR_NOT_AVAILABLE);
return sDefaultRootBranch->GetComplexValue(aPref, aType, aResult);
}
-// static
-int32_t
+/* static */ int32_t
Preferences::GetDefaultType(const char* aPref)
{
NS_ENSURE_TRUE(InitStaticMembers(), nsIPrefBranch::PREF_INVALID);
int32_t result;
return NS_SUCCEEDED(sDefaultRootBranch->GetPrefType(aPref, &result))
? result
: nsIPrefBranch::PREF_INVALID;
}