--- a/modules/libpref/Preferences.h
+++ b/modules/libpref/Preferences.h
@@ -17,45 +17,50 @@
#include "nsTArray.h"
#include "nsWeakReference.h"
#include "mozilla/Atomics.h"
#include "mozilla/MemoryReporting.h"
class nsIFile;
#ifndef have_PrefChangedFunc_typedef
-typedef void (*PrefChangedFunc)(const char *, void *);
+typedef void (*PrefChangedFunc)(const char*, void*);
#define have_PrefChangedFunc_typedef
#endif
#ifdef DEBUG
-enum pref_initPhase {
+enum pref_initPhase
+{
START,
BEGIN_INIT_PREFS,
END_INIT_PREFS,
BEGIN_ALL_PREFS,
END_ALL_PREFS
};
#define SET_PREF_PHASE(p) Preferences::SetInitPhase(p)
#else
-#define SET_PREF_PHASE(p) do { } while (0)
+#define SET_PREF_PHASE(p) \
+ do { \
+ } while (0)
#endif
namespace mozilla {
struct Ok;
-template <typename V, typename E> class Result;
+template<typename V, typename E>
+class Result;
namespace dom {
class PrefSetting;
} // namespace dom
-class Preferences final : public nsIPrefService,
- public nsIObserver,
- public nsIPrefBranch,
- public nsSupportsWeakReference
+class Preferences final
+ : public nsIPrefService
+ , public nsIObserver
+ , public nsIPrefBranch
+ , public nsSupportsWeakReference
{
public:
typedef mozilla::dom::PrefSetting PrefSetting;
NS_DECL_THREADSAFE_ISUPPORTS
NS_DECL_NSIPREFSERVICE
NS_FORWARD_NSIPREFBRANCH(sRootBranch->)
NS_DECL_NSIOBSERVER
@@ -173,35 +178,37 @@ public:
* @param aPref A pref name.
* @param aResult The value is never modified when these methods fail.
*/
static nsresult GetCString(const char* aPref, nsACString& aResult);
static nsresult GetString(const char* aPref, nsAString& aResult);
static nsresult GetLocalizedCString(const char* aPref, nsACString& aResult);
static nsresult GetLocalizedString(const char* aPref, nsAString& aResult);
- static nsresult GetComplex(const char* aPref, const nsIID &aType,
+ static nsresult GetComplex(const char* aPref,
+ const nsIID& aType,
void** aResult);
/**
* Sets various type pref values.
*/
static nsresult SetBool(const char* aPref, bool aValue);
static nsresult SetInt(const char* aPref, int32_t aValue);
static nsresult SetUint(const char* aPref, uint32_t aValue)
{
return SetInt(aPref, static_cast<int32_t>(aValue));
}
static nsresult SetFloat(const char* aPref, float aValue);
static nsresult SetCString(const char* aPref, const char* aValue);
- static nsresult SetCString(const char* aPref, const nsACString &aValue);
+ static nsresult SetCString(const char* aPref, const nsACString& aValue);
static nsresult SetString(const char* aPref, const char16ptr_t aValue);
- static nsresult SetString(const char* aPref, const nsAString &aValue);
+ static nsresult SetString(const char* aPref, const nsAString& aValue);
- static nsresult SetComplex(const char* aPref, const nsIID &aType,
+ static nsresult SetComplex(const char* aPref,
+ const nsIID& aType,
nsISupports* aValue);
/**
* Clears user set pref.
*/
static nsresult ClearUser(const char* aPref);
/**
@@ -225,20 +232,18 @@ public:
static nsresult RemoveObserver(nsIObserver* aObserver, const char* aPref);
/**
* Adds/Removes two or more observers for the root pref branch.
* Pass to aPrefs an array of const char* whose last item is nullptr.
*/
static nsresult AddStrongObservers(nsIObserver* aObserver,
const char** aPrefs);
- static nsresult AddWeakObservers(nsIObserver* aObserver,
- const char** aPrefs);
- static nsresult RemoveObservers(nsIObserver* aObserver,
- const char** aPrefs);
+ static nsresult AddWeakObservers(nsIObserver* aObserver, const char** aPrefs);
+ static nsresult RemoveObservers(nsIObserver* aObserver, const char** aPrefs);
/**
* Registers/Unregisters the callback function for the aPref.
*/
static nsresult RegisterCallback(PrefChangedFunc aCallback,
const char* aPref,
void* aClosure = nullptr)
{
@@ -302,17 +307,17 @@ public:
const char* aPref,
bool aDefault = false);
static nsresult AddIntVarCache(int32_t* aVariable,
const char* aPref,
int32_t aDefault = 0);
static nsresult AddUintVarCache(uint32_t* aVariable,
const char* aPref,
uint32_t aDefault = 0);
- template <MemoryOrdering Order>
+ template<MemoryOrdering Order>
static nsresult AddAtomicUintVarCache(Atomic<uint32_t, Order>* aVariable,
const char* aPref,
uint32_t aDefault = 0);
static nsresult AddFloatVarCache(float* aVariable,
const char* aPref,
float aDefault = 0.0f);
/**
@@ -332,41 +337,42 @@ public:
* Gets the default bool, int or uint value of the pref directly.
* You can set an invalid value of the pref to aFailedResult. If these
* methods failed to get the default value, they would return the
* aFailedResult value.
*/
static bool GetDefaultBool(const char* aPref, bool aFailedResult)
{
bool result;
- return NS_SUCCEEDED(GetDefaultBool(aPref, &result)) ? result :
- aFailedResult;
+ return NS_SUCCEEDED(GetDefaultBool(aPref, &result)) ? result
+ : aFailedResult;
}
static int32_t GetDefaultInt(const char* aPref, int32_t aFailedResult)
{
int32_t result;
return NS_SUCCEEDED(GetDefaultInt(aPref, &result)) ? result : aFailedResult;
}
static uint32_t GetDefaultUint(const char* aPref, uint32_t aFailedResult)
{
- return static_cast<uint32_t>(
- GetDefaultInt(aPref, static_cast<int32_t>(aFailedResult)));
+ return static_cast<uint32_t>(
+ GetDefaultInt(aPref, static_cast<int32_t>(aFailedResult)));
}
/**
* Gets the default value of the char type pref.
*/
static nsresult GetDefaultCString(const char* aPref, nsACString& aResult);
static nsresult GetDefaultString(const char* aPref, nsAString& aResult);
static nsresult GetDefaultLocalizedCString(const char* aPref,
nsACString& aResult);
static nsresult GetDefaultLocalizedString(const char* aPref,
nsAString& aResult);
- static nsresult GetDefaultComplex(const char* aPref, const nsIID &aType,
+ static nsresult GetDefaultComplex(const char* aPref,
+ const nsIID& aType,
void** aResult);
/**
* Gets the type of the pref.
*/
static int32_t GetDefaultType(const char* aPref);
// Used to synchronise preferences between chrome and content processes.
@@ -376,47 +382,49 @@ public:
static void SetInitPreferences(nsTArray<PrefSetting>* aPrefs);
#ifdef DEBUG
static void SetInitPhase(pref_initPhase phase);
static pref_initPhase InitPhase();
#endif
- static int64_t SizeOfIncludingThisAndOtherStuff(mozilla::MallocSizeOf aMallocSizeOf);
+ static int64_t SizeOfIncludingThisAndOtherStuff(
+ mozilla::MallocSizeOf aMallocSizeOf);
static void DirtyCallback();
// Explicitly choosing synchronous or asynchronous (if allowed)
// preferences file write. Only for the default file. The guarantee
// for the "blocking" is that when it returns, the file on disk
// reflect the current state of preferences.
nsresult SavePrefFileBlocking();
nsresult SavePrefFileAsynchronous();
protected:
virtual ~Preferences();
- nsresult NotifyServiceObservers(const char *aSubject);
+ nsresult NotifyServiceObservers(const char* aSubject);
/**
* Loads the prefs.js file from the profile, or creates a new one.
*
* @return the prefs file if successful, or nullptr on failure.
*/
already_AddRefed<nsIFile> ReadSavedPrefs();
/**
* Loads the user.js file from the profile if present.
*/
void ReadUserOverridePrefs();
- nsresult MakeBackupPrefFile(nsIFile *aFile);
+ nsresult MakeBackupPrefFile(nsIFile* aFile);
// Default pref file save can be blocking or not.
- enum class SaveMethod {
+ enum class SaveMethod
+ {
Blocking,
Asynchronous
};
// Off main thread is only respected for the default aFile value (nullptr)
nsresult SavePrefFileInternal(nsIFile* aFile, SaveMethod aSaveMethod);
nsresult WritePrefFile(nsIFile* aFile, SaveMethod aSaveMethod);
@@ -424,17 +432,18 @@ protected:
bool AllowOffMainThreadSave();
/**
* Helpers for implementing
* Register(Prefix)Callback/Unregister(Prefix)Callback.
*/
public:
// Public so the ValueObserver classes can use it.
- enum MatchKind {
+ enum MatchKind
+ {
PrefixMatch,
ExactMatch,
};
protected:
static nsresult RegisterCallback(PrefChangedFunc aCallback,
const char* aPref,
void* aClosure,
@@ -444,27 +453,27 @@ protected:
void* aClosure,
MatchKind aMatchKind);
static nsresult RegisterCallbackAndCall(PrefChangedFunc aCallback,
const char* aPref,
void* aClosure,
MatchKind aMatchKind);
private:
- nsCOMPtr<nsIFile> mCurrentFile;
- bool mDirty = false;
- bool mProfileShutdown = false;
+ nsCOMPtr<nsIFile> mCurrentFile;
+ bool mDirty = false;
+ bool mProfileShutdown = false;
// we wait a bit after prefs are dirty before writing them. In this
// period, mDirty and mSavePending will both be true.
- bool mSavePending = false;
+ bool mSavePending = false;
- static Preferences* sPreferences;
- static nsIPrefBranch* sRootBranch;
- static nsIPrefBranch* sDefaultRootBranch;
- static bool sShutdown;
+ static Preferences* sPreferences;
+ static nsIPrefBranch* sRootBranch;
+ static nsIPrefBranch* sDefaultRootBranch;
+ static bool sShutdown;
/**
* Init static members. TRUE if it succeeded. Otherwise, FALSE.
*/
static bool InitStaticMembers();
};
} // namespace mozilla
--- a/modules/libpref/nsPrefBranch.h
+++ b/modules/libpref/nsPrefBranch.h
@@ -25,270 +25,272 @@
#include "mozilla/Variant.h"
namespace mozilla {
class PreferenceServiceReporter;
} // namespace mozilla
class nsPrefBranch;
-class PrefCallback : public PLDHashEntryHdr {
+class PrefCallback : public PLDHashEntryHdr
+{
friend class mozilla::PreferenceServiceReporter;
- public:
- typedef PrefCallback* KeyType;
- typedef const PrefCallback* KeyTypePointer;
+public:
+ typedef PrefCallback* KeyType;
+ typedef const PrefCallback* KeyTypePointer;
+
+ static const PrefCallback* KeyToPointer(PrefCallback* aKey) { return aKey; }
+
+ static PLDHashNumber HashKey(const PrefCallback* aKey)
+ {
+ uint32_t hash = mozilla::HashString(aKey->mDomain);
+ return mozilla::AddToHash(hash, aKey->mCanonical);
+ }
- static const PrefCallback* KeyToPointer(PrefCallback *aKey)
- {
- return aKey;
- }
+public:
+ // Create a PrefCallback with a strong reference to its observer.
+ PrefCallback(const char* aDomain,
+ nsIObserver* aObserver,
+ nsPrefBranch* aBranch)
+ : mDomain(aDomain)
+ , mBranch(aBranch)
+ , mWeakRef(nullptr)
+ , mStrongRef(aObserver)
+ {
+ MOZ_COUNT_CTOR(PrefCallback);
+ nsCOMPtr<nsISupports> canonical = do_QueryInterface(aObserver);
+ mCanonical = canonical;
+ }
- static PLDHashNumber HashKey(const PrefCallback *aKey)
- {
- uint32_t hash = mozilla::HashString(aKey->mDomain);
- return mozilla::AddToHash(hash, aKey->mCanonical);
- }
-
+ // Create a PrefCallback with a weak reference to its observer.
+ PrefCallback(const char* aDomain,
+ nsISupportsWeakReference* aObserver,
+ nsPrefBranch* aBranch)
+ : mDomain(aDomain)
+ , mBranch(aBranch)
+ , mWeakRef(do_GetWeakReference(aObserver))
+ , mStrongRef(nullptr)
+ {
+ MOZ_COUNT_CTOR(PrefCallback);
+ nsCOMPtr<nsISupports> canonical = do_QueryInterface(aObserver);
+ mCanonical = canonical;
+ }
- public:
- // Create a PrefCallback with a strong reference to its observer.
- PrefCallback(const char *aDomain, nsIObserver *aObserver,
- nsPrefBranch *aBranch)
- : mDomain(aDomain),
- mBranch(aBranch),
- mWeakRef(nullptr),
- mStrongRef(aObserver)
- {
- MOZ_COUNT_CTOR(PrefCallback);
- nsCOMPtr<nsISupports> canonical = do_QueryInterface(aObserver);
- mCanonical = canonical;
- }
+ // Copy constructor needs to be explicit or the linker complains.
+ explicit PrefCallback(const PrefCallback*& aCopy)
+ : mDomain(aCopy->mDomain)
+ , mBranch(aCopy->mBranch)
+ , mWeakRef(aCopy->mWeakRef)
+ , mStrongRef(aCopy->mStrongRef)
+ , mCanonical(aCopy->mCanonical)
+ {
+ MOZ_COUNT_CTOR(PrefCallback);
+ }
+
+ ~PrefCallback() { MOZ_COUNT_DTOR(PrefCallback); }
- // Create a PrefCallback with a weak reference to its observer.
- PrefCallback(const char *aDomain,
- nsISupportsWeakReference *aObserver,
- nsPrefBranch *aBranch)
- : mDomain(aDomain),
- mBranch(aBranch),
- mWeakRef(do_GetWeakReference(aObserver)),
- mStrongRef(nullptr)
- {
- MOZ_COUNT_CTOR(PrefCallback);
- nsCOMPtr<nsISupports> canonical = do_QueryInterface(aObserver);
- mCanonical = canonical;
- }
+ bool KeyEquals(const PrefCallback* aKey) const
+ {
+ // We want to be able to look up a weakly-referencing PrefCallback after
+ // its observer has died so we can remove it from the table. Once the
+ // callback's observer dies, its canonical pointer is stale -- in
+ // particular, we may have allocated a new observer in the same spot in
+ // memory! So we can't just compare canonical pointers to determine
+ // whether aKey refers to the same observer as this.
+ //
+ // Our workaround is based on the way we use this hashtable: When we ask
+ // the hashtable to remove a PrefCallback whose weak reference has
+ // expired, we use as the key for removal the same object as was inserted
+ // into the hashtable. Thus we can say that if one of the keys' weak
+ // references has expired, the two keys are equal iff they're the same
+ // object.
- // Copy constructor needs to be explicit or the linker complains.
- explicit PrefCallback(const PrefCallback *&aCopy)
- : mDomain(aCopy->mDomain),
- mBranch(aCopy->mBranch),
- mWeakRef(aCopy->mWeakRef),
- mStrongRef(aCopy->mStrongRef),
- mCanonical(aCopy->mCanonical)
- {
- MOZ_COUNT_CTOR(PrefCallback);
- }
+ if (IsExpired() || aKey->IsExpired())
+ return this == aKey;
+
+ if (mCanonical != aKey->mCanonical)
+ return false;
+
+ return mDomain.Equals(aKey->mDomain);
+ }
- ~PrefCallback()
- {
- MOZ_COUNT_DTOR(PrefCallback);
+ PrefCallback* GetKey() const { return const_cast<PrefCallback*>(this); }
+
+ // Get a reference to the callback's observer, or null if the observer was
+ // weakly referenced and has been destroyed.
+ already_AddRefed<nsIObserver> GetObserver() const
+ {
+ if (!IsWeak()) {
+ nsCOMPtr<nsIObserver> copy = mStrongRef;
+ return copy.forget();
}
- bool KeyEquals(const PrefCallback *aKey) const
- {
- // We want to be able to look up a weakly-referencing PrefCallback after
- // its observer has died so we can remove it from the table. Once the
- // callback's observer dies, its canonical pointer is stale -- in
- // particular, we may have allocated a new observer in the same spot in
- // memory! So we can't just compare canonical pointers to determine
- // whether aKey refers to the same observer as this.
- //
- // Our workaround is based on the way we use this hashtable: When we ask
- // the hashtable to remove a PrefCallback whose weak reference has
- // expired, we use as the key for removal the same object as was inserted
- // into the hashtable. Thus we can say that if one of the keys' weak
- // references has expired, the two keys are equal iff they're the same
- // object.
+ nsCOMPtr<nsIObserver> observer = do_QueryReferent(mWeakRef);
+ return observer.forget();
+ }
- if (IsExpired() || aKey->IsExpired())
- return this == aKey;
+ const nsCString& GetDomain() const { return mDomain; }
+
+ nsPrefBranch* GetPrefBranch() const { return mBranch; }
- if (mCanonical != aKey->mCanonical)
- return false;
-
- return mDomain.Equals(aKey->mDomain);
- }
+ // Has this callback's weak reference died?
+ bool IsExpired() const
+ {
+ if (!IsWeak())
+ return false;
- PrefCallback *GetKey() const
- {
- return const_cast<PrefCallback*>(this);
- }
-
- // Get a reference to the callback's observer, or null if the observer was
- // weakly referenced and has been destroyed.
- already_AddRefed<nsIObserver> GetObserver() const
- {
- if (!IsWeak()) {
- nsCOMPtr<nsIObserver> copy = mStrongRef;
- return copy.forget();
- }
+ nsCOMPtr<nsIObserver> observer(do_QueryReferent(mWeakRef));
+ return !observer;
+ }
- nsCOMPtr<nsIObserver> observer = do_QueryReferent(mWeakRef);
- return observer.forget();
- }
-
- const nsCString& GetDomain() const
- {
- return mDomain;
- }
+ enum
+ {
+ ALLOW_MEMMOVE = true
+ };
- nsPrefBranch* GetPrefBranch() const
- {
- return mBranch;
- }
-
- // Has this callback's weak reference died?
- bool IsExpired() const
- {
- if (!IsWeak())
- return false;
+private:
+ nsCString mDomain;
+ nsPrefBranch* mBranch;
- nsCOMPtr<nsIObserver> observer(do_QueryReferent(mWeakRef));
- return !observer;
- }
-
- enum { ALLOW_MEMMOVE = true };
-
- private:
- nsCString mDomain;
- nsPrefBranch *mBranch;
+ // Exactly one of mWeakRef and mStrongRef should be non-null.
+ nsWeakPtr mWeakRef;
+ nsCOMPtr<nsIObserver> mStrongRef;
- // Exactly one of mWeakRef and mStrongRef should be non-null.
- nsWeakPtr mWeakRef;
- nsCOMPtr<nsIObserver> mStrongRef;
+ // We need a canonical nsISupports pointer, per bug 578392.
+ nsISupports* mCanonical;
- // We need a canonical nsISupports pointer, per bug 578392.
- nsISupports *mCanonical;
-
- bool IsWeak() const
- {
- return !!mWeakRef;
- }
+ bool IsWeak() const { return !!mWeakRef; }
};
-class nsPrefBranch final : public nsIPrefBranch,
- public nsIObserver,
- public nsSupportsWeakReference
+class nsPrefBranch final
+ : public nsIPrefBranch
+ , public nsIObserver
+ , public nsSupportsWeakReference
{
friend class mozilla::PreferenceServiceReporter;
+
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIPREFBRANCH
NS_DECL_NSIOBSERVER
- nsPrefBranch(const char *aPrefRoot, bool aDefaultBranch);
+ nsPrefBranch(const char* aPrefRoot, bool aDefaultBranch);
nsPrefBranch() = delete;
int32_t GetRootLength() const { return mPrefRoot.Length(); }
- nsresult RemoveObserverFromMap(const char *aDomain, nsISupports *aObserver);
+ nsresult RemoveObserverFromMap(const char* aDomain, nsISupports* aObserver);
- static void NotifyObserver(const char *newpref, void *data);
+ static void NotifyObserver(const char* newpref, void* data);
size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf);
static void ReportToConsole(const nsAString& aMessage);
protected:
/**
* Helper class for either returning a raw cstring or nsCString.
*/
typedef mozilla::Variant<const char*, const nsCString> PrefNameBase;
class PrefName : public PrefNameBase
{
public:
- explicit PrefName(const char* aName) : PrefNameBase(aName) {}
- explicit PrefName(const nsCString& aName) : PrefNameBase(aName) {}
+ explicit PrefName(const char* aName)
+ : PrefNameBase(aName)
+ {
+ }
+ explicit PrefName(const nsCString& aName)
+ : PrefNameBase(aName)
+ {
+ }
/**
* Use default move constructors, disallow copy constructors.
*/
PrefName(PrefName&& aOther) = default;
PrefName& operator=(PrefName&& aOther) = default;
PrefName(const PrefName&) = delete;
PrefName& operator=(const PrefName&) = delete;
- struct PtrMatcher {
+ struct PtrMatcher
+ {
static const char* match(const char* aVal) { return aVal; }
static const char* match(const nsCString& aVal) { return aVal.get(); }
};
- struct LenMatcher {
+ struct LenMatcher
+ {
static size_t match(const char* aVal) { return strlen(aVal); }
static size_t match(const nsCString& aVal) { return aVal.Length(); }
};
- const char* get() const {
+ const char* get() const
+ {
static PtrMatcher m;
return match(m);
}
- size_t Length() const {
+ size_t Length() const
+ {
static LenMatcher m;
return match(m);
}
};
virtual ~nsPrefBranch();
- nsresult GetDefaultFromPropertiesFile(const char *aPrefName, nsAString& aReturn);
+ nsresult GetDefaultFromPropertiesFile(const char* aPrefName,
+ nsAString& aReturn);
// As SetCharPref, but without any check on the length of |aValue|
- nsresult SetCharPrefInternal(const char *aPrefName, const char *aValue);
+ nsresult SetCharPrefInternal(const char* aPrefName, const char* aValue);
// Reject strings that are more than 1Mb, warn if strings are more than 16kb
- nsresult CheckSanityOfStringLength(const char* aPrefName, const nsAString& aValue);
- nsresult CheckSanityOfStringLength(const char* aPrefName, const nsACString& aValue);
- nsresult CheckSanityOfStringLength(const char* aPrefName, const char* aValue);
- nsresult CheckSanityOfStringLength(const char* aPrefName, const uint32_t aLength);
- void RemoveExpiredCallback(PrefCallback *aCallback);
- PrefName getPrefName(const char *aPrefName) const;
- void freeObserverList(void);
+ nsresult CheckSanityOfStringLength(const char* aPrefName,
+ const nsAString& aValue);
+ nsresult CheckSanityOfStringLength(const char* aPrefName,
+ const nsACString& aValue);
+ nsresult CheckSanityOfStringLength(const char* aPrefName, const char* aValue);
+ nsresult CheckSanityOfStringLength(const char* aPrefName,
+ const uint32_t aLength);
+ void RemoveExpiredCallback(PrefCallback* aCallback);
+ PrefName getPrefName(const char* aPrefName) const;
+ void freeObserverList(void);
private:
const nsCString mPrefRoot;
- bool mIsDefault;
+ bool mIsDefault;
- bool mFreeingObserverList;
+ bool mFreeingObserverList;
nsClassHashtable<PrefCallback, PrefCallback> mObservers;
};
-
-class nsPrefLocalizedString final : public nsIPrefLocalizedString,
- public nsISupportsString
+class nsPrefLocalizedString final
+ : public nsIPrefLocalizedString
+ , public nsISupportsString
{
public:
nsPrefLocalizedString();
NS_DECL_ISUPPORTS
NS_FORWARD_NSISUPPORTSSTRING(mUnicodeString->)
NS_FORWARD_NSISUPPORTSPRIMITIVE(mUnicodeString->)
nsresult Init();
private:
virtual ~nsPrefLocalizedString();
NS_IMETHOD GetData(char16_t**) override;
NS_IMETHOD SetData(const char16_t* aData) override;
- NS_IMETHOD SetDataWithLength(uint32_t aLength, const char16_t *aData) override;
+ NS_IMETHOD SetDataWithLength(uint32_t aLength,
+ const char16_t* aData) override;
nsCOMPtr<nsISupportsString> mUnicodeString;
};
-
class nsRelativeFilePref : public nsIRelativeFilePref
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIRELATIVEFILEPREF
nsRelativeFilePref();
--- a/modules/libpref/prefapi.h
+++ b/modules/libpref/prefapi.h
@@ -16,116 +16,145 @@
extern "C" {
#endif
// 1 MB should be enough for everyone.
static const uint32_t MAX_PREF_LENGTH = 1 * 1024 * 1024;
// Actually, 4kb should be enough for everyone.
static const uint32_t MAX_ADVISABLE_PREF_LENGTH = 4 * 1024;
-typedef union
-{
- char* stringVal;
- int32_t intVal;
- bool boolVal;
+typedef union {
+ char* stringVal;
+ int32_t intVal;
+ bool boolVal;
} PrefValue;
/*
// <font color=blue>
// The Init function initializes the preference context and creates
// the preference hashtable.
// </font>
*/
-void PREF_Init();
+void
+PREF_Init();
/*
// Cleanup should be called at program exit to free the
// list of registered callbacks.
*/
-void PREF_Cleanup();
-void PREF_CleanupPrefs();
+void
+PREF_Cleanup();
+void
+PREF_CleanupPrefs();
/*
// <font color=blue>
// Preference flags, including the native type of the preference. Changing any of these
// values will require modifying the code inside of PrefTypeFlags class.
// </font>
*/
-enum class PrefType {
+enum class PrefType
+{
Invalid = 0,
String = 1,
Int = 2,
Bool = 3,
};
// Keep the type of the preference, as well as the flags guiding its behaviour.
class PrefTypeFlags
{
public:
- PrefTypeFlags() : mValue(AsInt(PrefType::Invalid)) {}
- explicit PrefTypeFlags(PrefType aType) : mValue(AsInt(aType)) {}
- PrefTypeFlags& Reset() { mValue = AsInt(PrefType::Invalid); return *this; }
+ PrefTypeFlags()
+ : mValue(AsInt(PrefType::Invalid))
+ {
+ }
+ explicit PrefTypeFlags(PrefType aType)
+ : mValue(AsInt(aType))
+ {
+ }
+ PrefTypeFlags& Reset()
+ {
+ mValue = AsInt(PrefType::Invalid);
+ return *this;
+ }
bool IsTypeValid() const { return !IsPrefType(PrefType::Invalid); }
bool IsTypeString() const { return IsPrefType(PrefType::String); }
bool IsTypeInt() const { return IsPrefType(PrefType::Int); }
bool IsTypeBool() const { return IsPrefType(PrefType::Bool); }
bool IsPrefType(PrefType type) const { return GetPrefType() == type; }
- PrefTypeFlags& SetPrefType(PrefType aType) {
+ PrefTypeFlags& SetPrefType(PrefType aType)
+ {
mValue = mValue - AsInt(GetPrefType()) + AsInt(aType);
return *this;
}
- PrefType GetPrefType() const {
- return (PrefType)(mValue & (AsInt(PrefType::String) |
- AsInt(PrefType::Int) |
+ PrefType GetPrefType() const
+ {
+ return (PrefType)(mValue & (AsInt(PrefType::String) | AsInt(PrefType::Int) |
AsInt(PrefType::Bool)));
}
bool HasDefault() const { return mValue & PREF_FLAG_HAS_DEFAULT; }
- PrefTypeFlags& SetHasDefault(bool aSetOrUnset) { return SetFlag(PREF_FLAG_HAS_DEFAULT, aSetOrUnset); }
+ PrefTypeFlags& SetHasDefault(bool aSetOrUnset)
+ {
+ return SetFlag(PREF_FLAG_HAS_DEFAULT, aSetOrUnset);
+ }
bool HasStickyDefault() const { return mValue & PREF_FLAG_STICKY_DEFAULT; }
- PrefTypeFlags& SetHasStickyDefault(bool aSetOrUnset) { return SetFlag(PREF_FLAG_STICKY_DEFAULT, aSetOrUnset); }
+ PrefTypeFlags& SetHasStickyDefault(bool aSetOrUnset)
+ {
+ return SetFlag(PREF_FLAG_STICKY_DEFAULT, aSetOrUnset);
+ }
bool IsLocked() const { return mValue & PREF_FLAG_LOCKED; }
- PrefTypeFlags& SetLocked(bool aSetOrUnset) { return SetFlag(PREF_FLAG_LOCKED, aSetOrUnset); }
+ PrefTypeFlags& SetLocked(bool aSetOrUnset)
+ {
+ return SetFlag(PREF_FLAG_LOCKED, aSetOrUnset);
+ }
bool HasUserValue() const { return mValue & PREF_FLAG_USERSET; }
- PrefTypeFlags& SetHasUserValue(bool aSetOrUnset) { return SetFlag(PREF_FLAG_USERSET, aSetOrUnset); }
+ PrefTypeFlags& SetHasUserValue(bool aSetOrUnset)
+ {
+ return SetFlag(PREF_FLAG_USERSET, aSetOrUnset);
+ }
private:
static uint16_t AsInt(PrefType aType) { return (uint16_t)aType; }
- PrefTypeFlags& SetFlag(uint16_t aFlag, bool aSetOrUnset) {
+ PrefTypeFlags& SetFlag(uint16_t aFlag, bool aSetOrUnset)
+ {
mValue = aSetOrUnset ? mValue | aFlag : mValue & ~aFlag;
return *this;
}
// Pack both the value of type (PrefType) and flags into the same int. This is why
// the flag enum starts at 4, as PrefType occupies the bottom two bits.
- enum {
+ enum
+ {
PREF_FLAG_LOCKED = 4,
PREF_FLAG_USERSET = 8,
PREF_FLAG_CONFIG = 16,
PREF_FLAG_REMOTE = 32,
PREF_FLAG_LILOCAL = 64,
PREF_FLAG_HAS_DEFAULT = 128,
PREF_FLAG_STICKY_DEFAULT = 256,
};
uint16_t mValue;
};
struct PrefHashEntry : PLDHashEntryHdr
{
- PrefTypeFlags prefFlags; // This field goes first to minimize struct size on 64-bit.
- const char *key;
- PrefValue defaultPref;
- PrefValue userPref;
+ PrefTypeFlags
+ prefFlags; // This field goes first to minimize struct size on 64-bit.
+ const char* key;
+ PrefValue defaultPref;
+ PrefValue userPref;
};
/*
// <font color=blue>
// Set the various types of preferences. These functions take a dotted
// notation of the preference name (e.g. "browser.startup.homepage").
// Note that this will cause the preference to be saved to the file if
// it is different from the default. In other words, these are used
@@ -135,127 +164,143 @@ struct PrefHashEntry : PLDHashEntryHdr
// This will only affect the program behavior if the user does not have a value
// saved over it for the particular preference. In addition, these will never
// be saved out to disk.
//
// Each set returns PREF_VALUECHANGED if the user value changed
// (triggering a callback), or PREF_NOERROR if the value was unchanged.
// </font>
*/
-nsresult PREF_SetCharPref(const char *pref,const char* value, bool set_default = false);
-nsresult PREF_SetIntPref(const char *pref,int32_t value, bool set_default = false);
-nsresult PREF_SetBoolPref(const char *pref,bool value, bool set_default = false);
+nsresult
+PREF_SetCharPref(const char* pref, const char* value, bool set_default = false);
+nsresult
+PREF_SetIntPref(const char* pref, int32_t value, bool set_default = false);
+nsresult
+PREF_SetBoolPref(const char* pref, bool value, bool set_default = false);
-bool PREF_HasUserPref(const char* pref_name);
+bool
+PREF_HasUserPref(const char* pref_name);
/*
// <font color=blue>
// Get the various types of preferences. These functions take a dotted
// notation of the preference name (e.g. "browser.startup.homepage")
//
// They also take a pointer to fill in with the return value and return an
// error value. At the moment, this is simply an int but it may
// be converted to an enum once the global error strategy is worked out.
//
// They will perform conversion if the type doesn't match what was requested.
// (if it is reasonably possible)
// </font>
*/
-nsresult PREF_GetIntPref(const char *pref,
- int32_t * return_int, bool get_default);
-nsresult PREF_GetBoolPref(const char *pref, bool * return_val, bool get_default);
+nsresult
+PREF_GetIntPref(const char* pref, int32_t* return_int, bool get_default);
+nsresult
+PREF_GetBoolPref(const char* pref, bool* return_val, bool get_default);
/*
// <font color=blue>
// These functions are similar to the above "Get" version with the significant
// difference that the preference module will alloc the memory (e.g. XP_STRDUP) and
// the caller will need to be responsible for freeing it...
// </font>
*/
-nsresult PREF_CopyCharPref(const char *pref, char ** return_buf, bool get_default);
+nsresult
+PREF_CopyCharPref(const char* pref, char** return_buf, bool get_default);
/*
// <font color=blue>
// bool function that returns whether or not the preference is locked and therefore
// cannot be changed.
// </font>
*/
-bool PREF_PrefIsLocked(const char *pref_name);
+bool
+PREF_PrefIsLocked(const char* pref_name);
/*
// <font color=blue>
// Function that sets whether or not the preference is locked and therefore
// cannot be changed.
// </font>
*/
-nsresult PREF_LockPref(const char *key, bool lockIt);
+nsresult
+PREF_LockPref(const char* key, bool lockIt);
-PrefType PREF_GetPrefType(const char *pref_name);
+PrefType
+PREF_GetPrefType(const char* pref_name);
/*
* Delete a branch of the tree
*/
-nsresult PREF_DeleteBranch(const char *branch_name);
+nsresult
+PREF_DeleteBranch(const char* branch_name);
/*
* Clears the given pref (reverts it to its default value)
*/
-nsresult PREF_ClearUserPref(const char *pref_name);
+nsresult
+PREF_ClearUserPref(const char* pref_name);
/*
* Clears all user prefs
*/
-nsresult PREF_ClearAllUserPrefs();
-
+nsresult
+PREF_ClearAllUserPrefs();
/*
// <font color=blue>
// The callback function will get passed the pref_node which triggered the call
// and the void * instance_data which was passed to the register callback function.
// Return a non-zero result (nsresult) to pass an error up to the caller.
// </font>
*/
/* Temporarily conditionally compile PrefChangedFunc typedef.
** During migration from old libpref to nsIPref we need it in
** both header files. Eventually prefapi.h will become a private
** file. The two types need to be in sync for now. Certain
** compilers were having problems with multiple definitions.
*/
#ifndef have_PrefChangedFunc_typedef
-typedef void (*PrefChangedFunc) (const char *, void *);
+typedef void (*PrefChangedFunc)(const char*, void*);
#define have_PrefChangedFunc_typedef
#endif
/*
// <font color=blue>
// Register a callback. This takes a node in the preference tree and will
// call the callback function if anything below that node is modified.
// Unregister returns PREF_NOERROR if a callback was found that
// matched all the parameters; otherwise it returns PREF_ERROR.
// </font>
*/
-void PREF_RegisterPriorityCallback(const char* domain,
- PrefChangedFunc callback,
- void* instance_data );
-void PREF_RegisterCallback(const char* domain,
- PrefChangedFunc callback, void* instance_data );
-nsresult PREF_UnregisterCallback(const char* domain,
- PrefChangedFunc callback, void* instance_data );
+void
+PREF_RegisterPriorityCallback(const char* domain,
+ PrefChangedFunc callback,
+ void* instance_data);
+void
+PREF_RegisterCallback(const char* domain,
+ PrefChangedFunc callback,
+ void* instance_data);
+nsresult
+PREF_UnregisterCallback(const char* domain,
+ PrefChangedFunc callback,
+ void* instance_data);
/*
* Used by nsPrefService as the callback function of the 'pref' parser
*/
-void PREF_ReaderCallback( void *closure,
- const char *pref,
- PrefValue value,
- PrefType type,
- bool isDefault,
- bool isStickyDefault);
-
+void
+PREF_ReaderCallback(void* closure,
+ const char* pref,
+ PrefValue value,
+ PrefType type,
+ bool isDefault,
+ bool isStickyDefault);
/*
* Callback whenever we change a preference
*/
-typedef void (*PrefsDirtyFunc) ();
+typedef void (*PrefsDirtyFunc)();
void PREF_SetDirtyCallback(PrefsDirtyFunc);
#ifdef __cplusplus
}
#endif
#endif
--- a/modules/libpref/prefapi_private_data.h
+++ b/modules/libpref/prefapi_private_data.h
@@ -15,18 +15,17 @@
extern PLDHashTable* gHashTable;
namespace mozilla {
namespace dom {
class PrefSetting;
} // namespace dom
} // namespace mozilla
-
-typedef nsTArray<mozilla::UniqueFreePtr<char> > PrefSaveData;
+typedef nsTArray<mozilla::UniqueFreePtr<char>> PrefSaveData;
PrefSaveData
pref_savePrefs(PLDHashTable* aTable);
nsresult
pref_SetPref(const mozilla::dom::PrefSetting& aPref);
#ifdef DEBUG
@@ -35,20 +34,22 @@ pref_SetInitPhase(pref_initPhase phase);
pref_initPhase
pref_GetInitPhase();
void
pref_SetWatchingPref(bool watching);
#endif
-PrefHashEntry* pref_HashTableLookup(const char *key);
+PrefHashEntry*
+pref_HashTableLookup(const char* key);
bool
pref_EntryHasAdvisablySizedValues(PrefHashEntry* aHashEntry);
-void pref_GetPrefFromEntry(PrefHashEntry *aHashEntry,
- mozilla::dom::PrefSetting* aPref);
+void
+pref_GetPrefFromEntry(PrefHashEntry* aHashEntry,
+ mozilla::dom::PrefSetting* aPref);
size_t
pref_SizeOfPrivateData(mozilla::MallocSizeOf aMallocSizeOf);
#endif
--- a/modules/libpref/prefread.h
+++ b/modules/libpref/prefread.h
@@ -24,49 +24,52 @@ extern "C" {
* preference value
* @param type
* preference type (PREF_STRING, PREF_INT, or PREF_BOOL)
* @param defPref
* preference type (true: default, false: user preference)
* @param stickyPref
* default preference marked as a "sticky" pref
*/
-typedef void (*PrefReader)(void *closure,
- const char *pref,
- PrefValue val,
- PrefType type,
- bool defPref,
- bool stickyPref);
+typedef void (*PrefReader)(void* closure,
+ const char* pref,
+ PrefValue val,
+ PrefType type,
+ bool defPref,
+ bool stickyPref);
/**
* Report any errors or warnings we encounter during parsing.
*/
-typedef void (*PrefParseErrorReporter)(const char* message, int line, bool error);
+typedef void (*PrefParseErrorReporter)(const char* message,
+ int line,
+ bool error);
/* structure fields are private */
-typedef struct PrefParseState {
- PrefReader reader;
- PrefParseErrorReporter reporter;
- void *closure;
- int state; /* PREF_PARSE_... */
- int nextstate; /* sometimes used... */
- const char *smatch; /* string to match */
- int sindex; /* next char of smatch to check */
- /* also, counter in \u parsing */
- char16_t utf16[2]; /* parsing UTF16 (\u) escape */
- int esclen; /* length in esctmp */
- char esctmp[6]; /* raw escape to put back if err */
- char quotechar; /* char delimiter for quotations */
- char *lb; /* line buffer (only allocation) */
- char *lbcur; /* line buffer cursor */
- char *lbend; /* line buffer end */
- char *vb; /* value buffer (ptr into lb) */
- PrefType vtype; /* PREF_STRING,INT,BOOL */
- bool fdefault; /* true if (default) pref */
- bool fstickydefault; /* true if (sticky) pref */
+typedef struct PrefParseState
+{
+ PrefReader reader;
+ PrefParseErrorReporter reporter;
+ void* closure;
+ int state; /* PREF_PARSE_... */
+ int nextstate; /* sometimes used... */
+ const char* smatch; /* string to match */
+ int sindex; /* next char of smatch to check */
+ /* also, counter in \u parsing */
+ char16_t utf16[2]; /* parsing UTF16 (\u) escape */
+ int esclen; /* length in esctmp */
+ char esctmp[6]; /* raw escape to put back if err */
+ char quotechar; /* char delimiter for quotations */
+ char* lb; /* line buffer (only allocation) */
+ char* lbcur; /* line buffer cursor */
+ char* lbend; /* line buffer end */
+ char* vb; /* value buffer (ptr into lb) */
+ PrefType vtype; /* PREF_STRING,INT,BOOL */
+ bool fdefault; /* true if (default) pref */
+ bool fstickydefault; /* true if (sticky) pref */
} PrefParseState;
/**
* PREF_InitParseState
*
* Called to initialize a PrefParseState instance.
*
* @param ps
@@ -75,28 +78,32 @@ typedef struct PrefParseState {
* PrefReader callback function, which will be called once for each
* preference name value pair extracted.
* @param reporter
* PrefParseErrorReporter callback function, which will be called if we
* encounter any errors (stop) or warnings (continue) during parsing.
* @param closure
* PrefReader closure.
*/
-void PREF_InitParseState(PrefParseState *ps, PrefReader reader,
- PrefParseErrorReporter reporter, void *closure);
+void
+PREF_InitParseState(PrefParseState* ps,
+ PrefReader reader,
+ PrefParseErrorReporter reporter,
+ void* closure);
/**
* PREF_FinalizeParseState
*
* Called to release any memory in use by the PrefParseState instance.
*
* @param ps
* PrefParseState instance.
*/
-void PREF_FinalizeParseState(PrefParseState *ps);
+void
+PREF_FinalizeParseState(PrefParseState* ps);
/**
* PREF_ParseBuf
*
* Called to parse a buffer containing some portion of a preference file. This
* function may be called repeatedly as new data is made available. The
* PrefReader callback function passed PREF_InitParseState will be called as
* preference name value pairs are extracted from the data.
@@ -105,14 +112,15 @@ void PREF_FinalizeParseState(PrefParseSt
* PrefParseState instance. Must have been initialized.
* @param buf
* Raw buffer containing data to be parsed.
* @param bufLen
* Length of buffer.
*
* @return false if buffer contains malformed content.
*/
-bool PREF_ParseBuf(PrefParseState *ps, const char *buf, int bufLen);
+bool
+PREF_ParseBuf(PrefParseState* ps, const char* buf, int bufLen);
#ifdef __cplusplus
}
#endif
#endif /* prefread_h__ */