Bug 1793633 - Make the nsEffectiveTLDService use threadsafe refcounting, r=necko-reviewers,dragana

This type is used off-main-thread through the ThirdPartyUtil service
(hence the existing RwLock), however it is currently neither threadsafe
refcounted, nor refcounted off-main-thread. This change also allows it
to be directly used off-main-thread, rather than through the
`ThirdPartyUtil` service.

I also added thread-safety annotations to the fields to get better
static checking for the thread-safety of accesses.

Differential Revision: https://phabricator.services.mozilla.com/D158593
This commit is contained in:
Nika Layzell 2022-10-05 23:16:49 +00:00
parent 80e1bfa13c
commit 2746b3a507
2 changed files with 7 additions and 4 deletions

View File

@ -49,6 +49,7 @@ nsEffectiveTLDService::nsEffectiveTLDService()
}
nsresult nsEffectiveTLDService::Init() {
MOZ_ASSERT(NS_IsMainThread());
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
obs->AddObserver(this, "public-suffix-list-updated", false);

View File

@ -28,7 +28,7 @@ class nsEffectiveTLDService final : public nsIEffectiveTLDService,
public nsIObserver,
public nsIMemoryReporter {
public:
NS_DECL_ISUPPORTS
NS_DECL_THREADSAFE_ISUPPORTS
NS_DECL_NSIEFFECTIVETLDSERVICE
NS_DECL_NSIMEMORYREPORTER
NS_DECL_NSIOBSERVER
@ -47,16 +47,17 @@ class nsEffectiveTLDService final : public nsIEffectiveTLDService,
nsresult NormalizeHostname(nsCString& aHostname);
~nsEffectiveTLDService();
// Only set in `Init()` which is called during service construction.
nsCOMPtr<nsIIDNService> mIDNService;
// The DAFSA provides a compact encoding of the rather large eTLD list.
mozilla::Maybe<mozilla::Dafsa> mGraph;
mozilla::Maybe<mozilla::Dafsa> mGraph MOZ_GUARDED_BY(mGraphLock);
// Memory map used for a new updated dafsa
mozilla::loader::AutoMemMap mDafsaMap;
mozilla::loader::AutoMemMap mDafsaMap MOZ_GUARDED_BY(mGraphLock);
// Lock for mGraph and mDafsaMap
mozilla::RWLock mGraphLock MOZ_UNANNOTATED;
mozilla::RWLock mGraphLock;
// Note that the cache entries here can record entries that were cached
// successfully or unsuccessfully. mResult must be checked before using an
@ -86,6 +87,7 @@ class nsEffectiveTLDService final : public nsIEffectiveTLDService,
}
};
// NOTE: Only used on the main thread, so not guarded by mGraphLock.
TldCache mMruTable;
};