Bug 1688833 - Migrate LookupForAdd to WithEntryHandle in toolkit/components/antitracking. r=timhuang

Differential Revision: https://phabricator.services.mozilla.com/D104223
This commit is contained in:
Simon Giesecke 2021-02-09 18:19:42 +00:00
Родитель 8efce92e07
Коммит 0112be56fb
1 изменённых файлов: 21 добавлений и 20 удалений

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

@ -35,27 +35,28 @@ void TemporaryAccessGrantObserver::Create(PermissionManager* aPM,
if (!sObservers) {
sObservers = MakeUnique<ObserversTable>();
}
Unused << sObservers
->LookupForAdd(std::make_pair(
nsCOMPtr<nsIPrincipal>(aPrincipal), nsCString(aType)))
.OrInsert([&]() -> nsITimer* {
// Only create a new observer if we don't have a matching
// entry in our hashtable.
nsCOMPtr<nsITimer> timer;
RefPtr<TemporaryAccessGrantObserver> observer =
new TemporaryAccessGrantObserver(aPM, aPrincipal, aType);
nsresult rv =
NS_NewTimerWithObserver(getter_AddRefs(timer), observer,
24 * 60 * 60 * 1000, // 24 hours
nsITimer::TYPE_ONE_SHOT);
sObservers->WithEntryHandle(
std::make_pair(nsCOMPtr<nsIPrincipal>(aPrincipal), nsCString(aType)),
[&](auto&& entry) {
entry.OrInsertWith([&]() -> nsITimer* {
// Only create a new observer if we don't have a matching
// entry in our hashtable.
nsCOMPtr<nsITimer> timer;
RefPtr<TemporaryAccessGrantObserver> observer =
new TemporaryAccessGrantObserver(aPM, aPrincipal, aType);
nsresult rv =
NS_NewTimerWithObserver(getter_AddRefs(timer), observer,
24 * 60 * 60 * 1000, // 24 hours
nsITimer::TYPE_ONE_SHOT);
if (NS_SUCCEEDED(rv)) {
observer->SetTimer(timer);
return timer;
}
timer->Cancel();
return nullptr;
});
if (NS_SUCCEEDED(rv)) {
observer->SetTimer(timer);
return timer;
}
timer->Cancel();
return nullptr;
});
});
}
void TemporaryAccessGrantObserver::SetTimer(nsITimer* aTimer) {