Replace uses of std::function inside QUICHE.
Those are mostly replaced with quiche_callbacks.h types.
PiperOrigin-RevId: 537905671
diff --git a/quiche/http2/adapter/callback_visitor.h b/quiche/http2/adapter/callback_visitor.h
index 5132104..497bf95 100644
--- a/quiche/http2/adapter/callback_visitor.h
+++ b/quiche/http2/adapter/callback_visitor.h
@@ -11,6 +11,7 @@
#include "quiche/http2/adapter/nghttp2.h"
#include "quiche/http2/adapter/nghttp2_util.h"
#include "quiche/common/platform/api/quiche_export.h"
+#include "quiche/common/quiche_callbacks.h"
namespace http2 {
namespace adapter {
@@ -20,7 +21,8 @@
class QUICHE_EXPORT CallbackVisitor : public Http2VisitorInterface {
public:
// Called when the visitor receives a close event for `stream_id`.
- using StreamCloseListener = std::function<void(Http2StreamId stream_id)>;
+ using StreamCloseListener =
+ quiche::MultiUseCallback<void(Http2StreamId stream_id)>;
explicit CallbackVisitor(Perspective perspective,
const nghttp2_session_callbacks& callbacks,
diff --git a/quiche/http2/adapter/event_forwarder.h b/quiche/http2/adapter/event_forwarder.h
index 74140f9..36446f6 100644
--- a/quiche/http2/adapter/event_forwarder.h
+++ b/quiche/http2/adapter/event_forwarder.h
@@ -4,6 +4,7 @@
#include <functional>
#include "quiche/common/platform/api/quiche_export.h"
+#include "quiche/common/quiche_callbacks.h"
#include "quiche/spdy/core/http2_frame_decoder_adapter.h"
namespace http2 {
@@ -16,7 +17,7 @@
class QUICHE_EXPORT EventForwarder : public spdy::SpdyFramerVisitorInterface {
public:
// Whether the forwarder can forward events to the receiver.
- using ForwardPredicate = std::function<bool()>;
+ using ForwardPredicate = quiche::MultiUseCallback<bool()>;
EventForwarder(ForwardPredicate can_forward,
spdy::SpdyFramerVisitorInterface& receiver);
diff --git a/quiche/http2/adapter/oghttp2_session.cc b/quiche/http2/adapter/oghttp2_session.cc
index fe6127a..e7cccdd 100644
--- a/quiche/http2/adapter/oghttp2_session.cc
+++ b/quiche/http2/adapter/oghttp2_session.cc
@@ -5,6 +5,7 @@
#include <utility>
#include <vector>
+#include "absl/cleanup/cleanup.h"
#include "absl/memory/memory.h"
#include "absl/strings/escaping.h"
#include "quiche/http2/adapter/header_validator.h"
@@ -13,6 +14,7 @@
#include "quiche/http2/adapter/http2_visitor_interface.h"
#include "quiche/http2/adapter/noop_header_validator.h"
#include "quiche/http2/adapter/oghttp2_util.h"
+#include "quiche/common/quiche_callbacks.h"
#include "quiche/spdy/core/spdy_protocol.h"
namespace http2 {
@@ -127,29 +129,6 @@
return "OGHTTP2_SERVER";
}
-class RunOnExit {
- public:
- RunOnExit() = default;
- explicit RunOnExit(std::function<void()> f) : f_(std::move(f)) {}
-
- RunOnExit(const RunOnExit& other) = delete;
- RunOnExit& operator=(const RunOnExit& other) = delete;
- RunOnExit(RunOnExit&& other) = delete;
- RunOnExit& operator=(RunOnExit&& other) = delete;
-
- ~RunOnExit() {
- if (f_) {
- f_();
- }
- f_ = {};
- }
-
- void emplace(std::function<void()> f) { f_ = std::move(f); }
-
- private:
- std::function<void()> f_;
-};
-
Http2ErrorCode GetHttp2ErrorCode(SpdyFramerError error) {
switch (error) {
case SpdyFramerError::SPDY_NO_ERROR:
@@ -473,7 +452,7 @@
return 0;
}
processing_bytes_ = true;
- RunOnExit r{[this]() { processing_bytes_ = false; }};
+ auto cleanup = absl::MakeCleanup([this]() { processing_bytes_ = false; });
if (options_.blackhole_data_on_connection_error && latched_error_) {
return static_cast<int64_t>(bytes.size());
@@ -592,7 +571,7 @@
return 0;
}
sending_ = true;
- RunOnExit r{[this]() { sending_ = false; }};
+ auto cleanup = absl::MakeCleanup([this]() { sending_ = false; });
if (fatal_send_error_) {
return kSendError;
@@ -1313,7 +1292,7 @@
if (!settings_ack_callbacks_.empty()) {
SettingsAckCallback callback = std::move(settings_ack_callbacks_.front());
settings_ack_callbacks_.pop_front();
- callback();
+ std::move(callback)();
}
visitor_.OnSettingsAck();
diff --git a/quiche/http2/adapter/oghttp2_session.h b/quiche/http2/adapter/oghttp2_session.h
index 9b31fa4..0954395 100644
--- a/quiche/http2/adapter/oghttp2_session.h
+++ b/quiche/http2/adapter/oghttp2_session.h
@@ -24,6 +24,7 @@
#include "quiche/common/platform/api/quiche_bug_tracker.h"
#include "quiche/common/platform/api/quiche_export.h"
#include "quiche/common/platform/api/quiche_flags.h"
+#include "quiche/common/quiche_callbacks.h"
#include "quiche/common/quiche_linked_hash_map.h"
#include "quiche/spdy/core/http2_frame_decoder_adapter.h"
#include "quiche/spdy/core/http2_header_block.h"
@@ -468,7 +469,7 @@
// Stores the queue of callbacks to invoke upon receiving SETTINGS acks. At
// most one callback is invoked for each SETTINGS ack.
- using SettingsAckCallback = std::function<void()>;
+ using SettingsAckCallback = quiche::SingleUseCallback<void()>;
std::list<SettingsAckCallback> settings_ack_callbacks_;
// Delivers header name-value pairs to the visitor.
diff --git a/quiche/http2/adapter/window_manager.h b/quiche/http2/adapter/window_manager.h
index 7005974..ffe1a7f 100644
--- a/quiche/http2/adapter/window_manager.h
+++ b/quiche/http2/adapter/window_manager.h
@@ -7,6 +7,7 @@
#include <functional>
#include "quiche/common/platform/api/quiche_export.h"
+#include "quiche/common/quiche_callbacks.h"
namespace http2 {
namespace adapter {
@@ -20,12 +21,12 @@
class QUICHE_EXPORT WindowManager {
public:
// A WindowUpdateListener is invoked when it is time to send a window update.
- using WindowUpdateListener = std::function<void(int64_t)>;
+ using WindowUpdateListener = quiche::MultiUseCallback<void(int64_t)>;
// Invoked to determine whether to call the listener based on the window
// limit, window size, and delta that would be sent.
- using ShouldWindowUpdateFn =
- std::function<bool(int64_t limit, int64_t size, int64_t delta)>;
+ using ShouldWindowUpdateFn = bool (*)(int64_t limit, int64_t size,
+ int64_t delta);
WindowManager(int64_t window_size_limit, WindowUpdateListener listener,
ShouldWindowUpdateFn should_window_update_fn = {},
diff --git a/quiche/http2/core/http2_trace_logging.cc b/quiche/http2/core/http2_trace_logging.cc
index ac0a827..7d6a883 100644
--- a/quiche/http2/core/http2_trace_logging.cc
+++ b/quiche/http2/core/http2_trace_logging.cc
@@ -7,6 +7,7 @@
#include "absl/strings/string_view.h"
#include "quiche/common/platform/api/quiche_bug_tracker.h"
#include "quiche/common/platform/api/quiche_logging.h"
+#include "quiche/common/quiche_callbacks.h"
#include "quiche/spdy/core/http2_header_block.h"
#include "quiche/spdy/core/spdy_protocol.h"
@@ -114,7 +115,7 @@
Http2TraceLogger::Http2TraceLogger(SpdyFramerVisitorInterface* parent,
absl::string_view perspective,
- std::function<bool()> is_enabled,
+ quiche::MultiUseCallback<bool()> is_enabled,
const void* connection_id)
: wrapped_(parent),
perspective_(perspective),
diff --git a/quiche/http2/core/http2_trace_logging.h b/quiche/http2/core/http2_trace_logging.h
index f7218fe..7106a72 100644
--- a/quiche/http2/core/http2_trace_logging.h
+++ b/quiche/http2/core/http2_trace_logging.h
@@ -10,6 +10,7 @@
#include "absl/strings/string_view.h"
#include "quiche/common/platform/api/quiche_export.h"
#include "quiche/common/platform/api/quiche_logging.h"
+#include "quiche/common/quiche_callbacks.h"
#include "quiche/spdy/core/http2_frame_decoder_adapter.h"
#include "quiche/spdy/core/recording_headers_handler.h"
#include "quiche/spdy/core/spdy_headers_handler_interface.h"
@@ -41,7 +42,8 @@
Http2TraceLogger(SpdyFramerVisitorInterface* parent,
absl::string_view perspective,
- std::function<bool()> is_enabled, const void* connection_id);
+ quiche::MultiUseCallback<bool()> is_enabled,
+ const void* connection_id);
~Http2TraceLogger() override;
Http2TraceLogger(const Http2TraceLogger&) = delete;
@@ -98,7 +100,7 @@
SpdyFramerVisitorInterface* wrapped_;
const absl::string_view perspective_;
- const std::function<bool()> is_enabled_;
+ const quiche::MultiUseCallback<bool()> is_enabled_;
const void* connection_id_;
};
@@ -108,7 +110,8 @@
// This class will preface all of its log messages with the value of
// |connection_id| in hexadecimal.
Http2FrameLogger(absl::string_view perspective,
- std::function<bool()> is_enabled, const void* connection_id)
+ quiche::MultiUseCallback<bool()> is_enabled,
+ const void* connection_id)
: perspective_(perspective),
is_enabled_(std::move(is_enabled)),
connection_id_(connection_id) {}
@@ -135,7 +138,7 @@
private:
const absl::string_view perspective_;
- const std::function<bool()> is_enabled_;
+ const quiche::MultiUseCallback<bool()> is_enabled_;
const void* connection_id_;
};
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 375fee6..9f7a5f3 100644
--- a/quiche/http2/test_tools/payload_decoder_base_test_util.h
+++ b/quiche/http2/test_tools/payload_decoder_base_test_util.h
@@ -25,6 +25,7 @@
#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/quiche_callbacks.h"
namespace http2 {
namespace test {
@@ -119,7 +120,7 @@
// size of payload, else false to skip that size. Typically used for negative
// tests; for example, decoding a SETTINGS frame at all sizes except for
// multiples of 6.
- typedef std::function<bool(size_t size)> ApproveSize;
+ typedef quiche::MultiUseCallback<bool(size_t size)> ApproveSize;
AbstractPayloadDecoderTest() {}
@@ -303,13 +304,13 @@
// As above, but for frames without padding.
::testing::AssertionResult VerifyDetectsFrameSizeError(
uint8_t required_flags, absl::string_view unpadded_payload,
- const ApproveSize& approve_size) {
+ ApproveSize approve_size) {
Http2FrameType frame_type = DecoderPeer::FrameType();
uint8_t known_flags = KnownFlagsMaskForFrameType(frame_type);
HTTP2_VERIFY_EQ(0, known_flags & Http2FrameFlag::PADDED);
HTTP2_VERIFY_EQ(0, required_flags & Http2FrameFlag::PADDED);
return VerifyDetectsMultipleFrameSizeErrors(
- required_flags, unpadded_payload, approve_size, 0);
+ required_flags, unpadded_payload, std::move(approve_size), 0);
}
Listener listener_;
diff --git a/quiche/http2/test_tools/random_decoder_test_base_test.cc b/quiche/http2/test_tools/random_decoder_test_base_test.cc
index 29f665c..f5fe67e 100644
--- a/quiche/http2/test_tools/random_decoder_test_base_test.cc
+++ b/quiche/http2/test_tools/random_decoder_test_base_test.cc
@@ -11,6 +11,7 @@
#include "quiche/http2/test_tools/http2_random.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 {
@@ -27,7 +28,7 @@
}
protected:
- typedef std::function<DecodeStatus(DecodeBuffer* db)> DecodingFn;
+ typedef quiche::MultiUseCallback<DecodeStatus(DecodeBuffer* db)> DecodingFn;
DecodeStatus StartDecoding(DecodeBuffer* db) override {
++start_decoding_calls_;
diff --git a/quiche/spdy/core/hpack/hpack_encoder.h b/quiche/spdy/core/hpack/hpack_encoder.h
index 50e4711..a36b734 100644
--- a/quiche/spdy/core/hpack/hpack_encoder.h
+++ b/quiche/spdy/core/hpack/hpack_encoder.h
@@ -16,6 +16,7 @@
#include "absl/strings/string_view.h"
#include "quiche/common/platform/api/quiche_export.h"
+#include "quiche/common/quiche_callbacks.h"
#include "quiche/spdy/core/hpack/hpack_header_table.h"
#include "quiche/spdy/core/hpack/hpack_output_stream.h"
#include "quiche/spdy/core/http2_header_block.h"
@@ -38,12 +39,12 @@
// Callers may provide a HeaderListener to be informed of header name-value
// pairs processed by this encoder.
using HeaderListener =
- std::function<void(absl::string_view, absl::string_view)>;
+ quiche::MultiUseCallback<void(absl::string_view, absl::string_view)>;
// An indexing policy should return true if the provided header name-value
// pair should be inserted into the HPACK dynamic table.
using IndexingPolicy =
- std::function<bool(absl::string_view, absl::string_view)>;
+ quiche::MultiUseCallback<bool(absl::string_view, absl::string_view)>;
HpackEncoder();
HpackEncoder(const HpackEncoder&) = delete;
@@ -87,11 +88,15 @@
// This HpackEncoder will use |policy| to determine whether to insert header
// name-value pairs into the dynamic table.
- void SetIndexingPolicy(IndexingPolicy policy) { should_index_ = policy; }
+ void SetIndexingPolicy(IndexingPolicy policy) {
+ should_index_ = std::move(policy);
+ }
// |listener| will be invoked for each header name-value pair processed by
// this encoder.
- void SetHeaderListener(HeaderListener listener) { listener_ = listener; }
+ void SetHeaderListener(HeaderListener listener) {
+ listener_ = std::move(listener);
+ }
void DisableCompression() { enable_compression_ = false; }
diff --git a/quiche/spdy/core/metadata_extension.h b/quiche/spdy/core/metadata_extension.h
index 9ac2b91..66c79c8 100644
--- a/quiche/spdy/core/metadata_extension.h
+++ b/quiche/spdy/core/metadata_extension.h
@@ -7,6 +7,7 @@
#include "absl/container/flat_hash_map.h"
#include "quiche/common/platform/api/quiche_export.h"
+#include "quiche/common/quiche_callbacks.h"
#include "quiche/spdy/core/hpack/hpack_encoder.h"
#include "quiche/spdy/core/http2_frame_decoder_adapter.h"
#include "quiche/spdy/core/http2_header_block.h"
@@ -28,9 +29,9 @@
static_assert(!std::is_copy_constructible<MetadataPayload>::value,
"MetadataPayload should be a move-only type!");
- using OnMetadataSupport = std::function<void(bool)>;
+ using OnMetadataSupport = quiche::MultiUseCallback<void(bool)>;
using OnCompletePayload =
- std::function<void(spdy::SpdyStreamId, MetadataPayload)>;
+ quiche::MultiUseCallback<void(spdy::SpdyStreamId, MetadataPayload)>;
// The HTTP/2 SETTINGS ID that is used to indicate support for METADATA
// frames.