xref: /aosp_15_r20/external/cronet/net/third_party/quiche/src/quiche/quic/core/quic_connection_context.cc (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2021 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "quiche/quic/core/quic_connection_context.h"
6 
7 #include "absl/base/attributes.h"
8 #include "quiche/common/quiche_text_utils.h"
9 
10 namespace quic {
11 namespace {
12 ABSL_CONST_INIT thread_local QuicConnectionContext* current_context = nullptr;
13 }  // namespace
14 
DebugString() const15 std::string QuicConnectionProcessPacketContext::DebugString() const {
16   if (decrypted_payload.empty()) {
17     return "Not processing packet";
18   }
19 
20   return absl::StrCat("current_frame_offset: ", current_frame_offset,
21                       ", payload size: ", decrypted_payload.size(),
22                       ", payload hexdump: ",
23                       quiche::QuicheTextUtils::HexDump(decrypted_payload));
24 }
25 
26 // static
Current()27 QuicConnectionContext* QuicConnectionContext::Current() {
28   return current_context;
29 }
30 
QuicConnectionContextSwitcher(QuicConnectionContext * new_context)31 QuicConnectionContextSwitcher::QuicConnectionContextSwitcher(
32     QuicConnectionContext* new_context)
33     : old_context_(QuicConnectionContext::Current()) {
34   current_context = new_context;
35   if (new_context && new_context->tracer) {
36     new_context->tracer->Activate();
37   }
38 }
39 
~QuicConnectionContextSwitcher()40 QuicConnectionContextSwitcher::~QuicConnectionContextSwitcher() {
41   QuicConnectionContext* current = QuicConnectionContext::Current();
42   if (current && current->tracer) {
43     current->tracer->Deactivate();
44   }
45   current_context = old_context_;
46 }
47 
48 }  // namespace quic
49