Bug 860075 - Avoid duplicate BT signal observer registration from child process. r=echou, r=gyeh

This commit is contained in:
John Lin 2013-04-19 16:40:56 +08:00
Родитель d9e7ac27e5
Коммит e3cf00fa31
3 изменённых файлов: 18 добавлений и 4 удалений

Просмотреть файл

@ -378,6 +378,10 @@ BluetoothService::UnregisterBluetoothSignalHandler(
BluetoothSignalObserverList* ol;
if (mBluetoothSignalObserverTable.Get(aNodeName, &ol)) {
ol->RemoveObserver(aHandler);
// We shouldn't have duplicate instances in the ObserverList, but there's
// no appropriate way to do duplication check while registering, so
// assertions are added here.
MOZ_ASSERT(!ol->RemoveObserver(aHandler));
if (ol->Length() == 0) {
mBluetoothSignalObserverTable.Remove(aNodeName);
}
@ -392,7 +396,12 @@ RemoveAllSignalHandlers(const nsAString& aKey,
nsAutoPtr<BluetoothSignalObserverList>& aData,
void* aUserArg)
{
aData->RemoveObserver(static_cast<BluetoothSignalObserver*>(aUserArg));
BluetoothSignalObserver* handler = static_cast<BluetoothSignalObserver*>(aUserArg);
aData->RemoveObserver(handler);
// We shouldn't have duplicate instances in the ObserverList, but there's
// no appropriate way to do duplication check while registering, so
// assertions are added here.
MOZ_ASSERT(!aData->RemoveObserver(handler));
return aData->Length() ? PL_DHASH_NEXT : PL_DHASH_REMOVE;
}

Просмотреть файл

@ -77,7 +77,7 @@ BluetoothServiceChildProcess::RegisterBluetoothSignalHandler(
const nsAString& aNodeName,
BluetoothSignalObserver* aHandler)
{
if (gBluetoothChild) {
if (gBluetoothChild && !IsSignalRegistered(aNodeName)) {
gBluetoothChild->SendRegisterSignalHandler(nsString(aNodeName));
}
BluetoothService::RegisterBluetoothSignalHandler(aNodeName, aHandler);
@ -88,10 +88,10 @@ BluetoothServiceChildProcess::UnregisterBluetoothSignalHandler(
const nsAString& aNodeName,
BluetoothSignalObserver* aHandler)
{
if (gBluetoothChild) {
BluetoothService::UnregisterBluetoothSignalHandler(aNodeName, aHandler);
if (gBluetoothChild && !IsSignalRegistered(aNodeName)) {
gBluetoothChild->SendUnregisterSignalHandler(nsString(aNodeName));
}
BluetoothService::UnregisterBluetoothSignalHandler(aNodeName, aHandler);
}
nsresult

Просмотреть файл

@ -174,6 +174,11 @@ private:
// This method should never be called from the child.
virtual nsresult
PrepareAdapterInternal() MOZ_OVERRIDE;
bool
IsSignalRegistered(const nsAString& aNodeName) {
return !!mBluetoothSignalObserverTable.Get(aNodeName);
}
};
END_BLUETOOTH_NAMESPACE