Fix typo in 9b54bd30006c008b4a951331b273613d5bac3abf
[pm.git] / image / src / ShutdownTracker.cpp
blobe7bcb982d74169d41372b9fc69f6ed74a96d8ea4
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 "nsAutoPtr.h"
10 #include "nsIObserver.h"
11 #include "nsIObserverService.h"
13 namespace mozilla {
14 namespace image {
16 class ShutdownTrackerImpl;
18 ///////////////////////////////////////////////////////////////////////////////
19 // Static Data
20 ///////////////////////////////////////////////////////////////////////////////
22 // Whether we've observed shutdown starting yet.
23 static bool sShutdownHasStarted = false;
26 ///////////////////////////////////////////////////////////////////////////////
27 // Implementation
28 ///////////////////////////////////////////////////////////////////////////////
30 struct ShutdownObserver : public nsIObserver
32 NS_DECL_ISUPPORTS
34 NS_IMETHOD Observe(nsISupports*, const char* aTopic, const char16_t*) override
36 if (strcmp(aTopic, "xpcom-shutdown") != 0) {
37 return NS_OK;
40 nsCOMPtr<nsIObserverService> os = services::GetObserverService();
41 if (os) {
42 os->RemoveObserver(this, "xpcom-shutdown");
45 sShutdownHasStarted = true;
46 return NS_OK;
49 private:
50 virtual ~ShutdownObserver() { }
53 NS_IMPL_ISUPPORTS(ShutdownObserver, nsIObserver)
56 ///////////////////////////////////////////////////////////////////////////////
57 // Public API
58 ///////////////////////////////////////////////////////////////////////////////
60 /* static */ void
61 ShutdownTracker::Initialize()
63 nsCOMPtr<nsIObserverService> os = services::GetObserverService();
64 if (os) {
65 os->AddObserver(new ShutdownObserver, "xpcom-shutdown", false);
69 /* static */ bool
70 ShutdownTracker::ShutdownHasStarted()
72 return sShutdownHasStarted;
75 } // namespace image
76 } // namespace mozilla