зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1146580 - Make FinalizationWitnessService listen for xpcom shutdown. r=bholley
This commit is contained in:
Родитель
28516e84c1
Коммит
ff74bcf961
|
@ -120,7 +120,7 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsBrowserStatusFilter)
|
|||
#if defined(MOZ_UPDATER) && !defined(MOZ_WIDGET_ANDROID)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsUpdateProcessor)
|
||||
#endif
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(FinalizationWitnessService)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(FinalizationWitnessService, Init)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(NativeOSFileInternalsService)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(NativeFileWatcherService, Init)
|
||||
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
|
||||
// Implementation of nsIFinalizationWitnessService
|
||||
|
||||
static bool gShuttingDown = false;
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
namespace {
|
||||
|
@ -99,8 +101,8 @@ ExtractFinalizationEvent(JSObject *objSelf)
|
|||
void Finalize(JSFreeOp *fop, JSObject *objSelf)
|
||||
{
|
||||
nsRefPtr<FinalizationEvent> event = ExtractFinalizationEvent(objSelf);
|
||||
if (event == nullptr) {
|
||||
// Forget() has been called
|
||||
if (event == nullptr || gShuttingDown) {
|
||||
// NB: event will be null if Forget() has been called
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -171,7 +173,7 @@ static const JSFunctionSpec sWitnessClassFunctions[] = {
|
|||
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS(FinalizationWitnessService, nsIFinalizationWitnessService)
|
||||
NS_IMPL_ISUPPORTS(FinalizationWitnessService, nsIFinalizationWitnessService, nsIObserver)
|
||||
|
||||
/**
|
||||
* Create a new Finalization Witness.
|
||||
|
@ -209,4 +211,30 @@ FinalizationWitnessService::Make(const char* aTopic,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
FinalizationWitnessService::Observe(nsISupports* aSubject,
|
||||
const char* aTopic,
|
||||
const char16_t* aValue)
|
||||
{
|
||||
MOZ_ASSERT(strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID) == 0);
|
||||
gShuttingDown = true;
|
||||
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
|
||||
if (obs) {
|
||||
obs->RemoveObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
FinalizationWitnessService::Init()
|
||||
{
|
||||
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
|
||||
if (!obs) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
return obs->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, false);
|
||||
}
|
||||
|
||||
} // namespace mozilla
|
||||
|
|
|
@ -6,17 +6,22 @@
|
|||
#define mozilla_finalizationwitnessservice_h__
|
||||
|
||||
#include "nsIFinalizationWitnessService.h"
|
||||
#include "nsIObserver.h"
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
/**
|
||||
* XPConnect initializer, for use in the main thread.
|
||||
*/
|
||||
class FinalizationWitnessService final : public nsIFinalizationWitnessService
|
||||
class FinalizationWitnessService final : public nsIFinalizationWitnessService,
|
||||
public nsIObserver
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIFINALIZATIONWITNESSSERVICE
|
||||
NS_DECL_NSIOBSERVER
|
||||
|
||||
nsresult Init();
|
||||
private:
|
||||
~FinalizationWitnessService() {}
|
||||
void operator=(const FinalizationWitnessService* other) = delete;
|
||||
|
|
Загрузка…
Ссылка в новой задаче