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;
25 ///////////////////////////////////////////////////////////////////////////////
27 ///////////////////////////////////////////////////////////////////////////////
29 struct ShutdownObserver
: public nsIObserver
33 NS_IMETHOD
Observe(nsISupports
*, const char* aTopic
, const char16_t
*) override
35 if (strcmp(aTopic
, "xpcom-shutdown") != 0) {
39 nsCOMPtr
<nsIObserverService
> os
= services::GetObserverService();
41 os
->RemoveObserver(this, "xpcom-shutdown");
44 sShutdownHasStarted
= true;
49 virtual ~ShutdownObserver() { }
52 NS_IMPL_ISUPPORTS(ShutdownObserver
, nsIObserver
)
55 ///////////////////////////////////////////////////////////////////////////////
57 ///////////////////////////////////////////////////////////////////////////////
60 ShutdownTracker::Initialize()
62 nsCOMPtr
<nsIObserverService
> os
= services::GetObserverService();
64 os
->AddObserver(new ShutdownObserver
, "xpcom-shutdown", false);
69 ShutdownTracker::ShutdownHasStarted()
71 return sShutdownHasStarted
;
75 } // namespace mozilla