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 https://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_UntrustedModulesBackupService_h
8 #define mozilla_UntrustedModulesBackupService_h
10 #include "mozilla/UntrustedModulesData.h"
11 #include "nsRefPtrHashtable.h"
15 struct ProcessHashKey
{
16 GeckoProcessType mType
;
18 ProcessHashKey(GeckoProcessType aType
, DWORD aPid
);
19 bool operator==(const ProcessHashKey
& aOther
) const;
20 PLDHashNumber
Hash() const;
23 // UntrustedModulesData should not be refcounted as it's exchanged via IPC.
24 // Instead, we define this container class owning UntrustedModulesData along
26 class MOZ_HEAP_CLASS UntrustedModulesDataContainer final
{
27 ~UntrustedModulesDataContainer() = default;
30 UntrustedModulesData mData
;
32 explicit UntrustedModulesDataContainer(UntrustedModulesData
&& aData
)
33 : mData(std::move(aData
)) {}
35 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(UntrustedModulesDataContainer
)
38 class UntrustedModulesBackupData
39 : public nsRefPtrHashtable
<nsGenericHashKey
<ProcessHashKey
>,
40 UntrustedModulesDataContainer
> {
42 void Add(UntrustedModulesData
&& aData
);
43 void AddWithoutStacks(UntrustedModulesData
&& aData
);
46 class MOZ_HEAP_CLASS UntrustedModulesBackupService final
{
48 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(UntrustedModulesBackupService
)
50 static UntrustedModulesBackupService
* Get();
52 // Back up data to mStaging
53 void Backup(UntrustedModulesData
&& aData
);
55 void SettleAllStagingData();
57 const UntrustedModulesBackupData
& Staging() const { return mStaging
; }
58 const UntrustedModulesBackupData
& Settled() const { return mSettled
; }
61 // Data not yet submitted as telemetry
62 UntrustedModulesBackupData mStaging
;
64 // Data already submitted as telemetry
65 // (This does not have stack information)
66 UntrustedModulesBackupData mSettled
;
68 ~UntrustedModulesBackupService() = default;
71 } // namespace mozilla
73 #endif // mozilla_UntrustedModulesBackupService_h