Backed out changeset 2450366cf7ca (bug 1891629) for causing win msix mochitest failures
[gecko.git] / dom / quota / ScopedLogExtraInfo.h
blob5dc881a3b12639a0d3cc8c5a128cc8d2e3414595
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/Tainting.h"
16 #include "mozilla/ThreadLocal.h"
17 #include "nsString.h"
18 #include "nsXULAppAPI.h"
20 namespace mozilla::dom::quota {
22 struct MOZ_STACK_CLASS ScopedLogExtraInfo {
23 static constexpr const char kTagQueryTainted[] = "query";
24 static constexpr const char kTagContextTainted[] = "context";
25 // Using the storage origin (instead of normal origin) on purpose to store
26 // the masked origin (uuid based) on the stack for origins partitioned for
27 // private browsing.
28 static constexpr const char kTagStorageOriginTainted[] = "storage-origin";
30 #ifdef QM_SCOPED_LOG_EXTRA_INFO_ENABLED
31 private:
32 static auto FindSlot(const char* aTag);
34 public:
35 template <size_t N>
36 ScopedLogExtraInfo(const char (&aTag)[N], const nsACString& aExtraInfo)
37 : mTag{aTag}, mPreviousValue(nullptr), mCurrentValue{aExtraInfo} {
38 AddInfo();
41 ~ScopedLogExtraInfo();
43 ScopedLogExtraInfo(ScopedLogExtraInfo&& aOther) noexcept;
44 ScopedLogExtraInfo& operator=(ScopedLogExtraInfo&& aOther) = delete;
46 ScopedLogExtraInfo(const ScopedLogExtraInfo&) = delete;
47 ScopedLogExtraInfo& operator=(const ScopedLogExtraInfo&) = delete;
49 using ScopedLogExtraInfoMap =
50 std::map<const char*, const Tainted<nsCString>*>;
51 static ScopedLogExtraInfoMap GetExtraInfoMap();
53 static void Initialize();
55 private:
56 const char* mTag;
57 const Tainted<nsCString>* mPreviousValue;
58 Tainted<nsCString> mCurrentValue;
60 static MOZ_THREAD_LOCAL(const Tainted<nsCString>*) sQueryValueTainted;
61 static MOZ_THREAD_LOCAL(const Tainted<nsCString>*) sContextValueTainted;
62 static MOZ_THREAD_LOCAL(const Tainted<nsCString>*) sStorageOriginValueTainted;
64 void AddInfo();
65 #else
66 template <size_t N>
67 ScopedLogExtraInfo(const char (&aTag)[N], const nsACString& aExtraInfo) {}
69 // user-defined to silence unused variable warnings
70 ~ScopedLogExtraInfo() {}
71 #endif
74 } // namespace mozilla::dom::quota
76 #endif // DOM_QUOTA_SCOPEDLOGEXTRAINFO_H_