# HG changeset patch # User Luca Greco # Date 1603810809 0 # Tue Oct 27 15:00:09 2020 +0000 # Node ID 8de8cd3371e801d408650f102df04252c846f33d # Parent 5058a78c1008f0917866aa09abff7430bcefa085 Bug 1669466 - Change WebRequestService singleton to a StaticRefPtr. r=glandium,mixedpuppy Differential Revision: https://phabricator.services.mozilla.com/D94692 diff -r 5058a78c1008 -r 8de8cd3371e8 toolkit/components/extensions/webrequest/WebRequestService.cpp --- a/toolkit/components/extensions/webrequest/WebRequestService.cpp Tue Oct 27 15:07:07 2020 +0000 +++ b/toolkit/components/extensions/webrequest/WebRequestService.cpp Tue Oct 27 15:00:09 2020 +0000 @@ -13,22 +13,14 @@ using namespace mozilla::dom; using namespace mozilla::extensions; -static WebRequestService* sWeakWebRequestService; - -WebRequestService::~WebRequestService() { sWeakWebRequestService = nullptr; } +static StaticRefPtr sWebRequestService; /* static */ WebRequestService& WebRequestService::GetSingleton() { - static RefPtr instance; - if (!sWeakWebRequestService) { - instance = new WebRequestService(); - ClearOnShutdown(&instance); - - // A separate weak instance that we keep a reference to as long as the - // original service is alive, even after our strong reference is cleared to - // allow the service to be destroyed. - sWeakWebRequestService = instance; + if (!sWebRequestService) { + sWebRequestService = new WebRequestService(); + ClearOnShutdown(&sWebRequestService); } - return *sWeakWebRequestService; + return *sWebRequestService; } UniquePtr WebRequestService::RegisterChannel( @@ -56,7 +48,7 @@ : mChannelId(aChannel->Id()), mChannel(aChannel) {} WebRequestChannelEntry::~WebRequestChannelEntry() { - if (sWeakWebRequestService) { - sWeakWebRequestService->mChannelEntries.Remove(mChannelId); + if (sWebRequestService) { + sWebRequestService->mChannelEntries.Remove(mChannelId); } } diff -r 5058a78c1008 -r 8de8cd3371e8 toolkit/components/extensions/webrequest/WebRequestService.h --- a/toolkit/components/extensions/webrequest/WebRequestService.h Tue Oct 27 15:07:07 2020 +0000 +++ b/toolkit/components/extensions/webrequest/WebRequestService.h Tue Oct 27 15:00:09 2020 +0000 @@ -64,7 +64,7 @@ dom::ContentParent* aContentParent); private: - ~WebRequestService(); + ~WebRequestService() = default; friend ChannelEntry;