This patch makes PermissionManager::GetInstance do the instantiation work and GetXPCOMSingleton just uses it. We always acquire the creation mutex and return an already_AddRefed to avoid any possible race. We count on callers of GetInstance to (shortly) keep a local reference if they have more work to do. On async shutdown in the parent process, we first mark our singleton dead, then close all our resources async and finally null our instance holder only after the async shutdown has finished. Differential Revision: https://phabricator.services.mozilla.com/D233816