1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "ShutdownTracker.h"
8 #include "mozilla/Services.h"
9 #include "nsIObserver.h"
10 #include "nsIObserverService.h"
15 class ShutdownTrackerImpl
;
17 ///////////////////////////////////////////////////////////////////////////////
19 ///////////////////////////////////////////////////////////////////////////////
21 // Whether we've observed shutdown starting yet.
22 static bool sShutdownHasStarted
= false;
24 ///////////////////////////////////////////////////////////////////////////////
26 ///////////////////////////////////////////////////////////////////////////////
28 struct ShutdownObserver
: public nsIObserver
{
31 NS_IMETHOD
Observe(nsISupports
*, const char* aTopic
,
32 const char16_t
*) override
{
33 if (strcmp(aTopic
, "xpcom-will-shutdown") != 0) {
37 nsCOMPtr
<nsIObserverService
> os
= services::GetObserverService();
39 os
->RemoveObserver(this, "xpcom-will-shutdown");
42 sShutdownHasStarted
= true;
47 virtual ~ShutdownObserver() {}
50 NS_IMPL_ISUPPORTS(ShutdownObserver
, nsIObserver
)
52 ///////////////////////////////////////////////////////////////////////////////
54 ///////////////////////////////////////////////////////////////////////////////
57 void ShutdownTracker::Initialize() {
58 nsCOMPtr
<nsIObserverService
> os
= services::GetObserverService();
60 os
->AddObserver(new ShutdownObserver
, "xpcom-will-shutdown", false);
65 bool ShutdownTracker::ShutdownHasStarted() { return sShutdownHasStarted
; }
68 } // namespace mozilla