Bug 1407494 (part 9) - Merge PREF_RegisterCallback() and PREF_RegisterPriorityCallback. r=glandium.
This avoids some code duplication. MozReview-Commit-ID: 2Cb4YtL5RSu
This commit is contained in:
@@ -373,13 +373,10 @@ PREF_ClearAllUserPrefs();
|
|||||||
// returns PREF_NOERROR if a callback was found that matched all the
|
// returns PREF_NOERROR if a callback was found that matched all the
|
||||||
// parameters; otherwise it returns PREF_ERROR.
|
// parameters; otherwise it returns PREF_ERROR.
|
||||||
void
|
void
|
||||||
PREF_RegisterPriorityCallback(const char* aPrefNode,
|
|
||||||
PrefChangedFunc aCallback,
|
|
||||||
void* aData);
|
|
||||||
void
|
|
||||||
PREF_RegisterCallback(const char* aPrefNode,
|
PREF_RegisterCallback(const char* aPrefNode,
|
||||||
PrefChangedFunc aCallback,
|
PrefChangedFunc aCallback,
|
||||||
void* aData);
|
void* aData,
|
||||||
|
bool aIsPriority);
|
||||||
nsresult
|
nsresult
|
||||||
PREF_UnregisterCallback(const char* aPrefNode,
|
PREF_UnregisterCallback(const char* aPrefNode,
|
||||||
PrefChangedFunc aCallback,
|
PrefChangedFunc aCallback,
|
||||||
@@ -450,6 +447,8 @@ PLDHashTable* gHashTable;
|
|||||||
|
|
||||||
static ArenaAllocator<8192, 4> gPrefNameArena;
|
static ArenaAllocator<8192, 4> gPrefNameArena;
|
||||||
|
|
||||||
|
// The callback list contains all the priority callbacks followed by the
|
||||||
|
// non-priority callbacks. gLastPriorityNode records where the first part ends.
|
||||||
static CallbackNode* gFirstCallback = nullptr;
|
static CallbackNode* gFirstCallback = nullptr;
|
||||||
static CallbackNode* gLastPriorityNode = nullptr;
|
static CallbackNode* gLastPriorityNode = nullptr;
|
||||||
|
|
||||||
@@ -1302,11 +1301,12 @@ PREF_PrefIsLocked(const char* aPrefName)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Adds a node to the beginning of the callback list.
|
// Adds a node to the callback list; the position depends on aIsPriority.
|
||||||
void
|
void
|
||||||
PREF_RegisterPriorityCallback(const char* aPrefNode,
|
PREF_RegisterCallback(const char* aPrefNode,
|
||||||
PrefChangedFunc aCallback,
|
PrefChangedFunc aCallback,
|
||||||
void* aData)
|
void* aData,
|
||||||
|
bool aIsPriority)
|
||||||
{
|
{
|
||||||
NS_PRECONDITION(aPrefNode, "aPrefNode must not be nullptr");
|
NS_PRECONDITION(aPrefNode, "aPrefNode must not be nullptr");
|
||||||
NS_PRECONDITION(aCallback, "aCallback must not be nullptr");
|
NS_PRECONDITION(aCallback, "aCallback must not be nullptr");
|
||||||
@@ -1315,26 +1315,16 @@ PREF_RegisterPriorityCallback(const char* aPrefNode,
|
|||||||
node->mDomain = moz_xstrdup(aPrefNode);
|
node->mDomain = moz_xstrdup(aPrefNode);
|
||||||
node->mFunc = aCallback;
|
node->mFunc = aCallback;
|
||||||
node->mData = aData;
|
node->mData = aData;
|
||||||
|
|
||||||
|
if (aIsPriority) {
|
||||||
|
// Add to the start of the list.
|
||||||
node->mNext = gFirstCallback;
|
node->mNext = gFirstCallback;
|
||||||
gFirstCallback = node;
|
gFirstCallback = node;
|
||||||
if (!gLastPriorityNode) {
|
if (!gLastPriorityNode) {
|
||||||
gLastPriorityNode = node;
|
gLastPriorityNode = node;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
|
// Add to the start of the non-priority part of the list.
|
||||||
// Adds a node to the end of the callback list.
|
|
||||||
void
|
|
||||||
PREF_RegisterCallback(const char* aPrefNode,
|
|
||||||
PrefChangedFunc aCallback,
|
|
||||||
void* aData)
|
|
||||||
{
|
|
||||||
NS_PRECONDITION(aPrefNode, "aPrefNode must not be nullptr");
|
|
||||||
NS_PRECONDITION(aCallback, "aCallback must not be nullptr");
|
|
||||||
|
|
||||||
auto node = new CallbackNode();
|
|
||||||
node->mDomain = moz_xstrdup(aPrefNode);
|
|
||||||
node->mFunc = aCallback;
|
|
||||||
node->mData = aData;
|
|
||||||
if (gLastPriorityNode) {
|
if (gLastPriorityNode) {
|
||||||
node->mNext = gLastPriorityNode->mNext;
|
node->mNext = gLastPriorityNode->mNext;
|
||||||
gLastPriorityNode->mNext = node;
|
gLastPriorityNode->mNext = node;
|
||||||
@@ -1343,6 +1333,7 @@ PREF_RegisterCallback(const char* aPrefNode,
|
|||||||
gFirstCallback = node;
|
gFirstCallback = node;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Removes |node| from callback list. Returns the node after the deleted one.
|
// Removes |node| from callback list. Returns the node after the deleted one.
|
||||||
CallbackNode*
|
CallbackNode*
|
||||||
@@ -3176,7 +3167,8 @@ nsPrefBranch::AddObserver(const char* aDomain,
|
|||||||
// aDomain == nullptr is the only possible failure, and we trapped it with
|
// aDomain == nullptr is the only possible failure, and we trapped it with
|
||||||
// NS_ENSURE_ARG above.
|
// NS_ENSURE_ARG above.
|
||||||
const PrefName& pref = GetPrefName(aDomain);
|
const PrefName& pref = GetPrefName(aDomain);
|
||||||
PREF_RegisterCallback(pref.get(), NotifyObserver, pCallback);
|
PREF_RegisterCallback(
|
||||||
|
pref.get(), NotifyObserver, pCallback, /* isPriority */ false);
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -5338,8 +5330,10 @@ RegisterPriorityCallback(PrefChangedFunc aCallback,
|
|||||||
|
|
||||||
observer = new ValueObserver(aPref, aCallback, Preferences::ExactMatch);
|
observer = new ValueObserver(aPref, aCallback, Preferences::ExactMatch);
|
||||||
observer->AppendClosure(aClosure);
|
observer->AppendClosure(aClosure);
|
||||||
PREF_RegisterPriorityCallback(
|
PREF_RegisterCallback(aPref,
|
||||||
aPref, NotifyObserver, static_cast<nsIObserver*>(observer));
|
NotifyObserver,
|
||||||
|
static_cast<nsIObserver*>(observer),
|
||||||
|
/* isPriority */ true);
|
||||||
gObserverTable->Put(observer, observer);
|
gObserverTable->Put(observer, observer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user