Remove std::function from third_party/http2 PiperOrigin-RevId: 574902533
diff --git a/quiche/http2/decoder/http2_structure_decoder_test.cc b/quiche/http2/decoder/http2_structure_decoder_test.cc index bbb4ba8..0b2d0c8 100644 --- a/quiche/http2/decoder/http2_structure_decoder_test.cc +++ b/quiche/http2/decoder/http2_structure_decoder_test.cc
@@ -22,6 +22,7 @@ #include <cstdint> #include <string> +#include <utility> #include "absl/strings/string_view.h" #include "quiche/http2/decoder/decode_buffer.h" @@ -109,7 +110,7 @@ // Before that, validate that decoding is done and that we've advanced // the cursor the expected amount. - validator = ValidateDoneAndOffset(S::EncodedSize(), validator); + validator = ValidateDoneAndOffset(S::EncodedSize(), std::move(validator)); // Decode several times, with several segmentations of the input buffer. fast_decode_count_ = 0;
diff --git a/quiche/http2/hpack/decoder/hpack_block_decoder_test.cc b/quiche/http2/hpack/decoder/hpack_block_decoder_test.cc index 064ae44..1fc7550 100644 --- a/quiche/http2/hpack/decoder/hpack_block_decoder_test.cc +++ b/quiche/http2/hpack/decoder/hpack_block_decoder_test.cc
@@ -177,12 +177,10 @@ expected.ExpectIndexedHeader(4); expected.ExpectNameIndexAndLiteralValue(HpackEntryType::kIndexedLiteralHeader, 1, false, "www.example.com"); - NoArgValidator do_check = [expected, this]() { - return collector_.VerifyEq(expected); - }; EXPECT_TRUE(DecodeHpackExampleAndValidateSeveralWays( - example, ValidateDoneAndEmpty(do_check))); - EXPECT_TRUE(do_check()); + example, + ValidateDoneAndEmpty([&] { return collector_.VerifyEq(expected); }))); + EXPECT_TRUE(collector_.VerifyEq(expected)); } // http://httpwg.org/specs/rfc7541.html#rfc.section.C.5.1 @@ -227,12 +225,10 @@ "Mon, 21 Oct 2013 20:13:21 GMT"); expected.ExpectNameIndexAndLiteralValue(HpackEntryType::kIndexedLiteralHeader, 46, false, "https://www.example.com"); - NoArgValidator do_check = [expected, this]() { - return collector_.VerifyEq(expected); - }; EXPECT_TRUE(DecodeHpackExampleAndValidateSeveralWays( - example, ValidateDoneAndEmpty(do_check))); - EXPECT_TRUE(do_check()); + example, + ValidateDoneAndEmpty([&] { return collector_.VerifyEq(expected); }))); + EXPECT_TRUE(collector_.VerifyEq(expected)); } // Generate a bunch of HPACK block entries to expect, use those expectations @@ -277,12 +273,10 @@ HpackBlockBuilder hbb; expected.AppendToHpackBlockBuilder(&hbb); - NoArgValidator do_check = [expected, this]() { - return collector_.VerifyEq(expected); - }; - EXPECT_TRUE( - DecodeAndValidateSeveralWays(hbb, ValidateDoneAndEmpty(do_check))); - EXPECT_TRUE(do_check()); + EXPECT_TRUE(DecodeAndValidateSeveralWays( + hbb, + ValidateDoneAndEmpty([&] { return collector_.VerifyEq(expected); }))); + EXPECT_TRUE(collector_.VerifyEq(expected)); } } // namespace
diff --git a/quiche/http2/hpack/varint/hpack_varint_decoder_test.cc b/quiche/http2/hpack/varint/hpack_varint_decoder_test.cc index 950b01a..d895183 100644 --- a/quiche/http2/hpack/varint/hpack_varint_decoder_test.cc +++ b/quiche/http2/hpack/varint/hpack_varint_decoder_test.cc
@@ -8,6 +8,8 @@ #include <stddef.h> +#include <utility> + #include "absl/base/macros.h" #include "absl/strings/escaping.h" #include "absl/strings/string_view.h" @@ -44,9 +46,10 @@ // First validate that decoding is done and that we've advanced the cursor // the expected amount. - validator = ValidateDoneAndOffset(/* offset = */ data.size(), validator); + validator = + ValidateDoneAndOffset(/* offset = */ data.size(), std::move(validator)); - EXPECT_TRUE(Decode(data, prefix_length, validator)); + EXPECT_TRUE(Decode(data, prefix_length, std::move(validator))); EXPECT_EQ(expected_value, decoder_.value()); } @@ -58,7 +61,7 @@ return AssertionSuccess(); }; - EXPECT_TRUE(Decode(data, prefix_length, validator)); + EXPECT_TRUE(Decode(data, prefix_length, std::move(validator))); } private:
diff --git a/quiche/http2/hpack/varint/hpack_varint_round_trip_test.cc b/quiche/http2/hpack/varint/hpack_varint_round_trip_test.cc index d307ea0..d045d99 100644 --- a/quiche/http2/hpack/varint/hpack_varint_round_trip_test.cc +++ b/quiche/http2/hpack/varint/hpack_varint_round_trip_test.cc
@@ -11,6 +11,7 @@ #include <iterator> #include <set> +#include <utility> #include <vector> #include "absl/strings/str_cat.h" @@ -68,7 +69,7 @@ // First validate that decoding is done and that we've advanced the cursor // the expected amount. - validator = ValidateDoneAndOffset(expected_offset, validator); + validator = ValidateDoneAndOffset(expected_offset, std::move(validator)); // StartDecoding, above, requires the DecodeBuffer be non-empty so that it // can call Start with the prefix byte.
diff --git a/quiche/http2/test_tools/payload_decoder_base_test_util.h b/quiche/http2/test_tools/payload_decoder_base_test_util.h index 9f7a5f3..937cea8 100644 --- a/quiche/http2/test_tools/payload_decoder_base_test_util.h +++ b/quiche/http2/test_tools/payload_decoder_base_test_util.h
@@ -212,14 +212,13 @@ absl::string_view payload, const Http2FrameHeader& header, WrappedValidator wrapped_validator) { set_frame_header(header); - // If wrapped_validator is not a RandomDecoderTest::Validator, make it so. - Validator validator = ToValidator(wrapped_validator); - // And wrap that validator in another which will check that we've reached + // Wrap that validator in another which will check that we've reached // the expected state of kDecodeError with OnFrameSizeError having been // called by the payload decoder. - validator = [header, validator, this]( - const DecodeBuffer& input, - DecodeStatus status) -> ::testing::AssertionResult { + Validator validator = + [header, validator = ToValidator(wrapped_validator), this]( + const DecodeBuffer& input, + DecodeStatus status) -> ::testing::AssertionResult { QUICHE_DVLOG(2) << "VerifyDetectsFrameSizeError validator; status=" << status << "; input.Remaining=" << input.Remaining(); HTTP2_VERIFY_EQ(DecodeStatus::kDecodeError, status); @@ -234,7 +233,7 @@ return validator(input, status); }; return PayloadDecoderBaseTest::DecodePayloadAndValidateSeveralWays( - payload, validator); + payload, std::move(validator)); } // Confirm that we get OnFrameSizeError when trying to decode unpadded_payload @@ -397,7 +396,7 @@ return ::testing::AssertionSuccess(); }; return PayloadDecoderBaseTest::DecodePayloadAndValidateSeveralWays( - payload, validator); + payload, std::move(validator)); } // Verifies that we get OnPaddingTooLong for a padded frame payload whose
diff --git a/quiche/http2/test_tools/random_decoder_test_base.h b/quiche/http2/test_tools/random_decoder_test_base.h index a01ea8d..bdd0273 100644 --- a/quiche/http2/test_tools/random_decoder_test_base.h +++ b/quiche/http2/test_tools/random_decoder_test_base.h
@@ -13,9 +13,8 @@ #include <stddef.h> #include <cstdint> -#include <functional> -#include <memory> #include <type_traits> +#include <utility> #include "absl/strings/string_view.h" #include "quiche/http2/decoder/decode_buffer.h" @@ -23,8 +22,8 @@ #include "quiche/http2/test_tools/http2_random.h" #include "quiche/http2/test_tools/verify_macros.h" #include "quiche/common/platform/api/quiche_export.h" -#include "quiche/common/platform/api/quiche_logging.h" #include "quiche/common/platform/api/quiche_test.h" +#include "quiche/common/quiche_callbacks.h" namespace http2 { namespace test { @@ -61,16 +60,15 @@ // decoder. Note that RandomDecoderTest allows that size to be zero, though // some decoders can't deal with that on the first byte, hence the |first| // parameter. - typedef std::function<size_t(bool first, size_t offset, size_t remaining)> - SelectSize; + using SelectSize = quiche::MultiUseCallback<size_t(bool first, size_t offset, + size_t remaining)>; // Validator returns an AssertionResult so test can do: // EXPECT_THAT(DecodeAndValidate(..., validator)); - typedef ::testing::AssertionResult AssertionResult; - typedef std::function<AssertionResult(const DecodeBuffer& input, - DecodeStatus status)> - Validator; - typedef std::function<AssertionResult()> NoArgValidator; + using AssertionResult = ::testing::AssertionResult; + using Validator = quiche::MultiUseCallback<AssertionResult( + const DecodeBuffer& input, DecodeStatus status)>; + using NoArgValidator = quiche::MultiUseCallback<AssertionResult()>; RandomDecoderTest(); @@ -149,18 +147,19 @@ }; } - static Validator ToValidator(const Validator& validator) { + static Validator ToValidator(Validator validator) { if (validator == nullptr) { return ToValidator(nullptr); } return validator; } - static Validator ToValidator(const NoArgValidator& validator) { + static Validator ToValidator(NoArgValidator validator) { if (validator == nullptr) { return ToValidator(nullptr); } - return [validator](const DecodeBuffer& /*input*/, DecodeStatus /*status*/) { + return [validator = std::move(validator)](const DecodeBuffer& /*input*/, + DecodeStatus /*status*/) { return validator(); }; } @@ -171,9 +170,10 @@ // TODO(jamessynge): Replace this overload with the next, as using this method // usually means that the wrapped function doesn't need to be passed the // DecodeBuffer nor the DecodeStatus. - static Validator ValidateDoneAndEmpty(const Validator& wrapped) { - return [wrapped](const DecodeBuffer& input, - DecodeStatus status) -> AssertionResult { + static Validator ValidateDoneAndEmpty(Validator wrapped) { + return [wrapped = std::move(wrapped)]( + const DecodeBuffer& input, + DecodeStatus status) -> AssertionResult { HTTP2_VERIFY_EQ(status, DecodeStatus::kDecodeDone); HTTP2_VERIFY_EQ(0u, input.Remaining()) << "\nOffset=" << input.Offset(); if (wrapped) { @@ -183,8 +183,9 @@ }; } static Validator ValidateDoneAndEmpty(NoArgValidator wrapped) { - return [wrapped](const DecodeBuffer& input, - DecodeStatus status) -> AssertionResult { + return [wrapped = std::move(wrapped)]( + const DecodeBuffer& input, + DecodeStatus status) -> AssertionResult { HTTP2_VERIFY_EQ(status, DecodeStatus::kDecodeDone); HTTP2_VERIFY_EQ(0u, input.Remaining()) << "\nOffset=" << input.Offset(); if (wrapped) { @@ -194,8 +195,7 @@ }; } static Validator ValidateDoneAndEmpty() { - NoArgValidator validator; - return ValidateDoneAndEmpty(validator); + return ValidateDoneAndEmpty(NoArgValidator()); } // Wraps a validator with another validator @@ -204,10 +204,10 @@ // TODO(jamessynge): Replace this overload with the next, as using this method // usually means that the wrapped function doesn't need to be passed the // DecodeBuffer nor the DecodeStatus. - static Validator ValidateDoneAndOffset(uint32_t offset, - const Validator& wrapped) { - return [wrapped, offset](const DecodeBuffer& input, - DecodeStatus status) -> AssertionResult { + static Validator ValidateDoneAndOffset(uint32_t offset, Validator wrapped) { + return [wrapped = std::move(wrapped), offset]( + const DecodeBuffer& input, + DecodeStatus status) -> AssertionResult { HTTP2_VERIFY_EQ(status, DecodeStatus::kDecodeDone); HTTP2_VERIFY_EQ(offset, input.Offset()) << "\nRemaining=" << input.Remaining(); @@ -219,8 +219,9 @@ } static Validator ValidateDoneAndOffset(uint32_t offset, NoArgValidator wrapped) { - return [wrapped, offset](const DecodeBuffer& input, - DecodeStatus status) -> AssertionResult { + return [wrapped = std::move(wrapped), offset]( + const DecodeBuffer& input, + DecodeStatus status) -> AssertionResult { HTTP2_VERIFY_EQ(status, DecodeStatus::kDecodeDone); HTTP2_VERIFY_EQ(offset, input.Offset()) << "\nRemaining=" << input.Remaining(); @@ -231,8 +232,7 @@ }; } static Validator ValidateDoneAndOffset(uint32_t offset) { - NoArgValidator validator; - return ValidateDoneAndOffset(offset, validator); + return ValidateDoneAndOffset(offset, NoArgValidator()); } // Expose |random_| as Http2Random so callers don't have to care about which