Bug 1869043 assert that graph set access is main thread only r=padenot
[gecko.git] / image / ShutdownTracker.cpp
blob4eef66e52e66b9b935fb03ee96040967effecd26
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"
12 namespace mozilla {
13 namespace image {
15 class ShutdownTrackerImpl;
17 ///////////////////////////////////////////////////////////////////////////////
18 // Static Data
19 ///////////////////////////////////////////////////////////////////////////////
21 // Whether we've observed shutdown starting yet.
22 static bool sShutdownHasStarted = false;
24 ///////////////////////////////////////////////////////////////////////////////
25 // Implementation
26 ///////////////////////////////////////////////////////////////////////////////
28 struct ShutdownObserver : public nsIObserver {
29 NS_DECL_ISUPPORTS
31 NS_IMETHOD Observe(nsISupports*, const char* aTopic,
32 const char16_t*) override {
33 if (strcmp(aTopic, "xpcom-will-shutdown") != 0) {
34 return NS_OK;
37 nsCOMPtr<nsIObserverService> os = services::GetObserverService();
38 if (os) {
39 os->RemoveObserver(this, "xpcom-will-shutdown");
42 sShutdownHasStarted = true;
43 return NS_OK;
46 private:
47 virtual ~ShutdownObserver() {}
50 NS_IMPL_ISUPPORTS(ShutdownObserver, nsIObserver)
52 ///////////////////////////////////////////////////////////////////////////////
53 // Public API
54 ///////////////////////////////////////////////////////////////////////////////
56 /* static */
57 void ShutdownTracker::Initialize() {
58 nsCOMPtr<nsIObserverService> os = services::GetObserverService();
59 if (os) {
60 os->AddObserver(new ShutdownObserver, "xpcom-will-shutdown", false);
64 /* static */
65 bool ShutdownTracker::ShutdownHasStarted() { return sShutdownHasStarted; }
67 } // namespace image
68 } // namespace mozilla