mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-28 05:10:49 +00:00
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:
parent
8efce92e07
commit
0112be56fb
@ -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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user