Line data Source code
1 : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 : /* This Source Code Form is subject to the terms of the Mozilla Public
4 : * License, v. 2.0. If a copy of the MPL was not distributed with this
5 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 :
7 : #include "CrashReporterClient.h"
8 : #include "CrashReporterMetadataShmem.h"
9 : #include "nsISupportsImpl.h"
10 :
11 : #ifdef MOZ_CRASHREPORTER
12 : namespace mozilla {
13 : namespace ipc {
14 :
15 3 : StaticMutex CrashReporterClient::sLock;
16 3 : StaticRefPtr<CrashReporterClient> CrashReporterClient::sClientSingleton;
17 :
18 2 : CrashReporterClient::CrashReporterClient(const Shmem& aShmem)
19 4 : : mMetadata(new CrashReporterMetadataShmem(aShmem))
20 : {
21 2 : MOZ_COUNT_CTOR(CrashReporterClient);
22 2 : }
23 :
24 0 : CrashReporterClient::~CrashReporterClient()
25 : {
26 0 : MOZ_COUNT_DTOR(CrashReporterClient);
27 0 : }
28 :
29 : void
30 0 : CrashReporterClient::AnnotateCrashReport(const nsCString& aKey, const nsCString& aData)
31 : {
32 0 : StaticMutexAutoLock lock(sLock);
33 0 : mMetadata->AnnotateCrashReport(aKey, aData);
34 0 : }
35 :
36 : void
37 0 : CrashReporterClient::AppendAppNotes(const nsCString& aData)
38 : {
39 0 : StaticMutexAutoLock lock(sLock);
40 0 : mMetadata->AppendAppNotes(aData);
41 0 : }
42 :
43 : /* static */ void
44 2 : CrashReporterClient::InitSingletonWithShmem(const Shmem& aShmem)
45 : {
46 4 : StaticMutexAutoLock lock(sLock);
47 :
48 2 : MOZ_ASSERT(!sClientSingleton);
49 2 : sClientSingleton = new CrashReporterClient(aShmem);
50 2 : }
51 :
52 : /* static */ void
53 0 : CrashReporterClient::DestroySingleton()
54 : {
55 0 : StaticMutexAutoLock lock(sLock);
56 0 : sClientSingleton = nullptr;
57 0 : }
58 :
59 : /* static */ RefPtr<CrashReporterClient>
60 0 : CrashReporterClient::GetSingleton()
61 : {
62 0 : StaticMutexAutoLock lock(sLock);
63 0 : return sClientSingleton;
64 : }
65 :
66 : } // namespace ipc
67 : } // namespace mozilla
68 : #endif // MOZ_CRASHREPORTER
|