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"
10 #include "nsIObserver.h"
11 #include "nsIObserverService.h"
16 class ShutdownTrackerImpl
;
18 ///////////////////////////////////////////////////////////////////////////////
20 ///////////////////////////////////////////////////////////////////////////////
22 // Whether we've observed shutdown starting yet.
23 static bool sShutdownHasStarted
= false;
26 ///////////////////////////////////////////////////////////////////////////////
28 ///////////////////////////////////////////////////////////////////////////////
30 struct ShutdownObserver
: public nsIObserver
34 NS_IMETHOD
Observe(nsISupports
*, const char* aTopic
, const char16_t
*) override
36 if (strcmp(aTopic
, "xpcom-shutdown") != 0) {
40 nsCOMPtr
<nsIObserverService
> os
= services::GetObserverService();
42 os
->RemoveObserver(this, "xpcom-shutdown");
45 sShutdownHasStarted
= true;
50 virtual ~ShutdownObserver() { }
53 NS_IMPL_ISUPPORTS(ShutdownObserver
, nsIObserver
)
56 ///////////////////////////////////////////////////////////////////////////////
58 ///////////////////////////////////////////////////////////////////////////////
61 ShutdownTracker::Initialize()
63 nsCOMPtr
<nsIObserverService
> os
= services::GetObserverService();
65 os
->AddObserver(new ShutdownObserver
, "xpcom-shutdown", false);
70 ShutdownTracker::ShutdownHasStarted()
72 return sShutdownHasStarted
;
76 } // namespace mozilla