xref: /aosp_15_r20/external/cronet/net/third_party/quiche/src/quiche/quic/core/quic_default_connection_helper.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2022 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 #ifndef QUICHE_QUIC_CORE_QUIC_DEFAULT_CONNECTION_HELPER_H_
6 #define QUICHE_QUIC_CORE_QUIC_DEFAULT_CONNECTION_HELPER_H_
7 
8 #include "quiche/quic/core/crypto/quic_random.h"
9 #include "quiche/quic/core/quic_connection.h"
10 #include "quiche/quic/core/quic_default_clock.h"
11 #include "quiche/common/simple_buffer_allocator.h"
12 
13 namespace quic {
14 
15 // A default implementation of QuicConnectionHelperInterface.  Thread-safe.
16 class QUICHE_EXPORT QuicDefaultConnectionHelper
17     : public QuicConnectionHelperInterface {
18  public:
Get()19   static QuicDefaultConnectionHelper* Get() {
20     static QuicDefaultConnectionHelper* helper =
21         new QuicDefaultConnectionHelper();
22     return helper;
23   }
24 
25   // Creates a helper that uses the default allocator.
QuicDefaultConnectionHelper()26   QuicDefaultConnectionHelper() : QuicDefaultConnectionHelper(nullptr) {}
27   // If |allocator| is nullptr, the default one is used.
QuicDefaultConnectionHelper(std::unique_ptr<quiche::QuicheBufferAllocator> allocator)28   QuicDefaultConnectionHelper(
29       std::unique_ptr<quiche::QuicheBufferAllocator> allocator)
30       : allocator_(std::move(allocator)) {}
31 
32   QuicDefaultConnectionHelper(const QuicDefaultConnectionHelper&) = delete;
33   QuicDefaultConnectionHelper& operator=(const QuicDefaultConnectionHelper&) =
34       delete;
35 
GetClock()36   const QuicClock* GetClock() const override { return QuicDefaultClock::Get(); }
GetRandomGenerator()37   QuicRandom* GetRandomGenerator() override {
38     return QuicRandom::GetInstance();
39   }
GetStreamSendBufferAllocator()40   quiche::QuicheBufferAllocator* GetStreamSendBufferAllocator() override {
41     return allocator_ ? allocator_.get() : quiche::SimpleBufferAllocator::Get();
42   }
43 
44  private:
45   std::unique_ptr<quiche::QuicheBufferAllocator> allocator_;
46 };
47 }  // namespace quic
48 
49 #endif  // QUICHE_QUIC_CORE_QUIC_DEFAULT_CONNECTION_HELPER_H_
50