зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1688833 - Migrate LookupForAdd to WithEntryHandle in docshell. r=nika
Differential Revision: https://phabricator.services.mozilla.com/D104200
This commit is contained in:
Родитель
5ab2e2fc52
Коммит
183fad585f
|
@ -87,42 +87,44 @@ void BaseHistory::RegisterVisitedCallback(nsIURI* aURI, Link* aLink) {
|
|||
}
|
||||
|
||||
// Obtain our array of observers for this URI.
|
||||
auto entry = mTrackedURIs.LookupForAdd(aURI);
|
||||
MOZ_DIAGNOSTIC_ASSERT(!entry || !entry.Data().mLinks.IsEmpty(),
|
||||
"An empty key was kept around in our hashtable!");
|
||||
if (!entry) {
|
||||
ScheduleVisitedQuery(aURI);
|
||||
}
|
||||
auto* const links =
|
||||
mTrackedURIs.WithEntryHandle(aURI, [&](auto&& entry) -> ObservingLinks* {
|
||||
MOZ_DIAGNOSTIC_ASSERT(!entry || !entry.Data().mLinks.IsEmpty(),
|
||||
"An empty key was kept around in our hashtable!");
|
||||
if (!entry) {
|
||||
ScheduleVisitedQuery(aURI);
|
||||
}
|
||||
|
||||
if (!aLink) {
|
||||
// In IPC builds, we are passed a nullptr Link from
|
||||
// ContentParent::RecvStartVisitedQuery. All of our code after this point
|
||||
// assumes aLink is non-nullptr, so we have to return now.
|
||||
MOZ_DIAGNOSTIC_ASSERT(XRE_IsParentProcess(),
|
||||
"We should only ever get a null Link "
|
||||
"in the parent process!");
|
||||
// We don't want to remove if we're tracking other links.
|
||||
if (!entry) {
|
||||
entry.OrRemove();
|
||||
}
|
||||
if (!aLink) {
|
||||
// In IPC builds, we are passed a nullptr Link from
|
||||
// ContentParent::RecvStartVisitedQuery. All of our code after this
|
||||
// point assumes aLink is non-nullptr, so we have to return now.
|
||||
MOZ_DIAGNOSTIC_ASSERT(XRE_IsParentProcess(),
|
||||
"We should only ever get a null Link "
|
||||
"in the parent process!");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return &entry.OrInsertWith([] { return ObservingLinks{}; });
|
||||
});
|
||||
|
||||
if (!links) {
|
||||
return;
|
||||
}
|
||||
|
||||
ObservingLinks& links = entry.OrInsert([] { return ObservingLinks{}; });
|
||||
|
||||
// Sanity check that Links are not registered more than once for a given URI.
|
||||
// This will not catch a case where it is registered for two different URIs.
|
||||
MOZ_DIAGNOSTIC_ASSERT(!links.mLinks.Contains(aLink),
|
||||
MOZ_DIAGNOSTIC_ASSERT(!links->mLinks.Contains(aLink),
|
||||
"Already tracking this Link object!");
|
||||
// FIXME(emilio): We should consider changing this (see the entry.Remove()
|
||||
// call in NotifyVisitedInThisProcess).
|
||||
MOZ_DIAGNOSTIC_ASSERT(links.mStatus != VisitedStatus::Visited,
|
||||
MOZ_DIAGNOSTIC_ASSERT(links->mStatus != VisitedStatus::Visited,
|
||||
"We don't keep tracking known-visited links");
|
||||
|
||||
links.mLinks.AppendElement(aLink);
|
||||
links->mLinks.AppendElement(aLink);
|
||||
|
||||
// If this link has already been queried and we should notify, do so now.
|
||||
switch (links.mStatus) {
|
||||
switch (links->mStatus) {
|
||||
case VisitedStatus::Unknown:
|
||||
break;
|
||||
case VisitedStatus::Unvisited:
|
||||
|
@ -131,7 +133,7 @@ void BaseHistory::RegisterVisitedCallback(nsIURI* aURI, Link* aLink) {
|
|||
}
|
||||
[[fallthrough]];
|
||||
case VisitedStatus::Visited:
|
||||
aLink->VisitedQueryFinished(links.mStatus == VisitedStatus::Visited);
|
||||
aLink->VisitedQueryFinished(links->mStatus == VisitedStatus::Visited);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,10 +34,11 @@ already_AddRefed<BrowsingContextGroup> BrowsingContextGroup::GetOrCreate(
|
|||
ClearOnShutdown(&sBrowsingContextGroups);
|
||||
}
|
||||
|
||||
auto entry = sBrowsingContextGroups->LookupForAdd(aId);
|
||||
RefPtr<BrowsingContextGroup> group =
|
||||
entry.OrInsert([&] { return do_AddRef(new BrowsingContextGroup(aId)); });
|
||||
return group.forget();
|
||||
return sBrowsingContextGroups->WithEntryHandle(aId, [&aId](auto&& entry) {
|
||||
RefPtr<BrowsingContextGroup> group = entry.OrInsertWith(
|
||||
[&aId] { return do_AddRef(new BrowsingContextGroup(aId)); });
|
||||
return group.forget();
|
||||
});
|
||||
}
|
||||
|
||||
already_AddRefed<BrowsingContextGroup> BrowsingContextGroup::Create() {
|
||||
|
@ -75,21 +76,23 @@ void BrowsingContextGroup::EnsureHostProcess(ContentParent* aProcess) {
|
|||
MOZ_DIAGNOSTIC_ASSERT(!aProcess->GetRemoteType().IsEmpty(),
|
||||
"host process must have remote type");
|
||||
|
||||
if (!aProcess->IsDead()) {
|
||||
auto entry = mHosts.LookupForAdd(aProcess->GetRemoteType());
|
||||
if (entry) {
|
||||
MOZ_DIAGNOSTIC_ASSERT(
|
||||
entry.Data() == aProcess,
|
||||
"There's already another host process for this remote type");
|
||||
return;
|
||||
}
|
||||
if (aProcess->IsDead() ||
|
||||
mHosts.WithEntryHandle(aProcess->GetRemoteType(), [&](auto&& entry) {
|
||||
if (entry) {
|
||||
MOZ_DIAGNOSTIC_ASSERT(
|
||||
entry.Data() == aProcess,
|
||||
"There's already another host process for this remote type");
|
||||
return false;
|
||||
}
|
||||
|
||||
// This process wasn't already marked as our host, so insert it, and begin
|
||||
// subscribing, unless the process is still launching.
|
||||
entry.OrInsert([&] { return do_AddRef(aProcess); });
|
||||
// This process wasn't already marked as our host, so insert it, and
|
||||
// begin subscribing, unless the process is still launching.
|
||||
entry.Insert(do_AddRef(aProcess));
|
||||
|
||||
return true;
|
||||
})) {
|
||||
aProcess->AddBrowsingContextGroup(this);
|
||||
}
|
||||
|
||||
aProcess->AddBrowsingContextGroup(this);
|
||||
}
|
||||
|
||||
void BrowsingContextGroup::RemoveHostProcess(ContentParent* aProcess) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче