Bug 708901 - Migrate to nsTHashSet in dom/ipc. r=nika

Depends on D108597

Differential Revision: https://phabricator.services.mozilla.com/D108598
This commit is contained in:
Simon Giesecke 2021-03-23 10:36:34 +00:00
parent af20b2ddf6
commit 45420d4e39
5 changed files with 29 additions and 31 deletions

View File

@ -2696,7 +2696,7 @@ void ContentChild::AddIdleObserver(nsIObserver* aObserver,
// Make sure aObserver isn't released while we wait for the parent // Make sure aObserver isn't released while we wait for the parent
aObserver->AddRef(); aObserver->AddRef();
SendAddIdleObserver(reinterpret_cast<uint64_t>(aObserver), aIdleTimeInS); SendAddIdleObserver(reinterpret_cast<uint64_t>(aObserver), aIdleTimeInS);
mIdleObservers.PutEntry(aObserver); mIdleObservers.Insert(aObserver);
} }
void ContentChild::RemoveIdleObserver(nsIObserver* aObserver, void ContentChild::RemoveIdleObserver(nsIObserver* aObserver,
@ -2704,7 +2704,7 @@ void ContentChild::RemoveIdleObserver(nsIObserver* aObserver,
MOZ_ASSERT(aObserver, "null idle observer"); MOZ_ASSERT(aObserver, "null idle observer");
SendRemoveIdleObserver(reinterpret_cast<uint64_t>(aObserver), aIdleTimeInS); SendRemoveIdleObserver(reinterpret_cast<uint64_t>(aObserver), aIdleTimeInS);
aObserver->Release(); aObserver->Release();
mIdleObservers.RemoveEntry(aObserver); mIdleObservers.Remove(aObserver);
} }
mozilla::ipc::IPCResult ContentChild::RecvNotifyIdleObserver( mozilla::ipc::IPCResult ContentChild::RecvNotifyIdleObserver(

View File

@ -24,7 +24,7 @@
#include "nsRefPtrHashtable.h" #include "nsRefPtrHashtable.h"
#include "nsString.h" #include "nsString.h"
#include "nsTArrayForwardDeclare.h" #include "nsTArrayForwardDeclare.h"
#include "nsTHashtable.h" #include "nsTHashSet.h"
#if defined(XP_MACOSX) && defined(MOZ_SANDBOX) #if defined(XP_MACOSX) && defined(MOZ_SANDBOX)
# include "nsIFile.h" # include "nsIFile.h"
@ -845,7 +845,7 @@ class ContentChild final : public PContentChild,
nsTArray<mozilla::UniquePtr<AlertObserver>> mAlertObservers; nsTArray<mozilla::UniquePtr<AlertObserver>> mAlertObservers;
RefPtr<ConsoleListener> mConsoleListener; RefPtr<ConsoleListener> mConsoleListener;
nsTHashtable<nsPtrHashKey<nsIObserver>> mIdleObservers; nsTHashSet<nsIObserver*> mIdleObservers;
nsTArray<nsCString> mAvailableDictionaries; nsTArray<nsCString> mAvailableDictionaries;

View File

@ -1819,10 +1819,9 @@ void ContentParent::ShutDownProcess(ShutDownMethod aMethod) {
const ManagedContainer<POfflineCacheUpdateParent>& ocuParents = const ManagedContainer<POfflineCacheUpdateParent>& ocuParents =
ManagedPOfflineCacheUpdateParent(); ManagedPOfflineCacheUpdateParent();
for (auto iter = ocuParents.ConstIter(); !iter.Done(); iter.Next()) { for (auto* key : ocuParents.Keys()) {
RefPtr<mozilla::docshell::OfflineCacheUpdateParent> ocuParent = RefPtr<mozilla::docshell::OfflineCacheUpdateParent> ocuParent =
static_cast<mozilla::docshell::OfflineCacheUpdateParent*>( static_cast<mozilla::docshell::OfflineCacheUpdateParent*>(key);
iter.Get()->GetKey());
ocuParent->StopSendingMessagesToChild(); ocuParent->StopSendingMessagesToChild();
} }
@ -1885,8 +1884,8 @@ void ContentParent::AssertNotInPool() {
!sBrowserContentParents->Get(mRemoteType)->Contains(this) || !sBrowserContentParents->Get(mRemoteType)->Contains(this) ||
!sCanLaunchSubprocesses); // aka in shutdown - avoid timing issues !sCanLaunchSubprocesses); // aka in shutdown - avoid timing issues
for (auto& group : mGroups) { for (const auto& group : mGroups) {
MOZ_RELEASE_ASSERT(group.GetKey()->GetHostProcess(mRemoteType) != this, MOZ_RELEASE_ASSERT(group->GetHostProcess(mRemoteType) != this,
"still a host process for one of our groups?"); "still a host process for one of our groups?");
} }
} }
@ -1922,8 +1921,8 @@ void ContentParent::RemoveFromList() {
// Ensure that this BrowsingContextGroup is no longer used to host new // Ensure that this BrowsingContextGroup is no longer used to host new
// documents from any associated BrowsingContextGroups. It may become a host // documents from any associated BrowsingContextGroups. It may become a host
// again in the future, if it is restored to the pool. // again in the future, if it is restored to the pool.
for (auto& group : mGroups) { for (const auto& group : mGroups) {
group.GetKey()->RemoveHostProcess(this); group->RemoveHostProcess(this);
} }
StopRecycling(/* aForeground */ false); StopRecycling(/* aForeground */ false);
@ -2157,10 +2156,9 @@ void ContentParent::ActorDestroy(ActorDestroyReason why) {
// unsubscribed. // unsubscribed.
BrowsingContext::DiscardFromContentParent(this); BrowsingContext::DiscardFromContentParent(this);
nsTHashtable<nsRefPtrHashKey<BrowsingContextGroup>> groups; const nsTHashSet<RefPtr<BrowsingContextGroup>> groups = std::move(mGroups);
mGroups.SwapElements(groups); for (const auto& group : groups) {
for (auto& group : groups) { group->Unsubscribe(this);
group.GetKey()->Unsubscribe(this);
} }
MOZ_DIAGNOSTIC_ASSERT(mGroups.IsEmpty()); MOZ_DIAGNOSTIC_ASSERT(mGroups.IsEmpty());
} }
@ -3188,8 +3186,8 @@ bool ContentParent::InitInternal(ProcessPriority aInitialPriority) {
// Begin subscribing to any BrowsingContextGroups which were hosted by this // Begin subscribing to any BrowsingContextGroups which were hosted by this
// process before it finished launching. // process before it finished launching.
for (auto& group : mGroups) { for (const auto& group : mGroups) {
group.GetKey()->Subscribe(this); group->Subscribe(this);
} }
// Start up nsPluginHost and run FindPlugins to cache the plugin list. // Start up nsPluginHost and run FindPlugins to cache the plugin list.
@ -6154,10 +6152,9 @@ void ContentParent::EnsurePermissionsByKey(const nsCString& aKey,
return; return;
} }
if (mActivePermissionKeys.Contains(aKey)) { if (!mActivePermissionKeys.EnsureInserted(aKey)) {
return; return;
} }
mActivePermissionKeys.PutEntry(aKey);
nsTArray<IPC::Permission> perms; nsTArray<IPC::Permission> perms;
if (permManager->GetPermissionsFromOriginOrKey(aOrigin, aKey, perms)) { if (permManager->GetPermissionsFromOriginOrKey(aOrigin, aKey, perms)) {
@ -7149,7 +7146,7 @@ void ContentParent::RemoveBrowsingContextGroup(BrowsingContextGroup* aGroup) {
MOZ_DIAGNOSTIC_ASSERT(aGroup); MOZ_DIAGNOSTIC_ASSERT(aGroup);
// Remove the group from our list. This is called from the // Remove the group from our list. This is called from the
// BrowisngContextGroup when unsubscribing, so we don't need to do it here. // BrowisngContextGroup when unsubscribing, so we don't need to do it here.
mGroups.RemoveEntry(aGroup); mGroups.Remove(aGroup);
} }
mozilla::ipc::IPCResult ContentParent::RecvCommitBrowsingContextTransaction( mozilla::ipc::IPCResult ContentParent::RecvCommitBrowsingContextTransaction(

View File

@ -35,6 +35,7 @@
#include "nsClassHashtable.h" #include "nsClassHashtable.h"
#include "nsTHashMap.h" #include "nsTHashMap.h"
#include "nsTHashSet.h"
#include "nsPluginTags.h" #include "nsPluginTags.h"
#include "nsHashKeys.h" #include "nsHashKeys.h"
#include "nsIAsyncShutdown.h" #include "nsIAsyncShutdown.h"
@ -1593,7 +1594,7 @@ class ContentParent final
// GetFilesHelper can be aborted by receiving RecvDeleteGetFilesRequest. // GetFilesHelper can be aborted by receiving RecvDeleteGetFilesRequest.
nsRefPtrHashtable<nsIDHashKey, GetFilesHelper> mGetFilesPendingRequests; nsRefPtrHashtable<nsIDHashKey, GetFilesHelper> mGetFilesPendingRequests;
nsTHashtable<nsCStringHashKey> mActivePermissionKeys; nsTHashSet<nsCString> mActivePermissionKeys;
nsTArray<nsCString> mBlobURLs; nsTArray<nsCString> mBlobURLs;
@ -1622,7 +1623,7 @@ class ContentParent final
static bool sEarlySandboxInit; static bool sEarlySandboxInit;
#endif #endif
nsTHashtable<nsRefPtrHashKey<BrowsingContextGroup>> mGroups; nsTHashSet<RefPtr<BrowsingContextGroup>> mGroups;
// See `BrowsingContext::mEpochs` for an explanation of this field. // See `BrowsingContext::mEpochs` for an explanation of this field.
uint64_t mBrowsingContextFieldEpoch = 0; uint64_t mBrowsingContextFieldEpoch = 0;

View File

@ -29,7 +29,7 @@
#include "nsIPropertyBag2.h" #include "nsIPropertyBag2.h"
#include "nsComponentManagerUtils.h" #include "nsComponentManagerUtils.h"
#include "nsCRT.h" #include "nsCRT.h"
#include "nsTHashtable.h" #include "nsTHashSet.h"
#include "nsQueryObject.h" #include "nsQueryObject.h"
#include "nsTHashMap.h" #include "nsTHashMap.h"
@ -170,7 +170,7 @@ class ProcessPriorityManagerImpl final : public nsIObserver,
mParticularManagers; mParticularManagers;
/** Contains the PIDs of child processes holding high-priority wakelocks */ /** Contains the PIDs of child processes holding high-priority wakelocks */
nsTHashtable<nsUint64HashKey> mHighPriorityChildIDs; nsTHashSet<uint64_t> mHighPriorityChildIDs;
}; };
/** /**
@ -287,7 +287,7 @@ class ParticularProcessPriorityManager final : public WakeLockObserver,
nsCOMPtr<nsITimer> mResetPriorityTimer; nsCOMPtr<nsITimer> mResetPriorityTimer;
// This hashtable contains the list of active TabId for this process. // This hashtable contains the list of active TabId for this process.
nsTHashtable<nsUint64HashKey> mActiveBrowserParents; nsTHashSet<uint64_t> mActiveBrowserParents;
}; };
/* static */ /* static */
@ -447,7 +447,7 @@ void ProcessPriorityManagerImpl::ObserveContentParentDestroyed(
if (auto entry = mParticularManagers.Lookup(childID)) { if (auto entry = mParticularManagers.Lookup(childID)) {
entry.Data()->ShutDown(); entry.Data()->ShutDown();
mHighPriorityChildIDs.RemoveEntry(childID); mHighPriorityChildIDs.Remove(childID);
entry.Remove(); entry.Remove();
} }
} }
@ -459,10 +459,10 @@ void ProcessPriorityManagerImpl::NotifyProcessPriorityChanged(
if (newPriority >= PROCESS_PRIORITY_FOREGROUND_HIGH && if (newPriority >= PROCESS_PRIORITY_FOREGROUND_HIGH &&
aOldPriority < PROCESS_PRIORITY_FOREGROUND_HIGH) { aOldPriority < PROCESS_PRIORITY_FOREGROUND_HIGH) {
mHighPriorityChildIDs.PutEntry(aParticularManager->ChildID()); mHighPriorityChildIDs.Insert(aParticularManager->ChildID());
} else if (newPriority < PROCESS_PRIORITY_FOREGROUND_HIGH && } else if (newPriority < PROCESS_PRIORITY_FOREGROUND_HIGH &&
aOldPriority >= PROCESS_PRIORITY_FOREGROUND_HIGH) { aOldPriority >= PROCESS_PRIORITY_FOREGROUND_HIGH) {
mHighPriorityChildIDs.RemoveEntry(aParticularManager->ChildID()); mHighPriorityChildIDs.Remove(aParticularManager->ChildID());
} }
} }
@ -661,7 +661,7 @@ void ParticularProcessPriorityManager::OnBrowserParentDestroyed(
return; return;
} }
mActiveBrowserParents.RemoveEntry(browserHost->GetTabId()); mActiveBrowserParents.Remove(browserHost->GetTabId());
ResetPriority(); ResetPriority();
} }
@ -796,9 +796,9 @@ void ParticularProcessPriorityManager::TabActivityChanged(
MOZ_ASSERT(aBrowserParent); MOZ_ASSERT(aBrowserParent);
if (!aIsActive) { if (!aIsActive) {
mActiveBrowserParents.RemoveEntry(aBrowserParent->GetTabId()); mActiveBrowserParents.Remove(aBrowserParent->GetTabId());
} else { } else {
mActiveBrowserParents.PutEntry(aBrowserParent->GetTabId()); mActiveBrowserParents.Insert(aBrowserParent->GetTabId());
} }
ResetPriority(); ResetPriority();