Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/image/ShutdownTracker.cpp
Line
Count
Source (jump to first uncovered line)
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/. */
5
6
#include "ShutdownTracker.h"
7
8
#include "mozilla/Services.h"
9
#include "nsIObserver.h"
10
#include "nsIObserverService.h"
11
12
namespace mozilla {
13
namespace image {
14
15
class ShutdownTrackerImpl;
16
17
///////////////////////////////////////////////////////////////////////////////
18
// Static Data
19
///////////////////////////////////////////////////////////////////////////////
20
21
// Whether we've observed shutdown starting yet.
22
static bool sShutdownHasStarted = false;
23
24
25
///////////////////////////////////////////////////////////////////////////////
26
// Implementation
27
///////////////////////////////////////////////////////////////////////////////
28
29
struct ShutdownObserver : public nsIObserver
30
{
31
  NS_DECL_ISUPPORTS
32
33
  NS_IMETHOD Observe(nsISupports*, const char* aTopic, const char16_t*) override
34
0
  {
35
0
    if (strcmp(aTopic, "xpcom-will-shutdown") != 0) {
36
0
      return NS_OK;
37
0
    }
38
0
39
0
    nsCOMPtr<nsIObserverService> os = services::GetObserverService();
40
0
    if (os) {
41
0
      os->RemoveObserver(this, "xpcom-will-shutdown");
42
0
    }
43
0
44
0
    sShutdownHasStarted = true;
45
0
    return NS_OK;
46
0
  }
47
48
private:
49
0
  virtual ~ShutdownObserver() { }
50
};
51
52
NS_IMPL_ISUPPORTS(ShutdownObserver, nsIObserver)
53
54
55
///////////////////////////////////////////////////////////////////////////////
56
// Public API
57
///////////////////////////////////////////////////////////////////////////////
58
59
/* static */ void
60
ShutdownTracker::Initialize()
61
0
{
62
0
  nsCOMPtr<nsIObserverService> os = services::GetObserverService();
63
0
  if (os) {
64
0
    os->AddObserver(new ShutdownObserver, "xpcom-will-shutdown", false);
65
0
  }
66
0
}
67
68
/* static */ bool
69
ShutdownTracker::ShutdownHasStarted()
70
0
{
71
0
  return sShutdownHasStarted;
72
0
}
73
74
} // namespace image
75
} // namespace mozilla