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 file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef DOM_QUOTA_SCOPEDLOGEXTRAINFO_H_
8 #define DOM_QUOTA_SCOPEDLOGEXTRAINFO_H_
10 #include "mozilla/dom/quota/Config.h"
13 #include "mozilla/Assertions.h"
14 #include "mozilla/Attributes.h"
15 #include "mozilla/ThreadLocal.h"
17 #include "nsXULAppAPI.h"
19 namespace mozilla::dom::quota
{
21 struct MOZ_STACK_CLASS ScopedLogExtraInfo
{
22 static constexpr const char kTagQuery
[] = "query";
23 static constexpr const char kTagContext
[] = "context";
25 #ifdef QM_SCOPED_LOG_EXTRA_INFO_ENABLED
27 static auto FindSlot(const char* aTag
);
31 ScopedLogExtraInfo(const char (&aTag
)[N
], const nsACString
& aExtraInfo
)
32 : mTag
{aTag
}, mCurrentValue
{aExtraInfo
} {
33 // Initialize is currently only called in the parent process, we could call
34 // it directly from nsLayoutStatics::Initialize in the content process to
35 // allow use of ScopedLogExtraInfo in that too. The check in GetExtraInfoMap
36 // must be removed then.
37 MOZ_ASSERT(XRE_IsParentProcess());
42 ~ScopedLogExtraInfo();
44 ScopedLogExtraInfo(ScopedLogExtraInfo
&& aOther
);
45 ScopedLogExtraInfo
& operator=(ScopedLogExtraInfo
&& aOther
) = delete;
47 ScopedLogExtraInfo(const ScopedLogExtraInfo
&) = delete;
48 ScopedLogExtraInfo
& operator=(const ScopedLogExtraInfo
&) = delete;
50 using ScopedLogExtraInfoMap
= std::map
<const char*, const nsACString
*>;
51 static ScopedLogExtraInfoMap
GetExtraInfoMap();
53 static void Initialize();
57 const nsACString
* mPreviousValue
;
58 nsCString mCurrentValue
;
60 static MOZ_THREAD_LOCAL(const nsACString
*) sQueryValue
;
61 static MOZ_THREAD_LOCAL(const nsACString
*) sContextValue
;
66 ScopedLogExtraInfo(const char (&aTag
)[N
], const nsACString
& aExtraInfo
) {}
68 // user-defined to silence unused variable warnings
69 ~ScopedLogExtraInfo() {}
73 } // namespace mozilla::dom::quota
75 #endif // DOM_QUOTA_SCOPEDLOGEXTRAINFO_H_