mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-11-11 21:58:41 +02:00
Bug 1419648 - Remove and inline PREF_{LockPref,UnlockPref,PrefIsLocked}(). r=glandium
MozReview-Commit-ID: 7HatftTQwHr --HG-- extra : rebase_source : 686cec1ece58dafb2227819db308c17f6d30cacd
This commit is contained in:
parent
1bd63d481b
commit
b4b208fe70
2 changed files with 71 additions and 52 deletions
|
|
@ -662,34 +662,6 @@ pref_savePrefs()
|
||||||
return savedPrefs;
|
return savedPrefs;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Function that sets whether or not the preference is locked and therefore
|
|
||||||
// cannot be changed.
|
|
||||||
static nsresult
|
|
||||||
PREF_LockPref(const char* aPrefName, bool aLockIt)
|
|
||||||
{
|
|
||||||
if (!gHashTable) {
|
|
||||||
return NS_ERROR_NOT_INITIALIZED;
|
|
||||||
}
|
|
||||||
|
|
||||||
PrefHashEntry* pref = pref_HashTableLookup(aPrefName);
|
|
||||||
if (!pref) {
|
|
||||||
return NS_ERROR_UNEXPECTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (aLockIt) {
|
|
||||||
if (!pref->IsLocked()) {
|
|
||||||
pref->SetIsLocked(true);
|
|
||||||
gIsAnyPrefLocked = true;
|
|
||||||
NotifyCallbacks(aPrefName);
|
|
||||||
}
|
|
||||||
} else if (pref->IsLocked()) {
|
|
||||||
pref->SetIsLocked(false);
|
|
||||||
NotifyCallbacks(aPrefName);
|
|
||||||
}
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Hash table functions
|
// Hash table functions
|
||||||
//
|
//
|
||||||
|
|
@ -812,22 +784,6 @@ pref_SetPref(const char* aPrefName,
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bool function that returns whether or not the preference is locked and
|
|
||||||
// therefore cannot be changed.
|
|
||||||
static bool
|
|
||||||
PREF_PrefIsLocked(const char* aPrefName)
|
|
||||||
{
|
|
||||||
bool result = false;
|
|
||||||
if (gIsAnyPrefLocked && gHashTable) {
|
|
||||||
PrefHashEntry* pref = pref_HashTableLookup(aPrefName);
|
|
||||||
if (pref && pref->IsLocked()) {
|
|
||||||
result = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Adds a node to the callback list; the position depends on aIsPriority. The
|
// Adds a node to the callback list; the position depends on aIsPriority. The
|
||||||
// callback function will be called if anything below that node is modified.
|
// callback function will be called if anything below that node is modified.
|
||||||
static void
|
static void
|
||||||
|
|
@ -2142,7 +2098,7 @@ nsPrefBranch::GetComplexValue(const char* aPrefName,
|
||||||
} else {
|
} else {
|
||||||
// if there is no user (or locked) value
|
// if there is no user (or locked) value
|
||||||
if (!Preferences::HasUserValue(pref.get()) &&
|
if (!Preferences::HasUserValue(pref.get()) &&
|
||||||
!PREF_PrefIsLocked(pref.get())) {
|
!Preferences::IsLocked(pref.get())) {
|
||||||
bNeedDefault = true;
|
bNeedDefault = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -2407,33 +2363,30 @@ nsPrefBranch::PrefHasUserValue(const char* aPrefName, bool* aRetVal)
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsPrefBranch::LockPref(const char* aPrefName)
|
nsPrefBranch::LockPref(const char* aPrefName)
|
||||||
{
|
{
|
||||||
ENSURE_PARENT_PROCESS("LockPref", aPrefName);
|
|
||||||
NS_ENSURE_ARG(aPrefName);
|
NS_ENSURE_ARG(aPrefName);
|
||||||
|
|
||||||
const PrefName& pref = GetPrefName(aPrefName);
|
const PrefName& pref = GetPrefName(aPrefName);
|
||||||
return PREF_LockPref(pref.get(), true);
|
return Preferences::Lock(pref.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsPrefBranch::PrefIsLocked(const char* aPrefName, bool* aRetVal)
|
nsPrefBranch::PrefIsLocked(const char* aPrefName, bool* aRetVal)
|
||||||
{
|
{
|
||||||
ENSURE_PARENT_PROCESS("PrefIsLocked", aPrefName);
|
|
||||||
NS_ENSURE_ARG_POINTER(aRetVal);
|
NS_ENSURE_ARG_POINTER(aRetVal);
|
||||||
NS_ENSURE_ARG(aPrefName);
|
NS_ENSURE_ARG(aPrefName);
|
||||||
|
|
||||||
const PrefName& pref = GetPrefName(aPrefName);
|
const PrefName& pref = GetPrefName(aPrefName);
|
||||||
*aRetVal = PREF_PrefIsLocked(pref.get());
|
*aRetVal = Preferences::IsLocked(pref.get());
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsPrefBranch::UnlockPref(const char* aPrefName)
|
nsPrefBranch::UnlockPref(const char* aPrefName)
|
||||||
{
|
{
|
||||||
ENSURE_PARENT_PROCESS("UnlockPref", aPrefName);
|
|
||||||
NS_ENSURE_ARG(aPrefName);
|
NS_ENSURE_ARG(aPrefName);
|
||||||
|
|
||||||
const PrefName& pref = GetPrefName(aPrefName);
|
const PrefName& pref = GetPrefName(aPrefName);
|
||||||
return PREF_LockPref(pref.get(), false);
|
return Preferences::Unlock(pref.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
|
|
@ -4369,7 +4322,7 @@ Preferences::InitInitialObjects()
|
||||||
Preferences::SetBoolInAnyProcess(
|
Preferences::SetBoolInAnyProcess(
|
||||||
kTelemetryPref, false, PrefValueKind::Default);
|
kTelemetryPref, false, PrefValueKind::Default);
|
||||||
}
|
}
|
||||||
PREF_LockPref(kTelemetryPref, true);
|
Preferences::LockInAnyProcess(kTelemetryPref);
|
||||||
#endif // MOZ_WIDGET_ANDROID
|
#endif // MOZ_WIDGET_ANDROID
|
||||||
|
|
||||||
NS_CreateServicesFromCategory(NS_PREFSERVICE_APPDEFAULTS_TOPIC_ID,
|
NS_CreateServicesFromCategory(NS_PREFSERVICE_APPDEFAULTS_TOPIC_ID,
|
||||||
|
|
@ -4579,6 +4532,66 @@ Preferences::SetComplex(const char* aPrefName,
|
||||||
return GetRootBranch(aKind)->SetComplexValue(aPrefName, aType, aValue);
|
return GetRootBranch(aKind)->SetComplexValue(aPrefName, aType, aValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* static */ nsresult
|
||||||
|
Preferences::LockInAnyProcess(const char* aPrefName)
|
||||||
|
{
|
||||||
|
NS_ENSURE_TRUE(InitStaticMembers(), NS_ERROR_NOT_AVAILABLE);
|
||||||
|
|
||||||
|
PrefHashEntry* pref = pref_HashTableLookup(aPrefName);
|
||||||
|
if (!pref) {
|
||||||
|
return NS_ERROR_UNEXPECTED;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!pref->IsLocked()) {
|
||||||
|
pref->SetIsLocked(true);
|
||||||
|
gIsAnyPrefLocked = true;
|
||||||
|
NotifyCallbacks(aPrefName);
|
||||||
|
}
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* static */ nsresult
|
||||||
|
Preferences::Lock(const char* aPrefName)
|
||||||
|
{
|
||||||
|
ENSURE_PARENT_PROCESS("Lock", aPrefName);
|
||||||
|
return Preferences::LockInAnyProcess(aPrefName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* static */ nsresult
|
||||||
|
Preferences::Unlock(const char* aPrefName)
|
||||||
|
{
|
||||||
|
ENSURE_PARENT_PROCESS("Unlock", aPrefName);
|
||||||
|
NS_ENSURE_TRUE(InitStaticMembers(), NS_ERROR_NOT_AVAILABLE);
|
||||||
|
|
||||||
|
PrefHashEntry* pref = pref_HashTableLookup(aPrefName);
|
||||||
|
if (!pref) {
|
||||||
|
return NS_ERROR_UNEXPECTED;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pref->IsLocked()) {
|
||||||
|
pref->SetIsLocked(false);
|
||||||
|
NotifyCallbacks(aPrefName);
|
||||||
|
}
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* static */ bool
|
||||||
|
Preferences::IsLocked(const char* aPrefName)
|
||||||
|
{
|
||||||
|
NS_ENSURE_TRUE(InitStaticMembers(), false);
|
||||||
|
|
||||||
|
if (gIsAnyPrefLocked) {
|
||||||
|
PrefHashEntry* pref = pref_HashTableLookup(aPrefName);
|
||||||
|
if (pref && pref->IsLocked()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/* static */ nsresult
|
/* static */ nsresult
|
||||||
Preferences::ClearUserInAnyProcess(const char* aPrefName)
|
Preferences::ClearUserInAnyProcess(const char* aPrefName)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -237,6 +237,10 @@ public:
|
||||||
nsISupports* aValue,
|
nsISupports* aValue,
|
||||||
PrefValueKind aKind = PrefValueKind::User);
|
PrefValueKind aKind = PrefValueKind::User);
|
||||||
|
|
||||||
|
static nsresult Lock(const char* aPrefName);
|
||||||
|
static nsresult Unlock(const char* aPrefName);
|
||||||
|
static bool IsLocked(const char* aPrefName);
|
||||||
|
|
||||||
// Clears user set pref. Fails if run outside the parent process.
|
// Clears user set pref. Fails if run outside the parent process.
|
||||||
static nsresult ClearUser(const char* aPrefName);
|
static nsresult ClearUser(const char* aPrefName);
|
||||||
|
|
||||||
|
|
@ -429,6 +433,8 @@ private:
|
||||||
|
|
||||||
static nsresult ClearUserInAnyProcess(const char* aPrefName);
|
static nsresult ClearUserInAnyProcess(const char* aPrefName);
|
||||||
|
|
||||||
|
static nsresult LockInAnyProcess(const char* aPrefName);
|
||||||
|
|
||||||
static nsresult RegisterCallback(PrefChangedFunc aCallback,
|
static nsresult RegisterCallback(PrefChangedFunc aCallback,
|
||||||
const char* aPref,
|
const char* aPref,
|
||||||
void* aClosure,
|
void* aClosure,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue