no bug - Bumping Firefox l10n changesets r=release a=l10n-bump DONTBUILD CLOSED TREE
[gecko.git] / dom / quota / ScopedLogExtraInfo.h
blob54b8bccb3f9c4bf8817acb7e99864214141356b4
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"
12 #include <map>
13 #include "mozilla/Assertions.h"
14 #include "mozilla/Attributes.h"
15 #include "mozilla/ThreadLocal.h"
16 #include "nsString.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
26 private:
27 static auto FindSlot(const char* aTag);
29 public:
30 template <size_t N>
31 ScopedLogExtraInfo(const char (&aTag)[N], const nsACString& aExtraInfo)
32 : mTag{aTag}, mPreviousValue(nullptr), mCurrentValue{aExtraInfo} {
33 AddInfo();
36 ~ScopedLogExtraInfo();
38 ScopedLogExtraInfo(ScopedLogExtraInfo&& aOther) noexcept;
39 ScopedLogExtraInfo& operator=(ScopedLogExtraInfo&& aOther) = delete;
41 ScopedLogExtraInfo(const ScopedLogExtraInfo&) = delete;
42 ScopedLogExtraInfo& operator=(const ScopedLogExtraInfo&) = delete;
44 using ScopedLogExtraInfoMap = std::map<const char*, const nsACString*>;
45 static ScopedLogExtraInfoMap GetExtraInfoMap();
47 static void Initialize();
49 private:
50 const char* mTag;
51 const nsACString* mPreviousValue;
52 nsCString mCurrentValue;
54 static MOZ_THREAD_LOCAL(const nsACString*) sQueryValue;
55 static MOZ_THREAD_LOCAL(const nsACString*) sContextValue;
57 void AddInfo();
58 #else
59 template <size_t N>
60 ScopedLogExtraInfo(const char (&aTag)[N], const nsACString& aExtraInfo) {}
62 // user-defined to silence unused variable warnings
63 ~ScopedLogExtraInfo() {}
64 #endif
67 } // namespace mozilla::dom::quota
69 #endif // DOM_QUOTA_SCOPEDLOGEXTRAINFO_H_