Bug 1842509 - Remove media.webvtt.regions.enabled pref r=alwu,webidl,smaug,peterv
[gecko.git] / dom / quota / ScopedLogExtraInfo.cpp
blobe9ddf84a8d2f4d7a8eacb5d528612e98a715f092
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 #include "ScopedLogExtraInfo.h"
9 namespace mozilla::dom::quota {
11 #ifdef QM_SCOPED_LOG_EXTRA_INFO_ENABLED
12 MOZ_THREAD_LOCAL(const nsACString*) ScopedLogExtraInfo::sQueryValue;
13 MOZ_THREAD_LOCAL(const nsACString*) ScopedLogExtraInfo::sContextValue;
15 /* static */
16 auto ScopedLogExtraInfo::FindSlot(const char* aTag) {
17 // XXX For now, don't use a real map but just allow the known tag values.
19 if (aTag == kTagQuery) {
20 return &sQueryValue;
23 if (aTag == kTagContext) {
24 return &sContextValue;
27 MOZ_CRASH("Unknown tag!");
30 ScopedLogExtraInfo::~ScopedLogExtraInfo() {
31 if (mTag) {
32 MOZ_ASSERT(&mCurrentValue == FindSlot(mTag)->get(),
33 "Bad scoping of ScopedLogExtraInfo, must not be interleaved!");
35 FindSlot(mTag)->set(mPreviousValue);
39 ScopedLogExtraInfo::ScopedLogExtraInfo(ScopedLogExtraInfo&& aOther) noexcept
40 : mTag(aOther.mTag),
41 mPreviousValue(aOther.mPreviousValue),
42 mCurrentValue(std::move(aOther.mCurrentValue)) {
43 aOther.mTag = nullptr;
44 FindSlot(mTag)->set(&mCurrentValue);
47 /* static */ ScopedLogExtraInfo::ScopedLogExtraInfoMap
48 ScopedLogExtraInfo::GetExtraInfoMap() {
49 // This could be done in a cheaper way, but this is never called on a hot
50 // path, so we anticipate using a real map inside here to make use simpler for
51 // the caller(s).
53 ScopedLogExtraInfoMap map;
54 if (sQueryValue.get()) {
55 map.emplace(kTagQuery, sQueryValue.get());
58 if (sContextValue.get()) {
59 map.emplace(kTagContext, sContextValue.get());
62 return map;
65 /* static */ void ScopedLogExtraInfo::Initialize() {
66 MOZ_ALWAYS_TRUE(sQueryValue.init());
67 MOZ_ALWAYS_TRUE(sContextValue.init());
70 void ScopedLogExtraInfo::AddInfo() {
71 auto* slot = FindSlot(mTag);
72 MOZ_ASSERT(slot);
73 mPreviousValue = slot->get();
75 slot->set(&mCurrentValue);
77 #endif
79 } // namespace mozilla::dom::quota