merge mozilla-aurora to b2g44 a=merge
[gecko.git] / image / ShutdownTracker.cpp
blobdd073d0119ce908695dcfdebd3df4d9178e65dbc
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;
25 ///////////////////////////////////////////////////////////////////////////////
26 // Implementation
27 ///////////////////////////////////////////////////////////////////////////////
29 struct ShutdownObserver : public nsIObserver
31 NS_DECL_ISUPPORTS
33 NS_IMETHOD Observe(nsISupports*, const char* aTopic, const char16_t*) override
35 if (strcmp(aTopic, "xpcom-shutdown") != 0) {
36 return NS_OK;
39 nsCOMPtr<nsIObserverService> os = services::GetObserverService();
40 if (os) {
41 os->RemoveObserver(this, "xpcom-shutdown");
44 sShutdownHasStarted = true;
45 return NS_OK;
48 private:
49 virtual ~ShutdownObserver() { }
52 NS_IMPL_ISUPPORTS(ShutdownObserver, nsIObserver)
55 ///////////////////////////////////////////////////////////////////////////////
56 // Public API
57 ///////////////////////////////////////////////////////////////////////////////
59 /* static */ void
60 ShutdownTracker::Initialize()
62 nsCOMPtr<nsIObserverService> os = services::GetObserverService();
63 if (os) {
64 os->AddObserver(new ShutdownObserver, "xpcom-shutdown", false);
68 /* static */ bool
69 ShutdownTracker::ShutdownHasStarted()
71 return sShutdownHasStarted;
74 } // namespace image
75 } // namespace mozilla