Make BalsaBuffer constructors public. Constructors should be private when there is a public factory method for creating the object, to prevent accidental instantiation not by the factory method. However, this is not the case with BalsaBuffer. This class is instantiated using its constructors by BalsaHeaders and in tests, and there making the constructor public allows the removal of a forward declaration, two friend declaration together with their comment, and another comment stating "this is awkward". Also while working on BalsaBuffer constructors, replace absl::WrapUnique(new) with std::make_unique<>. PiperOrigin-RevId: 444855708
diff --git a/quiche/common/balsa/balsa_headers.h b/quiche/common/balsa/balsa_headers.h index fda2a10..3a00577 100644 --- a/quiche/common/balsa/balsa_headers.h +++ b/quiche/common/balsa/balsa_headers.h
@@ -34,8 +34,6 @@ namespace quiche { -class BalsaHeaders; - namespace test { class BalsaHeadersTestPeer; } // namespace test @@ -77,13 +75,6 @@ class QUICHE_EXPORT_PRIVATE BalsaBuffer { public: static constexpr size_t kDefaultBlocksize = 4096; - // We have two friends here. These exist as friends as we - // want to allow access to the constructors for the test - // class and the Balsa* classes. We put this into the - // header file as we want this class to be inlined into the - // BalsaHeaders implementation, yet be testable. - friend class BalsaBufferTestSpouse; - friend class BalsaHeaders; // The BufferBlock is a structure used internally by the // BalsaBuffer class to store the base buffer pointers to @@ -128,6 +119,12 @@ typedef std::vector<BufferBlock> Blocks; + BalsaBuffer() + : blocksize_(kDefaultBlocksize), can_write_to_contiguous_buffer_(true) {} + + explicit BalsaBuffer(size_t blocksize) + : blocksize_(blocksize), can_write_to_contiguous_buffer_(true) {} + BalsaBuffer(const BalsaBuffer&) = delete; BalsaBuffer& operator=(const BalsaBuffer&) = delete; BalsaBuffer(BalsaBuffer&&) = default; @@ -307,12 +304,6 @@ size_t bytes_used(size_t idx) const { return blocks_[idx].bytes_used(); } private: - BalsaBuffer() - : blocksize_(kDefaultBlocksize), can_write_to_contiguous_buffer_(true) {} - - explicit BalsaBuffer(size_t blocksize) - : blocksize_(blocksize), can_write_to_contiguous_buffer_(true) {} - BufferBlock AllocBlock() { return AllocCustomBlock(blocksize_); } BufferBlock AllocCustomBlock(size_t blocksize) {